Ricky12Awesome / json-schema-serialization

Adds support for Json Schema using Kotlin.serialization
MIT License
30 stars 9 forks source link

Error accessing empty elementDescriptors in jsonSchemaObjectSealed #7

Open altavir opened 3 years ago

altavir commented 3 years ago

Here is the stack trace:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Empty list doesn't contain element at index 1.
    at kotlin.collections.EmptyList.get(Collections.kt:36)
    at kotlin.collections.EmptyList.get(Collections.kt:24)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt.jsonSchemaObjectSealed(JsonSchema.kt:80)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt$createJsonSchema$7.invoke(JsonSchema.kt:203)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt$createJsonSchema$7.invoke(JsonSchema.kt)
    at com.github.ricky12awesome.jss.internal.JsonSchemaDefinitions.get(JsonSchema.kt:308)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt.createJsonSchema(JsonSchema.kt:203)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt.jsonSchemaObject(JsonSchema.kt:44)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt$createJsonSchema$5.invoke(JsonSchema.kt:201)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt$createJsonSchema$5.invoke(JsonSchema.kt)
    at com.github.ricky12awesome.jss.internal.JsonSchemaDefinitions.get(JsonSchema.kt:308)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt.createJsonSchema(JsonSchema.kt:201)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt.jsonSchemaObjectMap(JsonSchema.kt:70)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt$createJsonSchema$6.invoke(JsonSchema.kt:202)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt$createJsonSchema$6.invoke(JsonSchema.kt)
    at com.github.ricky12awesome.jss.internal.JsonSchemaDefinitions.get(JsonSchema.kt:308)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt.createJsonSchema(JsonSchema.kt:202)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt.jsonSchemaObject(JsonSchema.kt:44)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt$createJsonSchema$5.invoke(JsonSchema.kt:201)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt$createJsonSchema$5.invoke(JsonSchema.kt)
    at com.github.ricky12awesome.jss.internal.JsonSchemaDefinitions.get(JsonSchema.kt:308)
    at com.github.ricky12awesome.jss.internal.JsonSchemaKt.createJsonSchema(JsonSchema.kt:201)
    at com.github.ricky12awesome.jss.JsonSchemaKt.buildJsonSchema(JsonSchema.kt:203)
    at com.github.ricky12awesome.jss.JsonSchemaKt.encodeToSchema(JsonSchema.kt:174)
    at com.github.ricky12awesome.jss.JsonSchemaKt.encodeToSchema(JsonSchema.kt:192)
    at hep.dataforge.vision.solid.GenerateSchemaKt.main(generateSchema.kt:17)
    at hep.dataforge.vision.solid.GenerateSchemaKt.main(generateSchema.kt)

Here is the problematic line: https://github.com/Ricky12Awesome/json-schema-serialization/blob/ea5c0be9a3bc2be152e625dbe17b787a170b603a/src/commonMain/kotlin/com/github/ricky12awesome/jss/internal/JsonSchema.kt#L79

I use a manually created serializer for this class, so it is possible that the descriptor itself is not correct, but the situation is possible.