Skip to content

[BUG] Multi level inheritance (with discriminator declared) does not generate classes with inheritance #6950

@jeff9finger

Description

@jeff9finger

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Java classes are not generated with extends when the OpenAPI definition declares allOf' with a $refto a model with adiscriminator` declared. This seems to be a regression.

openapi-generator version

5.0.0 - master

OpenAPI declaration file content or url
swagger: 2.0

info:
  title: Test Command model generation
  description: Test Command model generation
  version: 1.0.0
definitions:
  PartyType:
    description: type
    type: string
    enum:
      - customer
      - contact

  CustomerType:
    description: type
    type: string
    enum:
      - person
      - organization

  Entity:
    type: object
    properties:
      id:
        type: string
        readOnly: true

  Party:
    allOf:
      - $ref: '#/definitions/Entity'
      - type: object
        discriminator: party_type
        required:
          - party_type
        properties:
          party_type:
            readOnly: true
            $ref: '#/definitions/PartyType'
          tax_id_number:
            type: string

  Contact:
    x-discriminator-value: contact
    allOf:
      - $ref: '#/definitions/Party'
      - type: object
        properties:
          first_name:
            type: string
          last_name:
            type: string
          suffix:
            type: string
          dob:
            type: string
            format: date

  Customer:
    x-discriminator-value: customer
    allOf:
      - $ref: '#/definitions/Party'
      - type: object
        discriminator: customer_type
        required:
          - customer_type
        properties:
          customer_type:
            readOnly: true
            $ref: '#/definitions/CustomerType'
          customer_num:
            type: string
          external_customer_num:
            type: string
  Person:
    x-discriminator-value: person
    allOf:
      - $ref: '#/definitions/Customer'
      - type: object
        properties:
          first_name:
            type: string
          last_name:
            type: string

  Organization:
    x-discriminator-value: organization
    allOf:
      - $ref: '#/definitions/Customer'
      - type: object
        required:
          - organization_name
        properties:
          organization_name:
            type: string

  ApiError:
    type: object
    required:
    - code
    - message
    properties:
      code:
        type: string
        readOnly: true
      message:
        type: string
        readOnly: true

parameters:

paths:
  /customers:
    get:
      consumes: []
      operationId: queryCustomers
      tags:
      - Customer
      summary: Get customers
      responses:
        200:
          description: Success
          schema:
            type: array
            items:
              $ref: '#/definitions/Customer'
        400:
          description: Bad request.
          schema:
            $ref: '#/definitions/ApiError'
        default:
          description: Unknown error.
          schema:
            $ref: '#/definitions/ApiError'
  /contacts:
    get:
      consumes: []
      operationId: queryContacts
      tags:
      - Contact
      summary: Get contact
      responses:
        200:
          description: Success
          schema:
            type: array
            items:
              $ref: '#/definitions/Contact'
        400:
          description: Bad request.
          schema:
            $ref: '#/definitions/ApiError'
        default:
          description: Unknown error.
          schema:
            $ref: '#/definitions/ApiError'
  /parties:
    get:
      consumes: []
      responses:
        200:
          description: Success
          schema:
            type: array
            items:
              $ref: '#/definitions/Party'
        400:
          description: Bad request.
          schema:
            $ref: '#/definitions/ApiError'
        default:
          description: Unknown error.
          schema:
            $ref: '#/definitions/ApiError'
Command line used for generation

java -jar openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i test.yaml --library jersey2

Steps to reproduce

Use the OpenAPI definitions above to generate a java client.
It produces stand alone classes like:

  • public class Organization { ... }
  • public class Person { ... }
  • public class Contact { ... }

I would expect at least the following classes to be generated with:

  • public class Organization extends Customer { ... }
  • public class Person extends Customer { ... }
  • public class Contact extends Party { ... }

but there is no inheritance at all.

Related issues/PRs
Suggest a fix

I have not had a change to investigate.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions