[英]python server stub generated from swagger-codegen is simply not working locally
I generated python server stub from swagger-codegen at swagger editor online, and I want to run generated python server stub locally but it is not working and endpoint gave me Not Found
error.我在线从swagger 编辑器的 swagger-codegen 生成 python 服务器存根,我想在本地运行生成的Not Found
服务器存根错误,但它不工作并且端点给了我错误。 I looked into swagger community, and not find single piece of issue related to this.我查看了 swagger 社区,没有找到与此相关的单个问题。 Basically, I used openapi spec in yaml
file to generate python server stub, but generated server stub can't be run locally.基本上,我在yaml
文件中使用了 openapi 规范来生成 python 服务器存根,但生成的服务器存根不能在本地运行。 I don't know what is going on.我不知道发生了什么事。 Is there anyone experienced with this issue?有没有人遇到过这个问题? what's the right way to generate python server stub from swagger-codegen which can be run and test locally?从可以在本地运行和测试的 swagger-codegen 生成 python 服务器存根的正确方法是什么? any idea?任何想法?
openapi spec file openapi 规范文件
here is how yaml file begins: 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
I generated python server stub by using this yaml file but generated python server stub is not working and can't run locally from python console/cmd.我使用此 yaml 文件生成了 python 服务器存根,但生成的 python 服务器存根不起作用,无法从 ZDDFCZ6/7cmdA67BDD75EE 本地运行。 any idea to make this work?任何想法使这项工作? any possible thought?任何可能的想法?
update更新
here is what I tried:这是我尝试过的:
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)
so I did pip install connexion[swagger-ui]
and try to run it locally, but endpoint always gave me this:所以我做了pip install connexion[swagger-ui]
并尝试在本地运行它,但端点总是给我这个:
for reproducible purpose, I also tested this openapi spec file to generate python server stub but it is not working as well.出于可重现的目的,我还测试了这个openapi 规范文件以生成 python 服务器存根,但它不能正常工作。 why?为什么? any idea to make this work?任何想法使这项工作? thanks谢谢
new update :新更新:
even I tried with http://localhost:8080/
, endpoint always give me this:即使我尝试使用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 -
To get it working in my machine, I cloned your repo openapi.yaml .为了让它在我的机器上工作,我克隆了你的 repo openapi.yaml 。 Then I modified the url to /api/v1/ in your openapi.yaml, and change the connexion to 2.6.0 in your requirements.txt .然后我在您的 openapi.yaml 中将 url 修改为 /api/v1/,并在您的requirements.txt中将连接更改为 2.6.0。 I created virtualenv and I followed the instructions in the README.md to install requirements.txt, and ran it.我创建了 virtualenv,并按照README.md中的说明安装了 requirements.txt,然后运行它。 In the browser, I type http://localhost:8080/api/v1/ui and this should show the swagger ui.在浏览器中,我输入http://localhost:8080/api/v1/ui这应该会显示 swagger ui。 I also tried the docker build instruction and this also works.我还尝试了 docker 构建指令,这也有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.