OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Java client] oneOf is refering a non existing class in Swagger annotation

Open
#2,056 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

If I use this component definitions

    CrossBorderCreditTransferResponse:
      description: Get payment response
      allOf:
        - $ref: './xs2a-common.yaml#/components/schemas/BaseResponse'
        - $ref: '#/components/schemas/SinglePayment'

    HungarianCreditTransferResponse:
      description: Get payment response
      allOf:
        - $ref: './xs2a-common.yaml#/components/schemas/BaseResponse'
        - $ref: '#/components/schemas/HungarianCreditTransfer'

    PeriodicHungarianCreditTransferResponse:
      description: Get periodic payment response
      allOf:
        - $ref: './xs2a-common.yaml#/components/schemas/BaseResponse'
        - $ref: '#/components/schemas/PeriodicHungarianCreditTransfer'

and generate an API for

  /{payment-service}/{payment-product}/{payment-id}:
    get:
      responses:
        '200':
          description: OK, request received
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/HungarianCreditTransferResponse'
                  - $ref: '#/components/schemas/CrossBorderCreditTransferResponse'
                  - $ref: '#/components/schemas/PeriodicHungarianCreditTransferResponse'

with Maven plugin (version 4.0.0-SNAPSHOT) I get an invalid Java code generated:

import hu.cib.psd2.model.xs2a.OneOfHungarianCreditTransferResponseCrossBorderCreditTransferResponsePeriodicHungarianCreditTransferResponse;

    @GET
    @Path("/{payment-service}/{payment-product}/{payment-id}")
    @Produces({ "application/json" })
    @ApiOperation(value = "", tags={ "payment-initiation-service",  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "OK, request received", response = OneOfHungarianCreditTransferResponseCrossBorderCreditTransferResponsePeriodicHungarianCreditTransferResponse.class) })
    public Response getPayment();

The generator doesn't recognize the common parent BaseResponse, instead it refers to a non existing
OneOfHungarianCreditTransferResponseCrossBorderCreditTransferResponsePeriodicHungarianCreditTransferResponse class.

Actually I don't event need this Swagger anotation to run my code, but this way it doesn't compile.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing Java client generation with the Maven plugin using the supplied allOf and oneOf schema definitions. Inspect the generated ApiResponse annotation and model reference; done means the generated Java code compiles without referring to the nonexistent OneOfHungarianCreditTransferResponseCrossBorderCreditTransferResponsePeriodicHungarianCreditTransferResponse class.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.