OpenAPITools / OpenAPITools/openapi-generator

[BUG] [java] Polymorphy of models broken in v4.3.1

Open
#9,615 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

Using the java generator, I used to get models where child-classes extend parent classes with version 4.3.0. With version 4.3.1 the child classes do not extend the parent class anymore.

openapi-generator version

It's a regression of version 4.3.1. 4.3.0 worked.

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
    version: 1.0.0
    title: Polymorphy demo
paths:
    /random-pet:
        get:
            responses:
                '200':
                    description: Returning a random pet.
                    content:
                        application/json:
                            schema:
                                $ref: "#/components/schemas/Pet"
components:
    schemas:
        Pet:
            oneOf: 
                - $ref: '#/components/schemas/Dog' 
                - $ref: '#/components/schemas/Cat' 
            discriminator: 
                propertyName: petType
                mapping: 
                    dog: '#/components/schemas/Dog' 
                    cat: '#/components/schemas/Cat' 
        PetBase:
            type: object
            required:
                - petType
            properties:
                petType:
                    type: string
                name:
                    type: string
        Dog:
            allOf:
                - $ref: '#/components/schemas/PetBase'
                - type: object
                  properties:
                      barksAlot:
                          type: boolean
        Cat:
            allOf:
                - $ref: '#/components/schemas/PetBase'
                - type: object
                  properties:
                      goesOutdoors:
                          type: boolean
Generation Details

I run the generator in version 4.3.0 and 4.3.1:

$ java -jar openapi-generator-cli-4.3.0.jar generate -g java -o 4.3.0_result -i polymorphy.yaml
$ java -jar openapi-generator-cli-4.3.1.jar generate -g java -o 4.3.1_result -i polymorphy.yaml
Steps to reproduce

After generating the code in 4.3.0 and 4.3.1, compare Cat.java. The generated model of 4.3.0 will contain public class Cat extends PetBase while the generated model of 4.3.1 will only contain public class Cat (without the inheritance).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided Java generator commands against polymorphy.yaml and compare the generated Cat.java files from versions 4.3.0 and 4.3.1. Trace the Java generator behavior responsible for model inheritance; done means the 4.3.1 output restores Cat extending PetBase, as in 4.3.0.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.