简体   繁体   English

如何挂钩swagger-ui

[英]How to hook up swagger-ui

I'm trying to hook in swagger-ui into a java dynamic web project. 我正在尝试将swagger-ui挂接到Java动态Web项目中。 Currently, the rest api works and I am able to hit the following url and see the json: http://localhost:8080/test/swagger.json 目前,其余的api都可以正常工作,并且我能够访问以下URL并查看json: http:// localhost:8080 / test / swagger.json

My project uses Java, Swagger, Wildfly, and RestEasy. 我的项目使用Java,Swagger,Wildfly和RestEasy。

public class SwaggerServlet extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);

        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setVersion("1.0.0");
        beanConfig.setSchemes(new String[] { "http" });
        beanConfig.setHost("localhost:8080");
        beanConfig.setBasePath("/test");
        beanConfig.setResourcePackage("com.test.rest");
        beanConfig.setScan(true);
    }
}

Following the tutorial found at this link: http://kjkrol.blogspot.ca/2015/01/how-to-integrate-swagger-ui-with-java.html to hook up swagger ui doesn't seem to work for me. 遵循在此链接上找到的教程: http : //kjkrol.blogspot.ca/2015/01/how-to-integrate-swagger-ui-with-java.html连接swagger ui似乎对我不起作用。 I downloaded swagger-ui repo from github. 我从github下载了swagger-ui repo。 I created a swagger folder in the following location: 我在以下位置创建了一个swagger文件夹:

my-project/src/main/webapp/swagger my-project / src / main / webapp / swagger

In the swagger folder, copied the dist folder from the swagger-ui project. 在swagger文件夹中,从swagger-ui项目复制dist文件夹。 I also edited the URL as the tutorial suggests: 我还按照本教程的建议编辑了URL:

  // Build a system
  const ui = SwaggerUIBundle({
    url: "test/api-docs",
    dom_id: '#swagger-ui',

I ended up following an example found at this link: https://github.com/K0NRAD/swagger-wildfly-resteasy 我最终在此链接找到一个示例: https : //github.com/K0NRAD/swagger-wildfly-resteasy

It works! 有用! I noticed that the documentation takes a slightly different approach that for some reason wasn't working for me... 我注意到该文档采用了稍微不同的方法,由于某种原因,该方法对我不起作用...

Thanks everyone! 感谢大家!

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

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