Module: Ask::Schema::DSL::Utilities
- Included in:
- Ask::Schema::DSL
- Defined in:
- lib/ask/schema/dsl/utilities.rb
Overview
Utility methods for schema definitions, references, and property registration.
Instance Method Summary collapse
-
#define(name) ⇒ Object
Define a named sub-schema for reuse via #reference.
-
#reference(schema_name) ⇒ Hash{"$ref" => String}
Create a ‘$ref` reference to a named definition or root.
Instance Method Details
#define(name) ⇒ Object
Define a named sub-schema for reuse via #reference.
Named definitions appear in the output under ‘$defs`.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ask/schema/dsl/utilities.rb', line 20 def define(name, &) sub_schema = Class.new(Schema) sub_schema.class_eval(&) schema = { type: "object", properties: sub_schema.properties, required: sub_schema.required_properties, additionalProperties: sub_schema.additional_properties } merge_conditions(schema, sub_schema) definitions[name] = schema end |
#reference(schema_name) ⇒ Hash{"$ref" => String}
Create a ‘$ref` reference to a named definition or root.
Use with object or array via the :of option, or standalone to produce a reference hash.
47 48 49 50 51 52 53 |
# File 'lib/ask/schema/dsl/utilities.rb', line 47 def reference(schema_name) if schema_name == :root {"$ref" => "#"} else {"$ref" => "#/$defs/#{schema_name}"} end end |