Description
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?
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
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.