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

Commit e96f260

Browse files
committed
1 parent 4a4a4b0 commit e96f260

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ class AllOfObjectDataType(
3434

3535
override val referencedImports: Set<String>
3636
get() {
37-
return items
38-
.filterIsInstance<ObjectDataType>()
39-
.map { it.getImports() }
40-
.flatten()
37+
return properties.values
38+
.flatMap { it.getImports() }
4139
.toSet()
4240
}
4341

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,33 @@ class ComposedObjectDataTypeSpec : StringSpec({
3939
composed.getImports() shouldBe setOf("pkg.FooX")
4040
}
4141

42+
// https://github.com/openapi-processor/openapi-processor-spring/issues/128
43+
"allOf creates imports for all items" {
44+
val composed = AllOfObjectDataType(DataTypeName("Foo"), "pkg", listOf(
45+
ObjectDataType("Foo", "pkg", linkedMapOf(
46+
"foo" to OffsetDateTimeDataType()
47+
)),
48+
ObjectDataType("Bar", "pkg", linkedMapOf(
49+
"bar" to ObjectDataType("BarBar", "pkg", linkedMapOf(
50+
"barbar" to OffsetDateTimeDataType()
51+
))
52+
))
53+
))
54+
55+
composed.getImports() shouldBe setOf("pkg.Foo")
56+
composed.referencedImports shouldBe setOf("java.time.OffsetDateTime", "pkg.BarBar")
57+
}
58+
59+
"allOf creates does not leak import for type-less item" {
60+
val composed = AllOfObjectDataType(DataTypeName("Foo"), "pkg", listOf(
61+
ObjectDataType("Bar", "pkg", linkedMapOf(
62+
"bar" to StringDataType())
63+
),
64+
NoDataType("Leak")
65+
))
66+
67+
composed.getImports() shouldBe setOf("pkg.Foo")
68+
composed.referencedImports shouldBe setOf("java.lang.String")
69+
}
70+
4271
})

0 commit comments

Comments
 (0)