Skip to content

Commit 53ce448

Browse files
committed
improve documentation (cherry picked from commit 74475a8)
1 parent 91e3fdc commit 53ce448

File tree

1 file changed

+48
-15
lines changed

1 file changed

+48
-15
lines changed

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

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,57 @@ 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 receive the additional annotation. This can be a **{type}:{format}** combination like `string:uuid`.
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`.
2828

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

31-
The link:{oap-samples}[samples project] has a small example using annotation mappings similar to the one described below.
31+
Here is a list of examples using different parameters:
32+
33+
[source,yaml]
34+
----
35+
- type: Foo @ annotation.Bar
36+
- type: Foo @ annotation.Bar()
37+
- type: Foo @ annotation.Bar("bar")
38+
- type: Foo @ annotation.Bar(2)
39+
- type: Foo @ annotation.Bar(true)
40+
- type: Foo @ annotation.Bar(package.Foobar.class) # <1>
41+
- type: Foo @ annotation.Bar(value = "bar", foo = 2)
42+
----
43+
44+
<1> [.badge .badge-since]+since 2023.2+ use a *class* as annotation parameter.
45+
46+
*`object` source type*
47+
48+
[.badge .badge-since]+since 2023.3+
49+
50+
it is also possible to add an annotation to **all** generated schema/model classes using a single annotation mapping:
51+
52+
[source,yaml]
53+
----
54+
- type: object @ annotation
55+
----
56+
57+
The `object` string represents **all** generated object classes (i.e. schema/model classes) and will add the given annotation **only** at the class level.
58+
59+
For example, a mapping like this:
60+
61+
[source,yaml]
62+
----
63+
map:
64+
types:
65+
- type: object @ lombok.Builder
66+
----
67+
68+
[source,java]
69+
----
70+
@Builder
71+
@Generated(...)
72+
public class Foo {
73+
...
74+
}
75+
----
76+
77+
The link:{oap-samples}[samples project] has a small example using annotation mappings.
3278

3379
== combining annotation mapping and type mapping
3480

@@ -171,26 +217,13 @@ map:
171217
172218
parameters:
173219
- type: Foo @ io.openapiprocessor.samples.validations.Sum(value = 42) # <3>
174-
175-
# this formats do work too <4>
176-
# - type: Foo @ annotation.Bar
177-
# - type: Foo @ annotation.Bar()
178-
# - type: Foo @ annotation.Bar("bar")
179-
# - type: Foo @ annotation.Bar(2)
180-
# - type: Foo @ annotation.Bar(true)
181-
# - type: Foo @ annotation.Bar(package.Foobar.class)
182-
# - type: Foo @ annotation.Bar(value = "bar", foo = 2)
183220
----
184221

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

187224
<1> use `v2.1` (or later) as the mapping version to avoid validation warnings in the mapping file.
188225
<2> the `Bar` mapping is using a global type annotation mapping, so the annotation is added to the generated `Bar` class.
189226
<3> the `Foo` mapping adds the annotation to the parameter of the endpoint methods that use `Foo`.
190-
<4> this is a list of examples that shows a number of different annotation parameter possibilities.
191-
+
192-
[.badge .badge-since]+NEW+ in this version is the possibility to use a *class* as annotation parameter.
193-
194227

195228
Here are the generated interfaces, first the `FooApi`:
196229

0 commit comments

Comments
 (0)