1
在我的Spring(4.3.2)项目中,我使用Swagger(2.7.0)为我的项目自动生成文档和swagger-ui。迄今为止这很有效。如何确认swagger来处理自定义Controller级别的PathVariable注释?
但是现在我确定我需要能够在控制器级别(而不是方法级别)声明路径变量。我需要教大家发现这些路径变量并将它们添加到文档和swagger-ui中。
我创建定制标注
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface HasCommonPathVariable {
/**
* The URI template variable to bind to.
*/
String name();
Class<?> type();
String defaultValue() default "";
}
而我使用它是这样的:
@RestController
@Secured(SecurityConstants.ROLE_USER)
@RequestMapping(path = "/rest/api/v1/env/{envId}/asset-type")
@HasCommonPathVariable(name = "envId", type = Long.class)
public class AssetTypeRestController extends CustomRestControllerBase<Long, AssetTypeRow, AssetTypeService> {
// ... contorller code
}
我没有与Spring的PathVariable注释中提到的参数控制方法,和点我不允许这么做(这是因为我正在构建微观框架)。
所以问题是:如何教大摇大摆发现路径变量描述使用自定义注释HasCommonPathVariable
在控制器级应用?