rubyjsonschema

Ruby JSON schema draft-07 validation


I'd like to be able to do two things in some Ruby code:

  1. Validate my schemas against the JSON schema draft-07 metaschemas, and
  2. Validate my data against the schemas validated in (1).

A difficulty here is finding a Ruby library.

https://github.com/notEthan/jsi/ fails to read any schemas, even its own example on that page. I'd guess that it's because I'm using Ruby 3.1; it's fine with Ruby 2.7.5.

https://github.com/voxpupuli/json-schema is not fully maintained any more and only supports draft-04. Other than that it does what is required. I'm currently using this library, e.g.

test "schema validates against the standard" do
  metaschema = JSON::Validator.validator_for_name("draft4").metaschema
  assert_equal JSON::Validator.validate(metaschema, @schema), true
end

https://github.com/davishmcclurg/json_schemer doesn't include metaschema validation.

Is there anything I've missed?


Solution

  • At this time:

    Are you expecting a special syntax for metaschema validation (of a given schema)? It really is just a particular case of regular json-schema validation, where your schema is the document. So you should be able to work around that w/ a local version of the metaschema, regardless of the library.

    Note that JSI license is Affero GPL, which may be an encumbrance in a given environment.