Class: Shale::Schema::JSONGenerator::Object Private

Inherits:
Base
  • Object
show all
Defined in:
lib/shale/schema/json_generator/object.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 JSON Schema object type

Instance Attribute Summary

Attributes inherited from Base

#name, #nullable, #schema

Instance Method Summary collapse

Methods inherited from Base

#as_json

Constructor Details

#initialize(name, properties, root) ⇒ Object

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 object

] properties

Parameters:



22
23
24
25
26
# File 'lib/shale/schema/json_generator/object.rb', line 22

def initialize(name, properties, root)
  super(name)
  @root = root
  @properties = properties
end

Instance Method Details

#as_typeHash

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)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/shale/schema/json_generator/object.rb', line 33

def as_type
  required_props = @properties.filter_map { |prop| prop.name if prop&.schema&.[](:required) }

  {
    'type' => 'object',
    'properties' => @properties.to_h { |el| [el.name, el.as_json] },
    'required' => required_props.empty? ? nil : required_props,
    'minProperties' => @root[:min_properties],
    'maxProperties' => @root[:max_properties],
    'dependentRequired' => @root[:dependent_required],
    'description' => @root[:description],
    'additionalProperties' => @root[:additional_properties],
  }.compact
end