Better error messages when oneOf/anyOf doesn't match
See original GitHub issueConsider this example:
var schema = {
"type": "object",
"required": ["foo", "bar"],
"additionalProperties": false,
"properties": {
"foo": {
"type": "integer"
},
"bar": {
"oneOf": [{
"type": "object",
"required": ["id"],
"additionalProperties": false,
"properties": {
"id": {
"type": "integer"
}
}
}, {
"type": null,
"additionalProperties": false
}]
}
}
};
var candidate = {
"foo": 123,
"bar": {
"id": 456
}
};
Based on the schema
the candidate
is valid. However, if I change the id
to a string value (e.g “456”), I will get this error:
[ { field: 'data.bar',
message: 'no (or more than one) schemas match' } ]
While the error message is not wrong, it can be more informative by saying which field has issue. The same thing can apply for missing required fields or having additional properties when it’s not allowed.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Data does not match any schemas from 'oneOf' - Stack Overflow
I added c.GeneratePolymorphicSchemas(); to the AddSwaggerGen options but it has not helped. [Update] Here is the first error message. ERROR: ...
Read more >Handling Validation Errors - python-jsonschema
Try to find an error that appears to be the best match among given errors. In general, errors that are higher up in...
Read more >Understanding JSON Schema
JSON Schema is a powerful tool for validating the structure of JSON data. However, learning to use it by reading its.
Read more >JSON validation - IBM
Nested oneOf, anyOf, and allOf schema constructs can result in a large number of error messages, as the JSON parser attempts to validate...
Read more >Language Guide (proto3) | Protocol Buffers - Google Developers
Message fields can be one of the following: singular : a well-formed message can have zero or one of this field (but not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@skilledDeveloper would something like the following work:
Then we could add a schema identifier to subschemas as well to solve stuff like #22 as well
+1