Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two JsonObject in data class break with kotlinx-serialization schema generator #2

Closed
waltkb opened this issue Jun 13, 2024 · 1 comment

Comments

@waltkb
Copy link

waltkb commented Jun 13, 2024

When using this setup:

type.processKotlinxSerialization()
    .connectSubTypes()
    .handleNameAnnotation()
    .generateSwaggerSchema()
    .handleCoreAnnotations()
    .withAutoTitle(TitleType.SIMPLE)
    .compileReferencingRoot()

It is able to compile a swagger schema for:

@Serializable
data class A(
    val a: JsonObject,
    // val b: JsonObject,
)

But will break when a second JsonObject is contained in the data class:

@Serializable
data class A(
    val a: JsonObject,
    val b: JsonObject,
)
java.lang.NullPointerException
	at io.github.smiley4.schemakenerator.swagger.steps.SwaggerSchemaCompileStep$referenceDefinitionsReferences$json$1.invoke(SwaggerSchemaCompileStep.kt:84)
	at io.github.smiley4.schemakenerator.swagger.steps.SwaggerSchemaCompileStep$referenceDefinitionsReferences$json$1.invoke(SwaggerSchemaCompileStep.kt:82)
	at io.github.smiley4.schemakenerator.swagger.steps.SwaggerSchemaCompileStep.replaceReferences(SwaggerSchemaCompileStep.kt:158)
	at io.github.smiley4.schemakenerator.swagger.steps.SwaggerSchemaCompileStep.replaceReferences(SwaggerSchemaCompileStep.kt:162)
	at io.github.smiley4.schemakenerator.swagger.steps.SwaggerSchemaCompileStep.referenceDefinitionsReferences(SwaggerSchemaCompileStep.kt:82)
	at io.github.smiley4.schemakenerator.swagger.steps.SwaggerSchemaCompileStep.compileReferencing(SwaggerSchemaCompileStep.kt:47)
	at io.github.smiley4.schemakenerator.swagger.steps.SwaggerSchemaCompileStep.compileReferencingRoot(SwaggerSchemaCompileStep.kt:60)
	at io.github.smiley4.schemakenerator.swagger.StepsKt.compileReferencingRoot(steps.kt:89)
	at io.github.smiley4.schemakenerator.swagger.StepsKt.compileReferencingRoot$default(steps.kt:88)

Though it does work when using the reflection schema generator instead of the kotlinx.serialization schema generator, like this:

type
    .collectSubTypes()
    .processReflection()
    .connectSubTypes()
    .handleNameAnnotation()
    .generateSwaggerSchema()
    .handleCoreAnnotations()
    .withAutoTitle(TitleType.SIMPLE)
    .compileReferencingRoot()
@SMILEY4
Copy link
Owner

SMILEY4 commented Jun 21, 2024

Hi, thanks for reporting this bug.
The issue should now be fixed with version 1.0.1 (and for ktor-swagger-ui soon aswell).
I you encounter any other issues just let me know :)

@SMILEY4 SMILEY4 closed this as completed Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants