-
Notifications
You must be signed in to change notification settings - Fork 151
Open
Description
If I have a JSON schema where the properties of an object are referenced by $ref and there are additional validations on such properties, then JSON's which do not fulfill the additional validations are considered valid. I want to do this to keep duplications of JSON objects to a minimum.
Visual Code does state that the JSON is invalid.
I'm using draft-07 for validation and version 2.3.0.
Here is an example of my schema. The workaround is copying everything from improvementNumber to improvementNumberNonNegative to remove the $ref and then validation will hold.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"improvements": {
"type": "object",
"properties": {
"improvementNumber": {
"$ref": "#/definitions/improvementNumber"
},
"improvementNumberNonNegative": {
"$ref": "#/definitions/improvementNumberNonNegative"
}
},
"additionalProperties": false
}
},
"additionalProperties": false,
"definitions": {
"renovationEffect": {
"type": "string",
"enum": [
"plus",
"new"
]
},
"improvementNumber": {
"type": "object",
"properties": {
"effectType": {
"$ref": "#/definitions/renovationEffect"
},
"value": {
"type": "number"
}
},
"additionalProperties": false,
"required": [
"effectType",
"value"
]
},
"improvementNumberNonNegative": {
"$ref": "#/definitions/improvementNumber",
"if": {
"properties": {
"effectType": {
"enum": [
"new"
]
}
}
},
"then": {
"properties": {
"value": {
"minimum": 0
}
}
}
}
}
}This JSON must be considered invalid:
{
"improvements": {
"improvementNumberNonNegative": {
"effectType": "new",
"value": -1
}
}
}Metadata
Metadata
Assignees
Labels
No labels