Skip to content

Enhancement: Is there a way to configure the OpenApi response globally #4470

@smac89

Description

@smac89

Summary

In the docs, it shows how to configure the OpenAPI schema generation for individual routes. One of the things we can configure is the responses dictionary.

However, in my openapi_config, I have configured a custom 400 response which I would like to use for all routes:

components=[
    Components(
        responses={
            "BadRequest": OpenAPIResponse(
                description="Bad Request",
                content={
                    "application/problem+json": OpenAPIMediaType(
                        schema=Schema(
                            type="object",
                            properties={
                                "type": Schema(type="string", format="uri"),
                                "title": Schema(type="string"),
                                "detail": Schema(type="string"),
                                "status": Schema(type="integer", format="int32"),
                                "instance": Schema(type="string", format="uri"),
                            },
                            required=["title", "detail", "status"],
                        )
                    )
                },
            )
        }
    )
]

I'm using the ProblemDetailsPlugin which converts all HttpExceptions to an object, and would like my typescript code to reflect that format.

Is it possible to support configuring the responses object globally in the main app config?

responses={"400": {"ref": "#/components/responses/BadRequest"}}

Thanks for your time

Basic Example

app = Litestar(responses={"400": {"ref": "#/components/responses/BadRequest"}})

Drawbacks and Impact

No response

Unresolved questions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementThis is a new feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions