This repository was archived by the owner on Mar 16, 2025. It is now read-only.
File tree 3 files changed +55
-6
lines changed
main/kotlin/io/openapiprocessor/core/processor
test/kotlin/io/openapiprocessor/core/processor/mapping/v2
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
25
25
26
26
/* *
27
27
* 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].
29
29
*
30
30
* @author Martin Hauner
31
31
*/
@@ -37,7 +37,7 @@ class MappingConverter {
37
37
}
38
38
39
39
return if (source.v2) {
40
- MappingConverterV2 ().convert( source as MappingV2 )
40
+ MappingConverterV2 (source as MappingV2 ).convert( )
41
41
} else {
42
42
MappingConverterV1 ().convert(source as MappingV1 )
43
43
}
Original file line number Diff line number Diff line change @@ -28,18 +28,18 @@ import org.antlr.v4.runtime.tree.ParseTreeWalker
28
28
29
29
/* *
30
30
* 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] .
32
32
*
33
33
* @author Martin Hauner
34
34
*/
35
- class MappingConverter {
35
+ class MappingConverter ( val mapping : MappingV2 ) {
36
36
companion object {
37
37
private const val SEPARATOR_TYPE = " => "
38
38
private const val SEPARATOR_FORMAT = " :"
39
39
private val PATTERN_GENERICS = " (\\ S+?)\\ s*<(.+?)>" .toPattern()
40
40
}
41
41
42
- fun convert (mapping : MappingV2 ): List <Mapping > {
42
+ fun convert (): List <Mapping > {
43
43
val result = ArrayList <Mapping >()
44
44
45
45
if (mapping.map.result != null ) {
@@ -201,7 +201,13 @@ class MappingConverter {
201
201
generics = typeGenerics
202
202
}
203
203
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
+ }
205
211
}
206
212
207
213
}
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