Class: OpenRouter::Schema::ItemsBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/open_router/schema.rb

Overview

Internal class for building array items

Instance Method Summary collapse

Constructor Details

#initializeItemsBuilder

Returns a new instance of ItemsBuilder.



297
298
299
# File 'lib/open_router/schema.rb', line 297

def initialize
  @items = {}
end

Instance Method Details

#boolean(description: nil, **options) ⇒ Object



319
320
321
322
323
# File 'lib/open_router/schema.rb', line 319

def boolean(description: nil, **options)
  @items = { type: "boolean" }
  @items[:description] = description if description
  @items.merge!(options)
end

#integer(description: nil, **options) ⇒ Object



307
308
309
310
311
# File 'lib/open_router/schema.rb', line 307

def integer(description: nil, **options)
  @items = { type: "integer" }
  @items[:description] = description if description
  @items.merge!(options)
end

#number(description: nil, **options) ⇒ Object



313
314
315
316
317
# File 'lib/open_router/schema.rb', line 313

def number(description: nil, **options)
  @items = { type: "number" }
  @items[:description] = description if description
  @items.merge!(options)
end

#object(&block) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/open_router/schema.rb', line 325

def object(&block)
  @items = { type: "object", properties: {}, required: [], additionalProperties: false }

  return unless block_given?

  object_builder = SchemaBuilder.new
  object_builder.instance_eval(&block)
  nested_schema = object_builder.to_h
  @items[:properties] = nested_schema[:properties]
  @items[:required] = nested_schema[:required]
  return unless nested_schema.key?(:additionalProperties)

  @items[:additionalProperties] =
    nested_schema[:additionalProperties]
end

#string(description: nil, **options) ⇒ Object



301
302
303
304
305
# File 'lib/open_router/schema.rb', line 301

def string(description: nil, **options)
  @items = { type: "string" }
  @items[:description] = description if description
  @items.merge!(options)
end

#to_hObject



341
342
343
# File 'lib/open_router/schema.rb', line 341

def to_h
  @items
end