自定义 Swagger 文档生成
Customize Swagger Document Generation
我有一个 spring 启动应用程序,配置如下。
@Configuration
@EnableWebMvc
@ComponentScan({ "com.xxx.mypackages" })
public class MyWebAppConfiguration extends WebMvcConfigurerAdapter {
}
在我的项目中,我有一些网络服务和 spring 控制器。我希望仅在我的 Web 服务 类 中启用 swagger。目前,它为 rest 和 controller 类 生成文档。我该如何自定义它?
我在 gradle 中使用了以下依赖项。
compile "com.mangofactory:swagger-springmvc:1.0.2"
如果您查看 1.0.2 documentation,您会发现 SwaggerSpringMvcPlugin
有一个 includePatterns 方法。此方法采用要包含的路径的正则表达式。例如如果你有一个像这样的其余端点的路径前缀 /rest/some-resource....
你可以包括一个模式,类似于下面显示的片段
@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 shortly with support for swagger spec 2.0 也会很有用。这可能也是需要考虑的事情。
我有一个 spring 启动应用程序,配置如下。
@Configuration
@EnableWebMvc
@ComponentScan({ "com.xxx.mypackages" })
public class MyWebAppConfiguration extends WebMvcConfigurerAdapter {
}
在我的项目中,我有一些网络服务和 spring 控制器。我希望仅在我的 Web 服务 类 中启用 swagger。目前,它为 rest 和 controller 类 生成文档。我该如何自定义它?
我在 gradle 中使用了以下依赖项。
compile "com.mangofactory:swagger-springmvc:1.0.2"
如果您查看 1.0.2 documentation,您会发现 SwaggerSpringMvcPlugin
有一个 includePatterns 方法。此方法采用要包含的路径的正则表达式。例如如果你有一个像这样的其余端点的路径前缀 /rest/some-resource....
你可以包括一个模式,类似于下面显示的片段
@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 shortly with support for swagger spec 2.0 也会很有用。这可能也是需要考虑的事情。