Intended interplay between "type" and "enum"
freeformz opened this issue · comments
What is the intended interplay between type
and enum
?
For instance I have to update a schema like the diff below because it was determined that the enum values are defined outside of engineering and those teams have almost no processes in place that could hook into how we are using this json schema.
...
"aProperty": {
- "type": "string",
- "enum": ["A", "B", "C", "D", "E", ""]
+ "type": "string"
},
...
We're using the Kafka Schema Registry and it is throwing the following error:
details: [{errorType:\"aProperty\", description:\"A type at path '#/properties/aProperoty' is different between the new schema and the old schema'}
Which led to confluentinc/schema-registry#2877
But discussing with one of the developers and reading the validation spec, I wasn't sure of the intended interplay between type and enum when used like above (type
specifies the type, but then enum
comes along and says it can be any type).
type
and enum
function entirely independently of each other. This is true of most JSON Schema keywords. Each keyword is an assertion about the value. "type": "string"
checks that the value is a string. "enum": [...]
checks that the value is one of the given values. type
is actually redundant in your schema. If the value passes enum
, it must be a string because all of the enum
values are strings. Therefore, we don't need to also have an assertion that the value is a string.
TY For the info!