Skip to content

Commit 721ad41

Browse files
committed
#55, find endpoint/method result mapping
1 parent 58ce1ef commit 721ad41

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,17 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
101101
* @return the "result" type mappings or null if there is no match.
102102
*/
103103
fun findEndpointResultTypeMapping(info: SchemaInfo): ResultTypeMapping? {
104-
val ep = filterMappings(EndpointTypeMatcher(info.getPath(), null/*info.getMethod()*/), typeMappings)
105-
104+
val ep = filterMappings(EndpointTypeMatcher(info.getPath(), info.getMethod()), typeMappings)
106105
val matches = filterMappings({ _: ResultTypeMapping -> true }, ep)
107-
if (matches.isEmpty())
108-
return null
106+
if (matches.isNotEmpty())
107+
return matches.first() as ResultTypeMapping
109108

110-
return matches.first() as ResultTypeMapping
109+
val epAll = filterMappings(EndpointTypeMatcher(info.getPath(), null), typeMappings)
110+
val matchesAll = filterMappings({ _: ResultTypeMapping -> true }, epAll)
111+
if (matchesAll.isNotEmpty())
112+
return matchesAll.first() as ResultTypeMapping
113+
114+
return null;
111115
}
112116

113117
/**

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,20 @@ class MappingFinderEndpointMethodSpec: StringSpec({
122122
result[1].parameterName.shouldBe("bar param")
123123
}
124124

125+
"endpoint/method result mapping matches" {
126+
val finder = MappingFinder(
127+
listOf(
128+
EndpointTypeMapping("/foo", null, emptyList()),
129+
EndpointTypeMapping("/foo", HttpMethod.GET, listOf(
130+
ResultTypeMapping("io.openapiprocessor.ResultWrapper")
131+
)))
132+
)
133+
134+
val info = SchemaInfo(foo, "", "", null, resolver)
135+
val result = finder.findEndpointResultTypeMapping(info)
136+
137+
result.shouldNotBeNull()
138+
result.targetTypeName.shouldBe("io.openapiprocessor.ResultWrapper")
139+
}
140+
125141
})

0 commit comments

Comments
 (0)