Skip to content

Commit ddef34d

Browse files
committed
update docs
1 parent 344978e commit ddef34d

File tree

5 files changed

+88
-33
lines changed

5 files changed

+88
-33
lines changed

docs/modules/ROOT/pages/mapping/annotation.adoc

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,62 @@ type: {source type} @ {annotation type}
2424

2525
* **type** is required.
2626
27-
** **{source type}** is the type name used in the OpenAPI description and names the type that should
28-
receive the additional annotation.
27+
** **{source type}** is the type name used in the OpenAPI description and names the type that should receive the additional annotation. This can be a **{type}:{format}** combination like `string:uuid`.
2928

3029
** **{annotation type}** is the fully qualified class name of the java annotation type. It may have parameters (see example below).
3130

3231
The link:{oap-samples}[samples project] has a small example using annotation mappings similar to the one described below.
3332

33+
== combining annotation mapping and type mapping
34+
35+
[.badge .badge-since]+since 2023.1+
36+
37+
Previously an annotation mapping was lost if the type was mapped at the same time to an existing class. It will now add the annotation to the existing class if possible.
38+
39+
Assume the following mapping:
40+
41+
[source,yaml]
42+
----
43+
openapi-processor-mapping: v3
44+
45+
options:
46+
47+
map:
48+
types:
49+
- type: Foo => openapiprocessor.MappedFoo
50+
- type: Foo @ annotation.Bar # <1>
51+
52+
parameters:
53+
- type: Foo @ annotation.Bar # <2>
54+
----
55+
56+
`MappedFoo` is a class that is not generated. Adding an annotation at the parameter level works as expected (mapping `<2>`). But it is not possible to add the `Bar` annotation directly at the class (mapping `<1>`) like it is possible on a generated class:
57+
58+
[source,java]
59+
----
60+
@Bar
61+
@Generated
62+
public class Foo {
63+
// ....
64+
}
65+
----
66+
67+
instead, openapi-processor will add it on any `MappedFoo` property used in the generated model classes:
68+
69+
[source,java]
70+
----
71+
@Generated
72+
public class FooBar {
73+
74+
@Bar
75+
@JsonProperty("foo")
76+
private MappedFoo foo;
77+
78+
// ....
79+
}
80+
----
81+
82+
3483
== mapping example
3584

3685
Given the following OpenAPI description, that describe two (echo like) endpoints that receive an object via post and return the same object. In the mapping file we add a custom bean validation annotation. It checks the sum of both properties in `Foo` and `Bar`.
@@ -132,7 +181,7 @@ map:
132181

133182
The `Sum` annotation in the example is a custom bean validation but the feature itself is not limited to bean validation.
134183

135-
<1> use `v2.1` as the mapping version to avoid validation warnings in the mapping file.
184+
<1> use `v2.1` (or later) as the mapping version to avoid validation warnings in the mapping file.
136185
<2> the `Bar` mapping is using a global type annotation mapping, so the annotation is added to the generated `Bar` class.
137186
<3> the `Foo` mapping adds the annotation to the parameter of the endpoint methods that use `Foo`.
138187
<4> this is a list of examples that shows annotation parameters.

docs/modules/ROOT/pages/mapping/structure.adoc

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
= type mapping structure
22
include::partial$links.adoc[]
33

4-
The type mapping is part of the mapping yaml (see xref:processor/configuration.adoc[Configuration])
5-
and configured under the `map` key. The `map` key contains multiple sections to define the different
6-
kinds of type mappings.
4+
The type mapping is part of the mapping yaml (see xref:processor/configuration.adoc[Configuration]) and configured under the `map` key. The `map` key contains multiple sections to define the different kinds of type mappings.
75

86
All sections are optional.
97

10-
== type mapping structure (v2)
8+
== type mapping structure
119

1210
//[.badge .badge-since]+since 1.0.0.M15+
1311

14-
This is the preferred format for the mapping. It is simpler than the previous format and uses fewer
15-
keywords.
16-
1712
[IMPORTANT]
1813
====
19-
To use the new format the mapping file needs the following key on the top-level. Best place is the
20-
first line of the `mapping.yaml` file.
14+
The mapping file needs the following key on the top-level. Best place is the first line of the `mapping.yaml` file.
2115
2216
[source,yaml]
2317
----
24-
openapi-processor-mapping: v2
18+
openapi-processor-mapping: v3
2519
----
2620
====
2721

22+
The version increases from time to time when openapi-processor requires a new or changed configuration. In case the version changes it is mentioned in the release notes.
23+
2824

29-
To map a source type to a destination type it is using an `=>` arrow as *mapping operator* instead
30-
of individual keywords:
25+
=== basic mapping
26+
27+
To map a source type to a destination type it is using an `=>` arrow as *mapping operator* instead of individual keywords:
3128

