OpenAPITools / OpenAPITools/openapi-generator
[BUG][Kotlin] Gson code in non-gson generation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Please see my comment below.
Generating from IntelliJ using the following configuration leads to unexpected Gson code to be in the generated result.
I think you forgot the following conditions:
{{#generateOneOfAnyOfWrappers}}
{{#gson}}in these files:
modules/openapi-generator/src/main/resources/kotlin-client/anyof_class.mustache
modules/openapi-generator/src/main/resources/kotlin-client/oneof_class.mustacheBefore you generate the Gson based TypeAdapter.
What do you think??
Originally posted by @sebastianblesgen in https://github.com/OpenAPITools/openapi-generator/issues/18965#issuecomment-2593473646
openapi-generator version
7.7.0
OpenAPI declaration file content or url
Generation Details
generateOneOfAnyOfWrappers=false
library=jvm-retrofit2
idea=true
serializationLibrary=moshi
Steps to reproduce
Using IntelliJ and generator V7 and the options specified above, I unexpectedly got some files with Gson dependencies.
Related issues/PRs
Suggest a fix
Add
{{#generateOneOfAnyOfWrappers}}
{{#gson}}
in
modules/openapi-generator/src/main/resources/kotlin-client/anyof_class.mustache
modules/openapi-generator/src/main/resources/kotlin-client/oneof_class.mustache
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/openapi-generator/src/main/resources/kotlin-client/anyof_class.mustache and oneof_class.mustache, using the reported IntelliJ configuration: generateOneOfAnyOfWrappers=false, library=jvm-retrofit2, and serializationLibrary=moshi. Check the conditions around generated Gson TypeAdapters. Done means generation with these settings no longer includes unexpected Gson dependencies.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100