Closed jessedc closed 8 years ago
Hi @jessedc - per the Swagger specification, each operation must contain at least one response (either numeric or default
and that response must have at least a description
). Without it, the definition you have is malformed as far as validation goes.
Sorry @webron, I may not have been clear my issue is not with validation, but rather the HTTP 500 errors.
My expectation is to see a validation error, or no error in the case of a valid schema - not 500s. I have valid schemas that also fail.
Here's an example of a valid schema that exhibits the same issue.
My bad, indeed we need to fail more gracefully than return 500s in general.
Completely agree @jessedc. The parser, which reads all swagger documents for validation purposes, is undergoing a major redo right now, for both providing better feedback to the user as well as less "explosions" when something is off (like something expected to be an object is actually an array).
Follow this: https://github.com/swagger-api/swagger-parser/issues/108 for updates.
This has been addressed in the updated validator. Your curl
command now shows the following:
{
"messages": [
"attribute paths.'/city'(get).responses is missing"
],
"schemaValidationMessages": [
{
"level": "error",
"domain": "validation",
"keyword": "required",
"message": "object has missing required properties ([\"responses\"])",
"schema": {
"loadingURI": "http://swagger.io/v2/schema.json#",
"pointer": "/definitions/operation"
},
"instance": {
"pointer": "/paths/~1city/get"
}
}
]
}
Thanks for the update @fehguy, I've noticed much better error reporting.
However the second curl
command that I mentioned above is still returning a 500 error.
For reference the JSON I am posting contains an empty responses
object.
{
"swagger": "2.0",
"info": {
"version": "2.0.0",
"title": "Beanhunter API",
"description": "Description of the api goes here."
},
"host": "local.xxx.com",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/city": {
"get": {
"description": "test description",
"responses": {}
}
}
},
"definitions": {
"Endpoints": {
"title": "Endpoints object",
"properties": {
"links": {}
}
}
}
}
curl -X "POST" "http://online.swagger.io/validator/debug" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "{\"swagger\":\"2.0\",\"info\":{\"version\":\"2.0.0\",\"title\":\"Beanhunter API\",\"description\":\"Description of the api goes here.\"},\"host\":\"local.xxx.com\",\"schemes\":[\"http\"],\"consumes\":[\"application/json\"],\"produces\":[\"application/json\"],\"paths\":{\"/city\":{\"get\":{\"description\":\"test description\",\"responses\":{}}}},\"definitions\":{\"Endpoints\":{\"title\":\"Endpoints object\",\"properties\":{\"links\":{}}}}}"
@jessedc I found the issue, fixed in https://github.com/swagger-api/validator-badge/commit/a51b3cf1995307304d2007c7e5b431811a43b29b
:+1:
I've been using the validator as part of my CI environment and recently the online.swagger.io endpoint is throwing 500 errors.
The following schema is invalid, and online.swagger.io correctly returns a validation error saying
object has missing required properties (["responses"])
The error returned is what I expect:
The following request attempts to fix the validation error by providing the missing
responses
key but the validator returns a 500 error.The response