Description
It would be good if we could get support for certain properties to be forbidden.
I was working with someone last night and found a use case where forbidden properties would be useful.
He was unable to disable additionalProperties
however had 2 difference cases. in the same schema.
this was the end result
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"app_id"
],
"oneOf": [
{
"properties": {
"app_id":{
"type": "string",
"pattern": "^[0-9]{10}$"
},
"my_id": {
"type": "string",
"pattern": "^[0-9]{8}$"
}
}
},
{
"properties": {
"app_id":{
"type": "string",
"pattern": "^[0-9]{10}$"
},
"m_id": {
"type": "string",
"pattern": "^[0-9]{9}$"
}
}
}
]
}
however his test payload caused it to validate against both test payloads.
Payload 1
{
"app_id":"1234567890",
"my_id":"12345678",
}
Payload 2
{
"app_id":"1234567890",
"m_id":"123456789",
}
Idealy there we should have a an exclusions list. excludeProperties:["propertyName", "property2Name"]
so the inital schema could look like.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"app_id"
],
"oneOf": [
{
"properties": {
"app_id":{
"type": "string",
"pattern": "^[0-9]{10}$"
},
"my_id": {
"type": "string",
"pattern": "^[0-9]{8}$"
}
},
"excludeProperties":["m_id"]
},
{
"properties": {
"app_id":{
"type": "string",
"pattern": "^[0-9]{10}$"
},
"m_id": {
"type": "string",
"pattern": "^[0-9]{9}$"
}
},
"excludeProperties":["my_id"]
}
]
}
This would then allow for easier versions of Schema so if your building an API Endpoint that you then wish to upgrade as your new schema could be in the "oneOf" allowing addditionalProperties
and still identify easily which one of the oneOf
's it is.
This could be added to the schema simply
"excludedProperties": { "$ref": "#/definitions/stringArray" },
Example Specification definition
<section title="excludedProperties">
<t>The "excludedProperties" keyword functions as both an annotation (Section 3.3) and as an assertion (Section 3.2). While no special effort is required to implement it as an annotation conveying semantic meaning, implementing validation is non-trivial.</t>
<t>Validation with "excludedProperties" applies only to the child values of instance names that do not match any names in "properties", and do not match any regular expression in "patternProperties".</t>
<t>This keyword determines how child instances validate properties and do not directly validate the immediate instance itself.</t>
<t>For all such properties, validation fails if the child instance contains a property by name supplied against the "excludedProperties".</t>
<t>Omitting this keyword has the same behaviour as an empty schema.</t>
</section>