Skip to content

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

@vincent-ch

Description

@vincent-ch

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;
}

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