3229
[source,yaml]
3330
----
@@ -36,6 +33,8 @@ some-key: {source type} => {target type}
3633
3734
----
3835

36+
=== full structure
37+
3938
The full structure of the mapping looks like this (a real mapping file will usually use just a few of the possible keys):
4039

4140
[source,yaml]
@@ -56,8 +55,12 @@ map:
5655
5756
# list of global mappings
5857
types:
58+
# replace source type with the given target type
5959
- type: {source type} => {target type}
6060
61+
# add an extra annotation to the source type
62+
- type: {source type} @ {target type}
63+
6164
# list of global parameter mappings
6265
parameters:
6366
- name: {parameter name} => {target type}
@@ -94,8 +97,12 @@ map:
9497
9598
# list of path specific mappings
9699
types:
100+
# replace source type with the given target type
97101
- from: {source type} => {target type}
98102
103+
# add an extra annotation to the source type
104+
- type: {source type} @ {target type}
105+
99106
# list of path specific parameter mappings
100107
parameters:
101108
- name: {parameter name} => {target type}
@@ -124,8 +131,4 @@ The structure below `paths` is similar to an OpenAPI yaml file to make it easier
124131

125132
== json schema
126133

127-
Some IDEs support json schemas to provide editing support (auto completion & validation) for text based files. To support this openapi-processor has a link:{json-schema}[json schema] for the v2 mapping format.
128-
129-
== type mapping structure (v1)
130-
131-
This format of the mapping ist still available but should not be used anymore.
134+
Some IDEs support json schemas to provide editing support (auto-completion & validation) for text based files. To support this, openapi-processor provides json schemas for the mapping formats at link:{json-schema-site}[`https://openapiprocessor.io/schemas/mapping/mapping-v{version}.json`].

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ A mapping yaml looks like this:
88

99
[source,yaml]
1010
----
11-
openapi-processor-mapping: v2
11+
openapi-processor-mapping: v3
1212
1313
options:
1414
package-name: io.openapiprocessor.sample
1515
model-name-suffix: Resource
1616
one-of-interface: true
17-
bean-validation: true
17+
bean-validation: jakarta
1818
generated-date: true
1919
format-code: false
2020
javadoc: true
@@ -23,12 +23,11 @@ map:
2323
# java type mappings
2424
----
2525

26-
The only required option is `package-name`.All other options or the type mappings are optional.
26+
The only required option is `package-name`. All other options or the type mappings are optional.
2727

2828
== options:
2929

30-
* `package-name`: (**required**) the root package name of the generated interfaces & models.The
31-
package folder tree will be created inside the `targetDir` (see xref:gradle.adoc[using gradle]).
30+
* `package-name`: (**required**) the root package name of the generated interfaces & models.The package folder tree will be created inside the `targetDir` (see xref:gradle.adoc[using gradle]).
3231
+
3332
Interfaces and models will be generated into the `api` and `model` subpackages of `package-name`.
3433
+
@@ -37,8 +36,14 @@ Interfaces and models will be generated into the `api` and `model` subpackages o
3736

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

40-
* `bean-validation` (**optional**, `true` or `false`) enables generation of bean validation
41-
annotations. Default is `false`. See link:{bean-validation}[Bean Validation Specification, window="_blank"].
39+
* `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"].
40+
+
41+
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`).
42+
43+
** `false`: disables bean validation annotations
44+
** `true`: enables bean validation annotations v2, with `javax` package name
45+
** `javax`: enables bean validation annotations v2, with `javax` package name
46+
** `jakarta`: enables bean validation annotations v3, with `jakarta` package name
4247

4348
* `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.
4449

@@ -141,9 +146,6 @@ public class BarResource { // <4>
141146
<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`.
142147

143148

144-
145-
146-
147149
== map:
148150

149151
Using type mapping we can tell the processor to map types (schemas) from an `openapi.yaml`

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ A call to the `/ping` endpoint will simply respond with a plain text string resu
1313
[source,yaml]
1414
----
1515
openapi: 3.0.2
16-
info:
17-
title: openapi-processor-spring sample
18-
version: 1.0.0
16+
info:
17+
title: openapi-processor-spring sample
18+
version: 1.0.0
1919
2020
paths:
2121
/ping:

docs/modules/ROOT/partials/links.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
:badge-central: https://img.shields.io/maven-central/v/io.openapiprocessor/openapi-processor-spring?label=Maven%20Central
1717
:oapc-inttests: https://github.com/openapi-processor/openapi-processor-core/tree/master/src/testInt/resources/tests
1818
:json-schema: https://github.com/openapi-processor/openapi-processor-core/blob/master/src/main/resources/mapping/v2/mapping.yaml.json
19+
:json-schema-site: https://openapiprocessor.io/schemas/mapping/mapping-v3.json
1920

2021
//
2122
// other external links

0 commit comments

Comments
 (0)