Skip to content

[BUG] [Java] Use of anyOf leads to uncompilable output (missing class) #5938

@ondrakucera

Description

@ondrakucera

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Use of anyOf leads to a model class referencing another model class which isn't generated. When using the definitions below, the following field is generated within Partner:

private JsonNullable<AnyOfAddress> partner2Address = JsonNullable.<AnyOfAddress>of(null);

The problem is that the class AnyOfAddress (org.openapitools.client.model.AnyOfAddress fully qualified) doesn't exist. It should probably be generated, too, but it isn't.

openapi-generator version

4.3.0

OpenAPI declaration file content or url

The example is actually split into two files because that's how the original set of files looked like (I only deleted most of the contents and all the other files that were originally there).

address.yaml:

openapi: 3.0.2
info:
    title: Address
    version: '1.0'
paths:
    '/Addresses(''{AddressID}'')':
        parameters:
            - description: 'key: AddressID'
              in: path
              name: AddressID
              required: true
              schema:
                  type: string
                  maxLength: 10
        get:
            summary: Get entity from Addresses by key
            responses:
                '200':
                    description: Retrieved entity
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Address'
components:
    schemas:
        Address:
            title: Address
            type: object
            properties:
                AddressID:
                    type: string
                    maxLength: 10
                Street:
                    type: string
                    maxLength: 60
                StreetNumber:
                    type: string
                    maxLength: 10
                City:
                    type: string
                    maxLength: 40

partner.yaml:

openapi: 3.0.2
info:
    title: Partner
    version: '1.0'
paths:
    '/Partners(''{PartnerId}'')':
        parameters:
            - description: 'key: PartnerId'
              in: path
              name: PartnerId
              required: true
              schema:
                  type: string
                  maxLength: 10
        get:
            summary: Get entity from Partners by key
            responses:
                '200':
                    description: Retrieved entity
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Partner'
components:
    schemas:
        Partner:
            title: Partner
            type: object
            properties:
                PartnerId:
                    type: string
                    maxLength: 10
                LastName:
                    type: string
                    maxLength: 40
                FirstName:
                    type: string
                    maxLength: 40
                Partner2Address:
                    anyOf:
                        - $ref: 'address.yaml#/components/schemas/Address'
                    nullable: true
Command line used for generation
-g java -p dateLibrary=java8,hideGenerationTimestamp=true,java8=true,library=resttemplate -i partner.yaml
Steps to reproduce
Related issues/PRs
Suggest a fix

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