[英]python server stub generated from swagger-codegen is simply not working locally
我在线从swagger 编辑器的 swagger-codegen 生成 python 服务器存根,我想在本地运行生成的Not Found
服务器存根错误,但它不工作并且端点给了我错误。 我查看了 swagger 社区,没有找到与此相关的单个问题。 基本上,我在yaml
文件中使用了 openapi 规范来生成 python 服务器存根,但生成的服务器存根不能在本地运行。 我不知道发生了什么事。 有没有人遇到过这个问题? 从可以在本地运行和测试的 swagger-codegen 生成 python 服务器存根的正确方法是什么? 任何想法?
openapi 规范文件
yaml 文件的开头如下:
openapi: 3.0.2
info:
title: api
description: test api
contact:
name: python server
url: /api/v1/
email: info@gmail.com
version: 1.0.0
servers:
- url: /api/v1/
description: SwaggerHub API Auto Mocking
- url: /api/v1/
description: IMM AWS Server 1
我使用此 yaml 文件生成了 python 服务器存根,但生成的 python 服务器存根不起作用,无法从 ZDDFCZ6/7cmdA67BDD75EE 本地运行。 任何想法使这项工作? 任何可能的想法?
更新
这是我尝试过的:
venv) C:\Users\kim\photoalbum_api>python -m swagger_server
The swagger_ui directory could not be found.
Please install connexion with extra install: pip install connexion[swagger-ui]
or provide the path to your local installation by passing swagger_path=<your path>
The swagger_ui directory could not be found.
Please install connexion with extra install: pip install connexion[swagger-ui]
or provide the path to your local installation by passing swagger_path=<your path>
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
所以我做了pip install connexion[swagger-ui]
并尝试在本地运行它,但端点总是给我这个:
出于可重现的目的,我还测试了这个openapi 规范文件以生成 python 服务器存根,但它不能正常工作。 为什么? 任何想法使这项工作? 谢谢
新更新:
即使我尝试使用http://localhost:8080/
,端点总是给我这个:
(venv) C:\Users\kim\photouser_api>python -m swagger_server
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 198-543-983
* Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
127.0.0.1 - - [16/May/2020 12:13:51] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [16/May/2020 12:14:02] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [16/May/2020 12:14:05] "GET /api HTTP/1.1" 404 -
127.0.0.1 - - [16/May/2020 12:14:10] "GET /api/v1 HTTP/1.1" 404 -
127.0.0.1 - - [16/May/2020 12:14:14] "GET /api/v1/ HTTP/1.1" 404 -
127.0.0.1 - - [16/May/2020 12:15:14] "GET / HTTP/1.1" 404 -
为了让它在我的机器上工作,我克隆了你的 repo openapi.yaml 。 然后我在您的 openapi.yaml 中将 url 修改为 /api/v1/,并在您的requirements.txt中将连接更改为 2.6.0。 我创建了 virtualenv,并按照README.md中的说明安装了 requirements.txt,然后运行它。 在浏览器中,我输入http://localhost:8080/api/v1/ui这应该会显示 swagger ui。 我还尝试了 docker 构建指令,这也有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.