【问题标题】:Swagger UI has wrong base pathSwagger UI 的基本路径错误
【发布时间】:2014-11-11 13:50:27
【问题描述】:

我正在使用grape-swagger gem 和SwaggerUI 的独立安装。我的 API 文档位于 http://example.com/api/v1/docs/。 SwaggerUI 发现所有资源,但将所有请求发送到http://example.com/v1/foo(URL 中缺少“api/”)。这是为什么呢?

【问题讨论】:

    标签: rest swagger-ui


    【解决方案1】:

    如果有人遇到相同问题,请查看文档:grape-swagger 方法 add_swagger_documentation 的参数称为 base_path。就我而言,我必须指定

    base_path: '/api'
    

    【讨论】:

      【解决方案2】:

      在使用 maven 和 spring-boot ans swagger-ui 2.4.0 时遇到了同样的问题。 与 thymeleaf 等其他软件包在资源 url 方面可能不兼容可能是导致该问题的原因。

      作为一种解决方法,我可以通过像这样重新映射 url 来克服损坏的链接:

      @Configuration
      public class CustomResourceMapping extends WebMvcConfigurerAdapter  { 
          @Override
          public void addViewControllers(ViewControllerRegistry registry) {
              registry.addRedirectViewController(
              "/configuration/ui", 
              "/swagger-resources/configuration/ui");
              registry.addRedirectViewController(
              "/configuration/security", 
              "/swagger-resources/configuration/security");
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-20
        • 2020-05-12
        • 2020-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多