KaiZen-OpenAPI-Editor
KaiZen-OpenAPI-Editor copied to clipboard
oneOf Schema Violations: filter error message to user's intended candidate schema
This idea was discussed in #60. There are some cases where an object failed to match one of several candidate schemas, and the error message shows the violations applicable to each of these schemas.
There are some cases where it should be possible to infer a single candidate schema that the user is trying to match. In the example given, if the user has specified a parameter with in : body, then we don't need to report any schema violations that would apply to non-body parameters. The in property acts as a discriminator.
This same optimization can also apply to anyOf violations.
Parameters are by far the most common stumbling block for this issue. The rules for different parameter locations (as determined by the in property value) are very different, and error messages related to this are very big and user-unfriendly.
If we could implement this logic to prune the error response tree for parameters alone, even without making it a more generic, schema-driven solution, this would be a significant usability improvement.
Note: The current draft of JSON Schema includes if, then, and else keywords as described here.
We could use this to implement discriminator-like logic. And a validating parser that works with this JSON Schema revision should be able to apply schema validations more selectively, and pinpoint error messages to the offending node.