[英]How to add custom annotation in swagger2 using with Springfox?
i am using swagger2 and i want to create new @ApiSepecificationInfo annotation and this should be consider in auto generator of swagger2 doc(like if i hit Gradlw generatordoc)我正在使用 swagger2,我想创建新的 @ApiSepecificationInfo 注释,这应该在 swagger2 文档的自动生成器中考虑(就像我点击 Gradlw generatordoc)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ApiSpecificationInfo {
String name();
String description();
}
please let me is this possible or not ?请让我这可能吗?
You can do custom annotation processing by implementing springfox plugins .您可以通过实现 springfox插件来进行自定义注释处理。
If you implement the OperationBuilderPlugin interface springfox is providing you with all information you need.如果您实现OperationBuilderPlugin接口,springfox 将为您提供您需要的所有信息。
@Component
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER)
public class OperationBuilderPluginImpl implements OperationBuilderPlugin {
@Override
public void apply(OperationContext context) {
Optional<ApiOperation> methodAnnotation = context.findAnnotation(ApiSpecificationInfo.class);
if (methodAnnotation.isPresent()) {
ApiSpecificationInfo apiSpecificationInfo = methodAnnotation.get();
// do your processing here
context.operationBuilder().notes(apiSpecificationInfo.name());
}
}
@Override
public boolean supports(DocumentationType delimiter) {
return SwaggerPluginSupport.pluginDoesApply(delimiter);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.