How to set up swagger-ui?
I'm researching swagger, trying to make a small change and see if it can be reflected in the index page. So the starting point is the index.html page, I made a copy of it from the jar file:
C: \ swagger-ny \ target \ swagger-ny-2.1.0-M1 \ WEB-INF \ lib \ swagger-ny-2.1.8-M1.jar
and saved the new page as index2.html, added the line to the html content inside and added it to the above jar file.
But I noticed that it has a .gz file for the original index.html file, don't know its purpose, so I also made a file called index2.html.gz and added it to the above jar file, then start the jetty server and load index .html: http: // localhost: 8080 / swagger-ui / webjars / swagger-ui / 2.1.8-M1 / index.html
This seemed fine to me, then I tried to load: index2.html but it couldn't find the page, why? Where should I enable it so that it appears at: http: // localhost: 8080 / swagger-ui / webjars / swagger-ui / 2.1.8-M1 / index2.html
Error message:
HTTP ERROR 404
Problem accessing / swagger -ui / webjars / swagger-ui / 2.1.8-M1 / index2.html. Cause:
Not Found
source to share
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
source to share
What exactly are you trying to change in Swagger-UI? I've been messing around with Swagger branding / customization. If you look at the swagger-ui.js file, you can see that it contains 30,000 lines of code and is poorly organized. They also use rudders and backbone.js which I am not familiar with. I added some custom functionality just by manipulating the DOM after the page was rendered. I did this by writing a JS file that was added to index.html.
source to share