Skip to content

Instantly share code, notes, and snippets.

@fge
Created February 26, 2013 11:19
Show Gist options
  • Save fge/5037784 to your computer and use it in GitHub Desktop.
Save fge/5037784 to your computer and use it in GitHub Desktop.
Animals with additionalProperties: false
{
"$schema": "http://json-schema.org/draft-04/schema#",
"oneOf": [
{
"description": "a single animal",
"$ref": "#/definitions/animal"
},
{
"description": "a collection of animals",
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": { "$ref": "#/definitions/animal" }
}
],
"definitions": {
"common": {
"type": "object",
"required": [ "type", "name" ],
"properties": {
"name": { "type": "string" }
},
"additionalProperties": false
},
"cat": {
"patch": { "$ref": "#/definitions/common" },
"with": [
{
"op": "add",
"path": "/properties/type",
"value": { "enum": [ "cat" ] }
},
{
"op": "replace",
"path": "/required",
"value": [ "type", "name", "favoriteToy" ]
},
{
"op": "add",
"path": "/properties/favoriteToy",
"value": { "type": "string" }
}
]
},
"dog": {
"patch": { "$ref": "#/definitions/common" },
"with": [
{
"op": "add",
"path": "/properties/type",
"value": { "enum": [ "dog" ] }
},
{
"op": "replace",
"path": "/required",
"value": [ "type", "name", "breed", "leashColor" ]
},
{
"op": "add",
"path": "/properties/breed",
"value": { "type": "string" }
},
{
"op": "add",
"path": "/properties/leashColot",
"value": { "type": "string" }
}
]
},
"animal": {
"oneOf": [
{ "$ref": "#/definitions/cat" },
{ "$ref": "#/definitions/dog" }
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment