Skip to content

Commit ae0f402

Browse files
committed
add response interface option (#247)
1 parent 4c7efae commit ae0f402

6 files changed

Lines changed: 630 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ class ApiOptions: MappingSettings {
9292
*/
9393
var oneOfInterface = false
9494

95+
/**
96+
* enable/disable generation of a marker interface for responses. If a response has multiple different responses
97+
* (multiple status codes for the same content type) all objects will implement the marker interface. If enabled
98+
* an endpoint will return the interface data type, if disabled it will return Object.
99+
*/
100+
var responseInterface = false
101+
95102
/**
96103
* enable/disable the code formatter (optional).
97104
*/

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
@@ -86,6 +86,7 @@ class OptionsConverter(private val checkObsoleteProcessorOptions: Boolean = fals
8686

8787
options.javadoc = mapping.options.javadoc
8888
options.oneOfInterface = mapping.options.oneOfInterface
89+
options.responseInterface = mapping.options.responseInterface
8990

9091
val (enableFormatCode, formatCodeFormatter) = checkFormatter(mapping.options)
9192
options.formatCode = enableFormatCode

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ data class Options(
7272
*/
7373
val oneOfInterface: Boolean = false,
7474

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

0 commit comments

Comments
 (0)