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

[BUG] Kotlin generator: generateOneOfAnyOfWrappers=true leads to broken code #19942

Open
andreas-umbricht opened this issue Oct 22, 2024 · 0 comments · May be fixed by #19981
Open

[BUG] Kotlin generator: generateOneOfAnyOfWrappers=true leads to broken code #19942

andreas-umbricht opened this issue Oct 22, 2024 · 0 comments · May be fixed by #19981

Comments

@andreas-umbricht
Copy link

Description

While using the Kotlin generator in a Android Project with "generateOneOfAnyOfWrappers=true", the generator generates code with the Gson Library even tough it should be Moshi by default(?). After including the Gson Library to the project, it still failed. Partly because of invalid naming of variables. As you can see in the picture below, on line 37 and 38, the generates variables are interpreted by kotlin as extension functions. So this won't compile.

Bildschirmfoto 2024-10-22 um 12 02 06

To start from the beginning: We received a new OpenAPI Spec from our server team. The spec contains some "OneOf" relations. The file itself should be valid, since our iOS team was able to generate the desired code with openapi-generator generate -i Common/MeteoMapsAPI/meteomapsapi.json -g swift5 -o Common/MeteoMapsAPI --model-name-prefix SRF --additional-properties=projectName=MeteoMapsAPI,generateAliasAsModel=true.
If we (Android team) run the generator without "generateOneOfAnyOfWrappers=true", an error get's thrown @JsonClass can't be applied to ch.srf.meteo.data.meteomap.model.MeteoMapLayer: must be a Kotlin class. This makes sense looking into the generated code:

Bildschirmfoto 2024-10-22 um 11 59 23

So I guess, the approach of using "generateOneOfAnyOfWrappers=true" should be correct?

The full OpenAPI declaration file can be found below.

openapi-generator version

7.9.0, 7.8.0

OpenAPI declaration file content or url

meteomap-api.json

Generation Details
    val generateMeteoMap by registering(GenerateTask::class) {
        generatorName.set("kotlin")
        .....
        configOptions.set(apiConfigOptions)
        additionalProperties.set(
            mapOf(
                "enumPropertyNaming" to "UPPERCASE",
                "useCoroutines" to "true",
                "moshiCodeGen" to "true",
                "generateOneOfAnyOfWrappers" to "true",
            )
        )
        library.set("jvm-retrofit2")
    }
Steps to reproduce

If you run the generator either with Gradle or via CLI with the attached OpenAPI declaration file (which should be valid in my opinion), the error occures.

@andreas-umbricht andreas-umbricht changed the title [BUG] Description [BUG] Kotlin generator: generateOneOfAnyOfWrappers=true leads to broken code Oct 22, 2024
CaptainAye added a commit to CaptainAye/openapi-generator that referenced this issue Oct 26, 2024
CaptainAye added a commit to CaptainAye/openapi-generator that referenced this issue Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant