Skip to content

Commit 3ec4d62

Browse files
committed
Merge pull request #381 from coffeejunk/validate-schema-readme
Document how to validate a JSON Schema
2 parents 780a7e1 + 1ab3ffe commit 3ec4d62

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,33 @@ schema = {
375375
errors = JSON::Validator.fully_validate(schema, {"a" => "23"})
376376
```
377377

378+
Validating a JSON Schema
379+
------------------------
380+
381+
To validate that a JSON Schema conforms to the JSON Schema standard,
382+
you need to validate your schema against the metaschema for the appropriate
383+
JSON Schema Draft. All of the normal validation methods can be used
384+
for this. First retrieve the appropriate metaschema from the internal
385+
cache (using `JSON::Validator.validator_for_name()` or
386+
`JSON::Validator.validator_for_uri()`) and then simply validate your
387+
schema against it.
388+
389+
390+
```ruby
391+
require "json-schema"
392+
393+
schema = {
394+
"type" => "object",
395+
"properties" => {
396+
"a" => {"type" => "integer"}
397+
}
398+
}
399+
400+
metaschema = JSON::Validator.validator_for_name("draft4").metaschema
401+
# => true
402+
JSON::Validator.validate(metaschema, schema)
403+
```
404+
378405
Controlling Remote Schema Reading
379406
---------------------------------
380407

0 commit comments

Comments
 (0)