【问题标题】:Customize Swagger Document Generation自定义 Swagger 文档生成
【发布时间】:2015-04-21 10:34:52
【问题描述】:

我有一个带有以下配置的 spring boot 应用程序。

@Configuration
@EnableWebMvc
@ComponentScan({ "com.xxx.mypackages" })
public class MyWebAppConfiguration extends WebMvcConfigurerAdapter {

}

在我的项目中,我有一些网络服务和弹簧控制器。我希望仅在我的 Web 服务类中启用 swagger。目前,它为 rest 和 controller 类生成文档。如何自定义?

我在 gradle 中使用以下依赖项。

compile "com.mangofactory:swagger-springmvc:1.0.2"

【问题讨论】:

    标签: spring-mvc spring-boot swagger


    【解决方案1】:

    如果您查看1.0.2 documentation,您会发现SwaggerSpringMvcPlugin 有一个includePatterns 方法。此方法采用要包含的路径的正则表达式。例如如果你有一个像 /rest/some-resource.... 这样的其余端点的路径前缀,你可以包含一个模式,如下所示的 sn-p

    @Bean
    public SwaggerSpringMvcPlugin customImplementation(){
        return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
        //... more config goes here
              //regex to identify your rest services path
              .includePatterns(".*rest.*"); 
    }
    

    此外,知道我们将很快成为releasing 2.0 并支持swagger spec 2.0 也会很有用。这可能也是需要考虑的事情。

    【讨论】:

      猜你喜欢
      • 2015-11-25
      • 2021-02-22
      • 2017-08-06
      • 2016-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多