OpenAPITools / OpenAPITools/openapi-generator

[BUG][Kotlin] An interface marked with @JsonClass annotation

Open
#15,358 0 comments 1 reaction 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

When generating models with inheritance, which is done via data class : interface manner, an interface is also marked with a @JsonClass annotation, which results into a compilation error: error: @JsonClass can't be applied to ...

openapi-generator version

6.5.0

Generation Details

Generate kotlin client with jvm-retrofit2 library and "moshiCodeGen" config option is set to "true".

Possible fix

file: data_class.mustache
change:

{{#moshiCodeGen}}@JsonClass(generateAdapter = true){{/moshiCodeGen}}

to:

{{#moshiCodeGen}}{{^discriminator}}@JsonClass(generateAdapter = true){{/discriminator}}{{/moshiCodeGen}}

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 data_class.mustache and generate a Kotlin client using the jvm-retrofit2 library with moshiCodeGen enabled, using an inherited data class and interface. Check the generated interface and compilation result; done means the interface is not given an invalid @JsonClass annotation while concrete models retain the expected generation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.