Skip to content

Instantly share code, notes, and snippets.

@reitzig
Created November 12, 2018 14:26
Show Gist options
  • Save reitzig/d1924f401af01d10b5d1267ff9f6801c to your computer and use it in GitHub Desktop.
Save reitzig/d1924f401af01d10b5d1267ff9f6801c to your computer and use it in GitHub Desktop.
JSON Schema MWE: $ref vs sibling keywords (Ruby)
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