panch mukesh
panch mukesh

Reputation: 119

How to hide request object from fastapi swagger page

I do have a fastapi implementation where I'm using couple of decorators one for handling all the exceptions for graceful error response other for access control. Here I'm using the request object to check the state and headers. For this I had to pass the request as a parameter in the endpoint. However this is showing in the swagger which I don't want to show. Is there any way around where we can explicitly hide the request object.

@router.get(
        "/overview",
        response_model=Union[ModelOverview],
        responses={HTTPStatus.BAD_REQUEST.value: {api_c.MODEL: Message}},
    )
    @api_error_handler()
    @requires_access_levels(access_levels=[
                api_c.REQUIRED_ACCESSES
            ])
    def get_tasks_overview(
        self,
        request: Request, # Hide this from Swagger
        start_date: str = None,
        end_date: str = None,
        user_id: str = None,
        group_by: str = None,
    ) -> JSONResponse:

I have tried using Depends(creating a dummy method to return None), Query, Header nothing working as Request object is Pydantic model which is not accepting custom handler.

Upvotes: 0

Views: 1581

Answers (1)

Geek Logbook
Geek Logbook

Reputation: 616

You should Exclude from OpenAPI

To exclude a query parameter from the generated OpenAPI schema (and thus, from the automatic documentation systems), set the parameter include_in_schema of Query to False

Exclude from OpenAPI

Upvotes: 1

Related Questions