Skip to content

Commit bdb082d

Browse files
committed
#55, find endpoint/method is excluded
1 parent 498bf12 commit bdb082d

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,17 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
202202
fun isExcludedEndpoint(path: String, method: HttpMethod): Boolean {
203203
val ep = typeMappings
204204
.filterIsInstance<EndpointTypeMapping>()
205-
.filter(EndpointTypeMatcher(path, null/*method*/))
205+
.filter(EndpointTypeMatcher(path, method))
206+
if (ep.isNotEmpty())
207+
return ep.first().exclude
206208

207-
if (ep.isEmpty())
208-
return false
209-
210-
// todo check multiple matches
209+
val epAll = typeMappings
210+
.filterIsInstance<EndpointTypeMapping>()
211+
.filter(EndpointTypeMatcher(path, null))
212+
if (epAll.isNotEmpty())
213+
return epAll.first().exclude
211214

212-
return ep.first().exclude
215+
return false
213216
}
214217

215218
/**

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

Lines changed: 28 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.booleans.shouldBeTrue
910
import io.kotest.matchers.collections.shouldNotBeEmpty
1011
import io.kotest.matchers.nulls.shouldNotBeNull
1112
import io.kotest.matchers.shouldBe
@@ -200,4 +201,31 @@ class MappingFinderEndpointMethodSpec: StringSpec({
200201
result.targetTypeName.shouldBe("io.openapiprocessor.MultiWrapper")
201202
}
202203

204+
"endpoint/method excluded" {
205+
val finder = MappingFinder(
206+
listOf(
207+
EndpointTypeMapping("/foo", null, emptyList()),
208+
EndpointTypeMapping("/foo", HttpMethod.GET, emptyList(), true)
209+
)
210+
)
211+
212+
val info = SchemaInfo(foo, "", "", null, resolver)
213+
val result = finder.isExcludedEndpoint(info.getPath(), info.getMethod())
214+
215+
result.shouldBeTrue()
216+
}
217+
218+
"endpoint excluded" {
219+
val finder = MappingFinder(
220+
listOf(
221+
EndpointTypeMapping("/foo", null, emptyList(), true)
222+
)
223+
)
224+
225+
val info = SchemaInfo(foo, "", "", null, resolver)
226+
val result = finder.isExcludedEndpoint(info.getPath(), info.getMethod())
227+
228+
result.shouldBeTrue()
229+
}
230+
203231
})

0 commit comments

Comments
 (0)