OpenAPITools / OpenAPITools/openapi-generator

[BUG][Kotlin] Gson code in non-gson generation

Open
#20,480 1 comment 0 reactions 0 assignees View on GitHub

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.mustache

Before 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.