cancel
Showing results for 
Search instead for 
Did you mean: 

CAP OpenAPI Generator for OData V4 Functions

aparr
Participant

Hi all,

When generating an openapi file for an SAP Cloud Application Programming Model Service via cds compile Swagger API uses a wrong URL to call that OData V4 function. Is that an know bug or limitation or am i doing something wrong?

CDS Service definition

service Substitute @(requires : 'ApiUser') {

    type SubstituteWrapper {
        Matnr      : String(18);
        Sugrd      : String(4);
        Material {
            Matwa  : String(18);
            Mstav  : String(2);
            Vmsta  : String(2);
        };
        Substitute : {
            Mstav  : String(2);
            Smatn  : String(18);
            Vmsta  : String(2);
        };
    }

   function GetSubstitute(
                           Matnr : String(18) not null,
                           Sugrd : String(4) null ,
                           VkOrg : String(4) null ,
                           VtWeg : String(2) null ,
                           Kschl : String(4) null ,
                           Kappl : String(2) null)) 
     returns               SubstituteWrapper;
}

Which results in the following URLs when using Swagger UI:

substitute/GetSubstitute?Matnr=389951

But should be like

substitute/GetSubstitute(Matnr='389951',Sugrd='',VkOrg='0100',VtWeg='20',Kschl='',Kappl='')

Any idea on this?

chgeo
Advisor
Advisor

ralf.handl can you shed a light on whether function calls like above is already covered by the OpenAPI converter?

joerg.mann FYI

aparr
Participant
0 Kudos

Hello ralf.handl christian.georgi joerg.mann

Could you please provide a sample for a function with an optional parameter which is considered in the OpenAPI File as well?

Best

Alex

Accepted Solutions (0)

Answers (1)

Answers (1)

RalfHandl
Product and Topic Expert
Product and Topic Expert

Generating an openapi file for your service with CAP 4.4.10 produces

  "paths": {
    "/GetSubstitute(Matnr='{Matnr}',Sugrd='{Sugrd}',VkOrg='{VkOrg}',VtWeg='{VtWeg}',Kschl='{Kschl}',Kappl='{Kappl}')": {
      "get": {
        "summary": "Invoke function GetSubstitute"

Which is what you expect.

aparr
Participant
0 Kudos

Thanks ralf.handl

I wondered why my openapi json file is different from yours and I saw that I removed some core annations in the cds file in order the keep the sample a little bit cleaner but this causes the url to change.

By adding annoation Core : {OptionalParameter : {$Type : 'Core.OptionalParameterType'}} the url changes. Full sample:

function GetSubstitute(Matnr : String(18) not null,
                                   Sugrd : String(4) null @(
                                                              description : 'Reason',
                                                              Core        : {OptionalParameter : {$Type : 'Core.OptionalParameterType'}}
                                                          ),
                                   VkOrg : String(4) null ,
                                   VtWeg : String(2) null ,
                                   Kschl : String(4) null ,
                                   Kappl : String(2) null 
                                   ) 
    returns SubstituteWrapper;

This changes the url to /GetSubstitute and removes the other parts needed to build up a valid OData V4 request, right?

Why did I add that annotation:

I like to mark mandatory and optional parameters of the function. 'null' and 'not null' keywords of the function parameters are not considered when creating the openapi file?

Thanks,
Alex

aparr
Participant
0 Kudos

ping ralf.handl christian.georgi joerg.mann

RalfHandl
Product and Topic Expert
Product and Topic Expert
0 Kudos

The suffix null only tells that null is an allowed parameter value, the parameter is still required in the request URL, e.g. as Sugrd=null.

Optional parameters in the sense that you can omit them from the request URL are marked with the annotation Core.OptionalParameter. This then implies sending the parameters in the query part of the URL.

See example 94 in https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_InlineParameterSyn...