Class: SchemaTest::Collection

Inherits:
Property::Object show all
Defined in:
lib/schema_test/collection.rb

Constant Summary

Constants inherited from Property::Object

Property::Object::SHORTHAND_ATTRIBUTES, Property::Object::TYPES

Constants inherited from Property

Property::NULL_TYPE

Instance Attribute Summary collapse

Attributes inherited from Property::Object

#excluded_property_names, #version

Attributes inherited from Property

#_type, #description, #name

Instance Method Summary collapse

Methods inherited from Property::Object

#==, #array, #base_json_schema_type, #based_on, #object, #properties, #resolve

Methods inherited from 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_name, location: nil, version: nil, description: nil) ⇒ Collection

Returns a new instance of Collection.



7
8
9
10
11
12
# File 'lib/schema_test/collection.rb', line 7

def initialize(name, of_name, location: nil, version: nil, description: nil)
  super(name, version: version, description: description)
  @item_type = lookup_object(of_name, version)
  @location = location
  SchemaTest::Definition.register(self)
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



5
6
7
# File 'lib/schema_test/collection.rb', line 5

def location
  @location
end

Instance Method Details

#as_json_schema(domain: SchemaTest.configuration.domain) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/schema_test/collection.rb', line 14

def as_json_schema(domain: SchemaTest.configuration.domain)
  id_part = version ? "v#{version}/#{name}" : name
  {
    '$schema' => SchemaTest::SCHEMA_VERSION,
    '$id' => "http://#{domain}/#{id_part}.json",
    'title' => name.to_s,
    'type' => 'array',
    'items' => @item_type.as_json_schema(false),
    'minItems' => 1
  }
end