Module: JSI::Schema::DescribesSchema

Defined in:
lib/jsi/schema.rb

Overview

JSI::Schema::DescribesSchema: a schema which describes another schema. this module extends a JSI::Schema instance and indicates that JSIs which instantiate the schema are themselves also schemas.

examples of a schema which describes a schema include the draft JSON Schema metaschemas and the OpenAPI schema definition which describes "A deterministic version of a JSON Schema object."

Instance Method Summary collapse

Instance Method Details

#new_schema(schema_content, uri: nil) ⇒ JSI::Base

instantiates the given schema content as a JSI Schema.

the schema is instantiated after recursively converting any symbol hash keys in the structure to strings. note that this is in contrast to JSI::Schema#new_jsi, which does not alter its given instance.

the schema will be registered with the JSI.schema_registry.

Parameters:

  • schema_content (#to_hash, Boolean)

    an object to be instantiated as a schema

  • uri (nil, #to_str, Addressable::URI) (defaults to: nil)

    the URI of the schema document. relative URIs within the document are resolved using this uri as their base. the result schema will be registered with this URI in the JSI.schema_registry.

Returns:

  • (JSI::Base)

    a JSI which is a JSI::Schema whose instance is the given schema_content and whose schemas are this schema's inplace applicators.



152
153
154
155
156
157
158
159
160
# File 'lib/jsi/schema.rb', line 152

def new_schema(schema_content,
    uri: nil
)
  schema_jsi = new_jsi(Util.deep_stringify_symbol_keys(schema_content),
    uri: uri,
  )
  JSI.schema_registry.register(schema_jsi)
  schema_jsi
end

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

instantiates a given schema object as a JSI Schema and returns its JSI Schema Module.

shortcut to chain #new_schema + JSI::Schema#jsi_schema_module.

Parameters:

  • schema_content (#to_hash, Boolean)

    an object to be instantiated as a schema

  • uri (nil, #to_str, Addressable::URI)

    the URI of the schema document. relative URIs within the document are resolved using this uri as their base. the result schema will be registered with this URI in the JSI.schema_registry.

Returns:



168
169
170
# File 'lib/jsi/schema.rb', line 168

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