alexschimpf / fastapi-versionizer

FastAPI Versionizer
MIT License
81 stars 13 forks source link

Allow further customisation of docs routes. #25

Closed ollz272 closed 1 year ago

ollz272 commented 1 year ago

Subject of the issue

In our application we want to be able to hide our docs through basic HTTP auth. We currently do that like this, for example:

    @docs_router.get("/docs", include_in_schema=False)
    def get_swagger_docs(self,  username: str = Depends(password_login)):
        """Return swagger format documentation."""
        return get_swagger_ui_html(openapi_url="/openapi.json", title="docs")

    @docs_router.get("/redoc", include_in_schema=False)
    def get_redoc_docs(self,  username: str = Depends(password_login)):
        """Return redoc format documentation."""
        return get_redoc_html(openapi_url="/openapi.json", title="docs")

    @docs_router.get("/openapi.json", include_in_schema=False)
    def openapi(self, username: str = Depends(password_login)):
        """Return openapi spec json."""
        return get_openapi(title="GE Timescale API", version=app.version, routes=app.routes)

And password login is just a HTTPBaiscCredentials thing. This works fine, but we want to move to versioned endpoint. It doesn't seem like we can customise this kinda behaviour. Maybe we could allow for a docs, redoc, and openapi kwargs to be passed into the initial function? Or even the functions themselves?

Your environment

Steps to reproduce

Tell us how to reproduce this issue

Expected behaviour

Tell us what should happen

Actual behaviour

Tell us what happens instead

alexschimpf commented 1 year ago

Does this work for you: https://github.com/alexschimpf/fastapi-versionizer/pull/26 ?

ollz272 commented 1 year ago

@alexschimpf Perfect!!! Thank you 🙏🏻

alexschimpf commented 1 year ago

Version 1.1.0 is now available with the callback feature. I'm going to consider this issue closed for now. Let me know if you find any issues.