Closed osanda2024 closed 4 months ago
@osanda2024 Can you share the code to reproduce this issue?
This is the code for generating mock server
import ballerina/http;
import ballerina/os;
boolean isBalBuild = os:getEnv("IS_BAL_BUILD") == "true";
string certPathPostFix = isBalBuild ? "../" : "/home/ballerina/ballerina/";
listener http:Listener ep0 = new (9090,
secureSocket = {
key: {
certFile: certPathPostFix + "resources/public.crt",
keyFile: certPathPostFix + "resources/private.key"
}
}
);
// The ODATA Version postfix in service path fails for Mock Server Requests
// Issue - https://github.com/ballerina-platform/ballerina-library/issues/6675
// service /sap/opu/odata/sap/API_CUSTOMER_RETURNS_DELIVERY_SRV\;v\=0002 on ep0 {
service /sap/opu/odata/sap/API_CUSTOMER_RETURNS_DELIVERY_SRV on ep0 {
resource function head .() returns http:Response {
http:Response res = new;
res.statusCode = 200;
res.setHeader("X-CSRF-TOKEN", "SAP-InfoRecord-Process");
return res;
}
# Reads customer returns delivery headers.
#
# + \$top - Show only the first n items, see [Paging - Top](https://help.sap.com/doc/5890d27be418427993fafa6722cdc03b/Cloud/en-US/OdataV2.pdf#page=66)
# + \$skip - Skip the first n items, see [Paging - Skip](https://help.sap.com/doc/5890d27be418427993fafa6722cdc03b/Cloud/en-US/OdataV2.pdf#page=65)
# + search - Search items by search phrases, see [Searching](https://wiki.scn.sap.com/wiki/display/EmTech/SAP+Annotations+for+OData+Version+2.0#SAPAnnotationsforODataVersion2.0-Query_Option_searchQueryOptionsearch)
# + \$filter - Filter items by property values, see [Filtering](https://help.sap.com/doc/5890d27be418427993fafa6722cdc03b/Cloud/en-US/OdataV2.pdf#page=64)
# + \$inlinecount - Include count of items, see [Inlinecount](https://help.sap.com/doc/5890d27be418427993fafa6722cdc03b/Cloud/en-US/OdataV2.pdf#page=67)
# + \$orderby - Order items by property values, see [Sorting](https://help.sap.com/doc/5890d27be418427993fafa6722cdc03b/Cloud/en-US/OdataV2.pdf#page=65)
# + \$select - Select properties to be returned, see [Select](https://help.sap.com/doc/5890d27be418427993fafa6722cdc03b/Cloud/en-US/OdataV2.pdf#page=68)
# + \$expand - Expand related entities, see [Expand](https://help.sap.com/doc/5890d27be418427993fafa6722cdc03b/Cloud/en-US/OdataV2.pdf#page=63)
# + return - returns can be any of following types
# http:Ok (Retrieved entities)
# http:Response (Error)
resource function get A_ReturnsDeliveryHeader(int? \$top, int? \$skip, string? search, string? \$filter, "allpages"|"none"? \$inlinecount, A_ReturnsDeliveryHeaderOrderByOptions? \$orderby, A_ReturnsDeliveryHeaderSelectOptions? \$select, A_ReturnsDeliveryHeaderExpandOptions? \$expand) returns CollectionOfA_ReturnsDeliveryHeaderWrapper|http:Response {
return {
d: {
results: [
{
"ReturnsDeliveryHeader": "12345"
}
]
}
};
}
}
@osanda2024 the version used with the path segment /API_CUSTOMER_RETURNS_DELIVERY_SRV
is a matrix parameter which is not part of the resource URL just like query parameters. This matrix parameter can be accessed via the http:Request
object.
So when defining the mock server you should not define it with the matrix parameter like this:
service /sap/opu/odata/sap/API_CUSTOMER_RETURNS_DELIVERY_SRV\;v\=0002 on ep0 {
If you do like this we will treat API_CUSTOMER_RETURNS_DELIVERY_SRV\;v\=0002
as a path segment when creating the service (special characters will be encoded). So you should define the service without the matrix parameter like this:
service /sap/opu/odata/sap/API_CUSTOMER_RETURNS_DELIVERY_SRV on ep0 {
Okay Got it ! Thank you !
Description:
I tried generating the mock server with the service path as "sap/opu/odata/sap/API_CUSTOMER_RETURNS_DELIVERY_SRV;v=0002" by running the command of
bal test
within the api package path. The server url (sap/opu/odata/sap/API_CUSTOMER_RETURNS_DELIVERY_SRV;v=0002) in the Open API spec having post fix of version doesn't find the path in mock server generation. It finds the correct path when generating the live server request.Therefore it gives the below error.
Error
Compiling source ballerinax/sap.s4hana.api_customer_returns_delivery_srv_0002:1.0.0
Running Tests
time=2024-07-02T10:46:45.845+05:30 level=INFO module=ballerinax/sap.s4hana.api_customer_returns_delivery_srv_0002$test message="Running tests on mock server" error: no matching service found for path: /sap/opu/odata/sap/API_CUSTOMER_RETURNS_DELIVERY_SRV/A_ReturnsDeliveryItem