Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 1 day ago
JSON representation

Find HTTPExceptions and turn them into documented responses! :tada:

Awesome Lists containing this project

README

        


FastAPI Responses




Latest Commit






Package version




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_openapi

app = 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.