如何自定义swagger-ui?

时间:2015-07-22 16:14:33

标签: swagger webjars

我正在学习招摇,尝试做一些改变,看看它是否可以在索引页面上反映出来。所以起点是index.html页面,我从jar文件中复制了它:

C:\招摇-UI \目标\招摇-UI-2.1.0-M1 \ WEB-INF \ lib中\招摇-UI-2.1.8-M1.jar

并将新页面保存为index2.html,在内部的html内容中添加了一行,并将其添加到上面的jar文件中。

但是我注意到它有原始index.html文件的.gz文件,不知道它的用途,所以我还创建了一个名为index2.html.gz的文件并将其添加到上面的jar文件中,然后运行jetty服务器,并加载index.html: http://localhost:8080/swagger-ui/webjars/swagger-ui/2.1.8-M1/index.html

它显示正常,然后我尝试加载:index2.html,但它找不到页面,为什么?我应该将它包含在哪里,以便显示在:http://localhost:8080/swagger-ui/webjars/swagger-ui/2.1.8-M1/index2.html

错误消息是:

HTTP错误404

访问/swagger-ui/webjars/swagger-ui/2.1.8-M1/index2.html时遇到问题。原因是:

Not Found

2 个答案:

答案 0 :(得分:1)

你想要在Swagger-UI中改变什么?我自己一直在搞乱品牌/定制Swagger。如果你看一下swagger-ui.js文件,你会发现它有30,000多行代码并且组织不良。他们也使用我不熟悉的把手和backbone.js。我通过简单地在页面渲染后操作DOM来添加一些自定义功能。我是通过编写一个添加到index.html的JS文件来完成的。

答案 1 :(得分:1)

I got it done with the following steps :

[1] Create : C:\swagger-ui\petstore
[2] Copy swagger.json into it [ This is where you can customize ]
[3] Copy the index.html and save it as : Swagger_Test.html into C:\swagger-ui\src\main\webapp [ This is where you can customize ]
[4] Unpack swagger-ui-2.1.8-M1.jar into : C:\swagger-ui\src\main\webapp
[5] Create C:\swagger-ui\src\main\webapp\css and move the *.css and  *.css.gz files mentioned in the original index.html file from C:\swagger-ui\src\main\webapp to C:\swagger-ui\src\main\webapp\css
[6] Create C:\swagger-ui\src\main\webapp\lib and move the *.js and *.js.gz files mentioned in the original index.html file from C:\swagger-ui\src\main\webapp to C:\swagger-ui\src\main\webapp\lib
[7] Maybe move another few files in the original index.html file from C:\swagger-ui\src\main\webapp to C:\swagger-ui\src\main\webapp\css or C:\swagger-ui\src\main\webapp\lib
[8] Comment out the following from the pom file

<dependency>
  <groupId>org.webjars</groupId>
  <artifactId>swagger-ui</artifactId>
  <version>2.1.8-M1</version>
</dependency>

[9] In the Swagger_Test.html file
    replace : url = "http://petstore.swagger.io/v2/swagger.json";
       with : url = "/swagger-ui/petstore/swagger.json";

[10] Recompile and start the server
[11] Load page : http://localhost:8080/swagger-ui/Swagger_Test.html
            or : http://localhost:8080/swagger-ui/Swagger_Test.html?url=http://localhost:8080/swagger-ui/petstore/swagger.json