简体   繁体   中英

How do you generate a live Swagger API page for your hosted Swagger API?

I have created an API using Swagger .

My customers will be able to make calls to my service like

https://theservice.com/data/items/category1/12345

This is fine and works ok.

However, I would like to have a page where they can see all available API calls, similar to how Swagger generates it on their SwaggerEditor app . For example by visiting https://theservice.com/index.html I would like them to see the API docs.

Is it possible (within Swagger) to do this on a live system (not just locally with swagger project edit which I already know)? If yes, how?

It sounds like you're using the Swagger Editor to describe your API, then generating some scaffolding code using the built-in generator. From your tags, I assume this is node.js code. You'll need to add your own logic to the generated code to complete this API implementation (if you haven't already done so).

If this is correct, then the interactive Swagger-UI documentation you're looking for should be available in your generated API at /docs endpoint, relative to the base URL of your running service.

The generated node.js project includes the Swagger spec you created in the editor, and uses Swagger-Tools to do the runtime magic. Among other things, Swagger-Tools auto-wires your Swagger spec to the /docs endpoint, and manages routing of requests to the generated controllers, based on information provided in your Swagger spec.

Note that the /docs page will look and behave somewhat differently from the documentation widget you see in the Swagger editor. The one in your application uses Swagger-UI , which is the runtime component for documentation, with interactive sandbox testing. Swagger-Editor has its own built-in documentation UI, and this is not currently packaged for use outside of the Swagger-Editor.

If you've already implemented an API, independent of the Swagger editor and code generator, you can still generate node.js code to see how to incorporate Swagger-Tools into your existing API implementation. Or, as wing328 suggests, take a look at Swagger-UI to see how you can add your own documentation page.

I think what you're looking for is swagger-ui and here is an example: http://petstore.swagger.io/

As you can see, it not only lists out all the available API endpoints but also lets visitors (developers) to try it out directly in the web page.

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