|
| 1 | += Spring Annotations |
| 2 | +include::partial$links.adoc[] |
| 3 | + |
| 4 | +Apart from the basic build plugin configuration, `openapi-processor-spring` has an additional configuration to select the annotation style. |
| 5 | + |
| 6 | +== `annotations` |
| 7 | + |
| 8 | +Spring Boot provides two annotation families |
| 9 | + |
| 10 | +* the standard _mapping_ annotations, i.e., `@RequestMapping`, `@GetMapping` and friends to define server side controllers |
| 11 | + |
| 12 | +* and the new _exchange_ (HTTP service clients) annotations, i.e., `@HttpExchange`, `@GetExchange` and friends to define server side controllers and http clients based on the same interface. |
| 13 | + |
| 14 | +`openapi-processor-spring` supports both kinds of annotations. |
| 15 | + |
| 16 | +In contrast to the usual `mapping.yaml` based configuration, it has to be configured as part of a processor configuration in the build instructions. |
| 17 | + |
| 18 | + |
| 19 | +[tabs] |
| 20 | +==== |
| 21 | +Maven:: |
| 22 | ++ |
| 23 | +++++ |
| 24 | +<div></div> |
| 25 | +++++ |
| 26 | +In the `pom.xml` configure the `annotations` in the processor `<execution>` block. |
| 27 | ++ |
| 28 | +[source,xml] |
| 29 | +---- |
| 30 | +<!--pom.xml --> |
| 31 | +
|
| 32 | +<plugin> |
| 33 | + <groupId>io.openapiprocessor</groupId> |
| 34 | + <artifactId>openapi-processor-maven-plugin</artifactId> |
| 35 | + <version>${openapiprocessor.maven}</version> |
| 36 | +
|
| 37 | + <dependencies> |
| 38 | + <dependency> |
| 39 | + <groupId>io.openapiprocessor</groupId> |
| 40 | + <artifactId>openapi-processor-spring</artifactId> |
| 41 | + <version>${openapiprocessor.spring}</version> |
| 42 | + </dependency> |
| 43 | + </dependencies> |
| 44 | +
|
| 45 | + <configuration> |
| 46 | + <id>processor-api</id> |
| 47 | + <apiPath>${project.basedir}/src/api/openapi.yaml</apiPath> |
| 48 | + </configuration> |
| 49 | +
|
| 50 | + <executions> |
| 51 | + <execution> |
| 52 | + <id>server</id> |
| 53 | + <phase>generate-sources</phase> |
| 54 | +
|
| 55 | + <configuration> |
| 56 | + <id>server</id> |
| 57 | + <processor>spring</processor> |
| 58 | + <addSourceRoot>true</addSourceRoot> |
| 59 | +
|
| 60 | + <options> |
| 61 | + <values> |
| 62 | + <targetDir>${project.basedir}/target/generated-sources/openapi/server</targetDir> |
| 63 | + <mapping>${project.basedir}/src/api/mapping-server.yaml</mapping> |
| 64 | + <annotations>exchange</annotations> <!-- <1> --> |
| 65 | + </values> |
| 66 | + </options> |
| 67 | + </configuration> |
| 68 | +
|
| 69 | + <goals> |
| 70 | + <goal>process</goal> |
| 71 | + </goals> |
| 72 | + </execution> |
| 73 | + </executions> |
| 74 | +</plugin> |
| 75 | +
|
| 76 | +<!-- .... --> |
| 77 | +---- |
| 78 | +Gradle:: |
| 79 | ++ |
| 80 | +++++ |
| 81 | +<div></div> |
| 82 | +++++ |
| 83 | +In the `build.gradle.kts` configure the `annotations` in to the processor configuration block. |
| 84 | ++ |
| 85 | +[source,kotlin] |
| 86 | +---- |
| 87 | +// build.gradle.kts |
| 88 | +
|
| 89 | +openapiProcessor { |
| 90 | +
|
| 91 | + // the path to the open api YAML file. Usually the same for all processors. |
| 92 | + apiPath("${projectDir}/src/api/openapi.yaml") |
| 93 | +
|
| 94 | + process("server") { |
| 95 | + processorName("spring") |
| 96 | +
|
| 97 | + // the spring processor dependenc(y|ies) |
| 98 | + dependencies { |
| 99 | + //process("${oap.processor.core.get()}") |
| 100 | + process("${oap.processor.spring.get()}") |
| 101 | + } |
| 102 | +
|
| 103 | + targetDir("$projectDir/build/openapi") |
| 104 | +
|
| 105 | + prop("annotations", "exchange") // <1> |
| 106 | + prop("mapping", layout.projectDirectory.file("src/api/mapping.yaml")) |
| 107 | + } |
| 108 | +} |
| 109 | +---- |
| 110 | +==== |
| 111 | + |
| 112 | +<1> this configures the processor to use the `Exchange` annotations instead of the `Mapping` annotations. |
| 113 | ++ |
| 114 | +Using the `Mapping` annotations is the default and will be used if the `annotations` property is not set. |
0 commit comments