Class: SchemaTest::Property::Array

Inherits:
SchemaTest::Property show all
Defined in:
lib/schema_test/property.rb

Constant Summary

Constants inherited from SchemaTest::Property

NULL_TYPE

Instance Attribute Summary collapse

Attributes inherited from SchemaTest::Property

#_type, #description, #name

Instance Method Summary collapse

Methods inherited from SchemaTest::Property

#base_json_schema_type, #json_schema_format, #json_schema_type, #lookup_object, #nullable, #nullable!, #nullable?, #optional, #optional!, #optional?, #type

Constructor Details

#initialize(name, of = nil, description = nil, &block) ⇒ Array

Returns a new instance of Array.



298
299
300
301
302
303
304
305
306
# File 'lib/schema_test/property.rb', line 298

def initialize(name, of=nil, description=nil, &block)
  super(name, :array, description)
  if block_given?
    @item_type = AnonymousObject.new(&block)
  else
    @item_type = of
  end
  # @items = { type: @item_type }
end

Instance Attribute Details

#item_typeObject (readonly)

Returns the value of attribute item_type.



296
297
298
# File 'lib/schema_test/property.rb', line 296

def item_type
  @item_type
end

Instance Method Details

#==(other) ⇒ Object



308
309
310
# File 'lib/schema_test/property.rb', line 308

def ==(other)
  super && @item_type == other.item_type
end

#as_json_schemaObject



312
313
314
315
316
317
# File 'lib/schema_test/property.rb', line 312

def as_json_schema
  super.tap do |json_schema|
    item_schema = @item_type.is_a?(SchemaTest::Property) ? @item_type.as_json_schema(false) : { 'type' => @item_type.to_s }
    json_schema[name.to_s]['items'] = item_schema
  end
end