Skip to content

Bug: examples not generated when added to a Body #4558

@kurtsys-vintecc

Description

@kurtsys-vintecc

Description

Having an endpoint:


@post(
    "/",
    status_code=status.HTTP_201_CREATED,
)
async def post_length_norms(
    data: Annotated[
        SomeType,
        Body(
            examples=[
                Example(
                    id="baseRequest",
                    summary="random base request",
                    value=generate_random_body(1),
                ),
                Example(
                    id="anotherRequest",
                    summary="second base request",
                    value=generate_random_body(2),
                ),
            ],
        ),
    ],
) -> SomeResponse:
   ...

Does not show any example bodies. The examples seem to end up wrongly in the openapi.yaml file:

...
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SomeResponse'


    SomeResponse:
      examples:
      - some_response:
        ...
      - some_response:
        ...
      properties:
        ...
      type: object
...

weirdly enough, I get 2x some_response instead of the id/summary, so things don't seem to render properly

Litestar Version

2.19.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛This is something that is not working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions