You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-19Lines changed: 41 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -117,11 +117,8 @@ asyncApi {
117
117
### <aname="spring-web-usage"></a>Spring Web
118
118
To serve your AsyncAPI specification via Spring Web:
119
119
- add the `kotlin-asyncapi-spring-web` dependency
120
-
- enable the autoconfiguration by annotating a configuration class with `@EnableAsyncApi`
121
-
-[optional] provide `AsyncApiExtension` beans for the application context
122
-
-[optional] add a Kotlin build script to the classpath -> see [Kotlin script usage](#kotlin-script-usage)
123
-
124
-
The library registers a default `info` extension using the `Implementation-Title` and `Implementation-Version` of the `MANIFEST.md` file. Please note that this information is only available if the application was started from a JAR file. The default info will **not** work if you start the application from your IDE.
120
+
- enable the auto-configuration by annotating a configuration class with `@EnableAsyncApi`
121
+
- document your API with `AsyncApiExtension` beans and/or Kotlin scripting (see [Kotlin script usage](#kotlin-script-usage))
125
122
126
123
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.
127
124
@@ -154,17 +151,19 @@ class AsyncApiConfiguration {
[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:
154
+
[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:
158
155
- separate AsyncAPI documentation from application source code
159
156
- focus on AsyncAPI content and don't worry about the build context or spring web integration
160
157
- use AsyncAPI Kotlin DSL in Java projects
161
158
162
159
You have two options to use Kotlin scripting in your project:
163
-
- let your Spring Boot application evaluate the script at runtime
164
-
- let the Maven plugin evaluate the script during build time
160
+
-[Plugin]let the Maven plugin evaluate the script during build time (recommended)
161
+
-[Embedded]let your Spring Boot application evaluate the script at runtime
165
162
166
-
#### Embedded Scripting
167
-
Your Spring Boot application can pick up your build script from the classpath and convert it to an `AsyncApiExtension`. You just have to place your script with the file extension `asyncapi.kts` in your `resources` folder. By default, the library expects the script to be named `build.asyncapi.kts` and placed in the root of the `resources` folder. This can be changed in the application properties.
163
+
#### Maven Plugin
164
+
The Maven plugin evaluates your `asyncapi.kts` script, generates a valid AsyncAPI JSON file and adds it to the project resources. The `kotlin-asyncapi-spring-web` module picks the generated resource up and converts it to an `AsyncApiExtension`.
165
+
166
+
By default, the plugin expects the script to be named `build.asyncapi.kts` and placed in the project root. The script path and resource target path can be changed in the plugin configuration.
168
167
169
168
**Example** (simplified version of [Gitter example](https://github.com/asyncapi/spec/blob/22c6f2c7a61846338bfbd43d81024cb12cf4ed5f/examples/gitter-streaming.yml))
170
169
```kotlin
@@ -179,15 +178,6 @@ servers {
179
178
180
179
// ...
181
180
```
182
-
Embedded scripting is enabled by default for Spring Boot applications. If you don't want to include the Kotlin compiler in your build, you can also evaluate the script with the Maven plugin and use the packaged script resources in your Spring Boot application.
183
-
184
-
You just need to exclude the `kotlin-scripting-jvm-host` dependency from the `kotlin-asyncapi-spring-web` artifact. The Spring Web integration automatically picks up the script resource from the `resource-path` and converts it to an `AsyncApiExtension`.
185
-
186
-
#### Maven Plugin
187
-
The Maven plugin will evaluate the script and put the generated AsyncAPI JSON on the package classpath. Your application can convert the resource to an AsyncApi model object.
188
-
189
-
By default, the plugin expects the script to be named `build.asyncapi.kts` and placed in the project root. The script path and resource target path can be changed in the plugin configuration.
190
-
191
181
```xml
192
182
<plugin>
193
183
<groupId>org.openfolder</groupId>
@@ -203,6 +193,38 @@ By default, the plugin expects the script to be named `build.asyncapi.kts` and p
203
193
</plugin>
204
194
```
205
195
196
+
#### Embedded Scripting
197
+
If you can't use the Maven plugin for your project, you can also let your Spring Boot application evaluate the script at runtime.
198
+
199
+
You have to place your script in your `resources` folder. Similarly to the plugin, the `kotlin-asyncapi-spring-web` module will pick up the script and convert it to an `AsyncApiExtension`. By default, the library expects the script to be named `build.asyncapi.kts` and placed in the root of the `resources` folder. This can be changed in the application properties.
200
+
201
+
In order to enable embedded scripting, you need to make some additional configurations:
202
+
- add `kotlin-scripting-jvm-host` to the classpath
203
+
- unpack `kotlin-compiler-embeddable` from the Spring Boot executable JAR file
0 commit comments