我正在使用FastAPI开发微服务并将其部署到Cloud Run。我在API Gateway前添加了API Gateway。在创建API Gateway时,它要求我上传API规范文件。由于我使用的是FastAPI,生成的文档是3.0.2版本的。
我尝试覆盖custom_openapi定义并提供openapi_version,但无效,并且出现错误,提示如下:
无法呈现此定义,提供的定义未指定有效的版本字段。请指示有效的Swagger或OpenAPI版本字段。支持的版本字段为swagger:“2.0”和与openapi:3.0.n匹配的字段(例如openapi: 3.0.0)。
这是我的custom_openapi定义的样子:
有没有一种方法可以为我的FastAPI生成Swagger 2.0文档?
我尝试覆盖custom_openapi定义并提供openapi_version,但无效,并且出现错误,提示如下:
无法呈现此定义,提供的定义未指定有效的版本字段。请指示有效的Swagger或OpenAPI版本字段。支持的版本字段为swagger:“2.0”和与openapi:3.0.n匹配的字段(例如openapi: 3.0.0)。
这是我的custom_openapi定义的样子:
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
)
有没有一种方法可以为我的FastAPI生成Swagger 2.0文档?