Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify swagger-ui.html for springfox?

Tags:

springfox

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?

like image 380
mad_fox Avatar asked Mar 22 '16 21:03

mad_fox


People also ask

Can we customize Swagger UI?

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.

How can I modify Swagger?

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.

How do I access Swagger UI in HTML?

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 .

How Swagger UI HTML is generated?

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.


1 Answers

  1. Pull Swagger UI from github.

    https://github.com/swagger-api/swagger-ui

  2. Copy & paste dist directory of swagger ui to resources directory

  3. 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/");
    
  4. 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
    
  5. Use the below url pattern to see the ui page

    http://localhost:8080/your_app/index.html

like image 130
pvrforpranavvr Avatar answered Nov 14 '22 04:11

pvrforpranavvr