Skip to content

Commit 211e824

Browse files
committed
jackson 3 support (#364)
1 parent de40d4e commit 211e824

12 files changed

Lines changed: 796 additions & 11 deletions

File tree

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/converter/ApiOptions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ class ApiOptions: MappingSettings {
6666
var beanValidationFormat: String? = null
6767

6868
/**
69-
* Bean Validation format: com.fasterxml.jackson (v2) or tools.jackson (v3)
69+
* jackson version: com.fasterxml.jackson (v2) or tools.jackson (v3)
7070
*/
71-
var jacksonFormat: String = "2"
71+
var jackson: String = "v2"
7272

7373
/**
7474
* enable/disable generation of Javadoc comments based on the `description` OpenAPI property.

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/converter/OptionsConverter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class OptionsConverter(private val checkObsoleteProcessorOptions: Boolean = fals
9898
options.targetDirOptions.layout = TargetDirLayout.STANDARD
9999
}
100100

101+
options.jackson = mapping.options.jackson
101102
options.javadoc = mapping.options.javadoc
102103
options.oneOfInterface = mapping.options.oneOfInterface
103104
options.responseInterface = mapping.options.responseInterface

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/processor/MappingConverter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import io.openapiprocessor.core.processor.mapping.v2.Mapping as MappingV2
1111
import io.openapiprocessor.core.processor.mapping.v2.MappingConverter as MappingConverterV2
1212

1313
/**
14-
* Converter for the type mapping from the mapping yaml. It converts the type mapping information
14+
* Converter for the type mapping from the mapping YAML. It converts the type mapping information
1515
* into the format used by [io.openapiprocessor.core.converter.DataTypeConverter].
1616
*/
1717
class MappingConverter {

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/processor/mapping/v2/Options.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ data class Options(
4040
val beanValidation: String = "false",
4141

4242
/**
43-
* generate javadoc (optional)
43+
* jackson (optional)
44+
*/
45+
val jackson: String = "v2",
46+
47+
/**
48+
* generate Javadoc (optional)
4449
*/
4550
val javadoc: Boolean = false,
4651

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/writer/java/JacksonAnnotations.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class JacksonAnnotations(apiOptions: ApiOptions) {
3333
fun getJsonValue(): Annotation = jsonValue
3434

3535
private fun getJacksonFormat(options: ApiOptions): JacksonFormat {
36-
return when (options.jacksonFormat) {
37-
"2" -> JacksonFormat.V2
38-
"3" -> JacksonFormat.V3
36+
return when (options.jackson) {
37+
"v2" -> JacksonFormat.V2
38+
"v3" -> JacksonFormat.V3
3939
else -> JacksonFormat.V2
4040
}
4141
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
##
2+
## mapping example with keys and values
3+
##
4+
5+
# mapping format (required)
6+
openapi-processor-mapping: v18
7+
8+
options: # general processor options (required)
9+
10+
# the target package (required): io.openapiprocessor.generated (default)
11+
# package-name: io.openapiprocessor.generated
12+
13+
# package-name related options
14+
package-names:
15+
# same as package-name
16+
base: io.openapiprocessor.generated
17+
18+
# base package name of location-based generated files
19+
location: io.openapiprocessor
20+
21+
# enable validation annotations (optional): true or false (default), javax, jakarta
22+
bean-validation: jakarta
23+
24+
# jackson version (optional): 2 (default), 3
25+
jackson: v2
26+
27+
# generate Javadoc from OpenAPI 'description' properties.
28+
javadoc: true
29+
30+
# enable/disable code formatter: false (default), true (= google), google or eclipse
31+
format-code: false
32+
33+
# add suffix for model class names and enum names. not set (default)
34+
model-name-suffix: Resource
35+
36+
# create pojo (= default) (default) or record
37+
model-type: default
38+
39+
# generate unreferenced model from components/schemas, true or false (default)
40+
model-unreferenced: true
41+
42+
# default, string, supplier
43+
enum-type: default
44+
45+
# generate common interface for an `oneOf` object list (optional): true or false (default)
46+
one-of-interface: true
47+
48+
# generate a common interface for different response types of the same content-type
49+
response-interface: true
50+
51+
# enable/disable deletion of targetDir: true (default) or false.
52+
clear-target-dir: false
53+
54+
# enable/disable @Generated annotation
55+
generated-annotation: true
56+
57+
# enable/disable date on @Generated annotation
58+
generated-date: true
59+
60+
# control @JsonProperty annotation (always|auto|never)
61+
json-property-annotation: always
62+
63+
# target-dir related configuration
64+
target-dir:
65+
clear: true
66+
layout: standard
67+
68+
# server-url related configuration
69+
base-path:
70+
# false, true = 0, 1, etc.
71+
prefix: 0
72+
# property resource with the uri base path
73+
properties-name: openapi.properties
74+
75+
logging:
76+
mapping: true
77+
mapping-target: stdout
78+
79+
compatibility:
80+
bean-validation-valid-on-reactive: false
81+
identifier-word-break-from-digit-to-letter: false
82+
83+
bean-validation:
84+
javax.validation.constraints.Size:
85+
- org.openapitools.jackson.nullable.JsonNullable
86+
87+
map: # the type mappings
88+
89+
# global mappings, applies to all paths/endpoints
90+
91+
# x-www-form-urlencoded as object ord destructured parameters
92+
body-style: destructure
93+
94+
# response wrapper (optional)
95+
result: org.springframework.http.ResponseEntity
96+
97+
# result style (optional, default "success")
98+
result-style: all
99+
100+
# result status annotation (optional, default true)
101+
result-status: true
102+
103+
# reactive single wrapper (optional)
104+
single: reactor.core.publisher.Mono
105+
106+
# reactive array wrapper (optional)
107+
multi: reactor.core.publisher.Flux
108+
109+
types: # global type mappings (optional)
110+
- type: array => java.util.Collection
111+
112+
- type: Schema => java.util.Map
113+
generics:
114+
- java.lang.String
115+
- java.lang.Double
116+
- type: Schema =+ java.io.Serializable
117+
- type: Schema @ io.openapiprocessor.Annotation()
118+
119+
schemas: # global schema mappings (optional)
120+
- type: Schema @ io.openapiprocessor.Annotation()
121+
122+
parameters: # global parameter mappings (optional)
123+
- name: foo => java.util.List
124+
- name: bar => com.github.hauner.openapi.Bar
125+
- name: param @ io.openapiprocessor.Annotation()
126+
- type: Schema =+ java.io.Serializable
127+
- type: Schema @ io.openapiprocessor.Annotation()
128+
129+
responses: # global response mappings (optional)
130+
- content: application/vnd.something => java.util.List
131+
- content: application/json => com.github.hauner.openapi.FooBar
132+
133+
paths: # path/endpoint specific mappings (optional)
134+
135+
/first: # a path/endpoint from the openapi.yaml
136+
137+
# generate endpoint to a separate "excluded" interface
138+
exclude: true
139+
140+
/second: # another path/endpoint from the openapi.yaml
141+
142+
# path mappings allow the same mappings as on the global level (except the "paths" property)
143+
# all mappings apply only to the parent path overriding any matching global mapping
144+
145+
# override top level "result" property, "plain" means no wrapper
146+
body-style: object
147+
result: plain
148+
single: reactor.core.publisher.Mono
149+
multi: reactor.core.publisher.Flux
150+
151+
types:
152+
- type: Schema => java.util.Collection
153+
- type: Schema =+ java.io.Serializable
154+
155+
schemas:
156+
- type: Schema @ io.openapiprocessor.Annotation()
157+
158+
parameters:
159+
- name: foo => java.util.List
160+
- add: bar => java.util.Set
161+
- type: Schema =+ java.io.Serializable
162+
- type: Schema @ io.openapiprocessor.Annotation()
163+
164+
responses:
165+
- content: application/vnd.any => java.util.Set
166+
- content: application/json => java.util.Map
167+
168+
/third:
169+
result: plain
170+
171+
# path mappings can be limited to a specific http method
172+
173+
patch:
174+
# path method mappings allow the same mappings as on the global level (except the "paths" property)
175+
# all mappings apply only to the parent path and method overriding any matching global mapping
176+
177+
null: org.openapitools.jackson.nullable.JsonNullable = JsonNullable.undefined()
178+
179+
extensions:
180+
x-something: foo @ some.Annotation
181+
x-something-else:
182+
- foo @ some.custom.FooAnnotation
183+
- bar @ some.custom.BarAnnotation
184+
185+
annotation-targets:
186+
lombok.Builder: ['type', 'method']

0 commit comments

Comments
 (0)