Skip to content

[Java] "allOf" does not support inheritance #3172

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

Closed
vincent-ch opened this issue Jun 18, 2019 · 5 comments
Closed

[Java] "allOf" does not support inheritance #3172

vincent-ch opened this issue Jun 18, 2019 · 5 comments

Comments

@vincent-ch
Copy link

Description
I just attempted to use allOf in my project to use inheritance in our data model.

openapi-generator version
I am using the Maven plugin: openapi-generator-maven-plugin:4.0.0-beta2

OpenAPI declaration file

UserSpecificService:
  type: object
  required:
    - typ
    - aktiviert
  properties:
    id:
      type: string
      format: int64
    typ:
      $ref: '#/components/schemas/ServiceTyp'
    aktiv:
      type: boolean

PushServiceETA:
  allOf:
    - $ref: '#/components/schemas/UserSpecificService'
    - type: object
      properties:
        verteilerListe:
          type: array
          items:
            $ref: '#/components/schemas/PushVerteilerETA'
        ort:
          $ref: '#/components/schemas/Ort'

Result

public class UserSpecificService {
  private String id;
  private ServiceTyp typ;
  private Boolean aktiv;
}

public class PushServiceETA {
  private String id;
  private ServiceTyp typ;
  private Boolean aktiv;
  private List<PushVerteilerETA> verteilerListe = new ArrayList<>();
  private Ort ort = null;
}

Suggest a fix/enhancement
The Java generator should support single inheritance. It would give us way more flexibilty in the usage of the generated classes in our code.

public class PushServiceETA extends UserSpecificService {
  private List<PushVerteilerETA> verteilerListe = new ArrayList<>();
  private Ort ort = null;
}
@mikhail-putilov
Copy link

mikhail-putilov commented Jun 28, 2019

Technically it is not a bug https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#does-openapi-generator-support-all-new-features-in-openapi-specification-v3

A bug is a mistake in an existing feature. Processing of allOf is simply not there.

@wing328
Copy link
Member

wing328 commented Jun 30, 2019

@vincent-ch for inheritance, please use discriminator as per OpenAPI spec v3.

Ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaComposition

@vincent-ch
Copy link
Author

Thanks for your answer @wing328 , I did a quick test and it looks good. I just have to test how I can configure it with my complexes cases. This is not a bug in this case.

@wing328
Copy link
Member

wing328 commented Jul 6, 2019

@vincent-ch glad to hear the issue has been resolved for you.

If you like what OpenAPI Generator offers, please consider supporting our voluntary work via https://opencollective.com/openapi_generator

@epabst
Copy link

epabst commented Nov 19, 2022

After I got the Pet model working that @marcdejonge provided in #9615 (comment), I figured out a workaround for my own issue. I had separate yaml files for my schema model classes, and by moving them into the same file as the endpoints under this, it worked for me!!!

components:
  schemas:

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