I'm learning JSON Schema for one of the open-source projects. Have a question concerning combining an already defined schema with some additional keywords.
Assume I've defined some schema which is available via the reference, for example #/definitions/positiveInteger
.
Now I would like to refer to that type and extend it with few other keywords. For instance, I'd like to add enum
or description
.
Is it allowed to do this:
{
"$ref" : "#/definitions/positiveInteger",
"description" : "This is positive integer with enums",
"enum" : [ 2, 4, 6, 8 ]
}
Or do I have to do this:
{
"allOf" : [ { "$ref" : "#/definitions/positiveInteger" } ],
"description" : "This is positive integer with enums",
"enum" : [ 2, 4, 6, 8 ]
}
I could not find the formal reference for that and not sure how validation tools would react.
Basically I have two question here:
- Should the validation keyword like
enum
work in the first case? - Will be there any conflicts if I include a metadata keyword like
description
next to$ref
like in the first case?
I'd actually prefer to inline $ref
s and not to include them in allOf
and kinds but not sure if this is legal. I couldn't even find a description of $ref
in the spec (just a couple of examples).