Class: Shale::Schema::JSONGenerator::Collection Private

Inherits:
Object
  • Object
show all
Defined in:
lib/shale/schema/json_generator/collection.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class representing array type in JSON Schema

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, schema: nil) ⇒ Collection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize Collection object

Parameters:



21
22
23
24
# File 'lib/shale/schema/json_generator/collection.rb', line 21

def initialize(type, schema: nil)
  @type = type
  @schema = schema
end

Instance Attribute Details

#schemaObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return schema hash



13
14
15
# File 'lib/shale/schema/json_generator/collection.rb', line 13

def schema
  @schema
end

Instance Method Details

#as_jsonHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return JSON Schema fragment as Ruby Hash

Returns:

  • (Hash)


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shale/schema/json_generator/collection.rb', line 40

def as_json
  schema = @schema || {}

  { 'type' => 'array',
    'items' => @type.as_type,
    'minItems' => schema[:min_items],
    'maxItems' => schema[:max_items],
    'uniqueItems' => schema[:unique],
    'minContains' => schema[:min_contains],
    'maxContains' => schema[:max_contains],
    'description' => schema[:description] }.compact
end

#nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Delegate name to wrapped type object

Returns:



31
32
33
# File 'lib/shale/schema/json_generator/collection.rb', line 31

def name
  @type.name
end