Skip to content

Commit ba5ae51

Browse files
committed
update/improve documentation
1 parent f7191ef commit ba5ae51

1 file changed

Lines changed: 88 additions & 23 deletions

File tree

docs/modules/ROOT/pages/index.adoc

Lines changed: 88 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ link:{oap-central}[image:{badge-central}[]]
2020

2121
a maven plugin based on the link:{oap-api}[openapi-processor-api] to handle any openapi-processor without an explicit dependency on the processor.
2222

23-
NOTE: unfortunately it is necessary to configure a few xref:oap::jdk.adoc[additional jvm parameter] to run the processor with JDK 16+
23+
NOTE: unfortunately, it may be necessary to configure a few xref:oap::jdk.adoc[additional jvm parameters] to run the processor with *enabled* code formatter on JDK 16+.
2424

2525
== plugin configuration
2626

@@ -35,8 +35,8 @@ The first step of the configuration is to add the plugin, and the processor(s) t
3535
<plugin>
3636
<groupId>io.openapiprocessor</groupId>
3737
<artifactId>openapi-processor-maven-plugin</artifactId>
38-
<!-- update to the latest version, see maven central badge at top -->
39-
<version>2024.1</version>
38+
<!-- to update to the latest version, see maven central badge at top -->
39+
<version>2026.1</version>
4040
4141
<!-- ... next step ... -->
4242
</plugin>
@@ -54,12 +54,12 @@ The processors are dependencies of the plugin, and they are expected in the `<pl
5454
<dependency>
5555
<groupId>io.openapiprocessor</groupId>
5656
<artifactId>openapi-processor-spring</artifactId>
57-
<version>2023.6.1</version>
57+
<version>2026.1</version>
5858
</dependency>
5959
<dependency>
6060
<groupId>io.openapiprocessor</groupId>
6161
<artifactId>openapi-processor-json</artifactId>
62-
<version>2023.6.1</version>
62+
<version>2026.1</version>
6363
</dependency>
6464
</dependencies>
6565
@@ -84,7 +84,7 @@ Then it should know where the processors will find the input OpenAPI yaml files
8484
* `<id/>`, maven wants this. It is not used by the processor.
8585
* `*<apiPath/>*`, defines the path to the openapi yaml file. This is usually the same for all processors and adding it directly into the plugin `<configuration/>` block sets it for all processors.
8686

87-
Next step is to configure the goals for processing. The plugin has only a single goal `process` that can run any processor. It is configured by an `<execution/>` element to run a specific processor.
87+
The next step is to configure the goals for processing. The plugin has only a single goal `process` that can run any processor. It is configured by an `<execution/>` element to run a specific processor.
8888

8989
If maven should run multiple processors, multiple `<execution/>` s are needed.
9090

@@ -100,6 +100,7 @@ Here is an example to run `openapi-processor-spring` that explains the configura
100100
101101
<configuration>
102102
<id>spring</id> <!--3-->
103+
<processor>spring</processor> <!--3-->
103104
104105
<!-- true is default -->
105106
<addSourceRoot>true</addSourceRoot> <!--9-->
@@ -112,7 +113,7 @@ Here is an example to run `openapi-processor-spring` that explains the configura
112113
<values>
113114
<targetDir>${project.basedir}/target/generated-sources/openapi</targetDir> <!--6-->
114115
<mapping>${project.basedir}/src/api/mapping.yaml</mapping> <!--7-->
115-
<parser>INTERNAL</parser>
116+
<parser>INTERNAL</parser> <!-- default -->
116117
<showWarnings>true</showWarnings>
117118
</values>
118119
@@ -136,17 +137,19 @@ Here is an example to run `openapi-processor-spring` that explains the configura
136137

137138
<1> `*<id/>*`: **execution id** of the goal (choose your id). It is necessary to configure multiple executions.
138139

139-
<2> `*<phase/>*` **phase** (mandatory): openapi-processor-spring generates java code, so the `<phase/>` should be `generate-source`. This tells maven to run the goal before compiling anything.
140+
<2> `*<phase/>*` **phase** (mandatory): openapi-processor-spring generates Java code, so the `<phase/>` should be `generate-source`. This tells maven to run the goal before compiling anything.
140141

141-
<3> `*<id/>*` **processor id** (mandatory): this configures the openapi-processor the goal should run. The processor id must match exactly with the name of the processor. The convention is, that the last part of the processor artifact name is the processor id.
142+
<3> `*<id/>*` **processor id** (mandatory): this configures the openapi-processor the goal should run. The processor id must match exactly with the name of the processor unless the `<processor/>` is used. In this case `<id/>` is used as a subfolder of an automatically created `<targetDir/>`.
142143
+
143-
If the artifact of a processor is called `openapi-processor-x`, the last part `x` is the id of the processor. For example for `openapi-processor-spring` the id is `spring`, for `openapi-processor-json` the id is `json`.
144+
`*<processor/>*` **processor id** (optional): this is an alternative configuration of the openapi-processor a goal should run. It is necessary to process multiple OpenAPI files with the same processor. See below for more on this.
145+
+
146+
The convention is that the last part of the processor artifact name is the processor id. If the artifact of a processor is called `openapi-processor-x`, the last part `x` is the id of the processor. For example, for `openapi-processor-spring` the id is `spring`, for `openapi-processor-json` the id is `json`.
144147

145-
<4> `*<apiPath/>*` (optional): the path to the open api yaml file. If set inside an `<execution>` `<configuration/>` it overrides the parent `apiPath` set in the `<plugin>` `<configuration/>`.
148+
<4> `*<apiPath/>*` (optional): the path to the open api YAML file. If set inside an `<execution>` `<configuration/>` it overrides the parent `apiPath` set in the `<plugin>` `<configuration/>`.
146149

147-
<5> `*<options/>*` (mandatory): **processor specific options**, the configuration of a single processor can have any number of additional parameters defined by the processor (all options will be passed as a map to the processor with the option name as the key). The nested `*<values/>*` element defines that map.
150+
<5> `*<options/>*` (mandatory): **processor-specific options**, the configuration of a single processor can have any number of additional parameters defined by the processor (all options will be passed as a map to the processor with the option name as the key). The nested `*<values/>*` element defines that map.
148151
+
149-
To allow any level of nesting it is possible to create `*<nested/>*` option maps, i.e. `*<nested/>*` can contain another `*<nested/>*` element and so on. In the configuration above the plugin would pass the following map to the processor:
152+
To allow any level of nesting, it is possible to create `*<nested/>*` option maps, i.e. `*<nested/>*` can contain another `*<nested/>*` element and so on. In the configuration above, the plugin would pass the following map to the processor:
150153
+
151154
[source,json,title=json notation]
152155
----
@@ -161,17 +164,26 @@ To allow any level of nesting it is possible to create `*<nested/>*` option maps
161164
}
162165
----
163166

164-
<6> `*<targetDir/>*` **target directory** (mandatory): the directory the processor should use for its output. By convention a processor should use this key to as the output directory.
167+
<6> `*<targetDir/>*` **target directory** (optional): the directory the processor should use for its output. By convention, a processor uses this key as the output directory.
168+
+
169+
If this is not given, the plugin will automatically select the target dir as:
170+
+
171+
[source,xml]
172+
----
173+
<targetDir>${project.basedir}/target/generated-sources/{processor id}</targetDir>
174+
----
175+
+
176+
where `{processor id}` is `<processor/>` if given, or `<id/>` if `<processor/>` is not given.
165177

166-
<7> the rest of the options are processor specific. See xref:spring::index.adoc[openapi-processor-spring].
178+
<7> the rest of the options are processor-specific. See xref:spring::index.adoc[openapi-processor-spring].
167179

168180
<8> `*<goal/>*` **goal** (mandatory): this is the goal maven should run. Since the plugin does only have a single goal the value is always `process`.
169181

170-
<9> `*<addSourceRoot/>*` **addSourceRoot* (optional): this defaults to `true` and automatically adds the `targetDir` as compile source root folder. It can be disabled by setting it to `false`.
182+
<9> `*<addSourceRoot/>*` **addSourceRoot** (optional): this defaults to `true` and automatically adds the `targetDir` as compile source root folder. It can be disabled by setting it to `false`.
171183

172-
=== multiple processors
184+
=== multiple different processors
173185

174-
To run a second processor add another `<execution>` element. Here is an example that configures xref:spring:ROOT:index.adoc[openapi-processor-spring] and xref:json:ROOT:index.adoc[openapi-processor-json]:
186+
To run a second processor, add another `<execution>` element. Here is an example that configures xref:spring:ROOT:index.adoc[openapi-processor-spring] and xref:json:ROOT:index.adoc[openapi-processor-json]:
175187

176188

177189
[source,xml]
@@ -203,6 +215,59 @@ To run a second processor add another `<execution>` element. Here is an example
203215

204216
<1> uses `generate-resources` phase for the json output, to consider it as a resource.
205217

218+
=== multiple identical processors
219+
220+
To run the same processor on different inputs, add another `<execution>` element. Here is an example that configures two xref:spring:ROOT:index.adoc[openapi-processor-spring] processors:
221+
222+
223+
[source,xml]
224+
----
225+
<plugin>
226+
<executions>
227+
<execution>
228+
<id>spring-interfaces api 1</id>
229+
<phase>generate-sources</phase>
230+
231+
<configuration>
232+
<id>api1</id> <!--1-->
233+
<processor>spring</processor> <!--2-->
234+
<apiPath>${project.basedir}/src/api1/openapi.yaml</apiPath>
235+
<options>
236+
<values>
237+
<!-- if not set, it will automatically add the configuration id:
238+
<targetDir>${project.basedir}/target/generated-sources/api1</targetDir>
239+
-->
240+
<mapping>${project.basedir}/src/api1/mapping.yaml</mapping>
241+
</values>
242+
</options>
243+
</configuration>
244+
</execution>
245+
246+
<execution>
247+
<id>spring-interfaces api 2</id>
248+
<phase>generate-sources</phase>
249+
250+
<configuration>
251+
<id>api2</id> <!--1-->
252+
<processor>spring</processor> <!--2-->
253+
<apiPath>${project.basedir}/src/api2/openapi.yaml</apiPath>
254+
<options>
255+
<values>
256+
<!-- if not set, it will automatically add the configuration id:
257+
<targetDir>${project.basedir}/target/generated-sources/api2</targetDir>
258+
-->
259+
<mapping>${project.basedir}/src/api2/mapping.yaml</mapping>
260+
</values>
261+
</options>
262+
</configuration>
263+
</execution>
264+
</executions>
265+
</plugin>
266+
----
267+
268+
<1> the configuration id, used to automatically select the `<targetDir/>` if it is not explicitly set. Otherwise, it is not used.
269+
<2> the processor id that should be used for this configuration.
270+
206271
== executing the goal
207272

208273
The `<execution>` s created in the previous chapter will automatically run the processor in the given `<phase>` s with commands like `./mvnw compile`.
@@ -213,7 +278,7 @@ Running the goal directly with `./mvnw openapi-processor:process` to check the s
213278

214279
This can be solved in two ways:
215280

216-
First, it is possible to the run the goal with an explicit `<execution>` like this:
281+
First, it is possible to run the goal with an explicit `<execution>` like this:
217282

218283
[source,shell script]
219284
----
@@ -243,7 +308,7 @@ The other solution is to change the `execution` that should run by default to a
243308
</plugin>
244309
----
245310

246-
<1> using maven's default execution id instead of a user selected id.
311+
<1> using maven's default execution id instead of a user-selected id.
247312

248313
With this configuration maven will use it when directly running the `process` goal from the shell, and it will also run it when the given phase is active.
249314

@@ -252,13 +317,13 @@ With this configuration maven will use it when directly running the `process` go
252317

253318
=== source files
254319

255-
Starting with the release 2024.1 it is no longer necessary to manually add the generated sources to the build. The plugin will automatically add the `targetDir` as compile source root.
320+
Starting with the release 2024.1, it is no longer necessary to manually add the generated sources to the build. The plugin will automatically add the `targetDir` as compile source root.
256321

257322
It can be disabled by setting the plugin configuration `<addSourceRoot>` to `false`.
258323

259324
=== resource files
260325

261-
If the output of the processor (e.g. generated by openapi-processor-json) should be used as resource add a resource directory.
326+
If the output of the processor, (e.g., generated by openapi-processor-json) should be used as a resource, add a resource directory.
262327

263328
[source,xml]
264329
----
@@ -276,4 +341,4 @@ If the output of the processor (e.g. generated by openapi-processor-json) should
276341

277342
== Samples
278343

279-
See the maven sample in the xref:samples::index.adoc[samples] for a working spring boot example.
344+
See the maven samples in the xref:samples::index.adoc[samples] for a working example using Spring Boot. Look into the parent `pom.xml` in the root folder to find the samples which have a maven configuration.

0 commit comments

Comments
 (0)