json_schema
json_schema copied to clipboard
oneOf error message is unclear and misleading.
oneOf fails to vaildate. I believe this is a ~~bug.~~ This is not a bug, but the error message is unclear.
Details
{
"description": "Set audio normalization mapping mode. Decibel (log) mode can provide higher quality at the cost of some additional CPU load",
"oneOf": [
{
"type": "object",
"properties": {
"mode": {
"type": "string",
"const": "linear"
}
},
"additionalProperties": false
},
{
"type": "object",
"properties": {
"mode": {
"type": "string",
"const": "decibel"
},
"intensity": {
"type": "integer",
"minimum": 1,
"maximum": 15
}
},
"additionalProperties": false
}
],
"default": { "mode": "linear" }
}
The above code block gives this error: #/properties/audio/properties/normalizer/properties/filters/properties/mapping/oneOf: violated No element
Steps to Reproduce
Run JsonSchema.validateWithErrors(); on a full schema object.
Your Environment
- Version: json_schema 2.2.1 flutter 1.7.8+4 dart 2
- Operating System and version: Android 8 (Samsung Experience version 9), Samsung Galaxy 7
FYI: @michaelcarter-wf
I forgot to include this, so for context, it is being validated against:
{intensity: '9', mode: 'decibel'}
It is throwing because intensity is a string and should not be. Please make this error message more clear.
This throw is non-existent when intensity
is an integer.
Came across this as we just spent a significant amount of time due to the same problem.
We have a quite complex validation schema of the form:
{ "oneOf" : [...] }
consisting of 3 different possibilities, each with nested objects in turn with further oneOf
s, etc.
Validation failed at a specific moment of our application, but we did not understand why. We then exclusively got the following output when printing the errors and warnings from the ValidationResults
instance returned via the validate()
call:
# (root): #/oneOf: violated No element
Unfortunately this did not help us in any way to determine the cause of the failed validation.
Accompanying the validation step-by-step using step debugging allowed us to determine the cause: a disallowed details
property was provided in the third sub-level of one of the objects allowed via the schema.
In our case, we've then even found that your package actually added the detailed message into the _errors
property of the Validator
instance during runtime, which in our case precisely was:
/financial/account/data: unallowed additional property details
But that error was overwritten with the final # (root): #/oneOf: violated No element
error message.
It would be better both for us and also for automated error monitoring (auto-forward validation errors to our servers) if the actual reason for failure (/financial/account/data: unallowed additional property details
) would be returned as the final ValidationResults
, instead of the general error feedback (# (root): #/oneOf: violated No element
) ...?
Closing because of how old this issue is. If this is still an issue, please reopen.