Skip to content

Commit 0f6bb41

Browse files
committed
1 parent 3db916b commit 0f6bb41

1 file changed

Lines changed: 66 additions & 4 deletions

File tree

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

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ A mapping yaml looks like this:
88

99
[source,yaml]
1010
----
11-
openapi-processor-mapping: v3
11+
openapi-processor-mapping: v4
1212
1313
options:
1414
package-name: io.openapiprocessor.sample
1515
model-name-suffix: Resource
16+
model-type: record
1617
one-of-interface: true
1718
bean-validation: jakarta
1819
generated-date: true
19-
format-code: false
20+
format-code: true
2021
javadoc: true
2122
2223
map:
@@ -36,6 +37,8 @@ Interfaces and models will be generated into the `api` and `model` subpackages o
3637

3738
* `model-suffix-name` (**optional**, default is empty). See xref:_model_name_suffix[below].
3839

40+
* `model-type` (*optional**, `default` or `record`, default is `default`). Generate pojos (class with get/set property methods) or records model classes from OpenAPI schemas. See xref:_model_type[below].
41+
3942
* `bean-validation` (**optional**, `true` or `false`, `javax`, `jakarta`) enables generation of bean validation annotations. Default is `false`. See link:{bean-validation}[Bean Validation Specification, window="_blank"].
4043
+
4144
With the [.badge .badge-since]+2023.1+ releases this key allows two new values to handle the package name change from bean validation v2 to v3 (`javax` => `jakarta`).
@@ -45,9 +48,9 @@ With the [.badge .badge-since]+2023.1+ releases this key allows two new values t
4548
** `javax`: enables bean validation annotations v2, with `javax` package name
4649
** `jakarta`: enables bean validation annotations v3, with `jakarta` package name
4750

48-
* `javadoc` (**optional**, `true` or `false`) enables generation of JavaDoc comments from the OpenAPI `description` s on the API interfaces and model pojos.Default is `false`.This is still experimental.
51+
* `javadoc` (**optional**, `true` or `false`) enables generation of JavaDoc comments from the OpenAPI `description` s on the API interfaces and model pojos.Default is `false`.
4952

50-
* `format-code` (**optional**, `true` or `false`) enable or disable the code formatter: Default is `true`.
53+
* `format-code` (**optional**, `true` or `false`) enable or disable the code formatter: Default is `false`.
5154

5255
* `one-of-interface` (**optional**, `true` or `false`) enables generation of marker interfaces for `oneOf` objects. See xref:processor/one-of-interface.adoc#_marker_interfaces[oneOf marker interfaces].
5356

@@ -145,6 +148,65 @@ public class BarResource { // <4>
145148
<3> the class name of the `Foo` schema got the configured `Resource` suffix
146149
<4> the class name of the `BarResource` is identical to the original schema name. Since the existing suffix is equal to `model-name-suffix` it is ignored. Otherwise, This prevents funny class names like `BarResourceResource`.
147150

151+
[#_model_type]
152+
=== model type:
153+
154+
(*optional**, `default` or `record`, default is `default`)
155+
156+
openapi-processor is now capable of generating java `record`s instead of pojos for schemas. This is a global setting in the `mapping.yaml`. It can either have the value `default` (which is default) to generate pojos or `record` to generate records.
157+
158+
*mapping.yaml*
159+
[source,yaml]
160+
----
161+
openapi-processor-mapping: v4
162+
163+
options:
164+
model-type: record
165+
----
166+
167+
With `model-type: record` the processor will generate `record` s like this:
168+
169+
*Java `record`*
170+
[source,java]
171+
----
172+
package generated.model;
173+
174+
import com.fasterxml.jackson.annotation.JsonProperty;
175+
import generated.support.Generated;
176+
177+
@Generated(value = "openapi-processor-core", version = "test")
178+
public record Foo(
179+
@JsonProperty("bar")
180+
String bar
181+
) {}
182+
----
183+
184+
and without `model-type` or `model-type: default` it will create a simple pojo:
185+
186+
*Java `pojo`*
187+
[source,java]
188+
----
189+
package generated.model;
190+
191+
import com.fasterxml.jackson.annotation.JsonProperty;
192+
import generated.support.Generated;
193+
194+
@Generated(value = "openapi-processor-core", version = "test")
195+
public class Foo {
196+
197+
@JsonProperty("bar")
198+
private String bar;
199+
200+
public String getBar() {
201+
return bar;
202+
}
203+
204+
public void setBar(String bar) {
205+
this.bar = bar;
206+
}
207+
208+
}
209+
----
148210

149211
== map:
150212

0 commit comments

Comments
 (0)