Class: Shale::Schema::JSONGenerator::Object Private
- 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
Instance Method Summary collapse
-
#as_type ⇒ Hash
private
Return JSON Schema fragment as Ruby Hash.
-
#initialize(name, properties, root) ⇒ Object
constructor
private
Initialize object.
Methods inherited from Base
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
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_type ⇒ Hash
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
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 |