JSON Schema validator. Supports drafts 4, 6, 7, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1.
open sourceMITself-hostablefree
json_schemer validates Ruby data against JSON Schema drafts 4, 6, 7, 2019-09 and 2020-12, and against OpenAPI 3.0 and 3.1: the document itself, or data by a schema's name in components/schemas or by $ref. Errors point at the data and the schema with JSON pointers, in its classic format or the specification's flag, basic, detailed and verbose output formats, and messages can be overridden with an x-error keyword or translated with I18n. It can insert default property values, check formats, resolve external references, bundle schemas, check readOnly and writeOnly, and match patterns with Ruby or ECMAScript regex rules. A json_schemer command validates JSON files from the shell.
Problems it solves
- validate incoming JSON request bodies in my Ruby API against a schema
- check that config files match their JSON Schema in CI and fail with readable errors
- validate API payloads against the schemas in our OpenAPI 3.1 document from Ruby
- tell users exactly which field failed validation and why, with the path to it
- fill in default values from the schema when a property is missing
- write custom, translatable error messages for failed schema checks
- my schemas use draft 2020-12 but our Ruby validator only understands draft 4
- resolve $ref references to schemas in other files or at URLs
- catch structural mistakes in an OpenAPI spec file from a Ruby script
- bundle a schema and everything it references into one document
- treat readOnly and writeOnly properties differently for requests and responses
Features
- JSON Schema drafts 4, 6, 7, 2019-09 and 2020-12
- OpenAPI 3.0 and 3.1 documents, and data by schema name or $ref
- error output with data and schema JSON pointers
- classic, flag, basic, detailed and verbose output formats
- x-error custom messages and I18n translations
- insert default property values during validation
- format validation and custom formats
- custom content encodings and media types
- external $ref resolution (net/http or your own resolver)
- schema bundling
View 3 more
- Ruby or ECMAScript regex matching
- readOnly and writeOnly access modes
- json_schemer command-line validator
Capabilities
| Has an API | plan not known |
|---|---|
| Has a command line tool | plan not known |
