cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAP: CDS Action with nullable array parameter

ckuczera
Participant
0 Kudos
2,009

Dear Community,

I am implementing a Node.js CAP CDS Service based on an interface definition provided and specified by SAP. The interface definition requires an entity action with following parameter:

  • code: String
  • comment: String
  • reasonCode: String
  • parameters: array of Object with following attributes:
    • code: String
    • value: String

According to that we have specified the action in the cds file:

ckuczera_0-1722321967136.png

The metadata is generated as

ckuczera_1-1722322074557.png

So far everything is working as expected, but the interface defintion specifies the "parameters" as nullable and provides an example executing the action as:

ckuczera_2-1722322269557.png

When performing an action without a "parameters" value the odata v4 logic is raising an error:

Deserialization Error: Parameter 'parameters' is not nullable.

Raised in:

ckuczera_3-1722322474468.png

I have not found a way to mark the parameter as nullable. Did I miss something?

Thanks

View Entire Topic
RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

For an array parameter "nullable" controls whether the array may contain null values as in

"parameter": [some-object, null, another-object]

The parameter still has to be provided in the action call.

What "interface definition" are you referring to?

 

ckuczera
Participant
0 Kudos

Hi @RalfHandl , thanks for your reply. I am reffering to the taskcenter 3rd party API which requires the parameters to be optional:

https://community.sap.com/t5/sap-builders-blog-posts/sap-task-center-s-new-3rd-party-integration/ba-...

Please checkout chapter 5.1.1.5. Performing Operations on Tasks

I decided to implement that interface using cap, but it seems that this optional part is not feasible with cap

ckuczera_0-1722439746623.png

The rest of the required interface objects is feasible using cap

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

You can make action parameters optional by annotating them, for example

 

action foo(
         param: array of String @Core.OptionalParameter : { $Type : 'Core.OptionalParameterType' }
       ) returns String;
RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

Then you can omit the annotated parameter from the action request body.

I've tested this with the latest CAP for Node.js.

ckuczera
Participant
0 Kudos

Hello @RalfHandl,

after applying the annotation and updating to the newest cap version 8.1.0 the parameter ist marked as optional.

 
action action(
    code: String,
    comment: String,
    reasonCode: String,
    @Core.OptionalParameter : { $Type : 'Core.OptionalParameterType' }
    parameters: array of customCodes
) returns tasks;

Thank you very much for your support