Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #12692
Closed
Open
Issue created Jun 24, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [SPRING] legacyDiscriminatorBehavior property is always ignored

Created by: LubomirS

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

When generating model classes using spring code generator, classes with inheritance aren't generated with correct json subtypes when using legacyDiscriminatorBehavior=true config option. According to the documentation, it is set to true by default for spring, which is not the case https://openapi-generator.tech/docs/generators/spring/#config-options. It is set to false by default and cannot be overridden because the config option is always ignored since 6.0.0 version, which was a change done in [#11650].

openapi-generator version

6.0.1-SNAPSHOT

OpenAPI declaration file content or url

https://gist.github.com/LubomirS/48cc3c0833adebc7dba7b8b30070422d

Generation Details

generatorName: spring inputSpec: OpenApiGenerator_Spring_LegacyDiscriminatorBehavior.json additionalProperties: legacyDiscriminatorBehavior: true

Steps to reproduce

Generate model classes

Check to see that Pet.class contains two Json subtypes:

@JsonSubTypes({
  @JsonSubTypes.Type(value = Cat.class, name = "Cat"),
  @JsonSubTypes.Type(value = Cat.class, name = "cat")
})

The expected result is to only have one json subtype as it is defined in the open api spec:

@JsonSubTypes({
  @JsonSubTypes.Type(value = Cat.class, name = "cat")
})
Related issues/PRs

As far as I can see there are no reported related issues.

Suggest a fix

the fix should be to move these two lines

useOneOfInterfaces = true;
legacyDiscriminatorBehavior = false;

before

super.processOpts();

in org.openapitools.codegen.languages.SpringCodegen#processOpts

Assignee
Assign to
Time tracking