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)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ApiSpecificationInfo {
String name();
String description();
}
please let me is this possible or not ?
React Full Stack Web Development With Spring Boot Swagger2 is an open source project used to generate the REST API documents for RESTful web services. It provides a user interface to access our RESTful web services via the web browser.
Springfox works by examining an application, once, at runtime to infer API semantics based on spring configurations, class structure and various compile time java Annotations.
In mid-2020 the version 3.0 of SpringFox was released and it supports Spring 5 and OpenAPI 3.
You can do custom annotation processing by implementing springfox plugins.
If you implement the OperationBuilderPlugin interface springfox is providing you with all information you need.
@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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With