[BUG][Java/Spring] putX method calls superclass method with incorrect arguments
Created by: WeihmannTNG
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
Assume that there is a schema ChildClass which inherits via allOf from schema ParentClass with discriminator, and ParentClass has a property x which references a schema that is defined via additionalProperty. Then the overwritten putX builder method in ChildClass is broken.
openapi-generator version
6.0.0, 6.0.1-SNAPSHOT
OpenAPI declaration file content or url
ChildClass:
description: ""
type: object
allOf:
- $ref: "#/components/schemas/ParentClass"
- type: object
description: ""
properties:
objectType:
type: string
default: "ChildClass"
ParentClass:
type: object
description: ""
discriminator:
propertyName: objectType
properties:
objectType:
type: string
default: "ParentClass"
someMap:
$ref: "#/components/schemas/MapClass"
MapClass:
type: object
description: ""
additionalProperties:
type: string
description: ""
Generation Details
Using openapi-generator-maven-plugin with the following configuration
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.0.1-SNAPSHOT</version>
<configuration>
<generateApis>true</generateApis>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<java8>true</java8>
<useTags>true</useTags>
<booleanGetterPrefix>is</booleanGetterPrefix>
<legacyDiscriminatorBehavior>false</legacyDiscriminatorBehavior>
<skipDefaultInterface>true</skipDefaultInterface>
</configOptions>
</configuration>
<executions>
<execution>
<id>generate-test-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<output>${project.build.directory}/generated-sources</output>
<inputSpec>${project.basedir}/src/main/openapi/test.yaml</inputSpec>
<generatorName>spring</generatorName>
<modelPackage>dto</modelPackage>
<apiPackage>api</apiPackage>
<invokerPackage>invoker</invokerPackage>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
Add the code at Generator Details to your pom and add the openapi code given above to some valid openapi file /src/main/openapi/test.yaml (I skipped parts of the yaml to keep it as succinct as possible).
The generated class ParentClass contains the following.
public ParentClass putSomeMapItem(String key, String someMapItem) {
if (this.someMap == null) {
this.someMap = new HashMap<>();
}
this.someMap.put(key, someMapItem);
return this;
}
The generated class ChildClass contains the following.
public ChildClass putSomeMapItem(String key, String someMapItem) {
super.putSomeMapItem(someMapItem);
return this;
}
However, expected is the following.
public ChildClass putSomeMapItem(String key, String someMapItem) {
super.putSomeMapItem(key, someMapItem);
return this;
}
Related issues/PRs
I did not find any.