Created
November 12, 2018 14:26
-
-
Save reitzig/d1924f401af01d10b5d1267ff9f6801c to your computer and use it in GitHub Desktop.
JSON Schema MWE: $ref vs sibling keywords (Ruby)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'json-schema' | |
require 'json-schema' | |
schema = <<~SCHEMA | |
{ | |
"$schema": "http://json-schema.org/draft-04/schema#", | |
"title": "A test schema", | |
"type": "object", | |
"oneOf": [ | |
{ | |
"properties": { | |
"type": { | |
"$ref": "#/definitions/foo", | |
"enum": ["a"] | |
}, | |
"name": { | |
"type": "string" | |
} | |
}, | |
"required": ["type", "name"] | |
}, | |
{ | |
"properties": { | |
"type": { | |
"$ref": "#/definitions/foo", | |
"enum": ["b"] | |
}, | |
"id": { | |
"type": "integer" | |
} | |
}, | |
"required": ["type", "id"] | |
} | |
], | |
"definitions": { | |
"foo": { | |
"type": "string", | |
"enum": ["a", "b", "c"] | |
} | |
} | |
} | |
SCHEMA | |
puts JSON::Validator.fully_validate(schema, '{ "type": "a", "id": 77 }') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment