Bug Report Checklist
Description
I have an inheritance hierarchy four levels deep: Child inherits from Parent which inherits from GrandParent which inherits from GreatGrandParent.
Each type has a required property (see full spec below).
This generates the following model classes, with constructors for the required parameters. The constructor of Child delegates to the super constructor with parameters in incorrect order, causing compiler errors if the types don't match and not causing compiler errors, if the types happen to be compatible:
public class GreatGrandParent {
private Integer greatGrandParentProp;
public GreatGrandParent(Integer greatGrandParentProp) {
this.greatGrandParentProp = greatGrandParentProp;
}
//...
}
public class GrandParent extends GreatGrandParent {
private String grandParentProp;
public GrandParent(String grandParentProp, Integer greatGrandParentProp) {
super(greatGrandParentProp);
this.grandParentProp = grandParentProp;
}
//...
}
public class Parent extends GrandParent {
private Boolean parentProp;
public Parent(Boolean parentProp, Integer greatGrandParentProp, String grandParentProp) {
super(grandParentProp, greatGrandParentProp);
this.parentProp = parentProp;
}
//...
}
public class Child extends Parent {
private String childProp;
public Child(String childProp, Integer greatGrandParentProp, String grandParentProp, Boolean parentProp) {
super(parentProp, grandParentProp, greatGrandParentProp); // <-- Compiler error here, param order should be parentProp, greatGrandParentProp, grandParentProp
this.childProp = childProp;
}
//...
}
openapi-generator version
6.5.0 and master (ba2c42e)
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Test
version: 1.0.0
paths:
/test:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Child'
responses:
200:
description: success
components:
schemas:
GreatGrandParent:
type: object
properties:
greatGrandParentProp:
type: integer
required:
- greatGrandParentProp
GrandParent:
allOf:
- $ref: '#/components/schemas/GreatGrandParent'
- type: object
properties:
grandParentProp:
type: string
required:
- grandParentProp
Parent:
allOf:
- $ref: '#/components/schemas/GrandParent'
- type: object
properties:
parentProp:
type: boolean
required:
- parentProp
Child:
allOf:
- $ref: '#/components/schemas/Parent'
- type: object
properties:
childProp:
type: string
required:
- childProp
Generation Details
java -jar openapi-generator-cli.jar generate -g spring -i spec.yaml -o out --openapi-normalizer=REF_AS_PARENT_IN_ALLOF=true
Steps to reproduce
Generate code from above spec with spring generator and REF_AS_PARENT_IN_ALLOF=true.
Related issues/PRs
#14934
#14941
#9756
#14172
Suggest a fix
Ensure that parameters are passed into parent constructor in the correct order.
Workaround
--additional-properties=generatedConstructorWithRequiredArgs=false can be used to skip generating the erroneous constructors.
Bug Report Checklist
Description
I have an inheritance hierarchy four levels deep:
Childinherits fromParentwhich inherits fromGrandParentwhich inherits fromGreatGrandParent.Each type has a
requiredproperty (see full spec below).This generates the following model classes, with constructors for the required parameters. The constructor of
Childdelegates to thesuperconstructor with parameters in incorrect order, causing compiler errors if the types don't match and not causing compiler errors, if the types happen to be compatible:openapi-generator version
6.5.0 and master (ba2c42e)
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Generate code from above spec with
springgenerator andREF_AS_PARENT_IN_ALLOF=true.Related issues/PRs
#14934
#14941
#9756
#14172
Suggest a fix
Ensure that parameters are passed into parent constructor in the correct order.
Workaround
--additional-properties=generatedConstructorWithRequiredArgs=falsecan be used to skip generating the erroneous constructors.