Support for many-to-many associations
See original GitHub issueIs your feature request related to a problem? Please describe.
I am currently unable to create an association using a $links segment for a many-to-many association, using the API Proxy and API Product resources of SAP API Management. It requires a POST to the $batch endpoint of the service (there are some examples in the Batch Requests section of the API Proxy resource on API Business Hub).
Describe the solution you’d like
I would like to be able to build the correct URL using asChildOf, as it allows me to address the specific record and not the entire entity (e.g. /APIProducts(‘Federated_API’) vs. /APIProducts). However, asChildOf requires me to pass the navigation field (e.g. apiProxiesApi.schema.API_PRODUCTS), which does not include the required $links segment.
Ideally, SAP Cloud SDK would identify this is a many-to-many association from the model metadata and automatically build the URL:
<NavigationProperty Name="apiProducts" Relationship="apiportal.APIProxy_APIProduct_Many_Many0" FromRole="APIProxy" ToRole="APIProduct"></NavigationProperty>
However, it would also be acceptable to pass this leading segment as an additional property to the asChildOf method as a workaround.
Describe alternatives you’ve considered I have tried many combinations of asChildOf, appendPath, Deep Create, etc. without any luck. My only other recourse is to use an external library but I would lose the benefits of destination support and the conciseness of the fluent API.
Impact / Priority
Affected development phase: Release
Impact: Blocked
Timeline: Release scheduled for Q4 2022
Additional context This is part of a code sample showing customers how to federate API documentation between different gateways (both SAP and Non-SAP) for a unified API catalog. It reacts to an inbound event, fetches the Open API spec programmatically from another provider, and creates a Remote API in SAP API Management.
Here is a complete sample payload for the batch call:
--batch_b2fe-fc86-d733
Content-Type: multipart/mixed; boundary=changeset_dbf2-c5bb-a344
--changeset_dbf2-c5bb-a344
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT APIProducts(name='SimplifiedS4HANAProducts') HTTP/1.1
x-csrf-token: d776c7a92458b493-_X7FJI30ncQz7nl3UV0xvW856cU
Accept-Language: en
Accept: application/json
MaxDataServiceVersion: 2.0
DataServiceVersion: 2.0
Content-Type: application/json
Content-Length: 249
{"name":"SimplifiedS4HANAProducts","title":"Simplified S/4HANA Product API","scope":"","description":"<p></p>","version":"1","status_code":"PUBLISHED","isRestricted":false,"isPublished":true,"quotaCount":-99,"quotaInterval":-99,"quotaTimeUnit":null}
--changeset_dbf2-c5bb-a344
Content-Type: application/http
Content-Transfer-Encoding: binary
POST APIProducts(name='SimplifiedS4HANAProducts')/$links/apiProxies HTTP/1.1
x-csrf-token: d776c7a92458b493-_X7FJI30ncQz7nl3UV0xvW856cU
Accept-Language: en
Accept: application/json
MaxDataServiceVersion: 2.0
DataServiceVersion: 2.0
Content-Type: application/json
Content-Length: 32
{"uri":"APIProxies('Ping_CPI')"}
--changeset_dbf2-c5bb-a344
Content-Type: application/http
Content-Transfer-Encoding: binary
POST APIProxies(name='Ping_CPI')/$links/apiProducts HTTP/1.1
x-csrf-token: d776c7a92458b493-_X7FJI30ncQz7nl3UV0xvW856cU
Accept-Language: en
Accept: application/json
MaxDataServiceVersion: 2.0
DataServiceVersion: 2.0
Content-Type: application/json
Content-Length: 49
{"uri":"APIProducts('SimplifiedS4HANAProducts')"}
--changeset_dbf2-c5bb-a344--
--batch_b2fe-fc86-d733--
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:7 (4 by maintainers)
Hi @jjtang1985 @marikaner - Thanks for the follow up on this issue. I was able to get it working as it seems appendPath can be used to append anything and not just paths. I eliminated asChildOf and added something like:
.appendPath(
(name='Federated_API')
, ‘/$links’, ‘/apiProxies’);or
.appendPath(
(name='${proxyName}')
, ‘/$links’, ‘/apiProducts’);to the requestBuilder() calls for each entity. I also had to add ‘as any’ to the create() and changeset() calls to prevent compilation errors. Even though it is less than ideal, I can utilize this as a workaround in Q4 while you finalize an ADR and plan for type-safe support in the future.
Hi @jmsrpp ,
Awesome. I’m happy to see it’s working with the workaround. Thanks for sharing your examples.
To answer your question:
The
stringProperty
is just a normal property of our test entity like any known properties ofApiProxies
defined in the specification file in your case.I’ll leave this ticket open and update later.