Skip to content

Invalid spec and missing requestBody when using json_or_form #600

@elbakerino

Description

@elbakerino

When using json_or_form in location, the produced request spec is invalid and misses the requestBody.

e.g.:
@app.input(SomeRequest, location='json_or_form')

Produces this invalid spec:

{
    "/some-request": {
        "post": {
            "parameters": [
                {
                    "in": "json_or_form",
                    "name": "input",
                    "required": false,
                    "schema": {
                        "type": "string"
                    }
                }
            ],
            "responses": {
                "... redacted": ""
            },
            "summary": "Some Request"
        }
    }
}

Instead of requestBody it has parameters, with an invalid in parameter-locations.

Example of requestBody with multiple types:

{
    "requestBody": {
        "content": {
            "application/json": {
                "schema": {
                    "$ref": "#/components/schemas/Order"
                }
            },
            "application/xml": {
                "schema": {
                    "$ref": "#/components/schemas/Order"
                }
            },
            "application/x-www-form-urlencoded": {
                "schema": {
                    "$ref": "#/components/schemas/Order"
                }
            }
        }
    }
}

See petstore3.swagger.io/api/v3/openapi.json for a full example.

While the OpenAPI file is unusable, the request parsing works in clients with a manual defined content-type header.

Environment:

  • Python version: 3.10
  • Flask version: 3.0.3
  • APIFlask version: 2.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions