uriyyo/fastapi-pagination

Using add_pagination breaks the custom OpenAPI configuration.

mmzeynalli opened this issue · 4 comments

So, in my project, I have a custom openAPI config:

def custom_openapi(app: Any) -> Any | Dict[str, Any]:
    """OpenApi settings"""
    if app.openapi_schema:
        return app.openapi_schema

    openapi_schema = get_openapi(
        title=settings.APP_TITLE,
        version=settings.API_VERSION,
        description=settings.APP_DESCRIPTION,
        routes=app.routes,
    )
    openapi_schema['components']['securitySchemes'] = {
        'Bearer Auth': {
            'type': 'http',
            'scheme': 'bearer',
            'in': 'header',
            'bearerFormat': 'JWT',
            'name': 'Authorization',
            'description': "Enter: **'<JWT>'**, where JWT is the access token",
        },
    }
    app.openapi_schema = openapi_schema

    return app.openapi_schema

Which worked all well until I added the add_pagination(app) line to the code. It does not matter if this function is before or after the custom_openapi call.

Before add_pagination was added:
image

After add_pagination was added:
image

Hi @mmzeynalli,

Could you please put your openapi schema patch inside lifespan?

@asynccontextmanager
async def lifespan(app: FastAPI):
    custom_openapi(app)
    yield

app = FastAPI(lifespan=lifespan)

It works, but I would ask for a fix, as this is a workaround. Thanks though.

Hi @mmzeynalli,

New version 0.12.22 has been released, this issue should be fixed.

Hi @mmzeynalli,

I'm closing this issue, please reopen it in case if issue still appears on your side.