简体   繁体   English

从 swagger-codegen 生成的 python 服务器存根根本无法在本地工作

[英]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.

相关问题 Swagger-codegen flask 在本地生成的服务器不起作用 - Swagger-codegen flask generated server locally doesn't works 将生成的Flask应用程序代码(Swagger-Codegen)粘合到后端实现的最简洁方法 - cleanest way to glue generated Flask app code (Swagger-Codegen) to backend implementation 无法运行由 swagger codegen 生成的服务器 - failed to run the server that generated by swagger codegen Swagger Codegen .swagger-codegen-ignore不起作用 - Swagger codegen .swagger-codegen-ignore not working 使用龙卷风在Connexion(Swagger Codegen)Python服务器中异步 - Async in connexion (swagger codegen) python server using tornado DJANGO:如何渲染 swagger-codegen model 对象而不是数据库 model ZA8CFDE63931BD59EB26ACZ6 - DJANGO: How to Render swagger-codegen model objects instead of database model object 如何在Swagger Codegen 3.x生成的Python API客户端中设置Bearer token? - How to set the Bearer token in the Python API client generated by Swagger Codegen 3.x? Swagger Codegen授权用于Python-Flask - Swagger Codegen Authorisation for Python-Flask 是否可以在 python/flask 服务器存根中的 Swagger 验证之前运行自定义代码? - Is it possible to run custom code before Swagger validations in a python/flask server stub? 将令牌授权装饰器添加到 swagger python 服务器存根端点的任何解决方法 - any workaround to add token authorization decorator to endpoint at swagger python server stub
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM