Module: JSI
- Defined in:
- lib/jsi.rb,
lib/jsi/ptr.rb,
lib/jsi/base.rb,
lib/jsi/util.rb,
lib/jsi/schema.rb,
lib/jsi/version.rb,
lib/jsi/base/node.rb,
lib/jsi/jsi_coder.rb,
lib/jsi/metaschema.rb,
lib/jsi/schema/ref.rb,
lib/jsi/schema_set.rb,
lib/jsi/validation.rb,
lib/jsi/simple_wrap.rb,
lib/jsi/schema/issue.rb,
lib/jsi/util/private.rb,
lib/jsi/util/typelike.rb,
lib/jsi/schema/draft04.rb,
lib/jsi/schema/draft06.rb,
lib/jsi/schema/draft07.rb,
lib/jsi/schema_classes.rb,
lib/jsi/metaschema_node.rb,
lib/jsi/schema_registry.rb,
lib/jsi/validation/error.rb,
lib/jsi/schema/validation.rb,
lib/jsi/validation/result.rb,
lib/jsi/schema/application.rb,
lib/jsi/schema/validation/not.rb,
lib/jsi/schema/validation/ref.rb,
lib/jsi/util/private/memo_map.rb,
lib/jsi/schema/validation/enum.rb,
lib/jsi/schema/validation/type.rb,
lib/jsi/schema/validation/array.rb,
lib/jsi/schema/validation/const.rb,
lib/jsi/schema/validation/items.rb,
lib/jsi/schema/validation/object.rb,
lib/jsi/schema/validation/someof.rb,
lib/jsi/schema/validation/string.rb,
lib/jsi/util/private/attr_struct.rb,
lib/jsi/schema/validation/draft04.rb,
lib/jsi/schema/validation/draft06.rb,
lib/jsi/schema/validation/draft07.rb,
lib/jsi/schema/validation/numeric.rb,
lib/jsi/schema/validation/pattern.rb,
lib/jsi/schema/application/draft04.rb,
lib/jsi/schema/application/draft06.rb,
lib/jsi/schema/application/draft07.rb,
lib/jsi/schema/validation/contains.rb,
lib/jsi/schema/validation/required.rb,
lib/jsi/schema/schema_ancestor_node.rb,
lib/jsi/schema/validation/ifthenelse.rb,
lib/jsi/schema/validation/properties.rb,
lib/jsi/schema/validation/dependencies.rb,
lib/jsi/metaschema_node/bootstrap_schema.rb,
lib/jsi/schema/validation/draft04/minmax.rb,
lib/jsi/schema/validation/property_names.rb,
lib/schemas/json-schema.org/draft-04/schema.rb,
lib/schemas/json-schema.org/draft-06/schema.rb,
lib/schemas/json-schema.org/draft-07/schema.rb,
lib/jsi/schema/application/child_application.rb,
lib/jsi/schema/application/inplace_application.rb,
lib/jsi/schema/application/child_application/items.rb,
lib/jsi/schema/application/inplace_application/ref.rb,
lib/jsi/schema/application/child_application/draft04.rb,
lib/jsi/schema/application/child_application/draft06.rb,
lib/jsi/schema/application/child_application/draft07.rb,
lib/jsi/schema/application/child_application/contains.rb,
lib/jsi/schema/application/inplace_application/someof.rb,
lib/jsi/schema/application/inplace_application/draft04.rb,
lib/jsi/schema/application/inplace_application/draft06.rb,
lib/jsi/schema/application/inplace_application/draft07.rb,
lib/jsi/schema/application/child_application/properties.rb,
lib/jsi/schema/application/inplace_application/ifthenelse.rb,
lib/jsi/schema/application/inplace_application/dependencies.rb
Defined Under Namespace
Modules: JSONSchemaDraft04, JSONSchemaDraft06, JSONSchemaDraft07, JSONSchemaOrgDraft04, JSONSchemaOrgDraft06, JSONSchemaOrgDraft07, Metaschema, Schema, SchemaClasses, SimpleWrap, Util, Validation Classes: Base, Bug, JSICoder, MetaschemaNode, Ptr, SchemaModule, SchemaRegistry, SchemaSet
Constant Summary collapse
- DEFAULT_SCHEMA_REGISTRY =
SchemaRegistry.new.tap do |schema_registry| schema_registry.autoload_uri("http://json-schema.org/draft-04/schema") { JSI::JSONSchemaDraft04.schema } schema_registry.autoload_uri("http://json-schema.org/draft-06/schema") { JSI::JSONSchemaDraft06.schema } schema_registry.autoload_uri("http://json-schema.org/draft-07/schema") { JSI::JSONSchemaDraft07.schema } end.freeze
- VERSION =
"0.7.0".freeze
Class Method Summary collapse
-
.default_metaschema ⇒ nil, Base + Schema + Schema::DescribesSchema
An application-wide default metaschema set by JSI.default_metaschema=, used by JSI.new_schema to instantiate schemas which do not specify their metaschema using a
$schema
property. -
.default_metaschema=(default_metaschema) ⇒ Object
Sets JSI.default_metaschema to a schema indicated by the given param.
-
.new_metaschema(metaschema_document, schema_implementation_modules:) ⇒ JSI::MetaschemaNode + JSI::DescribesSchema + JSI::Schema
Instantiates the given document as a JSI Metaschema.
-
.new_metaschema_module(metaschema_document, **kw) ⇒ Module + JSI::SchemaModule::DescribesSchemaModule + JSI::SchemaModule
Instantiates the given document as a JSI Metaschema, passing all params to JSI.new_metaschema, and returns its JSI Schema Module.
-
.new_schema(schema_content, default_metaschema: nil, uri: nil, register: true, schema_registry: JSI.schema_registry, stringify_symbol_keys: true) { ... } ⇒ JSI::Base subclass + JSI::Schema
Instantiates the given schema content as a JSI Schema.
-
.new_schema_module(schema_content, **kw, &block) ⇒ Module + JSI::SchemaModule
Instantiates the given schema content as a JSI Schema, passing all params to JSI.new_schema, and returns its JSI Schema Module.
-
.schema_registry ⇒ JSI::SchemaRegistry
JSI.schema_registry
is the default SchemaRegistry in which schemas are registered and from which they resolve references. - .schema_registry=(schema_registry) ⇒ Object
Class Method Details
.default_metaschema ⇒ nil, Base + Schema + Schema::DescribesSchema
An application-wide default metaschema set by default_metaschema=, used by new_schema
to instantiate schemas which do not specify their metaschema using a $schema
property.
224 225 226 |
# File 'lib/jsi/schema.rb', line 224 def @default_metaschema end |
.default_metaschema=(default_metaschema) ⇒ Object
Sets default_metaschema to a schema indicated by the given param.
236 237 238 |
# File 'lib/jsi/schema.rb', line 236 def () @default_metaschema = .nil? ? nil : ensure_describes_schema() end |
.new_metaschema(metaschema_document, schema_implementation_modules:) ⇒ JSI::MetaschemaNode + JSI::DescribesSchema + JSI::Schema
Instantiates the given document as a JSI Metaschema.
67 68 69 70 71 72 73 |
# File 'lib/jsi.rb', line 67 def self.(, schema_implementation_modules: ) MetaschemaNode.new(, schema_implementation_modules: schema_implementation_modules, ) end |
.new_metaschema_module(metaschema_document, **kw) ⇒ Module + JSI::SchemaModule::DescribesSchemaModule + JSI::SchemaModule
Instantiates the given document as a JSI Metaschema, passing all params to new_metaschema, and returns its JSI Schema Module.
79 80 81 |
# File 'lib/jsi.rb', line 79 def self.(, **kw) (, **kw).jsi_schema_module end |
.new_schema(schema_content, default_metaschema: nil, uri: nil, register: true, schema_registry: JSI.schema_registry, stringify_symbol_keys: true) { ... } ⇒ JSI::Base subclass + JSI::Schema
Instantiates the given schema content as a JSI Schema.
The metaschema which describes the schema must be indicated:
- If the schema object has a
$schema
property, that URI is resolved using theschema_registry
param (by default schema_registry), and that metaschema is used. For example:
JSI.new_schema({
"$schema" => "http://json-schema.org/draft-07/schema#",
"properties" => ...,
})
- if no
$schema
property is present, thedefault_metaschema
param is used, if the caller specifies it. For example:
JSI.new_schema({"properties" => ...}, default_metaschema: JSI::JSONSchemaDraft07)
- if no
default_metaschema
param is specified, the application-wide default JSI.default_metaschema is used, if the application has set it. For example:
JSI.default_metaschema = JSI::JSONSchemaDraft07
JSI.new_schema({"properties" => ...})
an ArgumentError is raised if none of these indicate a metaschema to use.
Note that if you are instantiating a schema known to have no $schema
property, an alternative to
specifying a default_metaschema
is to call new_schema
on the
metaschema or its
schema module, e.g.
JSI::JSONSchemaDraft07.new_schema(my_schema_content)
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/jsi/schema.rb', line 290 def new_schema(schema_content, default_metaschema: nil, # params of DescribesSchema#new_schema have their default values repeated here. delegating in a splat # would remove repetition, but yard doesn't display delegated defaults with its (see X) directive. uri: nil, register: true, schema_registry: JSI.schema_registry, stringify_symbol_keys: true, &block ) new_schema_params = { uri: uri, register: register, schema_registry: schema_registry, stringify_symbol_keys: stringify_symbol_keys, } = -> { = if Schema.ensure_describes_schema(, name: "default_metaschema") elsif self. self. else raise(ArgumentError, [ "When instantiating a schema with no `$schema` property, you must specify its metaschema by one of these methods:", "- pass the `default_metaschema` param to this method", " e.g.: JSI.new_schema(..., default_metaschema: JSI::JSONSchemaDraft07)", "- invoke `new_schema` on the appropriate metaschema or its schema module", " e.g.: JSI::JSONSchemaDraft07.new_schema(...)", "- set JSI.default_metaschema to an application-wide default metaschema initially", " e.g.: JSI.default_metaschema = JSI::JSONSchemaDraft07", "instantiating schema_content: #{schema_content.pretty_inspect.chomp}", ].join("\n")) end .new_schema(schema_content, **new_schema_params, &block) } if schema_content.is_a?(Schema) raise(TypeError, [ "Given schema_content is already a JSI::Schema. It cannot be instantiated as the content of a schema.", "given: #{schema_content.pretty_inspect.chomp}", ].join("\n")) elsif schema_content.is_a?(JSI::Base) raise(TypeError, [ "Given schema_content is a JSI::Base. It cannot be instantiated as the content of a schema.", "given: #{schema_content.pretty_inspect.chomp}", ].join("\n")) elsif schema_content.respond_to?(:to_hash) id = schema_content['$schema'] || stringify_symbol_keys && schema_content[:'$schema'] if id unless id.respond_to?(:to_str) raise(ArgumentError, "given schema_content keyword `$schema` is not a string") end = Schema.ensure_describes_schema(id, name: '$schema', schema_registry: schema_registry) .new_schema(schema_content, **new_schema_params, &block) else .call end else .call end end |
.new_schema_module(schema_content, **kw, &block) ⇒ Module + JSI::SchemaModule
Instantiates the given schema content as a JSI Schema, passing all params to new_schema, and returns its JSI Schema Module.
58 59 60 |
# File 'lib/jsi.rb', line 58 def self.new_schema_module(schema_content, **kw, &block) new_schema(schema_content, **kw, &block).jsi_schema_module end |
.schema_registry ⇒ JSI::SchemaRegistry
JSI.schema_registry
is the default SchemaRegistry in which schemas are registered and from
which they resolve references.
87 88 89 |
# File 'lib/jsi.rb', line 87 def self.schema_registry @schema_registry end |
.schema_registry=(schema_registry) ⇒ Object
92 93 94 |
# File 'lib/jsi.rb', line 92 def self.schema_registry=(schema_registry) @schema_registry = schema_registry end |