Skip to content

Commit 10fbf53

Browse files
sam0r040timonback
andauthored
docs: document usage of operation customizer and replacing Springwolf… (#93)
* docs: document usage of operation customizer and replacing Springwolf beans with + custom implementations (#80) * docs: linting * docs: spelling & ordering --------- Co-authored-by: Timon Back <timonback@users.noreply.github.com>
1 parent cdd5a08 commit 10fbf53

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-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: 41 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,33 @@ 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's 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 below:
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 && "true".equals(annotation.batch())) {
59+
Tag tag = new Tag();
60+
tag.setName("batch");
61+
62+
operation.getTags().add(tag);
63+
}
64+
}
65+
}
66+
```
67+
4168
## ObjectMapper in `DefaultAsyncApiSerializerService`
4269

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

0 commit comments

Comments
 (0)