Skip to content

Commit 79dc233

Browse files
committed
#150, updated documentation
1 parent b1b7061 commit 79dc233

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

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

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,9 @@ Another example:
9999

100100
== mapping with generic types
101101

102-
Type mapping allows to use a target type that has generic parameters. The generic types are given
103-
by the **generics** property of the mapping. **generics** is a list and can contain multiple types.
102+
Type mapping allows to use a target type that has generic parameters. The generic types are given by the **generics** property of the mapping. **generics** is a list and can contain multiple types.
104103

105-
For example if a `StringPage` schema in the OpenAPI corresponds to
106-
`org.springframework.data.domain.Page<java.lang.String>`, it can be mapped to the Spring type by:
104+
For example if a `StringPage` schema in the OpenAPI corresponds to `org.springframework.data.domain.Page<java.lang.String>`, it can be mapped to the Spring type by:
107105

108106
[source,yaml]
109107
----
@@ -112,22 +110,52 @@ For example if a `StringPage` schema in the OpenAPI corresponds to
112110
- java.lang.String
113111
----
114112

115-
The processor will replace any use of `StringPage` with the **{target type}** type and add the generic
116-
types (in the given order) to the **{target type}** type.
113+
The processor will replace any use of `StringPage` with the **{target type}** type and add the generic types (in the given order) to the **{target type}** type.
117114

118-
In case of the example above the processor will create `Page<String>` instead of `StringPage` with an
119-
additional `import` for the generic type (.. ignoring imports on `java.lang`).
115+
In case of the example above the processor will create `Page<String>` instead of `StringPage` with an additional `import` for the generic type (.. ignoring imports on `java.lang`).
120116

121-
[IMPORTANT]
122-
The processor does support only one level of generics. It is not possible to provide generic
123-
parameters to generic parameters.
124-
125-
To get a more compact description it is possible to write a shorter mapping by inlining the generic
126-
types:
117+
To get a more compact description it is possible to write a shorter mapping by inlining the generic types:
127118

128119
[source,yaml]
129120
----
130121
- type: StringPage => org.springframework.data.domain.Page<java.lang.String>
131122
----
132123

133124
This will generate the same code as the longer mapping version above.
125+
126+
=== nested generic types
127+
[.badge .badge-since]+since 2023.1+
128+
129+
It is possible to create type mappings with nested generics types. Here are a few examples:
130+
131+
[source,yaml]
132+
----
133+
openapi-processor-mapping: v3
134+
135+
options:
136+
package-name: generated
137+
138+
map:
139+
types:
140+
- type: Foo => java.util.Map<java.lang.String, java.util.List<java.lang.String>>
141+
142+
paths:
143+
/foo:
144+
responses:
145+
- content: application/json => java.util.Map<java.lang.String, java.lang.String>
146+
147+
/foo2:
148+
responses:
149+
- content: application/json => java.util.Map<java.lang.String, java.util.List<java.lang.String>>
150+
----
151+
152+
This is useful to map an OpenAPI dictionary description using `additionalProperties` to a proper java map type:
153+
154+
[source,yaml]
155+
----
156+
# a schema the defines a dictionary with string keys and string values
157+
Map:
158+
type: object
159+
additionalProperties:
160+
type: string
161+
----

0 commit comments

Comments
 (0)