Class: JsonSchemaView::JsonWorldExtensions::MapType

Inherits:
Object
  • Object
show all
Defined in:
lib/json_schema_view/json_world_extensions/map_type.rb

Overview

This class implements map type (string keys to values with the given type) in JSON Schema. You can specify the type of values but you cannot specify the type of keys, because JSON and JSON Schema only support String keys in objects.

Examples:

class Zoo
  include JsonWorld::DSL
  include JsonSchemaView::JsonWorldExtensions::MapType::DSL
  property(
    :dogMap,
    type: map_type(Dog),
  )
end

See Also:

Defined Under Namespace

Modules: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ MapType

Returns a new instance of MapType.



33
34
35
# File 'lib/json_schema_view/json_world_extensions/map_type.rb', line 33

def initialize(type)
  @type = type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



31
32
33
# File 'lib/json_schema_view/json_world_extensions/map_type.rb', line 31

def type
  @type
end

Instance Method Details

#as_json_schemaObject Also known as: as_json_schema_without_links



37
38
39
40
41
42
# File 'lib/json_schema_view/json_world_extensions/map_type.rb', line 37

def as_json_schema
  {
    type: "object",
    additionalProperties: JsonWorld::PropertyDefinition.new(type: type).as_json_schema
  }
end