How to integrate swagger-ui in my application

2019-02-16 14:08发布

I am trying to integrate swagger with camel project

following this example https://github.com/smparekh/camel-example-servlet-rest-tomcat

How do i access swagger-ui using this example project ?

I delopyed the war file in tomcat.

and access http://localhost:8080/camel-example-servlet-rest-tomcat/api-docs i get this ...

{"apiVersion":"1.2.3","swaggerVersion":"1.2","apis":[{"path":"/user","description":"User rest service"}],"info":{"title":"User Services","description":"Camel Rest Example with Swagger that provides an User REST service"}}

BUT MY QUESTION IS - how do i access swagger-ui/index.html?

what is the exact URL to access swagger-UI?

5条回答
▲ chillily
2楼-- · 2019-02-16 14:27

These are your Swagger Docs:

{"apiVersion":"1.2.3","swaggerVersion":"1.2","apis":[{"path"...

Now you need Swagger-UI to consume them. You can install it anywhere. There is no hard requirement that you put Swagger-UI in your project. You just need to edit the index.html file to point to your docs path (the JSON output above.)

查看更多
啃猪蹄的小仙女
3楼-- · 2019-02-16 14:34

You must copy the contents of the dist folder of swagger-ui into your project's webapp folder.

In index.html,

  window.swaggerUi = new SwaggerUi({
  url: "http://petstore.swagger.wordnik.com/api/api-docs",
  dom_id: "swagger-ui-container",

you must replace url with this

 http://localhost:8080/camel-example-servlet-rest-tomcat/api-docs

For details, Follow this link to integrate swagger-ui.

https://github.com/swagger-api/swagger-ui

查看更多
神经病院院长
4楼-- · 2019-02-16 14:34

You should use http://localhost:${port}/${contextPath}/swagger/index.html

查看更多
可以哭但决不认输i
5楼-- · 2019-02-16 14:43

http://localhost:8080/camel-example-servlet-rest-tomcat/{basepath}/dist/index.html if you have copied dist folder as is. If you have renamed dist folder, use the new name instead of dist. replace basepath with basepath you have configured in web.xml. The code snippet for that looks like this:

<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>/rest</param-value>
</init-param>
查看更多
孤傲高冷的网名
6楼-- · 2019-02-16 14:46

To access swagger2 it is

http://localhost:${port}/${contextPath}/swagger-ui.html
查看更多
登录 后发表回答