Skip to main content

Schemas

Under the hood springwolf relies on swagger-core ModelConverters.

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 to document payloads.

All properties are part of the produced AsyncApi file. However, not all of them are displayed in springwolf-ui. The ones listed above are included.

Usage

Add the following dependency:

dependencies {
implementation 'io.swagger.core.v3:swagger-core:2.2.10'
}

Then, add the @Schema annotation to the payload class:

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;
}
}

For a full example, take a look at ExamplePayloadDto.java in springwolf-amqp-example

Custom ModelConverters

Additionally, custom ModelConverters are supported. These are needed when swagger is unable to extract a schema from a class.

One example is javax.money.MonetaryAmount. Adding a model converter is demoed in springwolf-add-ons/springwolf-common-model-converters