api2swagger
api2swagger copied to clipboard
Request bodies are incorrectly added to the Swagger spec when no headers are included in the request
- Make a
POST
request which includes body data, but does not include acontent-type
header.api2swagger -X POST -e https://api.github.com -o ./testSwagger.json -d '{\"test\":\"test\"}'
- Note that the outputted Swagger file has an invalid schema in the parameters section:
"parameters": [
{
"in": "body",
"name": "body",
"description": "Request Payload Body",
"required": true,
"schema": "'{\"test\":\"test\"}'"
}
]
Several errors are also displayed in the Swagger Editor when pasting in the schema.
When the content-type
header is included in the request, the section looks like:
{
"name": "body",
"in": "body",
"schema": {
"description": "",
"type": "object",
"properties": {
"test": {
"type": "string",
"minLength": 1
}
},
"required": [
"test"
]
},
"description": "",
"required": true
}
Api2Swagger should handle the case when a content-type header is not provided along with a request body by either:
- Ignoring the request body
- Displaying an error message
- Assuming a content-type of
application/json
and trying to parse the request body. This follows Swagger's behavior of assumingapplication/json
when no media type is provided in the produces or consumes section.