Swagger 如何定制大摇大摆的用户界面?
我正在学习招摇过市,试着做一点改变,看看它是否能反映在索引页面上。因此,起点是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文件中,然后运行jetty服务器,并加载index.html: 它显示的很好,然后我尝试加载:index2.html,但它找不到页面,为什么?我应该将其包括在何处,以便在以下位置显示: 错误消息是: HTTP错误404 访问/swagger ui/webjars/swagger ui/2.1.8-M1/index2.html时出现问题。原因:Swagger 如何定制大摇大摆的用户界面?,swagger,webjars,Swagger,Webjars,我正在学习招摇过市,试着做一点改变,看看它是否能反映在索引页面上。因此,起点是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文件,不知道它的用途,所以我还创建了一个名为inde
Not Found
你到底想在大摇大摆的用户界面中改变什么?我自己一直在搞品牌/定制招摇。如果你看一看swagger-ui.js文件,你会发现它有30000多行代码,而且组织得很差。他们还使用了我不熟悉的Handlebar和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
[1] 创建:C:\swagger ui\petstore
[2] 将swagger.json复制到其中[这是您可以自定义的地方]
[3] 复制index.html并将其另存为:Swagger_Test.html到C:\Swagger ui\src\main\webapp[这是您可以自定义的地方]
[4] 将swagger-ui-2.1.8-M1.jar解包到:C:\swagger-ui\src\main\webapp
[5] 创建C:\swagger ui\src\main\webapp\css,并将原始index.html文件中提到的*.css和*.css.gz文件从C:\swagger ui\src\main\webapp移动到C:\swagger ui\src\main\webapp\css
[6] 创建C:\swagger ui\src\main\webapp\lib并将原始index.html文件中提到的*.js和*.js.gz文件从C:\swagger ui\src\main\webapp移动到C:\swagger ui\src\main\webapp\lib
[7] 可能会将原始index.html文件中的其他几个文件从C:\swagger ui\src\main\webapp移动到C:\swagger ui\src\main\webapp\css或C:\swagger ui\src\main\webapp\lib
[8] 从pom文件中注释掉以下内容
org.webjars
大摇大摆的用户界面
2.1.8-M1
[9] 在Swagger_Test.html文件中
替换:url=”http://petstore.swagger.io/v2/swagger.json";
使用:url=“/swagger ui/petstore/swagger.json”;
[10] 重新编译并启动服务器
[11] 加载页面:http://localhost:8080/swagger-ui/Swagger_Test.html
或:http://localhost:8080/swagger-ui/Swagger_Test.html?url=http://localhost:8080/swagger-ui/petstore/swagger.json