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
162 stars 55 forks source link

Generator: TypeScript error for required properties in complex types #341

Closed ja-ne closed 4 years ago

ja-ne commented 4 years ago

Description Complex types with non-nullable properties seem to lead to TypeScript type errors when working with the @sap-cloud-sdk/generator version 1.25.0. This did not occur with version 1.24.0.

To Reproduce

  1. Get the EDMX-specification for the Attachments ODATA API from SAP S/4HANA Cloud Package: https://api.sap.com/api/API_CV_ATTACHMENT_SRV/overview.

  2. Generate a service module from this specification using the @sap-cloud-sdk/generator version 1.25.0. You can, for instance, follow these steps or this introduction. generate-odata-client --inputDir specifications --outputDir generator-modules

  3. Use the generated TypeScript service module in a TypeScript project (e.g. import it in a file index.ts): import * as attachmentService from './generator-modules/cv-attachment-service';

  4. Transpile the project code to JavaScript. tsc index.ts

  5. Result: There is an error message indicating missing required properties. grafik These steps work for other specification files containing complex types with required properties as well.

Expected behavior The service module should transpile without errors.

Used Versions:

Did I miss something? Is there a workaround?

Many thanks in advance and best regards, ja-ne

marikaner commented 4 years ago

Hey @ja-ne,

thank you for reporting this. We will take a look at this. In the mean time I would be interested whether there is a reason for you to generate the S4Hana VDM on your own? Are you aware of the @sap/cloud-sdk-vdm-attachement-service module? This might be a suitable workaround for you.

ja-ne commented 4 years ago

Hello @marikaner , thanks for the quick response. I have several generated service modules and merely chose the attachment service as simple (but, as it turns out, unsuitable) example.

marikaner commented 4 years ago

Hey @ja-ne,

we have found and solved the issue, a new version will be available with the next release.

marikaner commented 4 years ago

Fixed with version 1.26.0. Please try again and let us know if there are any further issues.

ja-ne commented 4 years ago

Thanks for the fix, everything works fine now.