Class: EasyTalk::Builders::ObjectBuilder
- Inherits:
-
BaseBuilder
- Object
- BaseBuilder
- EasyTalk::Builders::ObjectBuilder
- Extended by:
- T::Sig
- Defined in:
- lib/easy_talk/builders/object_builder.rb
Overview
ObjectBuilder is responsible for turning a SchemaDefinition of an "object" type into a validated JSON Schema hash. It:
1) Recursively processes the schema's :properties, 2) Determines which properties are required (unless optional), 3) Handles sub-schema composition (allOf, anyOf, oneOf, not), 4) Produces the final object-level schema hash.
Constant Summary collapse
- VALID_OPTIONS =
Required by BaseBuilder: recognized schema options for "object" types
{ properties: { type: T::Hash[T.any(Symbol, String), T.untyped], key: :properties }, additional_properties: { type: T.any(T::Boolean, Class, T::Hash[Symbol, T.untyped]), key: :additionalProperties }, pattern_properties: { type: T::Hash[String, T.untyped], key: :patternProperties }, min_properties: { type: Integer, key: :minProperties }, max_properties: { type: Integer, key: :maxProperties }, dependencies: { type: T::Hash[String, T.any(T::Array[String], T::Hash[String, T.untyped])], key: :dependencies }, dependent_required: { type: T::Hash[String, T::Array[String]], key: :dependentRequired }, subschemas: { type: T::Array[T.untyped], key: :subschemas }, required: { type: T::Array[T.any(Symbol, String)], key: :required }, defs: { type: T.untyped, key: :$defs }, allOf: { type: T.untyped, key: :allOf }, anyOf: { type: T.untyped, key: :anyOf }, oneOf: { type: T.untyped, key: :oneOf }, not: { type: T.untyped, key: :not } }.freeze
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(schema_definition) ⇒ ObjectBuilder
constructor
A new instance of ObjectBuilder.
Constructor Details
#initialize(schema_definition) ⇒ ObjectBuilder
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/easy_talk/builders/object_builder.rb', line 40 def initialize(schema_definition) # Keep a reference to the original schema definition @schema_definition = schema_definition # Deep duplicate the raw schema hash so we can mutate it safely @original_schema = deep_dup(schema_definition.schema) # We'll collect required property names in this Set @required_properties = Set.new # Collect models that are referenced via $ref for $defs generation @ref_models = Set.new # Usually the name is a string (class name). Fallback to :klass if nil. name_for_builder = schema_definition.name ? schema_definition.name.to_sym : :klass # Build the base structure: { type: 'object' } plus any top-level options super( name_for_builder, { type: 'object' }, # minimal "object" structure , # method below merges & cleans final top-level keys VALID_OPTIONS ) end |
Instance Method Details
#build ⇒ Object
66 67 68 69 70 |
# File 'lib/easy_talk/builders/object_builder.rb', line 66 def build result = super process_additional_properties(result) result end |