Skip to content

Instantly share code, notes, and snippets.

@rolaveric
Created March 28, 2015 02:29
Show Gist options
  • Save rolaveric/01c77c5db2183fc26ffd to your computer and use it in GitHub Desktop.
Save rolaveric/01c77c5db2183fc26ffd to your computer and use it in GitHub Desktop.
Example of using "allOf" to make JSON Schema mixins
{
"definitions": {
"nameMixin": {
"type": "object",
"properties": {
"nameFirst": {"type": "string"},
"nameLast": {"type": "string"}
},
"required": ["nameFirst", "nameLast"]
},
"person": {
"allOf": [
{"$ref": "/definitions/nameMixin"},
{
"type": "object",
"properties": {
"age": {"type": "number"}
},
"required": ["age"]
}
]
}
}
}
@bzamecnik
Copy link

Nice. I tried the same idea. The only thing to overcome is how to combine this successfully with { "additionalProperties": false }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment