JSON schema validation with multiple conditions #904
-
I am experimenting with json schema validation and I stumbled across an issue I have a schema that is using the oneOf Keyword and I am using List format. For a simple schema in List format, things are clear. But when I add the oneOf keyword in order to reference two different local schemas, I am struggling to read the validation result. How should I take into consideration where those errors are coming from? Is there a common way of reading the validation result and make sure I am not reading a "failed validation" which is actually coming from an if statement? I mean, I need to make sure that the oneOf keyword works fine, but but when I navigate through the validation results, I might find and report "false positives" because as it says here, The output includes why. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
One tactic that I've found works well is to use the hierarchical ("verbose", maybe) format and follow the This process will highlight the problems you need to fix. Any "false positives" will occur in failed subschemas from within passing subschemas. Schema {
"anyOf": [
{"type": "integer"},
{"type": "string"}
]
} Instance: Output: {
"valid": true,
"evaluationPath": "",
"schemaLocation": "https://json-everything.net/f14e9c0a25#",
"instanceLocation": "",
"details": [
{
"valid": false,
"evaluationPath": "/anyOf/0",
"schemaLocation": "https://json-everything.net/f14e9c0a25#/anyOf/0",
"instanceLocation": "",
"errors": {
"type": "Value is \"string\" but should be \"integer\""
}
},
{
"valid": true,
"evaluationPath": "/anyOf/1",
"schemaLocation": "https://json-everything.net/f14e9c0a25#/anyOf/1",
"instanceLocation": ""
}
]
} The important part is that It's not hard to then imagine this structure more deeply in a larger schema that has an overall failing result. If you just simply scan for errors in a flat structure, you'll find the error from this subschema. But if you had followed the I hope all of that makes sense. |
Beta Was this translation helpful? Give feedback.
One tactic that I've found works well is to use the hierarchical ("verbose", maybe) format and follow the
valid: false
s. As you go deeper into the tree, you can ignore thevalid: true
s because they're not the problem (unless you have anot
keyword).This process will highlight the problems you need to fix. Any "false positives" will occur in failed subschemas from within passing subschemas.
Schema
Instance:
"dog"
Output: