how to generate swagger 2.0 documentation for FastAPI

Viewed 1225

I am using FastAPI to develop a microservice and deploy it to Cloud Run. I am adding API Gateway in front of API Gateway. While creating API Gateway, it is asking me to upload API Spec file. Because I am using FastAPI, the documentation that is being generated is for 3.0.2.

I tried to override custom_openapi definition and provide openapi_version but it does not work and I am getting an error saying

Unable to render this definition The provided definition does not specify a valid version field.

Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.0.n (for example, openapi: 3.0.0).

This is how my custom_openapi definition looks like:

def custom_openapi():
    if app.openapi_schema:
        return app.openapi_schema
    openapi_schema = get_openapi(
        title="Custom title",
        version="2.5.0",
        description="This is a very custom OpenAPI schema",
        routes=app.routes,
        openapi_version="swagger:2.0" # I have tried 2.0

    )

Is there a way I can generate Swagger 2.0 documentation for my FastAPI?

0 Answers
Related