简体   繁体   English

如何在本地运行 REST API 服务器和 Swagger?

[英]how to run REST API Server with Swagger locally?

I coded all my api codebase using flask-restplus and I want to integerate this with swagger server code artifact.我使用 flask-restplus 对我所有的 api 代码库进行了编码,我想将其与 swagger 服务器代码工件进行整合。 For the reference, I used this openapi specification file on github and generated swagger server using swagger editor online, which basically create server code artifacts nicely.作为参考,我在 github 上使用了这个openapi 规范文件,并使用在线swagger 编辑器生成了 swagger 服务器,这基本上很好地创建了服务器代码工件。 I want to integerate my code in flask-restplus to generated swagger server code together.我想在 flask-restplus 中整合我的代码以一起生成 swagger 服务器代码。 when I tried to run this from python terminal locally, I had following error:当我尝试从本地 python 终端运行它时,出现以下错误:

{
  "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"
}

funny thing is I could run my own flask-restplus api locally, I could open server endpoint.有趣的是我可以在本地运行我自己的 flask-restplus api,我可以打开服务器端点。 but I can't run swagger server which is generated based on openapi specification file from swagger editor.但我无法运行 swagger 服务器,它是根据 swagger 编辑器的 openapi 规范文件生成的。 why?为什么? what's the solution to run swagger server locally?在本地运行 swagger 服务器的解决方案是什么? I did try of using different host and post but still can't open swagger server.我确实尝试过使用不同的主机和帖子,但仍然无法打开 swagger 服务器。 any idea about this?对此有什么想法吗? thanks谢谢

update :更新

the point is I want to run swagger server artifact locally, then I can integerate my code-base in flask-restplus to this server, so I could have better shape.关键是我想在本地运行 swagger 服务器工件,然后我可以将我在 flask-restplus 中的代码库整合到这个服务器上,这样我就可以有更好的形状。 any idea to make this work?有什么想法让这个工作吗? thanks谢谢

my question is after I feed api specification file to swagger editor and download server codebase, how am I gonna run it from python console/cmd locally?我的问题是在我将 api 规范文件提供给 swagger 编辑器并下载服务器代码库之后,我如何从 python 控制台/cmd 在本地运行它? why I can't run by hitting python __main__.py ?为什么我不能通过点击python __main__.py来运行? what should I do?我应该怎么办? anyone can help me out?任何人都可以帮助我吗? thanks谢谢

Have you tried following the tutorial in this blog?您是否尝试按照此博客中的教程进行操作?

https://towardsdatascience.com/working-with-apis-using-flask-flask-restplus-and-swagger-ui-7cf447deda7f https://towardsdatascience.com/working-with-apis-using-flask-flask-restplus-and-swagger-ui-7cf447deda7f

You need to make sure the operationID in swagger matches your routes in your code.您需要确保 swagger 中的 operationID 与代码中的路由匹配。 I haven't used flask rest plus but I am using flask and connexion, and that usually the error I get when the routes name are different from the swagger documentation.我没有使用 flask rest plus 但我使用的是 flask 和连接,当路由名称与 swagger 文档不同时,这通常是我得到的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM