简体   繁体   English

如何使用 Springfox 在 swagger2 中添加自定义注释?

[英]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);
    }
}

See github for reference.请参阅github以供参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Springfox Swagger2-@ApiOperation不起作用 - Springfox Swagger2 - @ApiOperation not working 使用springfox和Swagger2时,为什么v2 / api-docs是默认URL? - Why is v2/api-docs the default URL when using springfox and Swagger2? 如何使用springfox在Swagger UI中绕过授权 - How to bypass Authorization in Swagger UI using springfox Swagger2:无法自省 Class [springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration] - Swagger2: Failed to introspect Class [springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration] 如何使用SpringBoot和SpringFox在Swagger中将声明的主体类型从String更改为自定义DTO类型 - How to change declared body type from String to custom DTO type in Swagger using SpringBoot and SpringFox Spring swagger2:如何设置 HTTPS 协议? - Spring swagger2: how to set HTTPS protocol? swagger2 多态性:将抽象类列表添加到 swagger 文档中 - swagger2 polymorphisme: add list of abstract classes to swagger documentation Springfox/Swagger 中用于返回 ObjectNode 的自定义 ResponseModel - Custom ResponseModel in Springfox/Swagger for returning of ObjectNode 当属性具有 @XmlJavaTypeAdapter 注释时,使用 Swagger/Springfox 更正数据类型 - Correct data type with Swagger/Springfox when property has @XmlJavaTypeAdapter annotation 如何使用ASM添加自定义注释 - How to add a Custom Annotation using ASM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM