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

一曲冷凌霜 提交于 2019-12-01 00:50:08

问题


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?


回答1:


If you're going to customize swagger-ui quite a bit, I would just recommend adding a private copy of swagger-ui to your web application resources and modify the ui based on your needs.

Swagger-ui bundled with springfox is optional.




回答2:


  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




回答3:


Yes, pull the swagger ui into your project and follow the steps here: https://github.com/springfox/springfox/issues/1176

Then edit the index.html and change where it points to the petstore to your endpoint. ( i.e. "http://localhost:8080/MyProjectName/v2/api-docs");

 $(function () {
  var url = window.location.search.match(/url=([^&]+)/);
  if (url && url.length > 1) {
    url = decodeURIComponent(url[1]);
  } else {
    url = "http://petstore.swagger.io/v2/swagger.json";


来源:https://stackoverflow.com/questions/36165448/how-can-i-modify-swagger-ui-html-for-springfox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!