-
Notifications
You must be signed in to change notification settings - Fork 13
Provide better error messages for oneOf
schema validation failures
#60
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
Comments
The json-validator returns an extensive report for each validation error, those reports are not easily convertible to marker errors. In the current implementation, the report is flatten to collect all errors, that's why the list of markers is so long. I'm not sure how to fix this without to implement a more advanced report processing tool that would identify the error that is relevant to the user's input or intend. For example the report returned for the error in the above document. {
"level": "error",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/parametersList/items"
},
"instance": {
"pointer": "/paths/~1taxFilings~1{id}/put/parameters/0"
},
"domain": "validation",
"keyword": "oneOf",
"message": "instance failed to match exactly one schema (matched 0 out of 2)",
"matched": 0,
"nrSchemas": 2,
"reports": {
"/definitions/parametersList/items/oneOf/0": [
{
"level": "error",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/parameter"
},
"instance": {
"pointer": "/paths/~1taxFilings~1{id}/put/parameters/0"
},
"domain": "validation",
"keyword": "oneOf",
"message": "instance failed to match exactly one schema (matched 0 out of 2)",
"matched": 0,
"nrSchemas": 2,
"reports": {
"/definitions/parameter/oneOf/0": [
{
"level": "error",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/bodyParameter"
},
"instance": {
"pointer": "/paths/~1taxFilings~1{id}/put/parameters/0"
},
"domain": "validation",
"keyword": "required",
"message": "object has missing required properties ([\"schema\"])",
"required": [
"in",
"name",
"schema"
],
"missing": [
"schema"
]
}
],
"/definitions/parameter/oneOf/1": [
{
"level": "error",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/nonBodyParameter"
},
"instance": {
"pointer": "/paths/~1taxFilings~1{id}/put/parameters/0"
},
"domain": "validation",
"keyword": "oneOf",
"message": "instance failed to match exactly one schema (matched 0 out of 4)",
"matched": 0,
"nrSchemas": 4,
"reports": {
"/definitions/nonBodyParameter/oneOf/0": [
{
"level": "error",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/headerParameterSubSchema/properties/in"
},
"instance": {
"pointer": "/paths/~1taxFilings~1{id}/put/parameters/0/in"
},
"domain": "validation",
"keyword": "enum",
"message": "instance value (\"body\") not found in enum (possible values: [\"header\"])",
"value": "body",
"enum": [
"header"
]
}
],
"/definitions/nonBodyParameter/oneOf/1": [
{
"level": "error",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/formDataParameterSubSchema/properties/in"
},
"instance": {
"pointer": "/paths/~1taxFilings~1{id}/put/parameters/0/in"
},
"domain": "validation",
"keyword": "enum",
"message": "instance value (\"body\") not found in enum (possible values: [\"formData\"])",
"value": "body",
"enum": [
"formData"
]
}
],
"/definitions/nonBodyParameter/oneOf/2": [
{
"level": "error",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/queryParameterSubSchema/properties/in"
},
"instance": {
"pointer": "/paths/~1taxFilings~1{id}/put/parameters/0/in"
},
"domain": "validation",
"keyword": "enum",
"message": "instance value (\"body\") not found in enum (possible values: [\"query\"])",
"value": "body",
"enum": [
"query"
]
}
],
"/definitions/nonBodyParameter/oneOf/3": [
{
"level": "error",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/pathParameterSubSchema/properties/in"
},
"instance": {
"pointer": "/paths/~1taxFilings~1{id}/put/parameters/0/in"
},
"domain": "validation",
"keyword": "enum",
"message": "instance value (\"body\") not found in enum (possible values: [\"path\"])",
"value": "body",
"enum": [
"path"
]
}
]
}
},
{
"level": "error",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/nonBodyParameter"
},
"instance": {
"pointer": "/paths/~1taxFilings~1{id}/put/parameters/0"
},
"domain": "validation",
"keyword": "required",
"message": "object has missing required properties ([\"type\"])",
"required": [
"in",
"name",
"type"
],
"missing": [
"type"
]
}
]
}
}
],
"/definitions/parametersList/items/oneOf/1": [
{
"level": "error",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/jsonReference"
},
"instance": {
"pointer": "/paths/~1taxFilings~1{id}/put/parameters/0"
},
"domain": "validation",
"keyword": "additionalProperties",
"message": "object instance has properties which are not allowed by the schema: [\"description\",\"in\",\"name\",\"required\"]",
"unwanted": [
"description",
"in",
"name",
"required"
]
},
{
"level": "error",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/jsonReference"
},
"instance": {
"pointer": "/paths/~1taxFilings~1{id}/put/parameters/0"
},
"domain": "validation",
"keyword": "required",
"message": "object has missing required properties ([\"$ref\"])",
"required": [
"$ref"
],
"missing": [
"$ref"
]
}
]
}
} |
@ghillairet , @tfesenko , I had made some comments about this in #9. Essentially, my suggestion is to list the schemas individually, like this:
There are a couple of challenges here: First, the individual candidate schemas within a Second, the schemas can be recursive. So we can A = oneOf (B, C), and C= oneOf(D, E). To report that, it's logically something like this:
In an earlier comment, I suggested that we should not expand beyond the first level, but now I think this is the only way to provide useful output. A possible optimization: detect cases where the instance data is clearly "trying" to conform to one candidate schema, and only report errors related to that schema. We could do this by using certain properties as discriminators. For example, in a parameter, we could use the We might want to encode those rules into the schema itself (e.g. using extended properties in the schema to specify criteria for each candidate schema in a There could still be cases where there is no logical discriminator, where the discriminator value(s) are not provided, or not legal. In those cases, the changes above (schema names + recursive error messages) would still be useful. For the moment, this is the best I can suggest. And because it's likely to be a significant amount of work, I think we should put it on the backlog. |
@ghillairet , please read my comment above. I'd like to know if you think the combination of named schemas + recursive error messages is feasible. How much time do you think that would take? To clarify, I am only asking about named schemas + recursive error messages, not including the discriminator optimization. That would be a separate scope. |
oneOf
schema validation failures
@ghillairet, what you're showing in the screenshot is already a significant improvement. Yes, formatting improvements (normalizing the indent levels, especially) would help. Thanks. |
[#60] Provide better error messages for `oneOf` schema validation failures
Opened new issue #111 to track the code review follow-ups. Closing this now. |
This Swagger Spec has a "body" parameter that is missing the required "schema" property:
I would hope for an error message like
missing required property: 'schema'.
But what it shows is a long, repetitive list of error messages on the parameter object:If it's reasonably easy to provide the user with a simple, helpful error message in cases like this, we should. If it's going to require a lot of work, we can defer it.
The text was updated successfully, but these errors were encountered: