on 01-18-2021 2:25 PM
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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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...
User | Count |
---|---|
74 | |
9 | |
7 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.