Skip to content

Commit 1c95b62

Browse files
committed
docs: Add documentation for Schema annotation
1 parent 64d5ab9 commit 1c95b62

File tree

8 files changed

+132
-3
lines changed

8 files changed

+132
-3
lines changed

docs/documenting-producers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 4
2+
sidebar_position: 5
33
---
44

55
# Documenting Producers

docs/documenting-schemas.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
sidebar_position: 4
3+
---
4+
5+
import Tabs from '@theme/Tabs';
6+
import TabItem from '@theme/TabItem';
7+
import CodeBlock from '@theme/CodeBlock';
8+
import CodeSchemaGroovy from '!!raw-loader!./snippets/_schema_groovy.md';
9+
import CodeSchemaMaven from '!!raw-loader!./snippets/_schema_maven.md';
10+
11+
# Documenting Schemas
12+
13+
Under the hood springwolf relies on swagger-core `ModelConverters`.
14+
15+
By default, the type and example values for the properties are guessed.
16+
The default Jackson `ModelResolver` supports schema definitions via `@Schema` to overwrite the property definitions.
17+
18+
## Using `@Schema`
19+
20+
The `@Schema` annotation allows to set many properties like `description`, `example`, `required` to document payloads.
21+
22+
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.
23+
24+
### Usage
25+
26+
Add the following dependency:
27+
28+
<Tabs>
29+
<TabItem value="Groovy" label="Groovy" default>
30+
<CodeBlock language="groovy">{CodeSchemaGroovy}</CodeBlock>
31+
</TabItem>
32+
<TabItem value="Maven" label="Maven">
33+
<CodeBlock language="xml">{CodeSchemaMaven}</CodeBlock>
34+
</TabItem>
35+
</Tabs>
36+
37+
Then, add the `@Schema` annotation to the payload class:
38+
```java
39+
import io.swagger.v3.oas.annotations.media.Schema;
40+
41+
@Schema(description = "Example payload model")
42+
public class ExamplePayloadDto {
43+
@Schema(description = "Some string field", example = "some string value", required = true)
44+
private String someString;
45+
46+
public String getSomeString() {
47+
return someString;
48+
}
49+
}
50+
```
51+
52+
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/stavshamir/springwolf/example/dtos/ExamplePayloadDto.java)
53+
54+
## Custom ModelConverters
55+
56+
Additionally, custom `ModelConverters` are supported.
57+
These are needed when swagger is unable to extract a schema from a class.
58+
59+
One example is `javax.money.MonetaryAmount`.
60+
Adding a model converter is demoed in [springwolf-add-ons/springwolf-common-model-converters](https://github.com/springwolf/springwolf-core/tree/master/springwolf-add-ons/springwolf-common-model-converters)

docs/manually-documenting-consumers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 4
2+
sidebar_position: 5
33
---
44

55
# Manually Documenting Consumers

docs/snippets/_schema_groovy.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies {
2+
implementation 'io.swagger.core.v3:swagger-core:2.2.0'
3+
}

docs/snippets/_schema_maven.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<dependencies>
2+
<dependency>
3+
<groupId>io.swagger.core.v3</groupId>
4+
<artifactId>swagger-core</artifactId>
5+
<version>2.2.0</version>
6+
</dependency>
7+
</dependencies>

docs/supported-protocols.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 5
2+
sidebar_position: 6
33
---
44

55
# Supported Protocols

package-lock.json

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"clsx": "^1.1.1",
2222
"file-loader": "^6.2.0",
2323
"prism-react-renderer": "^1.2.1",
24+
"raw-loader": "^4.0.2",
2425
"react": "^17.0.1",
2526
"react-dom": "^17.0.1",
2627
"url-loader": "^4.1.1"

0 commit comments

Comments
 (0)