报错“Please indicate a valid Swagger or OpenAPI version field”
报错“Please indicate a valid Swagger or OpenAPI 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).
原因分析
根据报错信息,分析是没指定版本信息
代码修改
def custom_openapi(): if application.openapi_schema: return application.openapi_schema openapi_schema = get_openapi( description=settings.DESCRIPTION, version=settings.VERSION, title=settings.PROJECT_NAME, routes=app.routes, ) openapi_schema["openapi"] = "3.0.0" openapi_schema["info"]["version"] = settings.VERSION openapi_schema["info"]["x-logo"] = { "url": "/static/logo-teal.png" } application.openapi_schema = openapi_schema return application.openapi_schema