Skip to content

Commit f5538e6

Browse files
committed
updated documentation (#439)
1 parent 0bfce1e commit f5538e6

1 file changed

Lines changed: 44 additions & 88 deletions

File tree

docs/modules/ROOT/pages/processor/annotations.adoc

Lines changed: 44 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Apart from the basic build plugin configuration, `openapi-processor-spring` has
55

66
== `annotations`
77

8+
[.badge .badge-since]+since 2026.3+
9+
810
Spring Boot provides two annotation families
911

1012
* the standard _mapping_ annotations, i.e., `@RequestMapping`, `@GetMapping` and friends to define server side controllers
@@ -13,102 +15,56 @@ Spring Boot provides two annotation families
1315

1416
`openapi-processor-spring` supports both kinds of annotations.
1517

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.
18+
[NOTE]
19+
The `@..Exchange` support is new and has minimal usage; it may still produce wrong code. Please open an issue if you find something.
1720

1821

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-
<!-- .... -->
22+
Switching between both annotation families is done in the `mapping.yaml`:
23+
24+
[source,yaml]
7725
----
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]
26+
openapi-processor-spring: v1 # <1>
27+
28+
options:
29+
package-name: io.openapiprocesser
30+
31+
spring: # <2>
32+
# default, i.e., mapping annotations
33+
#annotations: mapping
34+
# use exchange annotations
35+
annotations: exchange # <3>
8636
----
87-
// build.gradle.kts
8837

89-
openapiProcessor {
38+
There are a few things that are important here:
9039

91-
// the path to the open api YAML file. Usually the same for all processors.
92-
apiPath("${projectDir}/src/api/openapi.yaml")
40+
<1> the mapping identifier has changed. It is now expecting `openapi-processor-spring` instead of `openapi-processor-mapping`. The processor will still accept `openapi-processor-mapping`.
41+
+
42+
The new identifier is required to get proper editing support for the new option with the IntelliJ plugin.
9343

94-
process("server") {
95-
processorName("spring")
44+
<2> a new Spring specific section in the `options` object.
9645

97-
// the spring processor dependenc(y|ies)
98-
dependencies {
99-
//process("${oap.processor.core.get()}")
100-
process("${oap.processor.spring.get()}")
101-
}
46+
<3> the annotation family: `mapping` or `exchange`. With `mapping` being the default.
10247

103-
targetDir("$projectDir/build/openapi")
10448

105-
prop("annotations", "exchange") // <1>
106-
prop("mapping", layout.projectDirectory.file("src/api/mapping.yaml"))
107-
}
108-
}
109-
----
110-
====
49+
Here is a small example diff that shows which lines of the generated code would change when switching annotations from `mapping` to `exchange`.
11150

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.
51+
[source,java]
52+
----
53+
import generated.model.Foo;
54+
import generated.support.Generated;
55+
import org.springframework.http.HttpStatus;
56+
-import org.springframework.web.bind.annotation.PostMapping;
57+
import org.springframework.web.bind.annotation.RequestBody;
58+
import org.springframework.web.bind.annotation.ResponseStatus;
59+
+import org.springframework.web.service.annotation.PostExchange;
60+
61+
@Generated(value = "openapi-processor-spring", version = "test")
62+
public interface Api {
63+
64+
@ResponseStatus(HttpStatus.CREATED)
65+
+ @PostExchange(url = "/foo", contentType = "application/json", accept = {"application/json"})
66+
- @PostMapping(path = "/foo", consumes = {"application/json"}, produces = {"application/json"})
67+
Foo postFoo(@RequestBody Foo body);
68+
69+
}
70+
----

0 commit comments

Comments
 (0)