Elffuss BraidHub

kikocis/EDC public

cc2a9ff178c4 · 2.6 KiBRenderedRawPermalink
1# Generating the OpenApi Spec (*.yaml)
2
3It is possible to generate an OpenApi spec in the form of a `*.yaml` file by invoking two simple Gradle tasks.
4
5## Generate `*.yaml` files
6
7Every module (=subproject) that contains REST endpoints is scanned for Jakarta Annotations which are then used to
8generate a `*.yaml` specification for that particular module. This means that there is one `*.yaml`file _per module_,
9resulting in several `*.yaml` files.
10
11Those files are named `MODULENAME.yaml`, e.g. `observability.yaml` or `control.yaml`.
12
13To re-generate those files, simply invoke
14
15```shell
16./gradlew clean resolve
17```
18
19This will generate all `*.yaml` files in the `resources/openapi/yaml` directory.
20
21## Gradle Plugins
22
23We use the official Swagger Gradle plugins:
24
25- `"io.swagger.core.v3.swagger-gradle-plugin"`: used to generate a `*.yaml` file per module
26
27So in order for a module to be picked up by the Swagger Gradle plugin, simply add it to the `build.gradle.kts`:
28
29```kotlin
30// in yourModule/build.gradle.kts
31
32val rsApi: String by project
33
34plugins {
35 `java-library`
36 id(libs.plugins.swagger.get().pluginId) //<-- add this
37}
38
39dependencies {
40 implementation("jakarta.ws.rs:jakarta.ws.rs-api:${rsApi}") //<-- you'll probably already have this
41 // other dependencies
42}
43
44```
45
46If you developed a REST endpoint, you very likely already have the `jakarta.ws.rs:....` part in your build file. If you
47don't, it'll get added automatically for you.
48
49### Categorizing your API
50
51All APIs in EDC should be "categorized", i.e. they should belong to a certain group of APIs.
52Please see [this decision record](./decision-records/2022-11-09-api-refactoring/renaming.md) for reference. In order to
53add your module to one of the categories, simply add this block to your module's `build.gradle.kts`:
54
55```kotlin
56plugins {
57 `java-library`
58 id(libs.plugins.swagger.get().pluginId)
59}
60
61dependencies {
62 // ...
63}
64
65// add this block:
66edcBuild {
67 swagger {
68 apiGroup.set("management-api")
69 }
70}
71```
72
73This tells the build plugin how to categorize your API and SwaggerHub will list it accordingly.
74_Note: currently we have categories for `control-api` and `management-api`_
75
76## How to generate code
77
78This feature does **neither** expose the generated files through a REST endpoint providing any sort of live try-out
79feature, **nor** does it generate any sort of client code. A visual documentation page for our APIs is served
80through [SwaggerHub](https://app.swaggerhub.com/home?type=API).
81
82However, there is Gradle plugin capable of generating client code.
83Please refer to the [official documentation](https://github.com/int128/gradle-swagger-generator-plugin).