Skip to content

Commit cf9b73d

Browse files
authored
docs: Add documentation for annotation module (#58)
* docs - Add documentation for annotation module
1 parent 16c1799 commit cf9b73d

File tree

3 files changed

+69
-99
lines changed

3 files changed

+69
-99
lines changed

ARCHITECTURE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ The core module provides the Kotlin DSL for building the AsyncAPI POJO. This POJ
1212

1313
Every module in this project depends on the core. The core module itself is independent of the rest of the project and does not depend on any other module.
1414

15+
## `annotation`
16+
The annotation module defines technology-agnostic annotations that represent a subset of the core model.
17+
1518
## `script`
1619
The script module configures the context for the `asyncapi.kts` script and defines compilation properties for the Kotlin compiler. It tells the compiler what the script environment should look like.
1720

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [Usage](#usage)
1111
* [Kotlin DSL](#kotlin-dsl-usage)
1212
* [Spring Web](#spring-web-usage)
13+
* [Annotation](#annotation-usage)
1314
* [Kotlin Script](#kotlin-script-usage)
1415
* [Configuration](#configuration)
1516
* [Spring Web](#spring-web-configuration)
@@ -39,8 +40,8 @@ The framework generally supports any JVM project. Compatibility has been tested,
3940
| **spring‑web** | Spring Boot autoconfiguration for serving the generated document | :white_check_mark: |
4041
| **script** | Kotlin scripting support for configuration as code | :white_check_mark: |
4142
| **maven‑plugin** | Maven plugin for evaluating AsyncAPI scripts and packaging generated resources | :white_check_mark: |
42-
| **annotation** | Technology agnostic annotations for meta-configuration | :soon: |
43-
| **template** | Template engine for reusing similar AsyncAPI components | :eyes: |
43+
| **annotation** | Technology agnostic annotations for meta-configuration | :white_check_mark: |
44+
| **template** | Template engine for reusing similar AsyncAPI components | :x: |
4445

4546
## Usage
4647
### <a name="kotlin-dsl-usage"></a>Kotlin DSL
@@ -130,6 +131,7 @@ To serve your AsyncAPI specification via Spring Web:
130131
- add the `kotlin-asyncapi-spring-web` dependency
131132
- enable the auto-configuration by annotating a configuration class with `@EnableAsyncApi`
132133
- document your API with `AsyncApiExtension` beans and/or Kotlin scripting (see [Kotlin script usage](#kotlin-script-usage))
134+
- add annotations to auto-generate components (see [annotation usage](#annotation-usage))
133135

134136
You can register multiple extensions to extend and override AsyncAPI components. Extensions with a higher order override extensions with a lower order. Please note that you can only extend top-level components for now (`info`, `channels`, `servers`...). Subcomponents will always be overwritten.
135137

@@ -152,6 +154,30 @@ class AsyncApiConfiguration {
152154
// ...
153155
}
154156
}
157+
158+
@Channel(
159+
value = "/rooms/{roomId}",
160+
parameters = [
161+
Parameter(
162+
value = "parameter",
163+
schema = Schema(
164+
type = "string",
165+
examples = ["53307860c3599d1de448e19d"]
166+
)
167+
)
168+
]
169+
)
170+
class RoomsChannel {
171+
172+
@Subscribe(message = Message(ChatMessage::class))
173+
fun publish(/*...*/) { /*...*/ }
174+
}
175+
176+
@Message
177+
data class ChatMessage(
178+
val id: String,
179+
val text: String
180+
)
155181
```
156182
```xml
157183
<dependency>
@@ -161,6 +187,16 @@ class AsyncApiConfiguration {
161187
</dependency>
162188
```
163189

190+
### <a name="annotation-usage"></a>Annotation
191+
The `kotlin-asyncapi-annotation` module defines technology-agnostic annotations that can be used to document event-driven microservice APIs.
192+
193+
| Annotation | Target | Description |
194+
|-------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------|
195+
| Channel | `class` | Marks a class that represents a event channel. The value property defines the name of the channel. |
196+
| Subscribe/Publish | `method` | Marks a method that represents a channel operation. The method must be defined inside a channel class. |
197+
| Message | `class` | Marks a class that represents a message. The value property can be used to reference a class that is annotated with this annotation. |
198+
| Schema | `class` | Marks a class that represents a schema. The value property can be used to reference a class that is annotated with this annotation. |
199+
164200
### <a name="kotlin-script-usage"></a>Kotlin Script
165201
[Kotlin scripting](https://github.com/Kotlin/KEEP/blob/b0c8a37db684eaf74bb1305f3c180b5d2537d787/proposals/scripting-support.md) allows us to execute a piece of code in a provided context. The IDE can still provide features like autocompletion and syntax highlighting. Furthermore, it provides the following benefits:
166202
- separate AsyncAPI documentation from application source code
@@ -244,6 +280,7 @@ You can configure the Spring Web integration in the application properties:
244280
|---------------------------------|---------------------------------------------------------------|----------------------------------------------|
245281
| `asyncapi.enabled` | Enables the autoconfiguration | `true` |
246282
| `asyncapi.path` | The resource path for serving the generated AsyncAPI document | `/docs/asyncapi` |
283+
| `asyncapi.annotation.enabled` | Enables the annotation scanning and processing | `true` |
247284
| `asyncapi.script.enabled` | Enables the Kotlin script support | `true` |
248285
| `asyncapi.script.resource-path` | Path to the generated script resource file | `classpath:asyncapi/generated/asyncapi.json` |
249286
| `asyncapi.script.source-path` | Path to the AsyncAPI Kotlin script file | `classpath:build.asyncapi.kts` |

architecture.svg

Lines changed: 27 additions & 97 deletions
Loading

0 commit comments

Comments
 (0)