JSON Schema validator. Supports drafts 4, 6, 7, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1.
JSON Schema validator. Supports drafts 4, 6, 7, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1.
JSON Schema validator. Supports drafts 4, 6, 7, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1.
Add this line to your application's Gemfile:
gem 'json_schemer'And then execute:
$ bundleOr install it yourself as:
$ gem install json_schemer……Configuration options can be set globally by modifying JSONSchemer.configuration. Global options are applied to any new schemas at creation time (global configuration changes are not reflected in existing schemas). They can be overridden with the regular keyword arguments described above.
# configuration block
JSONSchemer.configure do |config|
config.regexp_resolver = 'ecma'
end
# configuration accessors
JSONSchemer.configuration.insert_property_defaults = trueError messages can be customized using the x-error keyword and/or I18n translations. x-error takes precedence if both are defined.
x-error Keyword…When the I18n gem is loaded, custom error messages are looked up under the json_schemer key. It may be necessary to restart your application after adding the root key because the existence check is cached for performance reasons.
Translation keys are looked up in this order:
$LOCALE.json_schemer.errors.$ABSOLUTE_KEYWORD_LOCATION$LOCALE.json_schemer.errors.$SCHEMA_ID.$KEYWORD_LOCATION$LOCALE.json_schemer.errors.$KEYWORD_LOCATION$LOCALE.json_schemer.errors.$SCHEMA_ID.$KEYWORD$LOCALE.json_schemer.errors.$SCHEMA_ID.*$LOCALE.json_schemer.errors.$META_SCHEMA_ID.$KEYWORD$LOCALE.json_schemer.errors.$META_SCHEMA_ID.*$LOCALE.json_schemer.errors.$KEYWORD$LOCALE.json_schemer.errors.*Example translations file:
…And output:
…In the example above, custom error messsages are looked up using the following keys (in order until one is found):
en.json_schemer.errors.'https://example.com/schema#/properties/abc/required'en.json_schemer.errors.'https://example.com/schema'.'#/properties/abc/required'en.json_schemer.errors.'#/properties/abc/required'en.json_schemer.errors.'https://example.com/schema'.requireden.json_schemer.errors.'https://example.com/schema'.*en.json_schemer.errors.'http://json-schema.org/draft-07/schema#'.requireden.json_schemer.errors.'http://json-schema.org/draft-07/schema#'.*en.json_schemer.errors.requireden.json_schemer.errors.*…The json_schemer executable takes a JSON schema file as the first argument followed by one or more JSON data files to validate. If there are any validation errors, it outputs them and returns an error code.
Validation errors are output as single-line JSON objects. The --errors option can be used to limit the number of errors returned or prevent output entirely (and fail fast).
The schema or data can also be read from stdin using -.
% json_schemer --help
Usage:
json_schemer [options] ...
json_schemer [options] -
json_schemer [options] - ...
json_schemer -h | --help
json_schemer --version
Options:
-e, --errors MAX Maximum number of errors to output
Use "0" to validate with no output
-h, --help Show help
-v, --version Show versionAfter checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
Bug reports and pull requests are welcome on GitHub at https://github.com/davishmcclurg/json_schemer.
The gem is available as open source under the terms of the MIT License.
No open issues yet, or sync has not completed.