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

Commit 8555e34

Browse files
committed
id/type split (allOf object), #65
1 parent 4d78fde commit 8555e34

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/main/kotlin/io/openapiprocessor/core/converter/DataTypeConverter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class DataTypeConverter(
103103
}
104104

105105
objectType = AllOfObjectDataType(
106-
schemaInfo.getName(),
106+
DataTypeName(schemaInfo.getName(), getTypeNameWithSuffix(schemaInfo.getName())),
107107
listOf(options.packageName, "model").joinToString ("."),
108108
items,
109109
null,

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package io.openapiprocessor.core.model.datatypes
99
* OpenAPI "allOf" composed schema type.
1010
*/
1111
class AllOfObjectDataType(
12-
private val type: String,
12+
private val name: DataTypeName,
1313
private val pkg: String,
1414
private val items: List<DataType> = emptyList(),
1515
override val constraints: DataTypeConstraints? = null,
@@ -18,15 +18,19 @@ class AllOfObjectDataType(
1818
): DataType, ModelDataType {
1919

2020
override fun getName(): String {
21-
return type
21+
return name.id
22+
}
23+
24+
override fun getTypeName(): String {
25+
return name.type
2226
}
2327

2428
override fun getPackageName(): String {
2529
return pkg
2630
}
2731

2832
override fun getImports(): Set<String> {
29-
return setOf(getPackageName() + "." + getName())
33+
return setOf(getPackageName() + "." + getTypeName())
3034
}
3135

3236
override val referencedImports: Set<String>

src/test/kotlin/io/openapiprocessor/core/model/datatypes/ComposedObjectDataTypeSpec.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import io.openapiprocessor.core.support.datatypes.ObjectDataType
1212
class ComposedObjectDataTypeSpec : StringSpec({
1313

1414
"loop properties of allOf objects as if it was a single object" {
15-
val composed = AllOfObjectDataType("Foo", "pkg", listOf(
15+
val composed = AllOfObjectDataType(DataTypeName("Foo"), "pkg", listOf(
1616
ObjectDataType("Foo", "pkg", linkedMapOf(
1717
Pair("foo", StringDataType()),
1818
Pair("foobar", StringDataType())
@@ -26,4 +26,17 @@ class ComposedObjectDataTypeSpec : StringSpec({
2626
composed.properties.keys shouldBe linkedSetOf("foo", "foobar", "bar", "barfoo")
2727
}
2828

29+
"allOf object has id name and type name" {
30+
val composed = AllOfObjectDataType(DataTypeName("Foo", "FooX"), "pkg", listOf())
31+
32+
composed.getName() shouldBe "Foo"
33+
composed.getTypeName() shouldBe "FooX"
34+
}
35+
36+
"allOf object has creates import with type name" {
37+
val composed = AllOfObjectDataType(DataTypeName("Foo", "FooX"), "pkg", listOf())
38+
39+
composed.getImports() shouldBe setOf("pkg.FooX")
40+
}
41+
2942
})

0 commit comments

Comments
 (0)