Utility toolkit to modify and override OpenAPI schema definitions in FastAPI.
Installation
pip install gadfastopenapi
Usage
from gadfastopenapi import OpenAPI
app.openapi = OpenAPI(app)
# or
@app.get("/api/openapi.json", include_in_schema=False)
async def openapi():
return OpenAPI(app, handlers=[affix, use_route_as_operation_id]).generate()
Extension gadfastopenapi.extensions.affix
from fastapi import FastAPI
from pydantic import BaseModel
from gadfastopenapi import OpenAPI
from gadfastopenapi.extensions.affix import affix
app = FastAPI()
app.openapi = OpenAPI(app, handlers=[affix])
class Deprecated(BaseModel):
__affix__ = "Deprecated:"
class User(Deprecated):
id: int
@app.get("/user", response_model=User)
def get_user():
return {"id": 1}
openapi.json
>>>
{
"paths": {
"schema": {
"$ref": "#/components/schemas/DeprecatedUser"
}
},
"schemas": {
"DeprecatedUser": {
"title": "DeprecatedUser"
}
}
}
Extension gadfastopenapi.extensions.operationid
from fastapi import FastAPI
from pydantic import BaseModel
from gadfastopenapi import OpenAPI
from gadfastopenapi.extensions.operationid import use_route_as_operation_id
app = FastAPI()
app.openapi = OpenAPI(app, handlers=[use_route_as_operation_id])
class User(BaseModel):
id: int
@app.get("/user", response_model=User)
def get_user():
return {"id": 1}
openapi.json
>>> BEFORE
{
"paths": {
"/user": {
"get": {
"operationId": "get_user_user_get",
}
}
}
}
>>> AFTER
{
"paths": {
"/user": {
"get": {
"operationId": "get_user",
}
}
}
}
Extension gadfastopenapi.extensions.errors
from fastapi import FastAPI
from gadfastopenapi.extensions.errors import APIError, openapi_errors
app = FastAPI()
class MyError(APIError):
...
@app.get("/user", response_model=dict, responses=openapi_errors(MyError))
def get_user():
return {"id": 1}
openapi.json
>>>
{
"paths": {
"/user": {
"get": {
"responses": {
"200": {
"description": "Successful Response"
},
"418": {
"description": "MyError",
"content": {
"application/json": {
"example": {
"status_code": 418,
"detail": {
"type": "MyError"
}
}
}
}
}
}
}
}
}
}
Custom handler
from fastapi import FastAPI
from gadfastopenapi import OpenAPI
def my_handler(app: FastAPI, openapi: dict) -> tuple[FastAPI, dict]:
# Mutate openapi here
return app, openapi
app = FastAPI()
app.openapi = OpenAPI(app, handlers=[my_handler])
@app.get("/user", response_model=dict)
def get_user():
return {"id": 1}
Metadata
Release files for gadfastopenapi 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gadfastopenapi-0.0.1.tar.gz | 6.8 kB | Without provenance | Details for gadfastopenapi-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gadfastopenapi-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for gadfastopenapi-0.0.1-py3-none-any.whl |
Total release size: 15.9 kB
Release files / gadfastopenapi-0.0.1.tar.gz
| Download URL | gadfastopenapi-0.0.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
061b554cbb161a71cc30be9992e6c2ce1dd9d536a478e52090e09cfbaa2f45e3
|
|
BLAKE2b-256 checksum How to use checksums |
2e3ea0a8b04ba287afddab84bf5411f2305110f2b3a1dbd773a78b53ab461512
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / gadfastopenapi-0.0.1-py3-none-any.whl
| Download URL | gadfastopenapi-0.0.1-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66e2091de8cd9a3be26c67ae71ccbad40a65df1f3b14cbb4d9b8a498f040f2bf
|
|
BLAKE2b-256 checksum How to use checksums |
26e1aa4adbf04f85e18278d2e53d34cbb8c3651d7d0dd83aa770d2e4ecd31d78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for gadfastopenapi 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.