Skip to content

Commit 58ce1ef

Browse files
committed
#55, find endpoint/method add parameter mapping
1 parent 335a6de commit 58ce1ef

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
8383
* @throws AmbiguousTypeMappingException if there is more than one match.
8484
*/
8585
fun findEndpointAddParameterTypeMappings(path: String, method: HttpMethod): List<AddParameterTypeMapping> {
86-
return filterMappings(EndpointTypeMatcher(path, method), typeMappings)
86+
// check with method
87+
val m = filterMappings(EndpointTypeMatcher(path, method), typeMappings)
88+
.filterIsInstance<AddParameterTypeMapping>()
89+
if (m.isNotEmpty())
90+
return m
91+
92+
// check without method, i.e. all methods
93+
return filterMappings(EndpointTypeMatcher(path, null), typeMappings)
8794
.filterIsInstance<AddParameterTypeMapping>()
8895
}
8996

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.openapiprocessor.core.converter.mapping
77

88
import io.kotest.core.spec.style.StringSpec
9+
import io.kotest.matchers.collections.shouldNotBeEmpty
910
import io.kotest.matchers.nulls.shouldNotBeNull
1011
import io.kotest.matchers.shouldBe
1112
import io.mockk.mockk
@@ -101,4 +102,24 @@ class MappingFinderEndpointMethodSpec: StringSpec({
101102
result.targetTypeName.shouldBe("org.openapitools.jackson.nullable.JsonNullable")
102103
}
103104

105+
"endpoint/method add parameter mapping matches" {
106+
val finder = MappingFinder(
107+
listOf(
108+
EndpointTypeMapping("/foo", null, emptyList()),
109+
EndpointTypeMapping("/foo", HttpMethod.GET, listOf(
110+
AddParameterTypeMapping("foo param",
111+
TypeMapping(null, "io.openapiprocessor.Foo")),
112+
AddParameterTypeMapping("bar param",
113+
TypeMapping(null, "io.openapiprocessor.Foo"))
114+
)))
115+
)
116+
117+
val info = SchemaInfo(foo, "", "", null, resolver)
118+
val result = finder.findEndpointAddParameterTypeMappings(info.getPath(), info.getMethod())
119+
120+
result.shouldNotBeEmpty()
121+
result[0].parameterName.shouldBe("foo param")
122+
result[1].parameterName.shouldBe("bar param")
123+
}
124+
104125
})

0 commit comments

Comments
 (0)