Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: document usage of operation customizer and replacing Springwolf… #93

Merged
merged 3 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.docusaurus
build/**
.idea
/*.iml
42 changes: 41 additions & 1 deletion docs/configuration/customizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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.
Loading