module

JSONSchema

Constants

VERSION = "0.1.0"

Class methods

fluent

Accessor for the Fluent API. See the JSONSchema::Fluent class for details on creating validators through methods on the Fluent API.

Source
from_json(node : JSON::Any) : Validator

Generates a Validator object from the JSON::Any provided as input. Raises if the schema is not created due to invalid schema. To generate the schema at compile time, see the JSONSchema#create_validator macro.

schema = JSON.parse(%<{"type": "string"}>)
validator = JSONSchema::Runtime.create_validator schema
Source
from_json?(node : JSON::Any) : Validator | Nil

Generates a Validator object from the JSON::Any provided as input. Returns nil if a validator cannot be created from the input JSON.

schema = JSON.parse(%<{"type": "string"}>)
validator = JSONSchema::Runtime.create_validator schema
Source
i18n

Provides a reference to the I18N instance global to the module

Source

Macros

create_validator(filename)

Generates code for a Validator object from the JSON schema in filename.

validator = JSONSchema.create_validator "my_schema.json"
Source
create_validator_method(filename)

Generates code for defining a method that returns a Validator object from the JSON schema in filename.

class Body
  JSONSchema.create_validator_method "my_schema.json"
end

b = Body.new
b.validator # => #<JSONSchema::ObjectValidator:...
Source
create_validator_method(filename, method_name)

Generates code for defining a method that returns a Validator object from the JSON schema in filename, with a custom method name.

class Request
  JSONSchema.create_validator_method "request_schema.json", "request_body_validator"
  JSONSchema.create_validator_method "response_schema.json", "response_body_validator"
end

r = Request.new

r.request_body_validator  # => #<JSONSchema::ObjectValidator:...
r.response_body_validator # => #<JSONSchema::ObjectValidator:...
Source

Nested types