module JSONSchema
Extended Modules
Defined in:
define.crerror.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
-
.fluent : Fluent
Accessor for the Fluent API.
-
.from_json(node : JSON::Any) : Validator
Generates a
Validator
object from theJSON::Any
provided as input. -
.from_json?(node : JSON::Any) : Validator | Nil
Generates a
Validator
object from theJSON::Any
provided as input. -
.i18n : I18N
Provides a reference to the I18N instance global to the module
Macro Summary
-
create_validator(filename)
Generates code for a
Validator
object from the JSON schema infilename
. -
create_validator_method(filename)
Generates code for defining a method that returns a
Validator
object from the JSON schema infilename
. -
create_validator_method(filename, method_name)
Generates code for defining a method that returns a
Validator
object from the JSON schema infilename
, with a custom method name.
Class Method Detail
Accessor for the Fluent API. See the JSONSchema::Fluent
class for details on creating validators through
methods on the Fluent API.
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
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
Macro Detail
Generates code for a Validator
object from the JSON schema in filename
.
validator = JSONSchema.create_validator "my_schema.json"
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:...
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:...