Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 of 6 tasks
jeff9finger opened this issue Jul 15, 2020 · 5 comments · Fixed by #7106
Closed
5 of 6 tasks

Comments

@jeff9finger
Copy link
Contributor

jeff9finger commented Jul 15, 2020

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.

@auto-labeler
Copy link

auto-labeler bot commented Jul 15, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@jimschubert
Copy link
Member

@spacether would you be able to look into this? I didn't do a git bisect, but I think it may be related to the composition changes you made.

@spacether
Copy link
Contributor

Yup I will look in to this.

@spacether
Copy link
Contributor

spacether commented Jul 26, 2020

@jeff9finger what release did this work for you in?
When I tested back to our 4.2.0 release I also did not see extend being used.
Are you sure that this was working in the way that you describe with the jersey2 library?
I am unable to verify this.

@jeff9finger
Copy link
Contributor Author

I just started recent work in 4.3.1. Am trying to move my company onto this tool. So, I'm not sure it was working, but accoring to @jimschubert, this should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants