FastJson::Schema

Validates JSON instances against given JSON schema.

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add fast_json-schema

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install fast_json-schema

Usage

TODO: Write usage instructions here

Roadmap

This gem is under development at the moment and I am planning to support only the Draft 7 in the first version. That being said, some of the validation keywords of Draft 8 are implemented. Here is the list of keywords/annotations and the progress;

  • Annotations
    • $id
    • $ref
    • $recursiveAnchor ✗ (Draft 8)
    • $recursiveRef ✗ (Draft 8)
  • Keywords for Applying Subschemas Conditionally
    • if
    • then
    • else
  • Keywords for Applying Subschemas With Boolean Logic
    • allOf
    • anyOf
    • oneOf
    • not
  • Validation keywords for any instance type
    • type
    • enum
    • const
  • Validation Keywords for Numeric Instances (number and integer)
    • multipleOf
    • maximum
    • exclusiveMaximum
    • minimum
    • exclusiveMinimum
  • Validation Keywords for Strings
    • maxLength
    • minLength
    • pattern
  • Validation Keywords for Arrays
    • items
    • additionalItems
    • unevaluatedItems ✗ (Draft 8)
    • maxItems
    • minItems
    • uniqueItems
    • contains
    • maxContains ✓ (Draft 8)
    • minContains ✓ (Draft 8)
  • Validation Keywords for Objects
    • properties
    • patternProperties
    • additionalProperties
    • unevaluatedProperties ✗ (Draft 8)
    • propertyNames
    • maxProperties
    • minProperties
    • required
    • dependentRequired ✗ (Draft 8)
    • dependencies
  • Formats
    • Enabling/disabling the format as assertion ✗
    • Custom format attributes
    • Dates, Times, and Duration
      • date-time
      • date
      • time
      • duration ✗ (Draft 8)
    • Email Addresses
      • email
      • idn-email
    • Hostnames
      • hostname
      • idn-hostname
    • IP Addresses
      • IPv4
      • IPv6
    • Resource Identifiers
      • uri
      • uri-reference
      • iri
      • iri-reference
      • uuid ✗ (Draft 8)
    • uri-template
    • JSON Pointers
      • json-pointer
      • relative-json-pointer
    • regex ✓ > Compiled with Ruby's Regexp.new (Onigmo engine). This matches json_schemer / json-schema behavior but differs slightly from strict ECMA-262 — Onigmo accepts some constructs ECMA rejects (possessive quantifiers, atomic groups, \A / \z / \Z anchors) and vice versa. For strict ECMA-262 conformance, pre-process patterns with a translation library before validation.
  • Vocabulary for the Contents of String-Encoded Data
    • I'm not planning to support validating string instances with these annotations in the near future.

Conformance

This project is verified against the official JSON Schema Test Suite, vendored as a git submodule at vendor/JSON-Schema-Test-Suite.

After cloning the repository, initialize the submodule:

git submodule update --init --recursive

Then run the Draft-7 conformance suite (includes core + optional tests):

bundle exec rake conformance:draft7

For a concise pass/fail summary:

bundle exec rake conformance:draft7:stats

Known failing tests can be tracked in spec/conformance/draft7_pending.yml; tests listed there are reported as pending instead of failing the build. To see a category breakdown of pending entries:

bundle exec rake conformance:draft7:gaps

Current pass rate

Draft-7: 1398 / 1584 (88.3%) — 186 pending, 0 failing.

Remote-ref resolution (refRemote.json) is intentionally not implemented and contributes to the failing count.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake to compile the extension and run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/meinac/fast_json-schema. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the FastJson::Schema project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.