question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
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 https://github.com/OpenAPITools/openapi-generator/issues/3100 and https://github.com/OpenAPITools/openapi-generator/issues/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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
argenstijncommented, Oct 13, 2021

Can this please be fixed? Because no there is no inheritance. Also check what happens if you have multiple discriminator or multiple allOf

0reactions
epabstcommented, Nov 19, 2022

After I got the Pet model working that @marcdejonge provided in https://github.com/OpenAPITools/openapi-generator/issues/9615#issuecomment-861304768, 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:

Note, I also applied this fix to avoid the extra AllOf classes: https://github.com/OpenAPITools/openapi-generator/issues/3100#issuecomment-703481081

Read more comments on GitHub >

github_iconTop Results From Across the Web

Json Schema Allof Override - KAMM Ky Association of Mitigation ...
server url supports adding your validator instance by tools for other. ... here are not two json schema that do inheritance and try...
Read more >
JSon schema and Inheritance - java - Stack Overflow
Because there is no such thing as schema inheritance currently defined. When using allOf , you require that all schemas in allOf match; ......
Read more >
OpenAPI Specification - Version 2.0 - Swagger
Version 2.0 specification defines a set of files required to describe an API. These files can then be used by the Swagger-UI project...
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
Tooling which supports OAS 3.1 SHOULD be compatible with all OAS 3.1.* versions. The patch version SHOULD NOT be considered by tooling, ...
Read more >
Details of the policy definition structure - Azure - Microsoft Learn
Policy assignments are inherited by child resources. ... While not required, it prevents resources that don't support tags and locations ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found