简体   繁体   中英

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. 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. I want to integerate my code in flask-restplus to generated swagger server code together. when I tried to run this from python terminal locally, I had following error:

{
  "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. but I can't run swagger server which is generated based on openapi specification file from swagger editor. why? what's the solution to run swagger server locally? I did try of using different host and post but still can't open swagger server. 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. 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? why I can't run by hitting 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

You need to make sure the operationID in swagger matches your routes in your code. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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