Skip to content

[BUG] [Java] "allOf" does not support inheritance #9756

@rgoers

Description

@rgoers
Description

I am trying to generate Java classes from an openapi schema that contains

OrganizationPage:
  type: object
  allOf:
    - $ref: '#/components/schemas/BasePage'
  properties:
    data:
      type: array
      items:
        $ref: '#/components/schemas/Organization'

this ends up generating a class named OrganizationPage with

public class OrganizationPage  implements Serializable {

but I require

public class OrganizationPage  extends BasePage implements Serializable {

the documentation seems to indicate that it is required that the definition of BasePage be modified to add a discriminator field. I am unable to do that as that file is in a different project that is shared by different projects, some of which use older versions of openapi-generator and do not populate a discriminator field. Furthermore, a discriminator field is never required as the base class is never referenced in the API, only the subclass is, so serialization/deserialization doesn't require a discriminator. However, there are utility methods that operate on the base class so all instances must extend the class.

openapi-generator version

openapi-generator-mave-plugin 5.1.0

OpenAPI declaration file content or url
    OrganizationPage:
      type: object
      allOf:
        - $ref: '#/components/schemas/BasePage'
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/Organization'

base-page.yml contains

description: Page resource object for paged REST resource response. Extend this object to return a strongly-typed payload.
type: object
properties:
  totalCount:
    description: The total number of resources at the requested location taking query parameters into account
    readOnly: true
    type: integer
    format: int64
  first:
    description: Link to the first page in the resource collection
    readOnly: true
    type: string
    format: uri
  prev:
    description: Link to the first page in the resource collection
    readOnly: true
    type: string
    format: uri
  next:
    description: Link to the first page in the resource collection
    readOnly: true
    type: string
    format: uri
  last:
    description: Link to the first page in the resource collection
    readOnly: true
    type: string
    format: uri
required:
  - totalCount
Generation Details

mvn clean install produces:

[deprecated] inheritance without use of 'discriminator.propertyName' has been deprecated in the 5.x release. Composed schema name: null. Title: null

The above line is emitted a few times during the build but it isn't clear if it is associated with this issue or not since it doesn't identify the file, line, or object it is referencing.

Related issues/PRs

Both #3100 and #3172 have similarities to this issue.

Suggest a fix

The only fix I can think of is to add an attribute to the definition of the object to direct it to use inheritance instead of composition.

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