Skip to content

Endpoint duplicated in documentation #364

@hmarcuzzo

Description

@hmarcuzzo

Description
I am using the @cbv decorator from fastapi-utils together with dependency_injector to avoid repeating the same dependency injections in each endpoint. However, when I register my router with @cbv(user_router), the endpoint appears twice in the OpenAPI documentation.

Here is the general structure of my code:

user_router = APIRouter(prefix="/user", tags=["Users"])

@cbv(user_router)
class UserController:
    @inject
    def __init__(self, user_service: UserService = Depends(Provide["user_service"])):
        self.user_service = user_service

    @user_router.post("/create")
    async def create_user(self, ...):
        return await self.user_service.create_user(...)

I then include this user_router inside another router (e.g., user_module_router.include_router(user_router)) and finally include that module router into my main application, like so:

app.include_router(user_module_router)

Despite confirming that this router is included only once, the endpoint POST /user/create is still listed twice in the OpenAPI documentation.

How can I avoid having the same endpoint duplicated in the OpenAPI docs while still using @cbv?
Is it possible to configure fastapi-utils or @cbv in such a way that I do not have to declare dependency injection in every single endpoint, yet also do not experience duplicated routes in the generated documentation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions