Skip to content

Instantly share code, notes, and snippets.

@vearutop
Last active January 1, 2024 10:53
Show Gist options
  • Save vearutop/376e2a148e6df044417264722f0d1319 to your computer and use it in GitHub Desktop.
Save vearutop/376e2a148e6df044417264722f0d1319 to your computer and use it in GitHub Desktop.
Sample schema and error responses for JSON Schema (proposal)
{
"type": ["object", "integer"],
"properties": {
"abcde": {
"type": "object",
"patternProperties": {
"^[a-zA-Z0-9_]+$": {
"oneOf": [
{"const": "a"},
{"const": "b"},
{"$ref": "#/cde"}
]}}},
"not1": false,
"not2": {"not":{}},
"not3": {"not": true}
},
"cde": {"$ref": "#/cdeDef"},
"cdeDef": {"anyOf": [
{"const": "c"},
{"const": "d"},
{"const": "e"}
]},
"anyOf": [
{"properties": {"foo": {"enum": ["a"]}, "bar": {"multipleOf": 3}}},
{"properties": {"foo": {"enum": ["b"]}, "bar": {"multipleOf": 5}}}
],
"oneOf": [
{"type": "object"},
{"minimum": 15},
{"maximum": 5}
],
"if": {"minimum": 15},
"then": {"multipleOf": 5},
"else": {"multipleOf": 3}
}
[
{
"data": 1,
"causeContext": [
{"keyword":"if", "schemaPath": "#/if", "dataPath": "#", "valid": false, "causeContext": [
{"keyword": "else", "schemaPath": "#/else", "dataPath": "#", "valid": false, "causeContext": [
{"keyword": "multipleOf", "schemaPath": "#/else/multipleOf", "dataPath": "#", "valid": false}
]}
]}
]
},
{
"data": "abc",
"causeContext": [
{"keyword":"type", "schemaPath": "#/type", "dataPath": "#", "valid": false},
{"keyword":"oneOf", "schemaPath": "#/oneOf", "dataPath": "#", "valid": false, "causeContext": [
{"schemaPath": "#/oneOf/0", "dataPath": "#", "valid": false, "causeContext": [
{"keyword":"type", "schemaPath": "#/oneOf/0/type", "dataPath": "#", "valid": false}
]},
{"schemaPath": "#/oneOf/1", "dataPath": "#", "valid": true},
{"schemaPath": "#/oneOf/2", "dataPath": "#", "valid": true}
]}
]
},
{
"data": 3,
"causeContext": []
},
{
"data":{"abcde": {"zoo":"f"}},
"causeContext": [
{"keyword":"oneOf", "schemaPath": "#/properties/abcde/patternProperties/%5E%5Ba-zA-Z0-9_%5D%2B%24/oneOf", "dataPath":"#/abcde/zoo", "valid": false, "causeContext":[
{"schemaPath": "#/properties/abcde/patternProperties/%5E%5Ba-zA-Z0-9_%5D%2B%24/oneOf/0", "dataPath": "#/abcde/zoo", "valid": false, "causeContext": [
{"keyword":"const", "schemaPath": "#/properties/abcde/patternProperties/%5E%5Ba-zA-Z0-9_%5D%2B%24/oneOf/0/const", "dataPath": "#/abcde/zoo", "valid": false}
]},
{"schemaPath": "#/properties/abcde/patternProperties/%5E%5Ba-zA-Z0-9_%5D%2B%24/oneOf/1", "dataPath": "#/abcde/zoo", "valid": false, "causeContext": [
{"keyword":"const", "schemaPath": "#/properties/abcde/patternProperties/%5E%5Ba-zA-Z0-9_%5D%2B%24/oneOf/1/const", "dataPath": "#/abcde/zoo", "valid": false}
]},
{"schemaPath": "#/properties/abcde/patternProperties/%5E%5Ba-zA-Z0-9_%5D%2B%24/oneOf/2", "dataPath": "#/abcde/zoo", "valid": false, "causeContext": [
{"keyword":"$ref", "schemaPath": "#/properties/abcde/patternProperties/%5E%5Ba-zA-Z0-9_%5D%2B%24/oneOf/2/$ref", "dataPath": "#/abcde/zoo", "valid": false, "causeContext": [
{"keyword":"$ref", "schemaPath": "#/cde/$ref", "dataPath": "#/abcde/zoo", "valid": false, "causeContext": [
{"keyword":"anyOf", "schemaPath": "#/cdeDef/anyOf", "dataPath": "#/abcde/zoo", "valid": false, "causeContext": [
{"schemaPath": "#/cdeDef/anyOf/0", "dataPath": "#/abcde/zoo", "valid": false, "causeContext": [
{"keyword":"const", "schemaPath": "#/cdeDef/anyOf/0/const", "dataPath": "#/abcde/zoo", "valid": false}
]},
{"schemaPath": "#/cdeDef/anyOf/1", "dataPath": "#/abcde/zoo", "valid": false, "causeContext": [
{"keyword":"const", "schemaPath": "#/cdeDef/anyOf/1/const", "dataPath": "#/abcde/zoo", "valid": false}
]},
{"schemaPath": "#/cdeDef/anyOf/2", "dataPath": "#/abcde/zoo", "valid": false, "causeContext": [
{"keyword":"const", "schemaPath": "#/cdeDef/anyOf/2/const", "dataPath": "#/abcde/zoo", "valid": false}
]}
]}
]}
]}
]}
]}
]
},
{
"data": {"foo": "a", "bar": 10},
"causeContext": [
{"keyword": "anyOf", "schemaPath": "#/anyOf", "dataPath": "#", "valid": false, "causeContext": [
{"schemaPath": "#/anyOf/0", "dataPath": "#", "valid": false, "causeContext": [
{"keyword": "multipleOf", "schemaPath": "#/anyOf/0/properties/bar/multipleOf", "dataPath": "#/bar", "valid": false}
]},
{"schemaPath": "#/anyOf/1", "dataPath": "#", "valid": false, "causeContext": [
{"keyword": "enum", "schemaPath": "#/anyOf/1/properties/foo/enum", "dataPath": "#/foo", "valid": false}
]}
]},
{"keyword":"oneOf", "schemaPath": "#/oneOf", "dataPath": "#", "valid": false, "causeContext": [
{"schemaPath": "#/oneOf/0", "dataPath": "#", "valid": true},
{"schemaPath": "#/oneOf/1", "dataPath": "#", "valid": true},
{"schemaPath": "#/oneOf/2", "dataPath": "#", "valid": true}
]}
]
},
{
"data": {"not1": 1},
"causeContext": [
{"schemaPath": "#/properties/not1", "dataPath": "#/not1", "valid": false},
{"keyword":"oneOf", "schemaPath": "#/oneOf", "dataPath": "#", "valid": false, "causeContext": [
{"schemaPath": "#/oneOf/0", "dataPath": "#", "valid": true},
{"schemaPath": "#/oneOf/1", "dataPath": "#", "valid": true},
{"schemaPath": "#/oneOf/2", "dataPath": "#", "valid": true}
]}
]
},
{
"data": {"not2": 1},
"causeContext": [
{"keyword": "not", "schemaPath": "#/properties/not2/not", "dataPath": "#/not2", "valid": false, "causeContext": [
{"schemaPath": "#/properties/not2/not", "dataPath": "#/not2", "valid": true}
]},
{"keyword":"oneOf", "schemaPath": "#/oneOf", "dataPath": "#", "valid": false, "causeContext": [
{"schemaPath": "#/oneOf/0", "dataPath": "#", "valid": true},
{"schemaPath": "#/oneOf/1", "dataPath": "#", "valid": true},
{"schemaPath": "#/oneOf/2", "dataPath": "#", "valid": true}
]}
]
},
{
"data": {"not3": 1},
"causeContext": [
{"keyword": "not", "schemaPath": "#/properties/not3/not", "dataPath": "#/not3", "valid": false, "causeContext": [
{"schemaPath": "#/properties/not3/not", "dataPath": "#/not3", "valid": true}
]},
{"keyword":"oneOf", "schemaPath": "#/oneOf", "dataPath": "#", "valid": false, "causeContext": [
{"schemaPath": "#/oneOf/0", "dataPath": "#", "valid": true},
{"schemaPath": "#/oneOf/1", "dataPath": "#", "valid": true},
{"schemaPath": "#/oneOf/2", "dataPath": "#", "valid": true}
]}
]
}
]
[
{
"data": 1,
"causeContext": [
{"keyword":"if", "schemaPath": "#/if", "dataPath": "#", "valid": false}
]
},
{
"data": "abc",
"causeContext": [
{"keyword":"type", "schemaPath": "#/type", "dataPath": "#", "valid": false},
{"keyword":"oneOf", "schemaPath": "#/oneOf", "dataPath": "#", "valid": false}
]
},
{
"data": 3,
"causeContext": []
},
{
"data":{"abcde": {"zoo":"f"}},
"causeContext": [
{"keyword":"oneOf", "schemaPath": "#/properties/abcde/patternProperties/%5E%5Ba-zA-Z0-9_%5D%2B%24/oneOf", "dataPath":"#/abcde/zoo", "valid": false}
]
},
{
"data": {"foo": "a", "bar": 10},
"causeContext": [
{"keyword": "anyOf", "schemaPath": "#/anyOf", "dataPath": "#", "valid": false},
{"keyword":"oneOf", "schemaPath": "#/oneOf", "dataPath": "#", "valid": false}
]
},
{
"data": {"not1": 1},
"causeContext": [
{"schemaPath": "#/properties/not1", "dataPath": "#/not1", "valid": false},
{"keyword":"oneOf", "schemaPath": "#/oneOf", "dataPath": "#", "valid": false}
]
},
{
"data": {"not2": 1},
"causeContext": [
{"keyword": "not", "schemaPath": "#/properties/not2/not", "dataPath": "#/not2", "valid": false},
{"keyword":"oneOf", "schemaPath": "#/oneOf", "dataPath": "#", "valid": false}
]
},
{
"data": {"not3": 1},
"causeContext": [
{"keyword": "not", "schemaPath": "#/properties/not3/not", "dataPath": "#/not3", "valid": false},
{"keyword":"oneOf", "schemaPath": "#/oneOf", "dataPath": "#", "valid": false}
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment