voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.53k stars 242 forks source link

Validate a schema #287

Closed jocubeit closed 8 years ago

jocubeit commented 8 years ago

How can I just validate a schema against any of the built-in drafts in /resources? I don't want to validate any data, just that a schema is valid.

iainbeeston commented 8 years ago

Try something like:

draft_schema = JSON::Validator.validator_for_name("http://json-schema.org/draft-04/schema#")
JSON::Validator.validate!(draft_schema, your_schema)
jocubeit commented 8 years ago

Excellent, thanks, I'll try that.

mchapman17 commented 8 years ago

To get this to work I had to use the metaschema of the draft schema. So:

draft_schema = JSON::Validator.validator_for_name("http://json-schema.org/draft-04/schema#").metaschema
JSON::Validator.validate!(draft_schema, your_schema)