问题
What is the difference between attributes id and uri within _metadata node of a OData request/response? All request/response sent by UI5 app contain those both attributes which are every time equal. Isn't this an unwanted redundancy? Is there any configuration in the gateway server which corresponds to those attributes? I would expect here only one attribute containing key which relates service part only i.e. SERVICE_ID/Entity_Name/keys
I'm currently working with version 1.71
let oDataResponse = {
"d": {
"__metadata": {
"id": "https://domain:port/sap/opu/odata/sap/SERVICE_ID/HeaderSet('000001234567890')",
"uri": "https://domain:port/sap/opu/odata/sap/SERVICE_ID/HeaderSet('000001234567890')",
"type": "SERVICE_ID.Header"
},
"FIELD_1": "abc",
"FIELD_2": "abc",
"FIELD_N": "abc"
}
};
回答1:
The ID can be a relative url, and can be null in case of a transient request. Furthermore, it can vary from the url in several other cases, see the odata documentation:
The id control information contains the entity-id, see [OData-Protocol]. By convention the entity-id is identical to the canonical URL of the entity, as defined in [OData-URL].
The id control information MUST appear in responses if metadata=full is requested, or if metadata=minimal is requested and any of a non-transient entity's key fields are omitted from the response or the entity-id is not identical to the canonical URL of the entity after
· IRI-to-URI conversion as defined in [RFC3987],
· relative resolution as defined in section 5.2 of [RFC3986], and
· percent-encoding normalization as defined in section 6 of [RFC3986].
Note that the entity-id MUST be invariant across languages, so if key values are language dependent then the id MUST be included if it does not match convention for the localized key values. If the id is represented, it MAY be a relative URL.
If the entity is transient (i.e. cannot be read or updated), the id control information MUST appear in OData 4.0 payloads and have the null value. In 4.01 payloads transient entities need not have the id control information, and 4.01 clients MUST treat entities with neither id control information nor a full set of key properties as transient entities.
The id control information MUST NOT appear for a collection. Its meaning in this context is reserved for future versions of this specification.
Entities with id equal to null cannot be compared to other entities, reread, or updated. If metadata=minimal is specified and the id is not present in the entity, then the canonical URL MUST be used as the entity-id.
来源:https://stackoverflow.com/questions/59837206/difference-between-attributes-id-and-uri-within-metadata-node-of-a-odata-reques