You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is possible to add additional annotations to a `source type`. Currently, this is *ONLY*available for endpoint method parameters. Since a `requestBody` is passed as parameter the mapping will work fot it too.
4
+
It is possible to add additional annotations to a `source type`. Currently, this is available as
4
5
5
-
== additional parameter annotations
6
+
* global _annotation type mapping_:
7
+
+
8
+
it adds an annotation to the model class generated for the `source type`.
6
9
7
-
To add an annotation to a `source type` (i.e. an OpenAPI type) parameter the mapping supports an _annotation type mapping_. It is defined like below, and it should be added to the `map/parameters` section in the mapping.yaml.
10
+
* global & endpoint parameter _annotation type mapping_:
11
+
+
12
+
it adds an annotation to a parameter of the `source type`. Since the request body is passed as parameter the mapping will work for it too.
8
13
9
-
It is also available as an endpoint (method) mapping to restrict the mapping to a specific endpoint. This will go to the `map/paths/<endpoint path>/parameters` section in the mapping.yaml.
14
+
It is defined like below, and it should be added to the `map/types` or `map/parameters` section in the mapping.yaml.
15
+
16
+
It is also available as an endpoint (http method) mapping to restrict the mapping to a specific endpoint. This will go to the `map/paths/<endpoint path>/parameters` section in the mapping.yaml.
10
17
11
18
The annotation type mapping is similar to other mappings and is defined like this:
12
19
@@ -22,96 +29,123 @@ receive the additional annotation.
22
29
23
30
****{annotation type}** is the fully qualified class name of the java annotation type. It may have parameters (see example below).
24
31
32
+
The link:{oap-samples}[samples project] has a small example using annotation mappings similar to the one described below.
25
33
26
34
== mapping example
27
35
28
-
Given the following OpenAPI description:
36
+
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`.
29
37
30
38
[source,yaml]
31
39
----
32
-
openapi: 3.0.3
40
+
openapi: 3.1.0
33
41
info:
34
42
title: openapi-processor-spring sample api
35
43
version: 1.0.0
36
44
37
45
paths:
38
46
/foo:
39
-
get:
47
+
post:
40
48
tags:
41
49
- foo
42
50
summary: annotation mapping example.
43
-
description: a simple endpoint where an annotation mapping is used
44
-
parameters:
45
-
- in: query
46
-
name: foo
47
-
schema:
48
-
$ref: '#/components/schemas/Foo'
51
+
description: a simple endpoint where an annotation mapping is used on the request body
52
+
requestBody:
53
+
content:
54
+
application/json:
55
+
schema:
56
+
$ref: '#/components/schemas/Foo'
57
+
required: true
49
58
responses:
50
-
'204':
51
-
description: no content
52
-
53
-
/foo-body:
59
+
'200':
60
+
description: echo of the source parameter
61
+
content:
62
+
application/json:
63
+
schema:
64
+
$ref: '#/components/schemas/Foo'
65
+
66
+
/bar:
54
67
post:
55
68
tags:
56
-
- foo
69
+
- bar
57
70
summary: annotation mapping example.
58
-
description: a simple endpoint where an annotation mapping is used
71
+
description: a simple endpoint where an annotation mapping is used on the request body
59
72
requestBody:
60
73
content:
61
74
application/json:
62
75
schema:
63
-
$ref: '#/components/schemas/Foo'
76
+
$ref: '#/components/schemas/Bar'
64
77
required: true
65
78
responses:
66
-
'204':
67
-
description: no content
79
+
'200':
80
+
description: echo of the source parameter
81
+
content:
82
+
application/json:
83
+
schema:
84
+
$ref: '#/components/schemas/Bar'
68
85
69
86
components:
70
87
schemas:
71
88
Foo:
72
89
type: object
73
90
properties:
74
-
bar:
75
-
type: string
91
+
foo1:
92
+
type: integer
93
+
minimum: 0
94
+
foo2:
95
+
type: integer
96
+
minimum: -10
97
+
98
+
Bar:
99
+
type: object
100
+
properties:
101
+
bar1:
102
+
type: integer
103
+
bar2:
104
+
type: integer
76
105
----
77
106
78
-
and a `mapping.yaml` with annotation type mappings. This one uses endpoint specific annotation mappings to show it with and without parameters.
107
+
and a `mapping.yaml` with annotation type mappings:
79
108
80
109
[source,yaml]
81
110
----
82
111
openapi-processor-mapping: v2
83
112
84
113
options:
85
114
package-name: io.openapiprocessor.openapi
115
+
javadoc: true
116
+
format-code: true
117
+
bean-validation: true
86
118
87
119
map:
120
+
types:
121
+
- type: Bar @ io.openapiprocessor.samples.validations.Sum(24) # <1>
To show the result with and without parameters the mappings are added only to the get/post http methods of the endpoint. We could call this an _endpoint http method annotation type mapping_ ;-).
133
+
The `Sum` annotation in the example is a custom bean validation but the feature itself is not limited to bean validation.
134
+
135
+
<1> the `Bar` mapping is using a global type annotation mapping, so the annotation is added to the generated `Bar` class.
136
+
<2> the `Foo` mapping adds the annotation to the parameter of the endpoint methods that use `Foo`.
137
+
<3> this is a list of examples that shows annotation parameters. It is nearly java code.
105
138
106
-
Here is the generated interface:
139
+
Here are the generated interfaces, first the `FooApi`:
0 commit comments