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 not generated correctly #3058

Closed
rlsf opened this issue Jun 2, 2019 · 3 comments
Closed

[BUG] Multi Level Inheritance not generated correctly #3058

rlsf opened this issue Jun 2, 2019 · 3 comments
Milestone

Comments

@rlsf
Copy link

rlsf commented Jun 2, 2019

As can be seen in these issues:
#1685
#2928

there is a problem with generating multi-level hierarchy with OpenAPI 4.x.x and 5.x.x.
the problem exists in numerous languages that we tested so we guess that it is a problem with the main code.

For example for the yaml below taken from issue 1685 version 3.3.4 generates the expected

class Animal {…}
class Cat extends Animal {…}
class Dog extends Animal {…}
class BigDog extends Dog {…}

While 4.xx and 5.xx generate

class Animal {…}
class Cat extends Animal {…}
class Dog extends Animal {…}
class BigDog {…}

generation was executed using the maven-openapi-generator of the respective version (4.x.x and 5.x.x)

openapi: 3.0.0
info:
  title: Sample API
  description: API description in Markdown.
  version: 1.0.0
paths:
  /animals:
    get:
      summary: Returns all animals.
      description: Optional extended description in Markdown.
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Animal'
components:
  schemas:
    Dog:
      allOf:
        - $ref: '#/components/schemas/Animal'
        - type: object
          properties:
            breed:
              type: string
    Cat:
      allOf:
        - $ref: '#/components/schemas/Animal'
        - type: object
          properties:
            breed:
              type: string
    BigDog:
      allOf:
        - $ref: '#/components/schemas/Dog'
        - type: object
          discriminator:
            propertyName: dogType
            required:
              - dogType
          properties:
            dogType:
              type: string
            declawed:
              type: boolean
    Animal:
      type: object
      discriminator:
        propertyName: className
      required:
        - className
      properties:
        className:
          type: string
        color:
          type: string
          default: red
@andys8
Copy link
Contributor

andys8 commented Jun 4, 2019

Having an issue with Elm and 4.0.0 release and inheritance, too.

@papegaaij
Copy link

papegaaij commented Jul 12, 2019

It seems the check for a discriminator only looks one level up. Repeating the discriminator in the intermediate type (Dog in the example) seems to fix the inheritance.

Update: this unfortunately generates java code that does not compile:

src/main/java/org/openapitools/client/model/Dog.java:[40,9] className has private access in org.openapitools.client.model.Animal

It tries to set the discriminator in the superclass from the constructor of the subclass. Redefining the className property in the subtypes fixes this, but duplicates the discriminiator in every type.

@jimschubert
Copy link
Member

Fixed by #4503 please evaluate and let us know if it needs to be reopened.

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

No branches or pull requests

4 participants