cloud-sdk-js icon indicating copy to clipboard operation
cloud-sdk-js copied to clipboard

Unable to compile OData v2 client of service with inheritance

Open lennart-m opened this issue 3 years ago • 3 comments

Describe the bug Hi, I am trying to generate a client for a service that uses inheritance (has entities with a BaseType). The client generates typescript files but they won't compile as the inheriting entities don't have key properties.

To Reproduce Use this MWE.

service-specs/service-mapping.json:

{
  "test": {
    "directoryName": "test",
    "servicePath": "/test",
    "npmPackageName": "test"
  }
}

service-specs/test.edmx:

<?xml version='1.0' encoding='UTF-8'?>
<edmx:Edmx 
  xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
  <edmx:DataServices m:DataServiceVersion="1.0" 
    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <Schema Namespace="ns" 
      xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
      <EntityType Name="MyBaseType">
        <Key>
          <PropertyRef Name="id"/>
        </Key>
        <Property Name="id" Type="Edm.String" Nullable="false"/>
      </EntityType>
      <EntityType Name="MyType" BaseType="ns.MyBaseType">
        <Property Name="name" Type="Edm.String" Nullable="true"/>
      </EntityType>
      <EntityContainer Name="DefaultContainer" m:IsDefaultEntityContainer="true">
        <EntitySet Name="MyType" EntityType="ns.MyType"/>
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>
  • Entity MyType inherits from MyBaseType
  • MyBaseType has the key
  • MyType only adds one non-key property

package.json:

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "generate-client": "generate-odata-client -i service-specs -o generated --forceOverwrite --clearOutputDir"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@sap-cloud-sdk/connectivity": "^2.6.0",
    "@sap-cloud-sdk/odata-common": "^2.6.0",
    "@sap-cloud-sdk/odata-v2": "^2.6.0",
    "@sap-cloud-sdk/util": "^2.6.0"
  },
  "devDependencies": {
    "@sap-cloud-sdk/generator": "^2.6.0"
  }
}

Steps to reproduce the behavior:

  1. Create files above
  2. Run command npm run generate-client
  3. Notice that service generation fails

Expected behavior The cloud SDK should generate valid typescript code. In this case it should respect entity inheritance and merge all properties and especially the key.

Screenshots

Error message when compiling: image

MyType class is generated without any reference to MyBaseType (which isn't generated at all) image

Actual TS errors: MyType has no key and so the delete method has no valid signature image

Used Versions:

  • node version via node -v: 14.15.1
  • npm version via npm -v: 8.11.0
  • SAP Cloud SDK version you used as dependency: 2.6.0

Impact / Priority

This is for an internal project only. There is no deadline. I will try to adjust the metadata so that there is no inheritance.

Additional context Instead of using the MWE above, you can also use SAP's IntegrationContent service at https://api.sap.com/api/IntegrationContent/overview. This is the service that I wasn't able to use because of the bug.

lennart-m avatar Jul 27 '22 09:07 lennart-m

Hi @lennart-m ,

Thanks for creating the issue with details.

Firstly, you mentioned the BaseType feature, which is only supported in OData V4 (not V2) from my knowledge. Here is a blog post, where the base type was marked as a new feature of OData V4. As you are using OData V2 specification file, the base type is not considered.

Then I tested the IntegrationContent you mentioned, which does not have a BaseType. Could you please double check, whether we are talking about the same service? The generation did fail, with the error:

Unable to find a return type for name {"Type":"com.sap.hci.api.DefaultValMap","Nullable":"false"}

Could you please share your error message of the generation?

jjtang1985 avatar Jul 27 '22 11:07 jjtang1985

Hi @jjtang1985,

Thanks for your reply. Maybe I should have checked the metadata on SAP api hub before posting this question. I am currently not able to do so but next week I will. However, I did use the metadata provided by the cloud integration API itself (available at /api/v1/$metadata). This metadata document does contain BaseTypes.

Regarding the availability of entity interitance in OData v2, unfortunately the OData v2 documentation is not at all helpful. All I can say is that OData v3 supports inheritance, as you can see here. Also, in SAP on premise it's possible to configure an entity type's BaseType in SEGW if I remember correctly.

SIncerely, Lennart

lennart-m avatar Jul 29 '22 14:07 lennart-m

Hi @lennart-m ,

However, I did use the metadata provided by the cloud integration API itself (available at /api/v1/$metadata). This metadata document does contain BaseTypes.

If the metadata downloaded from the API Hub and the one from the endpoint $metadata are different, please consider creating a support ticket here.

unfortunately the OData v2 documentation is not at all helpful.

I cannot agree more 😞

All I can say is that OData v3 supports inheritance, as you can see here.

You are right. Unfortunately, the SAP Cloud SDK only supports OData v2 and v4 for the time being. (see documentation)

Also, in SAP on premise it's possible to configure an entity type's BaseType in SEGW if I remember correctly.

I'm not sure whether the SEGW also consider the version of your current odata version. For v3 and v4, it makes sense but maybe not for v2.

I can keep this ticket open, if you still want to have this feature request. I'll discuss with the team, but mostly we will not work on it soon.

Best regards, Junjie

jjtang1985 avatar Aug 01 '22 07:08 jjtang1985

I will close this issue due to inactivity. If this is still relevant, please reopen the issue and continue the discussion.

Best regards, Dennis

mr-flannery avatar Nov 01 '23 15:11 mr-flannery