Module: Schemurai
- Defined in:
- lib/schemurai.rb,
lib/schemurai/backend.rb,
lib/schemurai/dialect.rb,
lib/schemurai/formats.rb,
lib/schemurai/version.rb,
lib/schemurai/evaluator.rb,
lib/schemurai/evaluation.rb,
lib/schemurai/schema_node.rb,
lib/schemurai/vm/compiler.rb,
lib/schemurai/meta_schemas.rb,
lib/schemurai/schema_graph.rb,
lib/schemurai/vm/evaluator.rb,
lib/schemurai/error_message.rb,
lib/schemurai/schema_domain.rb,
lib/schemurai/dialects/draft7.rb,
lib/schemurai/dialect_keywords.rb,
lib/schemurai/meta_schemas/draft7.rb,
lib/schemurai/dialects/draft2019_09.rb,
lib/schemurai/dialects/draft2020_12.rb,
lib/schemurai/meta_schemas/draft2019_09.rb,
lib/schemurai/meta_schemas/draft2020_12.rb,
sig/schemurai.rbs
Overview
Public API for compiling and evaluating JSON Schemas.
Defined Under Namespace
Modules: _Evaluator Classes: Error, InvalidSchemaError, ResolutionError, Result, SchemaRegistry, UnsupportedFormatError, ValidationError, Validator
Constant Summary collapse
- VERSION =
The installed Schemurai version.
"2.2.1"
Class Method Summary collapse
-
.backend ⇒ backend
Returns the backend selected by SCHEMURAI_BACKEND, either
:rubyor:vm. -
.compile(schema, schemas: {}, base_uri: nil, content: false, format: false, validate_schema: false, backend: Backend.requested) ⇒ Validator
Compiles
schemaand returns a reusable Validator. -
.valid?(schema, instance, schemas: {}, base_uri: nil, content: false, format: false, validate_schema: false, backend: Backend.requested) ⇒ Boolean
Returns whether
instanceis valid againstschema. -
.valid_schema?(schema, schemas: {}, backend: Backend.requested) ⇒ Boolean
Returns whether
schemaconforms to its declared meta-schema. -
.validate(schema, instance, schemas: {}, base_uri: nil, content: false, format: false, validate_schema: false, backend: Backend.requested) ⇒ Result
Validates
instanceagainstschemaand returns a Result. -
.validate_schema(schema, schemas: {}, backend: Backend.requested) ⇒ Result
Validates
schemaagainst its declared meta-schema and returns a Result.
Class Method Details
.backend ⇒ backend
Returns the backend selected by SCHEMURAI_BACKEND, either :ruby or :vm.
197 198 199 |
# File 'lib/schemurai.rb', line 197 module_function def backend Backend.resolve end |
.compile(schema, schemas: {}, base_uri: nil, content: false, format: false, validate_schema: false, backend: Backend.requested) ⇒ Validator
Compiles schema and returns a reusable Validator.
schemas maps external URI strings to schemas. base_uri supplies the
schema's base URI. Optional content and format assertions are disabled by
default. backend accepts :ruby, :vm, or :default.
206 207 208 209 210 211 212 213 |
# File 'lib/schemurai.rb', line 206 module_function def compile(schema, schemas: {}, base_uri: nil, content: false, format: false, validate_schema: false, backend: Backend.requested) SchemaRegistry.new(schemas: schemas, validate_schema: validate_schema, backend: backend).compile( schema, base_uri: base_uri, content: content, format: format ) end |
.valid?(schema, instance, schemas: {}, base_uri: nil, content: false, format: false, validate_schema: false, backend: Backend.requested) ⇒ Boolean
Returns whether instance is valid against schema.
This convenience method compiles the schema for each call. Use .compile when validating multiple instances against the same schema.
246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/schemurai.rb', line 246 module_function def valid?(schema, instance, schemas: {}, base_uri: nil, content: false, format: false, validate_schema: false, backend: Backend.requested) compile( schema, schemas: schemas, base_uri: base_uri, content: content, format: format, validate_schema: validate_schema, backend: backend ).valid?(instance) end |
.valid_schema?(schema, schemas: {}, backend: Backend.requested) ⇒ Boolean
Returns whether schema conforms to its declared meta-schema.
222 223 224 |
# File 'lib/schemurai.rb', line 222 module_function def valid_schema?(schema, schemas: {}, backend: Backend.requested) validate_schema(schema, schemas: schemas, backend: backend).valid? end |
.validate(schema, instance, schemas: {}, base_uri: nil, content: false, format: false, validate_schema: false, backend: Backend.requested) ⇒ Result
Validates instance against schema and returns a Result.
This convenience method compiles the schema for each call. Use .compile when validating multiple instances against the same schema.
230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/schemurai.rb', line 230 module_function def validate(schema, instance, schemas: {}, base_uri: nil, content: false, format: false, validate_schema: false, backend: Backend.requested) compile( schema, schemas: schemas, base_uri: base_uri, content: content, format: format, validate_schema: validate_schema, backend: backend ).validate(instance) end |
.validate_schema(schema, schemas: {}, backend: Backend.requested) ⇒ Result
Validates schema against its declared meta-schema and returns a Result.
Schemas without $schema are validated as Draft 7.
217 218 219 |
# File 'lib/schemurai.rb', line 217 module_function def validate_schema(schema, schemas: {}, backend: Backend.requested) SchemaRegistry.new(schemas: schemas, backend: backend).validate_schema(schema) end |