Closed pranavnag18 closed 4 months ago
Yes, your use-case is supported, but not like you configured it.
Explanation why you experience the current behavior
The CDS OData V2 Adapter was primarily designed to prepend an OData V2 path prefix before the OData V4 path to define the OData V2 routes. Example: OData V4 path is businesspartner
and OData V2 path is v2/businesspartner
.
So your configuration will prepend the cov2ap.path
to the service path, which does result in /api/v2/businesspartner/api/v4/businesspartner
. This is what you see.
The cov2ap.path
is not meant to specify a concrete service path, e.g. including the service name, but it is a OData V2 protocol prefix, like for example /api/v2
.
With the introduction of CDS protocol paths and endpoints there is now the possibility to be more flexible. So the path can be rewritten instead of just prepended, e.g. OData V4 path is odata/v4/businesspartner
and OData V2 path is odata/v2/businesspartner
How you can solve this requirement
Preparation: Remove the cov2ap.path
and cov2ap.targetPath
configuration
Option 1 - Globally
api/v4
or api/v2
protocol prefixes for OData services for whole projects, then I would propose to overwrite the protocol default in CDS protocol configuration like this (e.g. in package.json
)"cds": {
"protocols": {
"odata": {
"path": "/api/v4"
},
"odata-v2": {
"path": "/api/v2"
}
}
}
Then the service path is just defined as a relative path (does not start with a slash /
) appended to the protocol path: @(path: 'businesspartner')
The resulting routes are then:
OData v4: /api/v4/businesspartner
OData v2: /api/v2/businesspartner
Option 2 - Service local
odata
instead of api
, but want to change it on service-level, then this can be done using the @protocol
annotation on service level like this (in service.cds
)@protocol: [{
kind: 'odata-v4', path: '/api/v4/businesspartner'
}, {
kind: 'odata-v2', path: '/api/v2/businesspartner'
}]
service partner {
// ...
}
You remove the @path
annotation, and instead use the @protocol
annotation. Then you start your path
with a slash (/
) to indicate absolute paths. This will prevent, that the paths are prefixed with the global protocol path, as you don't want to get e.g. /odata/v4/api/v4/businesspartner
...
When you configure it like this, the resulting routes are then again:
OData v4: /api/v4/businesspartner
OData v2: /api/v2/businesspartner
The request URLs and the URLs in the response are then correct as you expected it.
A simple CAP application that needs to serve both OData v4 and v2. To achieve this, I'm using the cov2ap plugin. In the plugin configuration, I've specified path and targetPath to route requests for v2 to the corresponding v4 endpoint.
However, I've encountered an issue where the OData v2 API response incorrectly appends the v4 path to the v2 target URI. For example, my setup is as follows:
OData v4 endpoint:
/api/v4/businesspartner
OData v2 endpoint: /
api/v2/businesspartner
Yet, the OData v2 response for business partners navigation to orders uri includes URLs that combine paths from both v2 and v4, like this below,
Here is the relevant part of my package.json:
And the service.cds:
odata v2 request and response
Please see the uri in the response, it appends "/api/v4/businesspartner" in the navigation uri.