How do you look at such a solution?:
user_router = APIRouter(
prefix="/user", tags=["users"]
)
user_router.tags_metadata = [
{
"name": "users",
"description": "Operations with users. The **login** logic is also here.",
}
]
I am extending the APIRouter class in this way. Then, when adding all routers, I will use the function and connect the tags.
def collect_openapi_tags(*routers):
tags = []
for router in routers:
if hasattr(router, 'tags_metadata'):
tags.extend(router.tags_metadata)
return tags
app = FastAPI
app.openapi_tags = collect_openapi_tags(user_router)
It is frightening that the ApiRouter class does not imply the presence of the tags_metadata parameter. Does the approach have a place to be?
I was looking for similar solutions, but I didn’t find them.
New contributor
Артур Шаймарданов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.