Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7638
Closed
Open
Issue created Oct 09, 2020 by Administrator@rootContributor

[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"
                }
            },
Assignee
Assign to
Time tracking