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

ODATAv4 client is missing bound function/action

Open GoWale opened this issue 1 year ago • 3 comments
trafficstars

Describe the bug the documentation tell ther shoud be support for bound an unbound functions on: https://sap.github.io/cloud-sdk/docs/js/features/odata/v4-client#using-operations

but the bound functions/actions are missing in my odata v4 example

To Reproduce Steps to reproduce the behavior: git clone https://github.com/GoWale/issue-cloud_sdk-odatav4-action.git npm i

  1. Set up npm run start
  2. Execute sdk_gen_client
  3. Confirm go to /srv/server.ts and uncomment the example coding
  4. See error

Expected behavior Like the unbound function/action

  const {
    operations: { countOrders, cancelOrder, getOpenOrders },
  } = capOdatav4();
  await countOrders({}).execute(destination);
  await getOpenOrders({}).execute(destination);
  await cancelOrder({}).execute(destination);

also the bound function/action

  const entity = belegeApi.requestBuilder().getByKey("0292da0e-649d-4a4c-9a8b-fd47759e6e73").execute(destination);
  await entity.sendLetter({}).execute(destination);
  await entity.getViewsCount({}).execute(destination);

should work like stated in the documentation

Used Versions:

  • node version v20.10.0
  • npm version 10.2.5
  • SAP Cloud SDK version you used as dependency "@sap-cloud-sdk/generator": "^3.12.1",

Impact / Priority

medium: bound functions/action have to be implemented by hand an there are no types for parameter/results

Affected development phase: Development / CI/CD

GoWale avatar Mar 20 '24 03:03 GoWale

Hi @GoWale ,

There seems to be an issue with your v4 spec. If I also include the reference to bound action import inside the EntityContainer tag, then the generation works as expected.

<EntityContainer Name="EntityContainer">
...
...
<ActionImport Name="sendLetter" Action="main_service.sendLetter"/>
</EntityContainer>

deekshas8 avatar Mar 21 '24 09:03 deekshas8

Hi @deekshas8 ,

thanks for the reply. But just to be sure. As fare as I understand the OASIS OData documentation for bound actions there ist no need for an ActionImport. But it is required for unbound actions.

See chapter 12

12.1 Element edm:Action The edm:Action element represents an action in an entity model. Actions MAY have observable side effects and MAY return a single instance or a collection of instances of any type. Actions cannot be composed with additional path segments. The action MAY specify a return type using the edm:ReturnType element. The return type must be a primitive, entity or complex type, or a collection of primitive, entity or complex types. The action may also define zero or more edm:Parameter elements to be used during the execution of the action.

12.1.2 Attribute IsBound An action element MAY specify a Boolean value for the IsBound attribute. Actions whose IsBound attribute is false or not specified are considered unbound. Unbound actions are invoked through an action import. Actions whose IsBound attribute is true are considered bound. Bound actions are invoked by appending a segment containing the qualified action name to a segment of the appropriate binding parameter type within the resource path. Bound actions MUST contain at least one edm:Parameter element, and the first parameter is the binding parameter. The binding parameter can be of any type, and it MAY be nullable. Action from CAP framework: image

13.5 Element edm:ActionImport The edm:ActionImport element allows exposing an unbound action as a top-level element in an entity container. Action imports are never advertised in the service document.

For that reason I have created the issue here. But if you say also bound Actions have to be listed in the ActionImport I will create an OSS ticket for the CAP (JS) and RAP implementation. It seams like both implementations are doing it the same way (No ActionImport for bound actions).

regards Norbert

GoWale avatar Mar 21 '24 19:03 GoWale

I think this is related to #707 and also #4543

should we still ad a comment to #707 as mentioned here: https://sap.github.io/cloud-sdk/docs/js/features/odata/v4-client#known-issues

Currently, the Entity Type is not supported to be used as the parameters of the operation. Operations with such unsupported parameters are ignored during the generation. This feature will be implemented in the future. Please check this issue and comment if you need this feature.

ghost avatar Mar 22 '24 14:03 ghost

Hi @nlaenger ,

sorry for the late response. While we're aware that this is a gap in our generator, we currently do not have the capacity to address this. You can open tickets with CAP and RAP, but if they're following the spec, I'm not sure how keen they are on implementing workarounds for gaps in the Cloud SDK. I'm afraid you will either need to find a workaround or make a contribution to the SDK.

Feel free to also comment #707 so that we have everything in one place.

Best regards, Dennis

mr-flannery avatar Apr 15 '24 14:04 mr-flannery