Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
uroslates opened this issue Sep 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@uroslates
Copy link

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.
@uroslates uroslates added the bug Something isn't working label Sep 19, 2024
@deekshas8
Copy link
Contributor

Hi @uroslates ,

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

@armanozak
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants