如何自定义swagger-ui?

How to customize swagger-ui?

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

C:\swagger-ui\target\swagger-ui-2.1.0-M1\WEB-INF\lib\swagger-ui-2.1.8-M1.jar

并将新建的页面另存为index2.html,在里面的html内容中添加一行,并添加到上面的jar文件中。

但是我注意到它有一个原index.html文件的.gz文件,不知道它的用途,所以我也制作了一个名为index2.html.gz的文件并添加了它到上面的 jar 文件,然后 运行 码头服务器,并加载 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

您究竟想在 Swagger-UI 中更改什么?我自己一直在摆弄 branding/customizing Swagger。如果您查看 swagger-ui.js 文件,您会发现它有 30,000 多行代码并且组织不当。他们还使用我不熟悉的车把和 backbone.js。页面呈现后,我通过简单地操作 DOM 添加了一些自定义功能。我通过编写一个添加到 index.html.

的 JS 文件来做到这一点
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