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

mad_fox picture mad_fox · Mar 22, 2016 · Viewed 20.6k times · Source

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?

Answer

pvrforpranavvr picture pvrforpranavvr · Jan 23, 2018
  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