[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