cancel
Showing results for 
Search instead for 
Did you mean: 

CAP / CDS Nested JSON structures

former_member743968
Participant
0 Kudos

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.

  1. @sap/cds: "5.8.0
  2. cds2types: "^2.7.2"
  3. cds-swagger-ui-express: "^0.3.0"

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>
View Entire Topic
former_member743968
Participant
0 Kudos

After some trial and error, I found a solution for my use case shown below. I'm very interested if there are other suggetions on how to accomplish this without declaring types as entities.

cds definition:

swagger-ui

metadata:

<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">
<NavigationPropertyBinding Path="type" Target="type1"/>
</EntitySet>
<EntitySet Name="type1" EntityType="ShipExecService.type1"/>
</EntityContainer>
<EntityType Name="Shipments">
<Key>
<PropertyRef Name="ID"/>
</Key>
<Property Name="ID" Type="Edm.Guid" Nullable="false"/>
<NavigationProperty Name="type" Type="ShipExecService.type1">
<OnDelete Action="Cascade"/>
</NavigationProperty>
</EntityType>
<EntityType Name="type1">
<Property Name="field1" Type="Edm.String"/>
<Property Name="field2" Type="Edm.String"/>
</EntityType>
<Annotations Target="ShipExecService.Shipments/ID">
<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;">"); vertical-align: bottom; height: 10px;">