-
Notifications
You must be signed in to change notification settings - Fork 8
Labels
internal-usersIssues and PRs raised by internal usersIssues and PRs raised by internal users
Milestone
Description
Expected:
Recrusive references in closed polymorphic classes are correctly resolved without causing endless loops. Generator should detect that TestClosedPolymorphism class is being processed already and just put a $ref for recursiveTypeProperty instead of starting to process TestClosedPolymorphism class again.
Actual:
Infinite loop due to generator trying to process TestClosedPolymorphism for recursiveTypeProperty from scratch every time.
Reproduction using 0.3.1:
import kotlinx.schema.generator.json.serialization.SerializationClassJsonSchemaGenerator
import kotlinx.schema.json.encodeToString
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlin.test.Test
class SchemaGeneratorTest {
@Serializable
@SerialName("TestClosedPolymorphism")
sealed class TestClosedPolymorphism {
abstract val id: String
@Suppress("unused")
@Serializable
@SerialName("ClosedSubclass1")
data class SubClass1(
override val id: String,
val property1: String
) : TestClosedPolymorphism()
@Suppress("unused")
@Serializable
@SerialName("ClosedSubclass2")
data class SubClass2(
override val id: String,
val property2: Int,
// This property produces StackOverflowError when generating schema
val recursiveTypeProperty: TestClosedPolymorphism,
) : TestClosedPolymorphism()
}
@Test
fun test() {
val testSchema = SerializationClassJsonSchemaGenerator.Default.generateSchema(TestClosedPolymorphism.serializer().descriptor)
println(testSchema.encodeToString(json = Json { prettyPrint = true } ))
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
internal-usersIssues and PRs raised by internal usersIssues and PRs raised by internal users