Skip to main content

FastAPI OpenAPI Overrides

Document the dependency overrides of a FastAPI application into its OpenAPI schema.

Why?

FastAPI lets you replace a dependency with another one using app.dependency_overrides. Although designed for testing, this mechanism is also useful for reusable routers: each application can provide its own implementation of a dependency, such as authentication.

At runtime, FastAPI uses the overridden dependency to process requests, including reading its parameters and checking its security requirements. However, the OpenAPI schema still documents the original dependency. As a result, the API documentation does not reflect the actual behavior.

This library fixes this by generating the OpenAPI schema using the overridden dependencies.

A fix was proposed upstream but rejected. This functionality is therefore provided by an extension module.

Usage

from fastapi import APIRouter, Depends, FastAPI, Header

from fastapi_openapi_overrides import document_dependency_overrides


def authenticated_user() -> str:
    """Abstract dependency: the application must provide the implementation."""
    raise NotImplementedError()


router = APIRouter()


@router.get("/me")
def read_me(user: str = Depends(authenticated_user)) -> str:
    return user


def header_user(x_user: str = Header()) -> str:
    return x_user


app = FastAPI()
app.include_router(router)
app.dependency_overrides[authenticated_user] = header_user
document_dependency_overrides(app)

app.openapi()["paths"]["/me"]["get"]["parameters"]
#> [{'name': 'x-user', 'in': 'header', 'required': True, 'schema': {'type': 'string', 'title': 'X-User'}}]

Without document_dependency_overrides(app), the x-user header would not be documented, while it's required by the requests.

document_dependency_overrides() replaces the openapi() method of the app, as explained in the FastAPI documentation about extending OpenAPI. As with the original method, the schema is generated once and cached into app.openapi_schema: reset it to None to regenerate the schema if the dependency overrides are changed afterwards.

If you already generate the schema yourself, the lower level functions can be used:

  • get_openapi_with_overrides(app): generate the OpenAPI schema of the app with the same arguments as FastAPI.openapi();
  • get_routes_with_overrides(routes): return the routes to give to fastapi.openapi.utils.get_openapi();
  • get_dependant_with_overrides(dependant, dependency_overrides): return a copy of a dependant where the overridden dependencies are replaced.

The routes and the dependants of the application are never modified.

Compatibility

FastAPI >= 0.138.

Development

uv run --group test pytest
uv run --group typing mypy src
pre-commit run --all-files

Metadata

Release files for fastapi-openapi-overrides 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-openapi-overrides 0.1.0
File Size Uploaded Provenance Actions
fastapi_openapi_overrides-0.1.0.tar.gz 70.2 kB With provenance Details for fastapi_openapi_overrides-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-openapi-overrides 0.1.0
File Interpreter ABI Platform Actions
fastapi_openapi_overrides-0.1.0-py3-none-any.whl Python 3 none any Details for fastapi_openapi_overrides-0.1.0-py3-none-any.whl

Total release size: 75.4 kB

Release files / fastapi_openapi_overrides-0.1.0.tar.gz

Download URL fastapi_openapi_overrides-0.1.0.tar.gz
Size 70.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d44d225b9c68aa915e2a8094db45373ecfc94d030f983c993bf75476cfebfc1a
BLAKE2b-256 checksum
How to use checksums
a5b851f6c449d5c8506ae43f0d7e6d01c6c1f679bc85be4b46ddfe18f62c0966
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / fastapi_openapi_overrides-0.1.0-py3-none-any.whl

Download URL fastapi_openapi_overrides-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5af9e547832ecaccdb4c8577d914fcdaae89f7c3545c7b9ca173c44fb8345cca
BLAKE2b-256 checksum
How to use checksums
6c3bd8b0f7dbedf6d1a33ea3f0cab80ecd3aab27fe90e133bcee8954b0d8440a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Security for fastapi-openapi-overrides 0.1.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fastapi_openapi_overrides-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page