OpenAPITools / OpenAPITools/openapi-generator

[BUG][KOTLIN / JVM] Missing contextual annotation on optional List< java.math.BigDecimal>

Open
#20,944 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I am working on producing types from schema files using an openapi generator with the kotlinx_serialization library. This works flawlessly for 60ish types / data classes. But when serializing a Polygon schema with a Point inside, the kotlinx serializer does not add an @contextual tag to allow for BigDecimal serialization. I believe these schema's come from geojson, but I could be wrong. In the end, I end up with the following compiler error:

Serializer has not been found for type 'java.math.BigDecimal'. To use context serializer as fallback, explicitly annotate type or property with @Contextual
To fix this error, I have to hand edit the file to add the annotation before it's allowed to compile.

It's possible this is actually an kotlinx serialization bug report, so please let me know if this is not within y'all's domain.

I would expect that the serialization library would just add the contextual annotation, thus saving me from hand editing generated files. One file seems okay to manipulate by hand, but I worry about maintenance.

openapi-generator version

7.11.0

OpenAPI declaration file content or url

gist

Generation Details

Run during a gradle build process. Generator code below, version is 7.11.0, using kotlinx_serialization library

Steps to reproduce

Attempt to generate a kotlin data class from the above json schema using the following generator code
Generator code

tasks.register<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("generateTypes") {
    generatorName.set("kotlin")

    configOptions.set(
        mapOf(
            "serializationLibrary" to "kotlinx_serialization",
            "useKotlinDataClasses" to "true",
            "mapType" to "Map",
            "generateSupportingFiles" to "false",
            "generateTestFiles" to "false",
        ),
    )
}
Suggest a fix

My guess is that this problem exists because of the handling of nullable properties.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Kotlin generator run from the issue with the linked schema and the kotlinx_serialization options. Trace the generated data class for the optional BigDecimal list and compare it with the hand-edited version containing @Contextual. Done means the generated Kotlin output compiles without manual edits and includes the required contextual annotation.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.