Class: JsonSchemaView::JsonWorldExtensions::AnyOf

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

Overview

This class implements ‘anyOf` schema composition. Instances of this class acts as an json world compatible object and prints the schema for anyOf combination.

Examples:

class Zoo
  include JsonWorld::DSL
  include JsonSchemaView::JsonWorldExtensions::MapType::DSL
  property(
    :animal,
    type: any_of.new(Dog, Cat),
  )
end

See Also:

Defined Under Namespace

Modules: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*types) ⇒ AnyOf

Returns a new instance of AnyOf.



30
31
32
# File 'lib/json_schema_view/json_world_extensions/any_of.rb', line 30

def initialize(*types)
  @types = types
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



28
29
30
# File 'lib/json_schema_view/json_world_extensions/any_of.rb', line 28

def types
  @types
end

Instance Method Details

#as_json_schemaObject Also known as: as_json_schema_without_links



34
35
36
# File 'lib/json_schema_view/json_world_extensions/any_of.rb', line 34

def as_json_schema
  { "anyOf" => types.map(&:as_json_schema) }
end