-
Notifications
You must be signed in to change notification settings - Fork 327
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
Unevaluated properties and subschemas #1100
Comments
Unfortunately this is how the You can compare the results with another implementation From the specification: https://json-schema.org/draft/2020-12/json-schema-core#section-11-2
|
@justin-tay Thanks for the reply. This is very unfortunate because the error messages are confusing for the end user. The reason I am putting the server-schema in the {
"server": {
"host": "test",
"port": 80
},
"machines": [
{
"type": "server",
"host": "test",
"port": 80
},
{
"type": "client",
"name": "foo"
}
]
}
As you see server can be either a field ( Is there any other way to achieve the same goal without using Here is a simplified version of my schema at the moment: https://www.jsonschemavalidator.net/s/CwNzBNQj |
You can attempt to try using {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
"server": {
"type": "object",
"properties": {
"port": {
"type": "integer"
},
"type": {
"type": "string"
}
},
"required": [
"port"
],
"additionalProperties": false
},
"client": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string"
}
},
"required": [
"name"
],
"additionalProperties": false
}
},
"type": "object",
"properties": {
"server": {
"$ref": "#/$defs/server"
},
"client": {
"$ref": "#/$defs/client"
},
"machines": {
"type": "array",
"items": {
"allOf": [
{
"if": {
"properties": {
"type": {
"const": "server"
}
},
"required": [
"type"
]
},
"then": {
"$ref": "#/$defs/server"
}
},
{
"if": {
"properties": {
"type": {
"const": "client"
}
},
"required": [
"type"
]
},
"then": {
"$ref": "#/$defs/client"
}
}
]
}
}
},
"additionalProperties": false
} |
This requires adding the Thanks anyway. I am closing this issue. |
This bug is similar to #967 and #962 which are closed as fixed but the issue still is reproducible in
v1.5.1
Library Version:
1.5.1
.Sample schema to reproduce the issue:
If I validate the following data:
I would get the following messages, which are expected and correct:
But If I change the data to contain, for example, invalid port:
The validation result would be:
while 1, 4 and 5 are correct messages, 2 and 3 are not supposed to be there.
The text was updated successfully, but these errors were encountered: