Skip to content

Request bodies are incorrectly added to the Swagger spec when no headers are included in the request #8

Description

@ctuckz
  1. Make a POST request which includes body data, but does not include a content-type header.
    api2swagger -X POST -e https://api.github.com -o ./testSwagger.json -d '{\"test\":\"test\"}'
  2. 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:

  1. Ignoring the request body
  2. Displaying an error message
  3. Assuming a content-type of application/json and trying to parse the request body. This follows Swagger's behavior of assuming application/json when no media type is provided in the produces or consumes section.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions