module JSONSchema

Extended Modules

Defined in:

define.cr
error.cr
fluent.cr
format.cr
i18n.cr
jsonschema.cr
node_context.cr
process.cr
render.cr
serialize.cr
validator.cr

Constant Summary

VERSION = "0.1.0"

Class Method Summary

Macro Summary

Class Method Detail

def self.fluent : Fluent #

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


[View source]
def self.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

[View source]
def self.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

[View source]
def self.i18n : I18N #

Provides a reference to the I18N instance global to the module


[View source]

Macro Detail

macro create_validator(filename) #

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

validator = JSONSchema.create_validator "my_schema.json"

[View source]
macro 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:...

[View source]
macro 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:...

[View source]