Skip to content

Bug: RestAPI event resolver: OpenAPI generation with content-type header generated wrong spec #8347

Description

@RynoM

Expected Behaviour

Given the following route in our application:

@app.patch("/event-types/<event_type_id>/approved-consumers")
def patch_approved_consumers(
    event_type_id: str,
    approved_consumers: Annotated[list[ApprovedConsumersPatchOperation], Body()],
    content_type: Annotated[
        Literal["application/json-patch+json"],
        Header(alias="Content-Type"),
    ],
) -> EventTypeModel:
    """Patch approved consumers for an EventType."""
    return approved_consumers_controller.patch_approved_consumers(
        event_type_id, approved_consumers
    )

We would expect the following snippet in our OpenAPI spec:

        "requestBody": {
          "content": {
            "application/json-patch+json": {
              "schema": {
                "items": {
                  "$ref": "#/components/schemas/ApprovedConsumersPatchOperation"
                },
                "type": "array",
                "title": "Approved Consumers"
              }
            }
          },
          "required": true
        },

Current Behaviour

However currently this generates:

    "/event-types/{event_type_id}/approved-consumers": {
      "patch": {
        "summary": "PATCH /event-types/{event_type_id}/approved-consumers",
        "operationId": "patch_approved_consumers",
        "parameters": [
          {
            "required": true,
            "schema": {
              "type": "string",
              "title": "Event Type Id"
            },
            "name": "event_type_id",
            "in": "path"
          },
          {
            "required": true,
            "schema": {
              "type": "string",
              "const": "application/json-patch+json",
              "title": "Content-Type"
            },
            "name": "content-type",
            "in": "header"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "items": {
                  "$ref": "#/components/schemas/ApprovedConsumersPatchOperation"
                },
                "type": "array",
                "title": "Approved Consumers"
              }
            }
          },
          "required": true
        },

Code snippet

@app.patch("/event-types/<event_type_id>/approved-consumers")
def patch_approved_consumers(
    event_type_id: str,
    approved_consumers: Annotated[list[ApprovedConsumersPatchOperation], Body()],
    content_type: Annotated[
        Literal["application/json-patch+json"],
        Header(alias="Content-Type"),
    ],
) -> EventTypeModel:
    """Patch approved consumers for an EventType."""
    return approved_consumers_controller.patch_approved_consumers(
        event_type_id, approved_consumers
    )

Possible Solution

Couple headers should be treated as special cases:
https://swagger.io/docs/specification/v3_0/describing-parameters/#header-parameters

Steps to Reproduce

  • define route
  • generate openapi spec from it

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriagePending triage from maintainers

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions