OpenAPITools / OpenAPITools/openapi-generator

[REQ] Allow control of discriminator property in Spring

Open
#5,694 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

Typescript generator does not generate the needed discriminator property correctly. Event though the discriminator field is defined in the api declaration, it is missing in the generated typescript objects.
This can be solved by declaring discriminator as own property in the api specification. In Spring this property is then generated twice, once as own property, and once as an annotation JsonTypeInfo. This means
you have to specify the discriminator every time, you create the object in Spring.

Describe the solution you'd like

Adding a flag to the generator will allow to disable generating the own property in Spring and keep only the JsonTypeInfo annotation. While still keeping the Typescript implementation correct.

Describe alternatives you've considered

see discussion in PR #5263

maybe fix #3796

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

Read PR #5263 and issue #3796 first for the prior discussion. Then inspect the Spring generator alongside the TypeScript generator to understand the discriminator behavior. Done means a generator flag can control Spring's own discriminator property while retaining JsonTypeInfo, without regressing the TypeScript output.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring, typescript
Domain
backend-api-design, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.