I am using springfox's swagger implementation. I would like to modify the swagger-ui.html to take a custom header value. How do I modify this file? Or tell spring fox to use an alternate file?
You can define custom layouts in order to have high-level control over what ends up on the page. By default, Swagger UI uses BaseLayout , which is built into the application. You can specify a different layout to be used by passing the layout's name as the layout parameter to Swagger UI.
Customize the Swagger UI Using Style Sheet Right click on SwaggerStyle. css file and select Embedded Resource option for Build Action as shown below. Here I added CSS class in SwaggerStyle. css file as shown below.
By default, web servers default to the index. html file in the directory, so it will show the Swagger UI file automatically. If the browser doesn't direct to index. html , add it manually: http://localhost:8000/index.html .
When you open the webpage, the browser will load the webpage from the web server, and trigger requests to the API server to get data from a database. SwaggerUI is automatically generated from any API defined in the OpenAPI Specification and can be viewed within a browser.
Pull Swagger UI from github.
https://github.com/swagger-api/swagger-ui
Copy & paste dist directory of swagger ui to resources directory
Replace the code with below in swagger config
replace
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
with
registry.addResourceHandler("**").addResourceLocations("classpath:/dist/");
Change the api docs path in index.html to your path
Replace
http://petstore.swagger.io/v2/swagger.json
With
http://localhost:8080/your_app/v2/api-docs
Use the below url pattern to see the ui page
http://localhost:8080/your_app/index.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With