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

Commit 1009a0d

Browse files
committed
want to use option value, #68
1 parent 5308f45 commit 1009a0d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package io.openapiprocessor.core.converter.mapping
88
import io.openapiprocessor.core.converter.SchemaInfo
99
import io.openapiprocessor.core.converter.mapping.matcher.*
1010
import io.openapiprocessor.core.model.HttpMethod
11+
import io.openapiprocessor.core.processor.mapping.v2.ResultStyle
1112

1213
/**
1314
* find mappings of a given schema info in the type mapping list.
@@ -127,6 +128,24 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
127128
return matches.first() as ResultTypeMapping
128129
}
129130

131+
/**
132+
* get (global) result style option mapping value.
133+
*
134+
* @return the [ResultStyle] if set, else the default value [ResultStyle.ALL]
135+
*/
136+
fun findResultStyleMapping(): ResultStyle {
137+
val matches = typeMappings
138+
.filterIsInstance(OptionMapping::class.java)
139+
.filter { it.name == "resultStyle" }
140+
.map { it as OptionMapping<ResultStyle> }
141+
142+
// default
143+
if (matches.isEmpty())
144+
return ResultStyle.SUCCESS
145+
146+
return matches.first().value
147+
}
148+
130149
/**
131150
* find (endpoint) "single" type mappings.
132151
*

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

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

88
import io.kotest.assertions.throwables.shouldThrow
99
import io.kotest.core.spec.style.StringSpec
10+
import io.kotest.inspectors.forAll
1011
import io.kotest.matchers.nulls.shouldBeNull
1112
import io.kotest.matchers.nulls.shouldNotBeNull
1213
import io.kotest.matchers.shouldBe
1314
import io.mockk.mockk
1415
import io.openapiprocessor.core.converter.SchemaInfo
1516
import io.openapiprocessor.core.model.HttpMethod
1617
import io.openapiprocessor.core.parser.RefResolver
18+
import io.openapiprocessor.core.processor.mapping.v2.ResultStyle
1719

1820
class MappingFinderSpec: StringSpec({
1921
val resolver = mockk<RefResolver>()
@@ -278,4 +280,17 @@ class MappingFinderSpec: StringSpec({
278280
result.targetTypeName.shouldBe("org.openapitools.jackson.nullable.JsonNullable")
279281
}
280282

283+
"find result style option mapping" {
284+
listOf(
285+
ResultStyle.ALL,
286+
ResultStyle.SUCCESS
287+
).forAll { style ->
288+
val finder = MappingFinder(listOf(OptionMapping("resultStyle", style)))
289+
290+
val result = finder.findResultStyleMapping()
291+
292+
result.shouldBe(style)
293+
}
294+
}
295+
281296
})

0 commit comments

Comments
 (0)