OpenAPITools / OpenAPITools/openapi-generator

[BUG] Spring generator: inheritance now always requires discriminator

Open
#9,516 2 comments 6 reactions 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

According to the latest OAS3.0 specification the following is a perfect fine example of inheritance:

Animal:
      type: object
      properties:
        name:
          type: string
          
    Cat: 
      allOf:
      - $ref: '#/components/schemas/Animal'
      - type: object
        properties:
          breed:
            type: string

Till version 4.3.0 it works fine, the pojo is generated as:

public class Cat extends Animal{
  String breed;
}

From version 5.0.0 I instead get:

public class Cat {
  String name;
  String breed;
}

In order to make this work in version 5.0.x I have to edit the specification like this:

Animal:
      type: object
     discriminator:
       propertyName: className
      properties:
        name:
          type: string

Is this intentional? I find it much more confusing now

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

Start with the Spring generator's handling of OpenAPI 3 inheritance and discriminator settings, using the specification examples in this issue as the reproduction. Compare generation behavior between versions 4.3.0 and 5.0.x; done means the discriminator-free Cat schema generates a class extending Animal without duplicating inherited properties.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.