Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit f46d8b7

Browse files
committed
#55, want http method to find mapping
1 parent 0327dba commit f46d8b7

File tree

11 files changed

+36
-28
lines changed

11 files changed

+36
-28
lines changed

src/main/kotlin/io/openapiprocessor/core/converter/mapping/EndpointTypeMapping.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.openapiprocessor.core.converter.mapping
77

8+
import io.openapiprocessor.core.model.HttpMethod
9+
810
/**
911
* Used with [io.openapiprocessor.core.converter.ApiOptions] to store endpoint specific type
1012
* mappings. It can also be used to add parameters that are not defined in the api. For example
@@ -15,7 +17,13 @@ class EndpointTypeMapping @JvmOverloads constructor(
1517
/**
1618
* full path of the endpoint that is configured by this object.
1719
*/
18-
var path: String,
20+
val path: String,
21+
22+
/**
23+
* http method of this endpoint. If it is not set (i.e null) the mapping applies to all http
24+
* methods.
25+
*/
26+
val method: HttpMethod? = null,
1927

2028
/**
2129
* provides type mappings for the endpoint.

src/main/kotlin/io/openapiprocessor/core/processor/mapping/v1/MappingConverter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class MappingConverter {
154154
result.add (convertResponse (it))
155155
}
156156

157-
return EndpointTypeMapping(path, result, source.exclude)
157+
return EndpointTypeMapping(path, null, result, source.exclude)
158158
}
159159

160160
}

src/main/kotlin/io/openapiprocessor/core/processor/mapping/v2/MappingConverter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class MappingConverter(val mapping: MappingV2) {
172172
result.add (convertResponse (it))
173173
}
174174

175-
return EndpointTypeMapping(path, result, source.exclude)
175+
return EndpointTypeMapping(path, null, result, source.exclude)
176176
}
177177

178178
private data class MappingTypes(val result: String, val format: String)

src/test/groovy/com/github/hauner/openapi/core/converter/ApiConverterParameterSpec.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ paths:
213213
)
214214

215215
def options = new ApiOptions(packageName: 'pkg', typeMappings: [
216-
new EndpointTypeMapping('/foo', [
216+
new EndpointTypeMapping('/foo', null, [
217217
new AddParameterTypeMapping (
218218
'request', new TypeMapping (
219219
null,
@@ -258,7 +258,7 @@ paths:
258258
)
259259

260260
def options = new ApiOptions(packageName: 'pkg', typeMappings: [
261-
new EndpointTypeMapping('/foo', [
261+
new EndpointTypeMapping('/foo', null, [
262262
new AddParameterTypeMapping (
263263
'foo', new TypeMapping (
264264
null,

src/test/groovy/com/github/hauner/openapi/core/converter/ApiConverterRequestBodySpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ paths:
9999
)
100100

101101
def options = new ApiOptions(packageName: 'pkg', typeMappings: [
102-
new EndpointTypeMapping('/multipart/single-file', [
102+
new EndpointTypeMapping('/multipart/single-file', null, [
103103
new TypeMapping (
104104
'string',
105105
'binary',

src/test/groovy/com/github/hauner/openapi/core/converter/ApiConverterSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ paths:
227227
""")
228228

229229
def options = new ApiOptions(typeMappings: [
230-
new EndpointTypeMapping ('/foo', [], true)
230+
new EndpointTypeMapping ('/foo', null, [], true)
231231
])
232232

233233
when:

src/test/groovy/com/github/hauner/openapi/core/converter/DataTypeConverterArrayTypeMappingSpec.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ paths:
182182
)
183183
],
184184
[
185-
new EndpointTypeMapping ('/foo', [
185+
new EndpointTypeMapping ('/foo', null, [
186186
new ParameterTypeMapping (
187187
'param', new TypeMapping (
188188
'array',
@@ -221,7 +221,7 @@ paths:
221221

222222
when:
223223
def options = new ApiOptions(packageName: 'pkg', typeMappings: [
224-
new EndpointTypeMapping ('/foo', [
224+
new EndpointTypeMapping ('/foo', null, [
225225
new TypeMapping (
226226
'array',
227227
targetTypeName)
@@ -290,7 +290,7 @@ paths:
290290

291291
mappings << [
292292
[
293-
new EndpointTypeMapping ('/foobar', [
293+
new EndpointTypeMapping ('/foobar', null, [
294294
new ParameterTypeMapping (
295295
'foobar', new TypeMapping (
296296
'array',
@@ -352,7 +352,7 @@ paths:
352352

353353
mappings << [
354354
[
355-
new EndpointTypeMapping ('/array-string', [
355+
new EndpointTypeMapping ('/array-string', null, [
356356
new ResponseTypeMapping (
357357
'application/vnd.any', new TypeMapping (
358358
'array',
@@ -366,7 +366,7 @@ paths:
366366
'java.util.Collection')
367367
)
368368
], [
369-
new EndpointTypeMapping ('/array-string', [
369+
new EndpointTypeMapping ('/array-string', null, [
370370
new ResponseTypeMapping (
371371
'application/vnd.any', new TypeMapping (
372372
'array',
@@ -377,7 +377,7 @@ paths:
377377
'java.util.Collection')
378378
])
379379
], [
380-
new EndpointTypeMapping ('/array-string', [
380+
new EndpointTypeMapping ('/array-string', null, [
381381
new TypeMapping (
382382
'array',
383383
'java.util.Collection')

src/test/groovy/com/github/hauner/openapi/core/converter/DataTypeConverterObjectTypeMappingSpec.groovy

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ components:
221221
def options = new ApiOptions(
222222
packageName: 'pkg',
223223
typeMappings: [
224-
new EndpointTypeMapping ('/foobar', [
224+
new EndpointTypeMapping ('/foobar', null, [
225225
new TypeMapping (
226226
'Foo',
227227
'someA.ObjectA'),
@@ -290,7 +290,7 @@ paths:
290290

291291
mappings << [
292292
[
293-
new EndpointTypeMapping ('/foobar', [
293+
new EndpointTypeMapping ('/foobar', null, [
294294
new ParameterTypeMapping (
295295
'foobar', new TypeMapping (
296296
null,
@@ -355,7 +355,7 @@ paths:
355355

356356
mappings << [
357357
[
358-
new EndpointTypeMapping ('/object', [
358+
new EndpointTypeMapping ('/object', null, [
359359
new ResponseTypeMapping (
360360
'application/vnd.any', new TypeMapping (
361361
'object',
@@ -371,7 +371,7 @@ paths:
371371
['java.lang.String'])
372372
)
373373
], [
374-
new EndpointTypeMapping ('/object', [
374+
new EndpointTypeMapping ('/object', null, [
375375
new ResponseTypeMapping (
376376
'application/vnd.any', new TypeMapping (
377377
'object',
@@ -384,7 +384,7 @@ paths:
384384
['java.lang.StringType'])
385385
])
386386
], [
387-
new EndpointTypeMapping ('/object', [
387+
new EndpointTypeMapping ('/object', null, [
388388
new TypeMapping (
389389
'ObjectResponse200',
390390
'pkg.TargetClass',
@@ -433,7 +433,7 @@ components:
433433
def options = new ApiOptions(
434434
packageName: 'pkg',
435435
typeMappings: [
436-
new EndpointTypeMapping ('/endpoint-map', [
436+
new EndpointTypeMapping ('/endpoint-map', null, [
437437
new TypeMapping (
438438
'Props',
439439
'java.util.Map',
@@ -489,7 +489,7 @@ components:
489489
def options = new ApiOptions(
490490
packageName: 'pkg',
491491
typeMappings: [
492-
new EndpointTypeMapping ('/endpoint-map', [
492+
new EndpointTypeMapping ('/endpoint-map', null, [
493493
new TypeMapping (
494494
'Props',
495495
'org.springframework.util.MultiValueMap',

src/test/groovy/com/github/hauner/openapi/core/converter/DataTypeConverterPrimitiveTypeMappingSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ paths:
263263

264264
mappings << [
265265
[
266-
new EndpointTypeMapping ('/foo', [
266+
new EndpointTypeMapping ('/foo', null, [
267267
new ParameterTypeMapping (
268268
'bar', new TypeMapping (
269269
'string',

src/test/kotlin/io/openapiprocessor/core/converter/DataTypeConverterNullSpec.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DataTypeConverterNullSpec: StringSpec({
5555

5656
val options = ApiOptions()
5757
options.typeMappings = listOf(
58-
EndpointTypeMapping("/foo", listOf(
58+
EndpointTypeMapping("/foo", null, listOf(
5959
NullTypeMapping(
6060
"null",
6161
"org.openapitools.jackson.nullable.JsonNullable"

src/test/kotlin/io/openapiprocessor/core/converter/mapping/MappingFinderSpec.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class MappingFinderSpec: StringSpec({
159159
"endpoint parameter mapping matches single mapping" {
160160
val finder = MappingFinder(
161161
listOf(
162-
EndpointTypeMapping("/foo", listOf(
162+
EndpointTypeMapping("/foo", null, listOf(
163163
ParameterTypeMapping("foo param",
164164
TypeMapping("Foo", "io.openapiprocessor.Foo")),
165165
ParameterTypeMapping("far param",
@@ -180,7 +180,7 @@ class MappingFinderSpec: StringSpec({
180180
"endpoint response mapping matches single mapping" {
181181
val finder = MappingFinder(
182182
listOf(
183-
EndpointTypeMapping("/foo", listOf(
183+
EndpointTypeMapping("/foo", null, listOf(
184184
ResponseTypeMapping("application/json",
185185
TypeMapping("Foo", "io.openapiprocessor.Foo")),
186186
ResponseTypeMapping("application/json-2",
@@ -200,7 +200,7 @@ class MappingFinderSpec: StringSpec({
200200

201201
"throws on duplicate endpoint parameter mapping" {
202202
val finder = MappingFinder(listOf(
203-
EndpointTypeMapping("/foo", listOf(
203+
EndpointTypeMapping("/foo", null, listOf(
204204
ParameterTypeMapping("foo param",
205205
TypeMapping("Foo A", "io.openapiprocessor.Foo A")),
206206
ParameterTypeMapping("foo param",
@@ -218,7 +218,7 @@ class MappingFinderSpec: StringSpec({
218218
"throws on duplicate endpoint response mapping" {
219219
val finder = MappingFinder(
220220
listOf(
221-
EndpointTypeMapping("/foo", listOf(
221+
EndpointTypeMapping("/foo", null, listOf(
222222
ResponseTypeMapping("application/json",
223223
TypeMapping("Foo", "io.openapiprocessor.Foo")),
224224
ResponseTypeMapping("application/json",
@@ -236,7 +236,7 @@ class MappingFinderSpec: StringSpec({
236236
"endpoint type mapping matches single mapping" {
237237
val finder = MappingFinder(
238238
listOf(
239-
EndpointTypeMapping("/foo", listOf(
239+
EndpointTypeMapping("/foo", null, listOf(
240240
TypeMapping("Foo", "io.openapiprocessor.Foo"),
241241
TypeMapping("Far", "io.openapiprocessor.Far"),
242242
TypeMapping("Bar", "io.openapiprocessor.Bar")
@@ -263,7 +263,7 @@ class MappingFinderSpec: StringSpec({
263263
"endpoint type mapping matches null mapping" {
264264
val finder = MappingFinder(
265265
listOf(
266-
EndpointTypeMapping("/foo", listOf(
266+
EndpointTypeMapping("/foo", null, listOf(
267267
NullTypeMapping("null", "org.openapitools.jackson.nullable.JsonNullable"),
268268
TypeMapping("Far", "io.openapiprocessor.Far"),
269269
TypeMapping("Bar", "io.openapiprocessor.Bar")

0 commit comments

Comments
 (0)