From cdd5a08abc292b3514e5ba75ae1e95b017fa76bf Mon Sep 17 00:00:00 2001 From: Timon Back Date: Sun, 30 Jun 2024 17:06:29 +0200 Subject: [PATCH] docs: Update documenting-headers.mdx Remove duplicated section im comparison to messages --- docs/configuration/documenting-headers.mdx | 75 ---------------------- 1 file changed, 75 deletions(-) diff --git a/docs/configuration/documenting-headers.mdx b/docs/configuration/documenting-headers.mdx index c23df23..e3a2b10 100644 --- a/docs/configuration/documenting-headers.mdx +++ b/docs/configuration/documenting-headers.mdx @@ -54,78 +54,3 @@ 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: - - - - {CodeSchemaGroovy} - - - {CodeSchemaMaven} - - - -Then, add the `@Schema` annotation to the payload class: - - -```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; - } -} -``` - - -:::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 -:::