简体   繁体   English

如何在我的应用程序中集成swagger-ui

[英]How to integrate swagger-ui in my application

I am trying to integrate swagger with camel project 我试图将swagger与骆驼项目整合在一起

following this example https://github.com/smparekh/camel-example-servlet-rest-tomcat 按照这个例子https://github.com/smparekh/camel-example-servlet-rest-tomcat

How do i access swagger-ui using this example project ? 如何使用此示例项目访问swagger-ui?

I delopyed the war file in tomcat. 我在tomcat中删除了war文件。

and access http://localhost:8080/camel-example-servlet-rest-tomcat/api-docs i get this ... 并访问http:// localhost:8080 / camel-example-servlet-rest-tomcat / api-docs我得到这个...

{"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"}} {“apiVersion”:“1.2.3”,“swaggerVersion”:“1.2”,“apis”:[{“path”:“/ user”,“description”:“用户休息服务”}],“info”: {“title”:“用户服务”,“描述”:“提供用户REST服务的Swagger的Camel Rest示例”}}

BUT MY QUESTION IS - how do i access swagger-ui/index.html? 但我的问题是 - 如何访问swagger-ui / index.html?

what is the exact URL to access swagger-UI? 访问swagger-UI的确切URL是什么?

You must copy the contents of the dist folder of swagger-ui into your project's webapp folder. 您必须将swagger-ui的dist文件夹的内容复制到项目的webapp文件夹中。

In index.html, 在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 你必须用这个替换url

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

For details, Follow this link to integrate swagger-ui. 有关详细信息,请按照此链接集成swagger-ui。

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

http://localhost:8080/camel-example-servlet-rest-tomcat/ {basepath}/dist/index.html if you have copied dist folder as is. http:// localhost:8080 / camel-example-servlet-rest-tomcat / {basepath} /dist/index.html如果您按原样复制了dist文件夹。 If you have renamed dist folder, use the new name instead of dist. 如果您已重命名dist文件夹,请使用新名称而不是dist。 replace basepath with basepath you have configured in web.xml. 将basepath替换为您在web.xml中配置的basepath。 The code snippet for that looks like this: 该代码片段如下所示:

<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>/rest</param-value>
</init-param>

您应该使用http://localhost :${port}/${contextPath}/swagger/index.html

These are your Swagger Docs: 这些是您的Swagger文档:

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

Now you need Swagger-UI to consume them. 现在你需要Swagger-UI来使用它们。 You can install it anywhere . 你可以在任何地方安装它。 There is no hard requirement that you put Swagger-UI in your project. 没有硬性要求将Swagger-UI放入项目中。 You just need to edit the index.html file to point to your docs path (the JSON output above.) 您只需编辑index.html文件以指向您的文档路径(上面的JSON输出。)

要访问swagger2

http://localhost:${port}/${contextPath}/swagger-ui.html

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

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