-
Notifications
You must be signed in to change notification settings - Fork 4
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
docs: Add possible exceptions to API documentation #1569
Conversation
A Storybook preview is available for commit 02d1ae5. |
2675424
to
74e6084
Compare
387c2de
to
8f3de15
Compare
7a4d9e8
to
9468ce9
Compare
22b2b50
to
7725c5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! There are just a few minor comments that should be addressed before we merge this.
7725c5d
to
3f9b718
Compare
Exceptions are grouped by status codes. The exceptions have to be registered on the route using the responses attribute. A helper function `api_exceptions` can be used to automatically translate the exceptions to the OpenAPI format.
3f9b718
to
45512d5
Compare
Quality Gate passedIssues Measures |
When the refresh token was expired, the backend sent the error "TOKEN_SIGNATURE_EXPIRED". The frontend did then request a new refresh token, leading to an infinite loop and a DDOS attack on our backend. The error was accidentially added in #1569.
When the refresh token was expired, the backend sent the error "TOKEN_SIGNATURE_EXPIRED". The frontend did then request a new refresh token, leading to an infinite loop and a DDOS attack on our backend. The error was accidentially added in #1569.
The Collaboration Manager backend can throw a bunch of different errors. Those errors were only documented in the code by scanning the complete call trace, which is unintuitive for users who just want to talk to the API.
Therefore, I've migrated all legacy occurrences of
fastapi.HTTPException
to our own exception format. Those exceptions can be registered as response for a route using theresponses
attribute. A helper functionapi_exceptions
can be used to automatically translate the exceptions to the OpenAPI format. When registered, the exceptions are automatically added to the API documentation.This PR mainly focuses on the initial implementation of the behaviour and doesn't register exceptions for all routes. However, I did it for some routes, e.g. the "Request session" route, which can be used as example.
In the API documentation, exceptions are grouped by status codes. The generated responses are visible in the generated documentation clients. The large amount of error responses might be too bloated for some generated clients, e.g. our frontend client. Therefore, the addition of error responses in the OpenAPI schema can be disabled by setting the environment variable
CAPELLACOLLAB_SKIP_OPENAPI_ERROR_RESPONSES=1
.In SwaggerUI, the individual schemas slightly hidden. They are not displayed in example section, instead, you have to navigate to "Schema" to see all available error responses.
In ReDoc, they are better visible:
The best option is the right side in the ReDoc documentation where you can select the error in a dropdown to see the the returned JSON:
Resolves #883.