Skip to Content
avatar image
Former Member

Expand on mock data, where does the JSON go?

I'm trying to mock some data based on existing and working oData models. The Mock Server works, but I am struggling making the $expand to do it's job. I think it's mostly a matter of me not understanding where or how to store the JSON.

The metadata file is copied verbatim from the working service and contains all entities, entitysets, associations etcetera.

Here are some of the relevant bits. From Users entity:

<NavigationProperty Name="Dealers" Relationship="Y_DP_CORE_SRV.User_Dealer" FromRole="FromRole_User_Dealer" ToRole="ToRole_User_Dealer" />

The association:

<Association Name="User_Dealer" sap:content-version="1">
  <End Type="Y_DP_CORE_SRV.User" Multiplicity="1" Role="FromRole_User_Dealer" />
  <End Type="Y_DP_CORE_SRV.Dealer" Multiplicity="*" Role="ToRole_User_Dealer" />
  <ReferentialConstraint>
    <Principal Role="FromRole_User_Dealer">
      <PropertyRef Name="Id" />
    </Principal>
    <Dependent Role="ToRole_User_Dealer">
      <PropertyRef Name="Id" />
    </Dependent>
  </ReferentialConstraint>
</Association>

I can get Users('PRX-00015'). I cannot get Users('PRX-00015')/Dealers or Users('PRX-00015')?$expand=Dealers. There are no errors, but also no data.

Here's Users.JSON:

[{
    "__metadata": {
        "id": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Users('PRX-00015')",
        "uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Users('PRX-00015')",
        "type": "Y_DP_CORE_SRV.User"
    },
    "Id": "PRX-00015",
    "FullName": "Jorg",
    "Email": "",
    "Telephone": "",
    "InternalUser": false,
    "Enabled": true,
    "Dealers": {
        "results": [{
            "__metadata": {
                "id": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA2002')",
                "uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA2002')",
                "type": "Y_DP_CORE_SRV.Dealer"
            },
            "Id": "AA2002"
        }, {
            "__metadata": {
                "id": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA1046')",
                "uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA1046')",
                "type": "Y_DP_CORE_SRV.Dealer"
            },
            "Id": "AA1046"
        }]
    },
}]

I can also use the unexpanded version of Dealers and move the array into a Dealers.json file of it's own, in which case the line looks like

"Dealers": {
    "__deferred": {
        "uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Users('PRX-00015')/Dealers"
    }
}

And Dealers.json

[{
    "__metadata": {
        "id": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA2002')",
        "uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA2002')",
        "type": "Y_DP_CORE_SRV.Dealer"
    },
    "Id": "AA2002"
}, {
    "__metadata": {
        "id": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA1046')",
        "uri": "http://localhost/sap/opu/odata/sap/Y_DP_CORE_SRV/Dealers('AA1046')",
        "type": "Y_DP_CORE_SRV.Dealer"
    },
    "Id": "AA1046"
}]

All of these result in an empty Dealers array (Dealers.length being 0). Anyone know how this works?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Apr 12, 2017 at 02:07 PM

    Hello there,

    Still need help with this? I have some inputs and some questions.

    First, your meta data looks fine and contains the referential constraints needed for the mockserver to navigate between entities. Meaning your Jsons can be much simpler than what you currently have.

    The JSON file must have the same entity name as the metadata. So, Users.JSON and Dealers.JSON.
    And both can be like the following:

    [
      {
       "ID": "0001"
    
      },
    ]
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 12, 2017 at 02:07 PM

    Hello there,

    Still need help with this? I have some inputs and some questions.

    First, your meta data looks fine and contains the referential constraints needed for the mockserver to navigate between entities. Meaning your Jsons can be much simpler than what you currently have.

    The JSON file must have the same entity name as the metadata. So, Users.JSON and Dealers.JSON.
    And both can be like the following:

    //Users.JSON
    [
      {
       "ID": "0001"
      ...
      },
      {
       "ID": "0002"
      ...
      }
    ]
    
    
    //Dealers.JSON
    
    [
      {
       "ID": "0001"
      ...
      },
      {
       "ID": "0002"
      ...
      }
    ]
    
    

    Thanks to the navigation properties and the referential constraints the mockserver is able to correctly navigate your entities.

    However, I´m missing the binding paths of your applications. Does your application work without mockdata?

    Add comment
    10|10000 characters needed characters exceeded