Skip to content

Commit 3f41143

Browse files
sam0r040timonback
andcommitted
docs: document usage of operation customizer and replacing Springwolf beans with +
custom implementations (#80) Co-authored-by: Timon Back <timonback@users.noreply.github.com>
1 parent cdd5a08 commit 3f41143

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
.docusaurus
44
build/**
55
.idea
6+
/*.iml

docs/configuration/customizing.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ All default implementations are Spring managed beans, which can be overridden.
2323

2424
## `AsyncApiCustomizer` - Full AsyncAPI document
2525

26-
By implementing the `AsyncApiCustomizer`, the AsyncAPI document can be modified after Springwolf has done all the scanning and has built the document.
26+
By implementing the `AsyncApiCustomizer` interface, the AsyncAPI document can be modified after Springwolf has done all the scanning and has built the document.
2727
It's the final interception point before the document is available to the user.
2828

2929
For example, the title can be adjusted - although this should be done through the configuration:
@@ -38,6 +38,32 @@ public class AsyncApiTitleCustomizer implements AsyncApiCustomizer {
3838
}
3939
```
4040

41+
## `OperationCustomizer` - Operation object
42+
43+
By implementing the `OperationCustomizer` interface, the Operation object can be modified after Springwolf has scanned an
44+
annotated method and extracted the data.
45+
46+
It is possible to create multiple implementations of `OperationCustomizer`.
47+
The order of execution can be controlled by the `@Order` annotation of Spring.
48+
49+
An example to conditionally add a custom AsyncAPI tag for Kafka batch listeners is shown bellow:
50+
51+
```java
52+
@Component
53+
public class TagCustomizer implements OperationCustomizer {
54+
55+
@Override
56+
public void customize(Operation operation, Method method) {
57+
KafkaListener annotation = AnnotationScannerUtil.findAnnotation(KafkaListener.class, method);
58+
if (annotation != null && annotation.batch().equals("true")) {
59+
Tag tag = new Tag();
60+
tag.setName("batch");
61+
operation.getTags().add(tag);
62+
}
63+
}
64+
}
65+
```
66+
4167
## ObjectMapper in `DefaultAsyncApiSerializerService`
4268

4369
The `DefaultAsyncApiSerializerService` is responsible for serializing the AsyncAPI document into a `String` for the Controller.
@@ -49,3 +75,16 @@ Use `DefaultAsyncApiSerializerService#getJsonObjectMapper()` and `DefaultAsyncAp
4975
All `ChannelScanner` beans are called to scan for channels.
5076
This interface is helpful when a protocol currently unsupported by Springwolf is used.
5177
Remember to register all payloads in the `ComponentsService`.
78+
79+
## Customize internal behavior
80+
81+
Springwolf uses `@ConditionalOnMissingBean` annotations for almost all internal Spring beans.
82+
If you have a special use-case that requires custom logic,
83+
you can replace almost every Springwolf bean by adding your custom implementation as a bean to the Spring context.
84+
85+
:::note
86+
Replacing Springwolf beans with custom implementations is only for experts,
87+
and we do **not** offer support for using internal API.
88+
89+
Custom implementations may break during updates without notice.
90+
:::

0 commit comments

Comments
 (0)