SAP / cloud-sdk-js

Use the SAP Cloud SDK for JavaScript / TypeScript to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
167 stars 57 forks source link

Wrong Schema Model property type generation - for schema properties of Array of oneOf type #5016

Closed uroslates closed 6 days ago

uroslates commented 2 months ago

Describe the bug There is a type generation error when generating ab array of oneOf types.

To Reproduce

E.g. when generating the type for an object of this shape:

"CheckoutOperationList": {
        "description": "List of checkout operations.",
        "properties": {
          "operations": {
            "description": "List of checkout operations.",
            "items": {
              "oneOf": [
                {
                  "$ref": "#/components/schemas/SetCostCenter"
                },
                {
                  "$ref": "#/components/schemas/SetDeliveryOption"
                },
                {
                  "$ref": "#/components/schemas/SetGuestEmail"
                },
                {
                  "$ref": "#/components/schemas/SetPaymentType"
                },
                {
                  "$ref": "#/components/schemas/SetPurchaseOrderNumber"
                },
                {
                  "$ref": "#/components/schemas/SetShippingAddress"
                },
                {
                  "$ref": "#/components/schemas/addShippingAddress"
                }
              ]
            },
            "type": "array"
          }
        },
        "required": [
          "operations"
        ],
        "type": "object",
        "additionalProperties": false
      }

the generated output is the following:

/*
 * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved.
 *
 * This is a generated file powered by the SAP Cloud SDK for JavaScript.
 */
import type { SetCostCenter } from './set-cost-center';
import type { SetDeliveryOption } from './set-delivery-option';
import type { SetGuestEmail } from './set-guest-email';
import type { SetPaymentType } from './set-payment-type';
import type { SetPurchaseOrderNumber } from './set-purchase-order-number';
import type { SetShippingAddress } from './set-shipping-address';
import type { AddShippingAddress } from './add-shipping-address';
/**
 * List of checkout operations.
 */
export type CheckoutOperationList = {
  /**
   * List of checkout operations.
   */
  operations:
    | SetCostCenter
    | SetDeliveryOption
    | SetGuestEmail
    | SetPaymentType
    | SetPurchaseOrderNumber
    | SetShippingAddress
    | AddShippingAddress[];
};  

Expected behavior

In the generated schema example from above we see that only last union type (AddShippingAddress[]) is marked as array. The expected behaviour is that entire union is marked as array! Example:


...
  operations:
    (SetCostCenter
    | SetDeliveryOption
    | SetGuestEmail
    | SetPaymentType
    | SetPurchaseOrderNumber
    | SetShippingAddress
    | AddShippingAddress)[];
...
` ``

**Used Versions:**

- node version via `node -v` -> v20.12.2
- npm version via `npm -v` -> 10.5.0
- SAP Cloud SDK version you used as dependency -> 3.15.0

**Impact / Priority**

This is blocking our team from generating correct schema SDK. Affects our Release & Production Phase.

Timeline: e.g. Go-Live is in few weeks.
deekshas8 commented 2 months ago

Hi @uroslates ,

We fixed this issue in the latest release. Can you try generating after updating the version?

armanozak commented 1 month ago

Hi @deekshas8,

Thank you for the quick reply. I can confirm that this issue does not exist in the latest release and the generation output is the array of the union type as expected.