diff --git a/.gitignore b/.gitignore index 91418e1..ce4c783 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules .docusaurus build/** .idea +/*.iml diff --git a/docs/configuration/customizing.md b/docs/configuration/customizing.md index 17ebf30..9df7459 100644 --- a/docs/configuration/customizing.md +++ b/docs/configuration/customizing.md @@ -23,7 +23,7 @@ All default implementations are Spring managed beans, which can be overridden. ## `AsyncApiCustomizer` - Full AsyncAPI document -By implementing the `AsyncApiCustomizer`, the AsyncAPI document can be modified after Springwolf has done all the scanning and has built the document. +By implementing the `AsyncApiCustomizer` interface, the AsyncAPI document can be modified after Springwolf has done all the scanning and has built the document. It's the final interception point before the document is available to the user. For example, the title can be adjusted - although this should be done through the configuration: @@ -38,6 +38,33 @@ public class AsyncApiTitleCustomizer implements AsyncApiCustomizer { } ``` +## `OperationCustomizer` - Operation object + +By implementing the `OperationCustomizer` interface, the Operation object can be modified after Springwolf has scanned an +annotated method and extracted the data. + +It's possible to create multiple implementations of `OperationCustomizer`. +The order of execution can be controlled by the `@Order` annotation of Spring. + +An example to conditionally add a custom AsyncAPI `tag` for Kafka batch listeners is shown below: + +```java +@Component +public class TagCustomizer implements OperationCustomizer { + + @Override + public void customize(Operation operation, Method method) { + KafkaListener annotation = AnnotationScannerUtil.findAnnotation(KafkaListener.class, method); + if (annotation != null && "true".equals(annotation.batch())) { + Tag tag = new Tag(); + tag.setName("batch"); + + operation.getTags().add(tag); + } + } +} +``` + ## ObjectMapper in `DefaultAsyncApiSerializerService` The `DefaultAsyncApiSerializerService` is responsible for serializing the AsyncAPI document into a `String` for the Controller. @@ -49,3 +76,16 @@ Use `DefaultAsyncApiSerializerService#getJsonObjectMapper()` and `DefaultAsyncAp All `ChannelScanner` beans are called to scan for channels. This interface is helpful when a protocol currently unsupported by Springwolf is used. Remember to register all payloads in the `ComponentsService`. + +## Customize internal behavior + +:::note +Replacing Springwolf beans with custom implementations is for experts only. +**No** support is offered for using internal API. + +Custom implementations may break during updates without notice. +::: + +Springwolf uses `@ConditionalOnMissingBean` annotations for most internal Spring beans. +If you have a special use-case that requires custom logic, +you can replace almost every Springwolf bean by adding your custom implementation as a bean to the Spring context.