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

Commit 722225a

Browse files
committed
#55, find endpoint/method null mapping
1 parent cefc40f commit 722225a

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,16 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
201201
*/
202202
fun findEndpointNullTypeMapping(info: SchemaInfo): NullTypeMapping? {
203203
val ep = filterMappings(EndpointTypeMatcher(info.getPath(), info.getMethod()), typeMappings)
204-
205204
val matches = filterMappings(NullTypeMatcher(), ep)
206-
if (matches.isEmpty())
207-
return null
205+
if (matches.isNotEmpty())
206+
return matches.first() as NullTypeMapping
208207

209-
return matches.first() as NullTypeMapping
208+
val epAll = filterMappings(EndpointTypeMatcher(info.getPath(), null), typeMappings)
209+
val matchesAll = filterMappings(NullTypeMatcher(), epAll)
210+
if (matchesAll.isNotEmpty())
211+
return matchesAll.first() as NullTypeMapping
212+
213+
return null
210214
}
211215

212216
/**

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,69 @@ class MappingFinderEndpointMethodSpec: StringSpec({
3636
result.targetTypeName.shouldBe("io.openapiprocessor.Foo")
3737
}
3838

39+
"endpoint/method parameter mapping matches single mapping" {
40+
val finder = MappingFinder(
41+
listOf(
42+
EndpointTypeMapping("/foo", null, emptyList()),
43+
EndpointTypeMapping("/foo", HttpMethod.GET, listOf(
44+
ParameterTypeMapping("foo param",
45+
TypeMapping("Foo", "io.openapiprocessor.Foo")),
46+
ParameterTypeMapping("far param",
47+
TypeMapping("far", "io.openapiprocessor.Far")),
48+
ParameterTypeMapping("bar param",
49+
TypeMapping("Bar", "io.openapiprocessor.Bar"))
50+
)))
51+
)
52+
53+
val info = SchemaInfo(foo, "far param", "", null, resolver)
54+
val result = finder.findEndpointTypeMapping(info)
55+
56+
result.shouldNotBeNull()
57+
result.sourceTypeName.shouldBe("far")
58+
result.targetTypeName.shouldBe("io.openapiprocessor.Far")
59+
}
60+
61+
"endpoint/method response mapping matches single mapping" {
62+
val finder = MappingFinder(
63+
listOf(
64+
EndpointTypeMapping("/foo", null, emptyList()),
65+
EndpointTypeMapping("/foo", HttpMethod.GET, listOf(
66+
ResponseTypeMapping("application/json",
67+
TypeMapping("Foo", "io.openapiprocessor.Foo")),
68+
ResponseTypeMapping("application/json-2",
69+
TypeMapping("far", "io.openapiprocessor.Far")),
70+
ResponseTypeMapping("application/json-3",
71+
TypeMapping("Bar", "io.openapiprocessor.Bar"))
72+
)))
73+
)
74+
75+
val info = SchemaInfo(foo, "", "application/json",null, resolver)
76+
val result = finder.findEndpointTypeMapping(info)
77+
78+
result.shouldNotBeNull()
79+
result.sourceTypeName.shouldBe("Foo")
80+
result.targetTypeName.shouldBe("io.openapiprocessor.Foo")
81+
}
82+
83+
"endpoint type mapping matches null mapping" {
84+
val finder = MappingFinder(
85+
listOf(
86+
EndpointTypeMapping("/foo", null, emptyList()),
87+
EndpointTypeMapping("/foo", HttpMethod.PATCH, listOf(
88+
NullTypeMapping("null", "org.openapitools.jackson.nullable.JsonNullable"),
89+
TypeMapping("Far", "io.openapiprocessor.Far"),
90+
TypeMapping("Bar", "io.openapiprocessor.Bar")
91+
)))
92+
)
93+
94+
val info = SchemaInfo(
95+
SchemaInfo.Endpoint("/foo", HttpMethod.PATCH),
96+
"Foo", "", null, resolver)
97+
val result = finder.findEndpointNullTypeMapping(info)
98+
99+
result.shouldNotBeNull()
100+
result.sourceTypeName.shouldBe("null")
101+
result.targetTypeName.shouldBe("org.openapitools.jackson.nullable.JsonNullable")
102+
}
103+
39104
})

0 commit comments

Comments
 (0)