fastapi-versioning icon indicating copy to clipboard operation
fastapi-versioning copied to clipboard

Docs URL is served even when set to None

Open jshields opened this issue 3 years ago • 2 comments

Describe the bug Even with docs_url set to None, the docs are still served. Per the FastAPI documentation, the app should no longer serve docs with this option set.

You can disable it by setting docs_url=None. https://fastapi.tiangolo.com/tutorial/metadata/#docs-urls

def docs_url_kwargs() -> dict:
    return  {
        "openapi_url": None,
        "docs_url": None,
        "redoc_url": None,
    }

application = FastAPI(
    title='Example FastApi',
    description='Nice',
    **docs_url_kwargs(),
)
application = VersionedFastAPI(
    application,
    version_format="{major}",
    prefix_format="/v{major}/api/",
    description='version',
    enable_latest=True,
    **docs_url_kwargs(),
)

To Reproduce Set docs_url=None when instantiating the FastAPI app and VersionedFastAPI but still see the docs served at /docs.

Expected behavior Expecting docs to no longer be served (for production use case).

Additional details Issue may be here: https://github.com/DeanWay/fastapi-versioning/blob/18d480f5bb067088f157f235a673cb4c65ec77d5/fastapi_versioning/versioning.py#L68-L73

jshields avatar Jul 15 '22 01:07 jshields

That same bit of code seems to be the responsible for always making the documentation avaialable at /docs even when provided a different url via the docs_url parameter.

This: https://github.com/DeanWay/fastapi-versioning/blob/18d480f5bb067088f157f235a673cb4c65ec77d5/fastapi_versioning/versioning.py#L71

Should probably check the docs_url of the FastAPI instance or take it from the kwargs of the VersionedFastAPI

josemarcosrf avatar Jul 18 '22 14:07 josemarcosrf

I also have same problem - docs enabled, but: app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)

D1ver avatar May 28 '24 15:05 D1ver