This repository was archived by the owner on Mar 16, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +55
-6
lines changed
main/kotlin/io/openapiprocessor/core/processor
test/kotlin/io/openapiprocessor/core/processor/mapping/v2 Expand file tree Collapse file tree 3 files changed +55
-6
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ import io.openapiprocessor.core.processor.mapping.v2.Mapping as MappingV2
2525
2626/* *
2727 * Converter for the type mapping from the mapping yaml. It converts the type mapping information
28- * into the format used by [com.github.hauner.openapi .core.converter.DataTypeConverter].
28+ * into the format used by [io.openapiprocessor .core.converter.DataTypeConverter].
2929 *
3030 * @author Martin Hauner
3131 */
@@ -37,7 +37,7 @@ class MappingConverter {
3737 }
3838
3939 return if (source.v2) {
40- MappingConverterV2 ().convert( source as MappingV2 )
40+ MappingConverterV2 (source as MappingV2 ).convert( )
4141 } else {
4242 MappingConverterV1 ().convert(source as MappingV1 )
4343 }
Original file line number Diff line number Diff line change @@ -28,18 +28,18 @@ import org.antlr.v4.runtime.tree.ParseTreeWalker
2828
2929/* *
3030 * Converter for the type mapping from the mapping yaml. It converts the type mapping information
31- * into the format used by {@link com.github.hauner.openapi.spring. converter.DataTypeConverter} .
31+ * into the format used by [io.openapiprocessor.core. converter.DataTypeConverter] .
3232 *
3333 * @author Martin Hauner
3434 */
35- class MappingConverter {
35+ class MappingConverter ( val mapping : MappingV2 ) {
3636 companion object {
3737 private const val SEPARATOR_TYPE = " => "
3838 private const val SEPARATOR_FORMAT = " :"
3939 private val PATTERN_GENERICS = " (\\ S+?)\\ s*<(.+?)>" .toPattern()
4040 }
4141
42- fun convert (mapping : MappingV2 ): List <Mapping > {
42+ fun convert (): List <Mapping > {
4343 val result = ArrayList <Mapping >()
4444
4545 if (mapping.map.result != null ) {
@@ -201,7 +201,13 @@ class MappingConverter {
201201 generics = typeGenerics
202202 }
203203
204- return ToType (name, generics)
204+ return ToType (name, resolvePackageVariable(generics))
205+ }
206+
207+ private fun resolvePackageVariable (source : List <String >): List <String > {
208+ return source.map {
209+ it.replace(" {package-name}" , mapping.options.packageName)
210+ }
205211 }
206212
207213}
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright © 2020 https://github.com/openapi-processor/openapi-processor-core
3+ * PDX-License-Identifier: Apache-2.0
4+ */
5+
6+ package io.openapiprocessor.core.processor.mapping.v2
7+
8+ import io.kotest.core.spec.IsolationMode
9+ import io.kotest.core.spec.style.StringSpec
10+ import io.kotest.matchers.shouldBe
11+ import io.openapiprocessor.core.converter.mapping.TypeMapping
12+ import io.openapiprocessor.core.processor.MappingConverter
13+ import io.openapiprocessor.core.processor.MappingReader
14+
15+ class MappingConverterSpec : StringSpec ({
16+ isolationMode = IsolationMode .InstancePerTest
17+
18+ val reader = MappingReader ()
19+ val converter = MappingConverter ()
20+
21+ " read generic parameter with generated package ref" {
22+ val yaml = """
23+ |openapi-processor-mapping: v2
24+ |
25+ |options:
26+ | package-name: io.openapiprocessor.somewhere
27+ |
28+ |map:
29+ | types:
30+ | - type: Foo => io.openapiprocessor.Foo<{package-name}.Bar>
31+ """ .trimMargin()
32+
33+ // when:
34+ val mapping = reader.read (yaml)
35+ val mappings = converter.convert (mapping)
36+
37+ // then:
38+ val type = mappings.first() as TypeMapping
39+ type.targetTypeName shouldBe " io.openapiprocessor.Foo"
40+ type.genericTypeNames shouldBe listOf("io.openapiprocessor.somewhere.Bar ")
41+ }
42+
43+ })
You can’t perform that action at this time.
0 commit comments