Skip to content

Commit be025c9

Browse files
committed
Fixed enum schema builder not handling nullable types.
1 parent 7e84774 commit be025c9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/kotlin/com/papsign/ktor/openapigen/schema/builder/provider/DefaultEnumSchemaProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlin.reflect.jvm.jvmErasure
1313
object DefaultEnumSchemaProvider: SchemaBuilderProviderModule, OpenAPIGenModuleExtension {
1414

1515
private object Builder: SchemaBuilder {
16-
override val superType: KType = getKType<Enum<*>>()
16+
override val superType: KType = getKType<Enum<*>?>()
1717

1818
override fun build(
1919
type: KType,

src/test/kotlin/GeneralBehaviorTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class GeneralBehaviorTest {
4646
assert(!getKType<FloatArray>().isSubtypeOf(getKType<Array<Any>>()))
4747
assert(!getKType<Array<Any>>().isSubtypeOf(getKType<Iterable<Any>>()))
4848
assert(getKType<List<Any>>().isSubtypeOf(getKType<Iterable<Any>>()))
49+
assert(getKType<List<Any>>().isSubtypeOf(getKType<Iterable<Any?>>()))
4950
}
5051

5152
@Test
@@ -60,4 +61,19 @@ class GeneralBehaviorTest {
6061
fun testEnumSubtypes() {
6162
assert(getKType<TestEnum>().isSubtypeOf(getKType<Enum<*>>()))
6263
}
64+
65+
66+
lateinit var nothing: Nothing
67+
val nullableNothing: Nothing? = null
68+
69+
val nothingType = ::nothing.returnType
70+
val nullNothingType = ::nullableNothing.returnType
71+
72+
@Test
73+
fun testNothingSubtypes() {
74+
println(nothingType)
75+
println(nullNothingType)
76+
assert(nothingType.isSubtypeOf(nullNothingType))
77+
assert(!nullNothingType.isSubtypeOf(nothingType))
78+
}
6379
}

0 commit comments

Comments
 (0)