[BUG] If superclass has no properties, it will not be generated, but derived class does extend not existing/generated class
Created by: sascha-friederich
Description
I use the openapi gradle-plugin to generate java classes - but if the superclass has no properties, the class will not be generated but the derived class extends the non existing class. So the code does not compile.
Using the command-line I see the following message:
Model Pet not generated since it's a free-form object
As a workaround we modify the openapi json to add some dummy attribute in the superclass, so that it will be generated.
openapi-generator version
org.openapi.generator 4.3.1
OpenAPI declaration file content or url
{
"openapi": "3.0.1",
"info": {
"title": "Abstract Generation problem",
"description": "Abstract Generation problem",
"version": "1.0.0-SNAPSHOT"
},
"servers": [],
"paths": {},
"components": {
"schemas": {
"Pet": {
"title": "AbstractPet",
"type": "object",
"description": "model containing all the details of a pet",
"discriminator": {
"propertyName": "petTypeName"
}
},
"Dog": {
"title": "DogDetails",
"description": "The model containing the details of the dog",
"allOf": [
{
"$ref": "#/components/schemas/Pet"
},
{
"title": "DogDetails",
"type": "object",
"properties": {
"legs": {
"type": "string",
"description": "the number of legs"
}
},
"description": "The model containing the details of the dog"
}
]
}
}
}
}
Generation Details
java -jar openapi-generator-cli-4.3.1.jar generate -i openapi.json -g spring -o ./temp
Generated Models
There were two java classes generated:
- Dog.java
- DogDetails.java
Dog.java does extend Pet, that does not exist!
public class Dog extends Pet {
@JsonProperty("legs")
private String legs;
public Dog legs(String legs) {
this.legs = legs;
return this;
}
...
Workaround
change definition of Pet to:
"Pet": {
"title": "AbstractPet",
"type": "object",
"properties": {
"dummyProperty": {
"type": "string",
"description": "Workaround - OpenAPI generator does not consider definitions without properties"
}
},
"description": "model containing all the details of a pet",
"discriminator": {
"propertyName": "petTypeName"
}
},