-
-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unsatisfiable schema when flattening an enum and denying unknown fields #164
Comments
I was thinking about what a solution to this would look like. It seems like:
I think this would also fix #165, if there is a It gets a bit more complicated if the flattened enum is optional: perhaps there needs to be another oneOf branch asserting that none of the properties from any of the branches exist? I think you could write that as |
For schemas using draft 2019-09 and above, the fix is relatively straightforward:
Then the resulting schema for this issue's example would be: {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyStruct",
"type": "object",
"properties": {
"property": {
"type": "string"
}
},
"oneOf": [
{
"type": "object",
"properties": {
"variant": {
"type": "string"
}
},
"required": [
"variant"
]
}
],
"required": [
"property"
],
"unevaluatedProperties": false
} For earlier JSON Schema versions like draft 7 which don't support {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyStruct",
"type": "object",
"properties": {
"property": {
"type": "string"
},
"variant": true
},
"oneOf": [
{
"type": "object",
"properties": {
"variant": {
"type": "string"
}
},
"required": [
"variant"
]
}
],
"required": [
"property"
],
"additionalProperties": false
} And for OpenAPI 3.0, it could be the same but with |
Fixed in 1.0.0-alpha.10 - the example from this issue now produces the same schema I suggested in my previous comment |
The following generates an unsatisfiable schema
The resulting schema is:
in which the
properties
/additionalProperties
fields demand that the only valid field beproperty
, but theoneOf
(also denying additional properties) demands that the only valid field bevariant
.The text was updated successfully, but these errors were encountered: