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

Commit e31b9aa

Browse files
committed
#55, find endpoint/method single/multi mapping
1 parent 89fd0d8 commit e31b9aa

File tree

2 files changed

+79
-9
lines changed

2 files changed

+79
-9
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
111111
if (matchesAll.isNotEmpty())
112112
return matchesAll.first() as ResultTypeMapping
113113

114-
return null;
114+
return null
115115
}
116116

117117
/**
@@ -135,12 +135,16 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
135135
*/
136136
fun findEndpointSingleTypeMapping(info: SchemaInfo): TypeMapping? {
137137
val ep = filterMappings(EndpointTypeMatcher(info.getPath(), info.getMethod()), typeMappings)
138-
139138
val matches = filterMappings(SingleTypeMatcher(), ep)
140-
if (matches.isEmpty())
141-
return null
139+
if (matches.isNotEmpty())
140+
return matches.first() as TypeMapping
142141

143-
return matches.first() as TypeMapping
142+
val epAll = filterMappings(EndpointTypeMatcher(info.getPath(), null), typeMappings)
143+
val matchesAll = filterMappings(SingleTypeMatcher(), epAll)
144+
if (matchesAll.isNotEmpty())
145+
return matchesAll.first() as TypeMapping
146+
147+
return null
144148
}
145149

146150
/**
@@ -164,12 +168,16 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
164168
*/
165169
fun findEndpointMultiTypeMapping(info: SchemaInfo): TypeMapping? {
166170
val ep = filterMappings(EndpointTypeMatcher(info.getPath(), info.getMethod()), typeMappings)
167-
168171
val matches = filterMappings(MultiTypeMatcher(), ep)
169-
if (matches.isEmpty())
170-
return null
172+
if (matches.isNotEmpty())
173+
return matches.first() as TypeMapping
171174

172-
return matches.first() as TypeMapping
175+
val epAll = filterMappings(EndpointTypeMatcher(info.getPath(), null), typeMappings)
176+
val matchesAll = filterMappings(MultiTypeMatcher(), epAll)
177+
if (matchesAll.isNotEmpty())
178+
return matchesAll.first() as TypeMapping
179+
180+
return null
173181
}
174182

175183
/**

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,66 @@ class MappingFinderEndpointMethodSpec: StringSpec({
138138
result.targetTypeName.shouldBe("io.openapiprocessor.ResultWrapper")
139139
}
140140

141+
"endpoint/method single mapping matches" {
142+
val finder = MappingFinder(
143+
listOf(
144+
EndpointTypeMapping("/foo", null, emptyList()),
145+
EndpointTypeMapping("/foo", HttpMethod.GET, listOf(
146+
TypeMapping("single", "io.openapiprocessor.SingleWrapper")
147+
)))
148+
)
149+
150+
val info = SchemaInfo(foo, "", "", null, resolver)
151+
val result = finder.findEndpointSingleTypeMapping(info)
152+
153+
result.shouldNotBeNull()
154+
result.targetTypeName.shouldBe("io.openapiprocessor.SingleWrapper")
155+
}
156+
157+
"endpoint single mapping matches" {
158+
val finder = MappingFinder(
159+
listOf(
160+
EndpointTypeMapping("/foo", null, listOf(
161+
TypeMapping("single", "io.openapiprocessor.SingleWrapper")
162+
)))
163+
)
164+
165+
val info = SchemaInfo(foo, "", "", null, resolver)
166+
val result = finder.findEndpointSingleTypeMapping(info)
167+
168+
result.shouldNotBeNull()
169+
result.targetTypeName.shouldBe("io.openapiprocessor.SingleWrapper")
170+
}
171+
172+
"endpoint/method multi mapping matches" {
173+
val finder = MappingFinder(
174+
listOf(
175+
EndpointTypeMapping("/foo", null, emptyList()),
176+
EndpointTypeMapping("/foo", HttpMethod.GET, listOf(
177+
TypeMapping("multi", "io.openapiprocessor.MultiWrapper")
178+
)))
179+
)
180+
181+
val info = SchemaInfo(foo, "", "", null, resolver)
182+
val result = finder.findEndpointMultiTypeMapping(info)
183+
184+
result.shouldNotBeNull()
185+
result.targetTypeName.shouldBe("io.openapiprocessor.MultiWrapper")
186+
}
187+
188+
"endpoint multi mapping matches" {
189+
val finder = MappingFinder(
190+
listOf(
191+
EndpointTypeMapping("/foo", null, listOf(
192+
TypeMapping("multi", "io.openapiprocessor.MultiWrapper")
193+
)))
194+
)
195+
196+
val info = SchemaInfo(foo, "", "", null, resolver)
197+
val result = finder.findEndpointMultiTypeMapping(info)
198+
199+
result.shouldNotBeNull()
200+
result.targetTypeName.shouldBe("io.openapiprocessor.MultiWrapper")
201+
}
202+
141203
})

0 commit comments

Comments
 (0)