Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Kludex/fastapi-responses
Find HTTPExceptions and turn them into documented responses! :tada:
https://github.com/Kludex/fastapi-responses
fastapi openapi python
Last synced: about 2 months ago
JSON representation
Find HTTPExceptions and turn them into documented responses! :tada:
- Host: GitHub
- URL: https://github.com/Kludex/fastapi-responses
- Owner: Kludex
- License: mit
- Created: 2020-12-09T21:30:43.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-27T05:00:06.000Z (about 1 year ago)
- Last Synced: 2024-10-30T06:23:57.432Z (about 2 months ago)
- Topics: fastapi, openapi, python
- Language: Python
- Homepage: https://github.com/Kludex/fastapi-responses
- Size: 143 KB
- Stars: 97
- Watchers: 4
- Forks: 11
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
FastAPI Responses
Find HTTPExceptions and turn them into documented responses. :tada:## Installation
``` bash
pip install fastapi-responses
```## Usage
The simplest use case happens when we have a single exception being raised. We don't want to document the possible response manually, so **FastAPI Responses** comes in handy.
``` python
from fastapi import FastAPI, HTTPException
from fastapi_responses import custom_openapiapp = FastAPI()
app.openapi = custom_openapi(app)
@app.get("/{item_id}")
def get_item(item_id: int):
if item_id == 0:
raise HTTPException(status_code=404, detail="Item not found.")
return "Item exists!"
```### Without FastAPI Responses
### With FastAPI Responses
## Roadmap
- [X] Extract HTTPException from stack.
- [ ] Extract any exception and document based on the `exception_handler` container.
- [ ] Accept Python objects on `HTTPException` instantiation.## License
This project is licensed under the terms of the MIT license.