-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update documentation for actuator (#92)
* Update documentation for actuator * docs: update to 1.4.0 * docs: document stomp binding and plugin * chore: add lint command * docs: update swagger version * docs: add headers page * docs: improve consumer docs * docs: add springwolf.studio-compatibility configuration * docs: add presentation link
- Loading branch information
Showing
25 changed files
with
232 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ Kotlinx | |
Protobuf | ||
Springfox | ||
Springwolf | ||
STOMP | ||
UI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
--- | ||
sidebar_position: 69 | ||
--- | ||
|
||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
import CodeBlock from '@theme/CodeBlock'; | ||
import CodeSchemaGroovy from '!!raw-loader!./snippets/_schema_groovy.gradle'; | ||
import CodeSchemaMaven from '!!raw-loader!./snippets/_schema_maven.xml'; | ||
|
||
# Headers | ||
|
||
Springwolf provides different ways to document headers. The `header` is mapped to an AsyncAPI `schemaObject`. | ||
|
||
## Auto-detection | ||
|
||
Besides the payload, Springwolf detects the Spring `@Header` annotation within the method signature: | ||
|
||
```java | ||
@KafkaListener(topics = "example-topic") | ||
public void receiveExamplePayload( | ||
@Payload ExamplePayloadDto payload, // @Payload is required for multiple parameters | ||
@Header(KafkaHeaders.RECEIVED_KEY) String key, | ||
@Header(KafkaHeaders.OFFSET) Integer offset) { | ||
// process | ||
} | ||
``` | ||
|
||
## Using `@AsyncOperation.Headers` | ||
|
||
Again, the annotation property `headers` of `@AsyncOperation` allows to overwrite the headers, as shown below: | ||
|
||
```java | ||
@AsyncPublisher(operation = @AsyncOperation( | ||
channelName = "example-producer-topic", | ||
headers = @AsyncOperation.Headers( // Optional | ||
schemaName = "SpringKafkaDefaultHeaders", | ||
values = { | ||
@AsyncOperation.Headers.Header( | ||
name = DEFAULT_CLASSID_FIELD_NAME, | ||
description = "Spring Type Id Header", | ||
value = "io.github.springwolf.example.dtos.ExamplePayloadDto" | ||
), | ||
// demonstrating https://cloudevents.io | ||
@AsyncOperation.Headers.Header( | ||
name = AsyncHeadersCloudEventConstants.TYPE, | ||
description = AsyncHeadersCloudEventConstants.TYPE_DESC, | ||
value = "ExamplePayloadDto.v1") | ||
// ... | ||
} | ||
) | ||
)) | ||
public void sendMessage(ExamplePayloadDto msg) { | ||
// process | ||
} | ||
``` | ||
|
||
## Schema | ||
|
||
Under the hood Springwolf relies on swagger-core `ModelConverters` to define the message schema. | ||
|
||
By default, the type and example values for the properties are guessed. | ||
The default Jackson `ModelResolver` supports schema definitions via `@Schema` to overwrite the property definitions. | ||
|
||
### Using `@Schema` | ||
|
||
The `@Schema` annotation allows to set many properties like `description`, `example`, `requiredMode`, `minimum` to document payloads. | ||
|
||
All properties are part of the produced AsyncAPI file. However, not all are displayed in `springwolf-ui` (see [#378](https://github.com/springwolf/springwolf-core/issues/378)) | ||
|
||
#### Usage | ||
|
||
Add the following dependency: | ||
|
||
<Tabs> | ||
<TabItem value="Groovy" label="Groovy" default> | ||
<CodeBlock language="groovy">{CodeSchemaGroovy}</CodeBlock> | ||
</TabItem> | ||
<TabItem value="Maven" label="Maven"> | ||
<CodeBlock language="xml">{CodeSchemaMaven}</CodeBlock> | ||
</TabItem> | ||
</Tabs> | ||
|
||
Then, add the `@Schema` annotation to the payload class: | ||
|
||
<!-- vale off --> | ||
```java | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | ||
|
||
@Schema(description = "Example payload model") | ||
public class ExamplePayloadDto { | ||
@Schema(description = "Some string field", example = "some string value", requiredMode = REQUIRED) | ||
private String someString; | ||
|
||
public String getSomeString() { | ||
return someString; | ||
} | ||
} | ||
``` | ||
<!-- vale on --> | ||
|
||
:::note | ||
The `@AsyncMessage.description` field will always override the `@Schema` description if provided | ||
::: | ||
|
||
For a full example, take a look at [ExamplePayloadDto.java in `springwolf-amqp-example`](https://github.com/springwolf/springwolf-core/blob/master/springwolf-examples/springwolf-amqp-example/src/main/java/io/github/springwolf/examples/amqp/dtos/ExamplePayloadDto.java) | ||
|
||
#### Primitive, final and external classes | ||
|
||
When the `@Schema` annotation can't be attached to the payload class (that's `java.lang.String`), the payload can be wrapped in an envelope class. The actual payload is a field within this class (`StringEnvelope`), marked using `@AsyncApiPayload` and documented using the `@Schema` annotation. | ||
|
||
```java | ||
@AsyncListener( operation = @AsyncOperation( channelName = TOPIC, | ||
payloadType = StringEnvelope.class) // <- envelope class | ||
) | ||
public void receiveStringPayload(String stringPayload) { // <- The original class is used here | ||
// ... | ||
} | ||
|
||
@Data | ||
static class StringEnvelope { | ||
@AsyncApiPayload // <- The annotation marker | ||
@Schema(description = "Payload description using @Schema annotation and @AsyncApiPayload within envelope class") | ||
private final String payload; | ||
} | ||
``` | ||
|
||
:::info | ||
See [Add-Ons](../add-ons) for more information on how to document other formats | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
dependencies { | ||
implementation 'io.swagger.core.v3:swagger-core:2.2.20' | ||
implementation 'io.swagger.core.v3:swagger-core:2.2.22' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.