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

Commit dd65466

Browse files
committed
id/type split (mapped collection), #65
1 parent 21a40b0 commit dd65466

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

src/main/kotlin/io/openapiprocessor/core/model/datatypes/MappedCollectionDataType.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,31 @@ package io.openapiprocessor.core.model.datatypes
1010
* generic parameter.
1111
*/
1212
open class MappedCollectionDataType(
13-
private val type: String,
13+
private val name: String,
1414
private val pkg: String,
1515
override val item: DataType,
1616
override val constraints: DataTypeConstraints? = null,
1717
override val deprecated: Boolean = false
1818
): DataType, CollectionDataType {
1919

2020
override fun getName(): String {
21-
return "${type}<${item.getName()}>"
21+
return "${name}<${item.getName()}>"
2222
}
2323

24-
fun getName(annotation: String): String {
25-
return "${type}<$annotation ${item.getName()}>"
24+
override fun getTypeName(): String {
25+
return "${name}<${item.getTypeName()}>"
26+
}
27+
28+
fun getTypeNameWithAnnotatedItem(annotation: String): String {
29+
return "${name}<$annotation ${item.getTypeName()}>"
2630
}
2731

2832
override fun getPackageName(): String {
2933
return pkg
3034
}
3135

3236
override fun getImports(): Set<String> {
33-
return setOf(getPackageName() + "." + type) + item.getImports()
37+
return setOf(getPackageName() + "." + name) + item.getImports()
3438
}
3539

3640
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2021 https://github.com/openapi-processor/openapi-processor-core
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.core.model.datatypes
7+
8+
import io.kotest.core.spec.style.StringSpec
9+
import io.kotest.data.blocking.forAll
10+
import io.kotest.data.row
11+
import io.kotest.matchers.shouldBe
12+
13+
class MappedCollectionDataTypeSpec : StringSpec({
14+
15+
"collection uses id name and type name of item" {
16+
val collection = MappedCollectionDataType("List", "java",
17+
ObjectDataType(DataTypeName("Foo", "FooX"), "pkg", linkedMapOf()))
18+
19+
collection.getName() shouldBe "List<Foo>"
20+
collection.getTypeName() shouldBe "List<FooX>"
21+
}
22+
23+
"should create import with type name" {
24+
forAll(row("Foo", "Foo"), row("Fooo", "FoooX")) { id, type ->
25+
val dt = MappedCollectionDataType("List", "java",
26+
ObjectDataType(DataTypeName(id, type), "pkg"))
27+
dt.getImports() shouldBe setOf(
28+
"java.List",
29+
"pkg.$type"
30+
)
31+
}
32+
}
33+
34+
})

0 commit comments

Comments
 (0)