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
  • #6950
Closed
Open
Issue created Jul 15, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

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

Created by: 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
  • https://github.com/OpenAPITools/openapi-generator/issues/6815
  • https://github.com/OpenAPITools/openapi-generator/pull/6901
  • https://github.com/OpenAPITools/openapi-generator/pull/6849
Suggest a fix

I have not had a change to investigate.

Assignee
Assign to
Time tracking