我正在尝试使用Swagger/Flask/Connexion构建一个简单的应用程序接口,但是他们的GitHub上的示例不起作用,即使在按照指定的here安装Connexion Swagger-ui之后也是如此。
pip3 install 'connexion[swagger-ui]'这是我的helloworld-api.yaml:
openapi: "3.0.0"
info:
title: Hello World
version: "1.0"
servers:
- url: http://localhost:9090/swagger
paths:
/greeting:
get:
summary: Generate greeting
description: Generates a greeting message.
operationId: hello.get_greeting
responses:
200:
description: greeting response
content:
text/plain:
schema:
type: string
example: "hello dave!"
parameters:
- in: query
name: name
required: true
schema:
type: string
example: "dave"
description: Name of the person to greet.还有我的hello.py
#!/usr/bin/env python3
import connexion
def get_greeting(name: str) -> str:
return f'Hello {name}'
if __name__ == '__main__':
app = connexion.FlaskApp(__name__, specification_dir='openapi/')
app.add_api('helloworld-api.yaml', arguments={'title': 'Hello World Example'})
app.run(port=8080)hello.py在根目录中,helloworld-api.yaml在一个名为openapi/的文件夹中。在浏览器中导航到0.0.0.0:8080/swagger将返回以下内容:
{
"detail": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
"status": 404,
"title": "Not Found",
"type": "about:blank"
}我指定的get方法也是如此。有什么想法吗?我一直在为这件事碰壁。
发布于 2021-11-06 11:07:02
您使用了错误的修补程序,要访问Swagger UI,您必须访问0.0.0.0:8080/ui/中的{base_path}/ui/
您可以查看文档的https://connexion.readthedocs.io/en/latest/quickstart.html#the-swagger-ui-console
https://stackoverflow.com/questions/69836189
复制相似问题