Module: JSI::SchemaModule::MetaSchemaModule

Included in:
JSONSchemaDraft04, JSONSchemaDraft06, JSONSchemaDraft07
Defined in:
lib/jsi/schema_classes.rb

Overview

A module to extend the JSI::SchemaModule of a schema which describes other schemas (a JSI::Schema::MetaSchema)

Instance Method Summary collapse

Instance Method Details

#new_schema(schema_content, **kw) { ... } ⇒ JSI::Base subclass + JSI::Schema

Instantiates the given schema content as a JSI Schema.

see JSI::Schema::MetaSchema#new_schema

Parameters:

  • schema_content

    an object to be instantiated as a JSI Schema - typically a Hash

  • uri (#to_str, Addressable::URI)

    The retrieval URI of the schema document. If specified, the root schema will be identified by this URI, in addition to any absolute URI declared with an id keyword, for resolution in the schema_registry.

    It is rare that this needs to be specified. Most schemas, if they use absolute URIs, will use the $id keyword (id in draft 4) to specify this. A different retrieval URI is useful in unusual cases:

    • A schema in the document uses relative URIs for $id or $ref without an absolute id in an ancestor schema - these will be resolved relative to this URI
    • Another schema refers with $ref to the schema being instantiated by this retrieval URI, rather than an id declared in the schema - the schema is resolvable by this URI in the schema_registry.
  • register (Boolean)

    Whether the instantiated schema and any subschemas with absolute URIs will be registered in the schema registry indicated by param schema_registry.

  • schema_registry (SchemaRegistry, nil)

    The registry this schema will use.

    • The schema and subschemas will be registered here with any declared URI, unless the register param is false.
    • References from within the schema (typically from $ref keywords) are resolved using this registry.
  • stringify_symbol_keys (Boolean)

    Whether the schema content will have any Symbol keys of Hashes replaced with Strings (recursively through the document). Replacement is done on a copy; the given schema content is not modified.

  • to_immutable (#call, nil)

    A proc/callable which takes given instance content and results in an immutable (i.e. deeply frozen) object equal to that. If the instantiated JSI will be mutable, this is not used. Though not recommended, this may be nil with immutable JSIs if the instance content is otherwise guaranteed to be immutable, as well as any modified copies of the instance.

Yields:

  • If a block is given, it is evaluated in the context of the schema's JSI schema module using Module#module_exec.

Returns:

  • (JSI::Base subclass + JSI::Schema)

    a JSI which is a JSI::Schema whose content comes from the given schema_content and whose schemas are inplace applicators of this module's schema



81
82
83
# File 'lib/jsi/schema_classes.rb', line 81

def new_schema(schema_content, **kw, &block)
  schema.new_schema(schema_content, **kw, &block)
end

#new_schema_module(schema_content, **kw, &block) ⇒ JSI::SchemaModule

Instantiates the given schema content as a JSI Schema, passing all params to JSI::Schema::MetaSchema#new_schema, and returns its JSI Schema Module.

Returns:



86
87
88
# File 'lib/jsi/schema_classes.rb', line 86

def new_schema_module(schema_content, **kw, &block)
  schema.new_schema(schema_content, **kw, &block).jsi_schema_module
end

#schema_implementation_modulesSet<Module>

Returns:

  • (Set<Module>)


91
92
93
# File 'lib/jsi/schema_classes.rb', line 91

def schema_implementation_modules
  schema.schema_implementation_modules
end