Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💡 » improve openapi error responses #37

Open
lucas-labs opened this issue Sep 5, 2024 · 0 comments
Open

💡 » improve openapi error responses #37

lucas-labs opened this issue Sep 5, 2024 · 0 comments
Labels
💡 feat New feature or request

Comments

@lucas-labs
Copy link
Owner

Instead of having to define something like:

@get(
    '/foo/{id}',
    responses={
        404: {  # or exc_response(404)
            'description': 'Execution not found',
            'model': ExceptionResponse,
            'content': {
                'application/json': {
                    'example': ExceptionResponse.example(404),
                },
            },
        },
        500: {...},
        ..
    },
)
def get_foo(self, id: str) -> list[OperationResponse]:
    ...

Accept a new argument throws or raises:

@get('/foo/{id}', raises=[404, 500, ...])
def get_foo(self, id: str) -> list[OperationResponse]:
    ...

We can then use the already existing exc_response function to generate the examples.

Note

The responses argument should be kept and then combined with raises|throws if provided

@lucas-labs lucas-labs added the 💡 feat New feature or request label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 feat New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant