DeanWay / fastapi-versioning

api versioning for fastapi web applications
MIT License
659 stars 64 forks source link

Description from tags metadata not shown in OpenAPI docs #28

Closed Acerinth closed 3 years ago

Acerinth commented 3 years ago

First of all, thank you so much for this extension, saved us a lot of additional unnecessary work!

Bug description Looks like description from tags metadata is not loaded/visible on OpenAPI docs, even if I pass it directly to VersionedFastAPI constructor. name is loaded, but description not. I haven't checked externalDocs attribute yet.

To Reproduce Here is the part of the code from my main.py:

tags_metadata = [
    {"name": "products", "description": "Operations with products and product types."},
    {"name": "cameras", "description": "Operations with cameras."}
]

app = FastAPI(title="My App")

app.include_router(product_router.router)
app.include_router(camera_router.router)

@app.get("/")
@version(1, 0)
def root():
    return {"message": "Hello World!"}

app = VersionedFastAPI(app, openapi_tags=tags_metadata)

... and in the product_router.py, I have defined:

router = APIRouter(prefix="/products", tags=["products"])

... and the same way in camera_router.py.

Expected behavior How it should look like, is described here: FastAPI-Metadata. When I turn off fastapi-versioning, everything works like expected.

Environment

Thanks!

davidkartuzinski commented 3 years ago

I was scratching my head on this for a bit. I also could not get the metadata to show up properly in the FastAPI docs. You may have fixed it already, but the solution for me was to add openapi_tags=tags_metadata, to the app=FastAPI().

Like this example:

app = FastAPI(openapi_tags=tags_metadata)

The app declaration has to come after your tags_metadata.

As a side note, there are a lot of other metadata you can add, FastAPI Docs.

Acerinth commented 3 years ago

Hey @davidkartuzinski , thanks for your response! Unfortunately, meanwhile I had to quit using the library as it was impossible for me to run tests with it - to be more precise, dependency overrides weren't working as expected and I could not override my database info for the tests :(

But let's assume your answer would be correct, so I will close the issue :)

davidkartuzinski commented 3 years ago

@Acerinth - Cool. I understand. In case you're interested, I have tests set-up like this: https://github.com/open-apprentice/ellie-platform/blob/main/tests/test_app.py. I am still new to testing but this does work. I am using Postgres for my production DB and sqlite for testing.