on 03-10-2022 12:34 PM
Does CAP / CDS allow us to expose 1 to 1 nested JSON objects? I see that defining a to many relationship creates an object array however, I am trying to expose nested objects without created 1 to n relationship.
To many scenerio:
To one scenerio causes for the entire entity to flatten on itself. I need to be able to control how whether included structures are flattened or nested.
desired structure:
{
"ShipRequest": {
"Pickup":{
"Carrier":"string",
...
}
}
}<br>
Hi akloske ,
You can also model 1-to-1 relations, does that fit your use case?
https://cap.cloud.sap/docs/cds/cdl#managed-associations
In your request, you can then perform an expand on the child entity.
Best regards,
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
david.kunz2 This isn't ideal for my scenerio because I want to expose a virtual type with deep structure as an inbound API. I wanted to use the cds definitions to generate typescript definitions for mapping data (data will be normalized to another CDS model before it is peristed).
To use, the managed associations above, It looks like I'll need to convert all of my nested types into entities, assign each a primary key and expose them to to my odata service. This also causes swagger UI documentation to lose the ability to show the full structure of my API.
Do you know if it's possible to accomplish my original goal using CDS without converting all types to persistent entities and assigning primary keys to each?
I see, you can have structured types, i.e.
entity Foo {
key ID: UUID;
myStruct: {
someField: Integer;
someField2: Integer;
}
See here for more information:
https://cap.cloud.sap/docs/releases/sep20#structured-elements-in-odata-v4-for-apis
david.kunz2 Thank you for this information. Does SAP have any samples of this being implemented or more details on how to activate this feature?
I'm struggling with implementing structured types with odata flavor = "x4".
Nest a json structure into entity:
run cds.compile(csn).for.odata('x4).
metadata still flattens structures:
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<script/>
<edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.xml">
<edmx:Include Alias="Core" Namespace="Org.OData.Core.V1"/>
</edmx:Reference>
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="ShipExecService">
<EntityContainer Name="EntityContainer">
<EntitySet Name="Shipments" EntityType="ShipExecService.Shipments"/>
</EntityContainer>
<EntityType Name="Shipments">
<Key>
<PropertyRef Name="ID"/>
</Key>
<Property Name="ID" Type="Edm.Guid" Nullable="false"/>
<Property Name="type_field1" Type="Edm.String"/>
<Property Name="type_field2" Type="Edm.String"/>
</EntityType>
<Annotations Target="ShipExecService.Shipments/ID">
<Annotation Term="Core.Computed" Bool="true"/>
</Annotations>
<Annotations Target="ShipExecService.Shipments/type_field1">
<Annotation Term="Core.Computed" Bool="true"/>
</Annotations>
<Annotations Target="ShipExecService.Shipments/type_field2">
<Annotation Term="Core.Computed" Bool="true"/>
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">"); vertical-align: bottom; height: 10px;">
User | Count |
---|---|
76 | |
8 | |
8 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.