You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Charly Coussot <ch...@univ-grenoble-alpes.fr> on 2025/01/15 14:21:19 UTC
Entity key properties are always added in $select request
Hi Olingo user,
I find that entity key properties are automatically added to $select
query. For example request like
/"http://localhost:8080/v1.1/Datastreams?$select=name/" will return
elements such as :
{
"@odata.id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
"id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
"name": "Precipitation amount at ALKAMA - Recording raingauge - LOP"
},
I'm fairly new to Odata and I'm wondering why "id" and "@odata.id"
properties are added to the response. I can't find the justification
from the spec (here
<https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptionselect>
and here
<https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid>).
Any ideas?
Best regards,
Charly
Re: Entity key properties are always added in $select request
Posted by Charly Coussot <ch...@univ-grenoble-alpes.fr>.
Hi Emma,
Thank you for pointing me the link to the Odata v4 service. I'm indeed
using Odata v4.01.
Your example requests confirm what I have noticed and it seems that
Olingo should not print the key property in the response if this one is
not included in the select query option (as per your second request).
I don't know why this feature as been but the library Json serializer
always add the key property as you can see in the following code lines
(link to the github section
<https://github.com/apache/olingo-odata4/blob/20b0d7a2c0134d00cd86ef42545bf4af9b254d32/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java#L511C1-L540C4>):
protected void writeProperties(final ServiceMetadata metadata, final
EdmStructuredType type,
final List<Property> properties,
final SelectOption select, final JsonGenerator json, Linked
linked, ExpandOption expand)
throws IOException, SerializerException, DecoderException {
final boolean all = ExpandSelectHelper.isAll(select);
final Set<String> selected = all ? new HashSet<>() :
ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems());
addKeyPropertiesToSelected(selected, type);
Set<List<String>> expandedPaths =
ExpandSelectHelper.getExpandedItemsPath(expand);
for (final String propertyName : type.getPropertyNames()) {
if (all || selected.contains(propertyName)) {
final EdmProperty edmProperty =
type.getStructuralProperty(propertyName);
final Property property = findProperty(propertyName, properties);
final Set<List<String>> selectedPaths = all ||
edmProperty.isPrimitive() ? null :
ExpandSelectHelper.getSelectedPaths(select.getSelectItems(), propertyName);
writeProperty(metadata, edmProperty, property, selectedPaths,
json, expandedPaths, linked, expand);
}
}
}
private void addKeyPropertiesToSelected(Set<String> selected,
EdmStructuredType type) {
if (!selected.isEmpty() && type instanceof EdmEntityType) {
List<String> keyNames = ((EdmEntityType)
type).getKeyPredicateNames();
for (String key : keyNames) {
if (!selected.contains(key)) {
selected.add(key);
}
}
}
}
I ended up writing my own functions to handle select query option.
Thanks for the support!
Charly
On 1/16/25 15:20, Sajic, Emma via user wrote:
> Hi Charly,
> You're welcome.
>
> I noticed the link you gave to the Odata service you're trying out is
> an OData v3 service, but the spec links you've been sending are for
> OData v4?
>
> The OData v4 reference service is TripPin and you can find info on how
> to access it here https://www.odata.org/odata-services/
> <https://www.odata.org/odata-services/>
>
> To get the metadata about the Entities in the OData v4 reference
> service and find out what their "key properties" are, make a GET
> request to https://services.odata.org/TripPinRESTierService/$metadata
> <https://services.odata.org/TripPinRESTierService/$metadata>
>
> For example, the "Airport" Entity has this metadata:
>
> <EntityType Name="Airport">
> <Key>
> <PropertyRef Name="IcaoCode"/>
> </Key>
> <Property Name="Name" Type="Edm.String"/>
> <Property Name="IcaoCode" Type="Edm.String" Nullable="false"/>
> <Property Name="IataCode" Type="Edm.String"/>
> <Property Name="Location" Type="Trippin.AirportLocation"/>
> </EntityType>
>
> Example requests:
>
> $select list includes IcaoCode key property so all key properties of
> the Airport Entity are in the $select list:
>
> curl --location --request GET --url
> 'https://services.odata.org/TripPinRESTierService/Airports?$top=1&$select=IcaoCode,Name'
> \
> --header 'Accept: application/json;odata.metadata=full'
>
> Response:
> {
> "@odata.context":
> "https://services.odata.org/TripPinRESTierService/(S(imzulymosped5v3qxz0pqr5o))/$metadata#Airports(IcaoCode,Name)",
> "value": [
> {
> "@odata.type": "#Trippin.Airport",
> "@odata.id":
> "https://services.odata.org/TripPinRESTierService/(S(imzulymosped5v3qxz0pqr5o))/Airports('KJFK')",
> "@odata.editLink":
> "https://services.odata.org/TripPinRESTierService/(S(imzulymosped5v3qxz0pqr5o))/Airports('KJFK')",
> "Name": "John F. Kennedy International Airport",
> "IcaoCode": "KJFK"
> }
> ]
> }
>
> $select list does not include IcaoCode key property so no key
> properties of the Airport Entity are in the $select list:
>
> curl --location --request GET --url
> 'https://services.odata.org/TripPinRESTierService/Airports?$top=1&$select=Name'
> \
> --header 'Accept: application/json;odata.metadata=full'
>
> {
> "@odata.context":
> "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/$metadata#Airports(Name)",
> "value": [
> {
> "@odata.type": "#Trippin.Airport",
> "@odata.id":
> "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/Airports('KJFK')",
> "@odata.editLink":
> "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/Airports('KJFK')",
> "Name": "John F. Kennedy International Airport"
> }
> ]
> }
>
> The @odata.id here gives you a URL you can use to directly get that
> individual entity (note there are double quotes on outside of url here
> to allow single quotes inside):
>
> curl --location --request GET --url
> "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/Airports('KJFK')"
> \
> --header 'Accept: application/json;odata.metadata=full'
>
> Response:
> {
> "@odata.context":
> "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/$metadata#Airports/$entity",
> "@odata.type": "#Trippin.Airport",
> "@odata.id":
> "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/Airports('KJFK')",
> "@odata.editLink":
> "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/Airports('KJFK')",
> "Name": "John F. Kennedy International Airport",
> "IcaoCode": "KJFK",
> "IataCode": "JFK",
> "Location": {
> "@odata.type": "#Trippin.AirportLocation",
> "Address": "Jamaica, New York, NY 11430",
> "Loc@odata.type": "#GeographyPoint",
> "Loc": {
> "type": "Point",
> "coordinates": [
> -73.7788888888889,
> 40.6397222222222
> ],
> "crs": {
> "type": "name",
> "properties": {
> "name": "EPSG:4326"
> }
> }
> },
> "City": {
> "@odata.type": "#Trippin.City",
> "Name": "New York City",
> "CountryRegion": "United States",
> "Region": "New York"
> }
> }
> }
>
> Thanks,
>
> Emma Sajic
> ------------------------------------------------------------------------
> *From:* Charly Coussot <ch...@univ-grenoble-alpes.fr>
> *Sent:* 15 January 2025 22:45
> *To:* user@olingo.apache.org <us...@olingo.apache.org>
> *Subject:* Re: Entity key properties are always added in $select request
>
>
> You don't often get email from charly.coussot@univ-grenoble-alpes.fr.
> Learn why this is important
> <https://aka.ms/LearnAboutSenderIdentification>
>
>
> Hi Emma,
>
>
> Thanks for your answer and the pieces of information that help me to
> clarify things.
>
>
> I understand that the key property is needed to address the individual
> entity and that this information must somehow be accessible. But the
> sentence from the 4.5.8 Control Information: id (odata.id) paragraph
> <https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid>
> mentions "the id control information" (i.e. odata.id) while, in my
> example, Olingo also add the "id" property.
>
> To illustrate, requesting the same url with "metadata=none" returns:
>
>
> {
> "id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
> "name": "Precipitation amount at ALKAMA - Recording raingauge - LOP"
> }
>
>
> I found that a similar request on a odata.org example endpoint behave
> differently (without adding "ID" property to the
>
> response which is what I expected) :
> https://services.odata.org/V3/OData/OData.svc/Products?$select=Name
> <https://services.odata.org/V3/OData/OData.svc/Products?$select=Name>
>
>
> Thanks for your help.
>
>
> Charly
>
>
>
> On 1/15/25 19:27, Sajic, Emma via user wrote:
>> Hi Charly,
>>
>> In the second link you posted to the spec here
>> <https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid> 4.5.8
>> Control Information: id (odata.id) it mentions that:
>>
>> "The id control information MUST appear in responses if metadata=full
>> <https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_metadatafullodatametadatafull> is
>> requested, or if metadata=minimal
>> <https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_metadataminimalodatametadataminimal>
>> is requested and any of a non-transient entity's key fields are
>> omitted from the response"
>>
>> If your request has a $select list of fields to return, and that list
>> doesn't include the field(s) in your OData entity's key, then the
>> OData server must still somehow return the key field(s) (OData term
>> for the key fields is "key properties") in the response. This is
>> because the "key properties" uniquely identify the entity (like a
>> primary key on a database record) and are mandatory to "address an
>> entity", in other words, be able to make a request to get that
>> individual entity.
>>
>> In my experience, Olingo handles this automatically during
>> serializing the response to a $select request as long as the "key
>> properties" are populated on the entities being serialized. (I'm not
>> an Olingo expert, just a user of Olingo).
>>
>> So, if you are using Olingo to develop an OData server, when handling
>> a $select request, you need to make sure your entities have all their
>> "key properties" populated before passing them to the Olingo response
>> serializer.
>>
>> Also see section 4.3 Addressing Entities
>> <https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_AddressingEntities> in
>> the URL conventions spec and also section 3 Data Model
>> <https://docs.oasis-open.org/odata/odata/v4.01/os/part1-protocol/odata-v4.01-os-part1-protocol.html#sec_DataModel> in
>> the Protocol spec for more information about the key on the OData entity.
>>
>> Hope this helps,
>> Thanks,
>> Emma Sajic
>> ------------------------------------------------------------------------
>> *From:* Charly Coussot <ch...@univ-grenoble-alpes.fr>
>> <ma...@univ-grenoble-alpes.fr>
>> *Sent:* 15 January 2025 14:21
>> *To:* user@olingo.apache.org <ma...@olingo.apache.org>
>> <us...@olingo.apache.org> <ma...@olingo.apache.org>
>> *Subject:* Entity key properties are always added in $select request
>>
>>
>> You don't often get email from charly.coussot@univ-grenoble-alpes.fr
>> <ma...@univ-grenoble-alpes.fr>. Learn why this is
>> important <https://aka.ms/LearnAboutSenderIdentification>
>>
>>
>> Hi Olingo user,
>>
>> I find that entity key properties are automatically added to $select
>> query. For example request like
>> /"http://localhost:8080/v1.1/Datastreams?$select=name
>> <http://localhost:8080/v1.1/Datastreams?$select=name>/" will return
>> elements such as :
>> {
>> "@odata.id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
>> "id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
>> "name": "Precipitation amount at ALKAMA - Recording raingauge - LOP"
>> },
>>
>> I'm fairly new to Odata and I'm wondering why "id" and "@odata.id"
>> properties are added to the response. I can't find the justification
>> from the spec (here
>> <https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptionselect>
>> and here
>> <https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid>).
>>
>> Any ideas?
>>
>> Best regards,
>>
>> Charly
Re: Entity key properties are always added in $select request
Posted by "Sajic, Emma via user" <us...@olingo.apache.org>.
Hi Charly,
You're welcome.
I noticed the link you gave to the Odata service you're trying out is an OData v3 service, but the spec links you've been sending are for OData v4?
The OData v4 reference service is TripPin and you can find info on how to access it here https://www.odata.org/odata-services/
To get the metadata about the Entities in the OData v4 reference service and find out what their "key properties" are, make a GET request to https://services.odata.org/TripPinRESTierService/$metadata
For example, the "Airport" Entity has this metadata:
<EntityType Name="Airport">
<Key>
<PropertyRef Name="IcaoCode"/>
</Key>
<Property Name="Name" Type="Edm.String"/>
<Property Name="IcaoCode" Type="Edm.String" Nullable="false"/>
<Property Name="IataCode" Type="Edm.String"/>
<Property Name="Location" Type="Trippin.AirportLocation"/>
</EntityType>
Example requests:
$select list includes IcaoCode key property so all key properties of the Airport Entity are in the $select list:
curl --location --request GET --url 'https://services.odata.org/TripPinRESTierService/Airports?$top=1&$select=IcaoCode,Name' \
--header 'Accept: application/json;odata.metadata=full'
Response:
{
"@odata.context": "https://services.odata.org/TripPinRESTierService/(S(imzulymosped5v3qxz0pqr5o))/$metadata#Airports(IcaoCode,Name)",
"value": [
{
"@odata.type": "#Trippin.Airport",
"@odata.id": "https://services.odata.org/TripPinRESTierService/(S(imzulymosped5v3qxz0pqr5o))/Airports('KJFK')",
"@odata.editLink": "https://services.odata.org/TripPinRESTierService/(S(imzulymosped5v3qxz0pqr5o))/Airports('KJFK')",
"Name": "John F. Kennedy International Airport",
"IcaoCode": "KJFK"
}
]
}
$select list does not include IcaoCode key property so no key properties of the Airport Entity are in the $select list:
curl --location --request GET --url 'https://services.odata.org/TripPinRESTierService/Airports?$top=1&$select=Name' \
--header 'Accept: application/json;odata.metadata=full'
{
"@odata.context": "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/$metadata#Airports(Name)",
"value": [
{
"@odata.type": "#Trippin.Airport",
"@odata.id": "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/Airports('KJFK')",
"@odata.editLink": "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/Airports('KJFK')",
"Name": "John F. Kennedy International Airport"
}
]
}
The @odata.id here gives you a URL you can use to directly get that individual entity (note there are double quotes on outside of url here to allow single quotes inside):
curl --location --request GET --url "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/Airports('KJFK')" \
--header 'Accept: application/json;odata.metadata=full'
Response:
{
"@odata.context": "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/$metadata#Airports/$entity",
"@odata.type": "#Trippin.Airport",
"@odata.id": "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/Airports('KJFK')",
"@odata.editLink": "https://services.odata.org/TripPinRESTierService/(S(fc5wnrwjy5dgfus5rkyrxkmh))/Airports('KJFK')",
"Name": "John F. Kennedy International Airport",
"IcaoCode": "KJFK",
"IataCode": "JFK",
"Location": {
"@odata.type": "#Trippin.AirportLocation",
"Address": "Jamaica, New York, NY 11430",
"Loc@odata.type": "#GeographyPoint",
"Loc": {
"type": "Point",
"coordinates": [
-73.7788888888889,
40.6397222222222
],
"crs": {
"type": "name",
"properties": {
"name": "EPSG:4326"
}
}
},
"City": {
"@odata.type": "#Trippin.City",
"Name": "New York City",
"CountryRegion": "United States",
"Region": "New York"
}
}
}
Thanks,
Emma Sajic
________________________________
From: Charly Coussot <ch...@univ-grenoble-alpes.fr>
Sent: 15 January 2025 22:45
To: user@olingo.apache.org <us...@olingo.apache.org>
Subject: Re: Entity key properties are always added in $select request
You don't often get email from charly.coussot@univ-grenoble-alpes.fr. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
Hi Emma,
Thanks for your answer and the pieces of information that help me to clarify things.
I understand that the key property is needed to address the individual entity and that this information must somehow be accessible. But the sentence from the 4.5.8 Control Information: id (odata.id) paragraph<https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid> mentions "the id control information" (i.e. odata.id) while, in my example, Olingo also add the "id" property.
To illustrate, requesting the same url with "metadata=none" returns:
{
"id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
"name": "Precipitation amount at ALKAMA - Recording raingauge - LOP"
}
I found that a similar request on a odata.org example endpoint behave differently (without adding "ID" property to the
response which is what I expected) : https://services.odata.org/V3/OData/OData.svc/Products?$select=Name
Thanks for your help.
Charly
On 1/15/25 19:27, Sajic, Emma via user wrote:
Hi Charly,
In the second link you posted to the spec here<https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid> 4.5.8 Control Information: id (odata.id) it mentions that:
"The id control information MUST appear in responses if metadata=full<https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_metadatafullodatametadatafull> is requested, or if metadata=minimal<https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_metadataminimalodatametadataminimal> is requested and any of a non-transient entity's key fields are omitted from the response"
If your request has a $select list of fields to return, and that list doesn't include the field(s) in your OData entity's key, then the OData server must still somehow return the key field(s) (OData term for the key fields is "key properties") in the response. This is because the "key properties" uniquely identify the entity (like a primary key on a database record) and are mandatory to "address an entity", in other words, be able to make a request to get that individual entity.
In my experience, Olingo handles this automatically during serializing the response to a $select request as long as the "key properties" are populated on the entities being serialized. (I'm not an Olingo expert, just a user of Olingo).
So, if you are using Olingo to develop an OData server, when handling a $select request, you need to make sure your entities have all their "key properties" populated before passing them to the Olingo response serializer.
Also see section 4.3 Addressing Entities<https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_AddressingEntities> in the URL conventions spec and also section 3 Data Model<https://docs.oasis-open.org/odata/odata/v4.01/os/part1-protocol/odata-v4.01-os-part1-protocol.html#sec_DataModel> in the Protocol spec for more information about the key on the OData entity.
Hope this helps,
Thanks,
Emma Sajic
________________________________
From: Charly Coussot <ch...@univ-grenoble-alpes.fr>
Sent: 15 January 2025 14:21
To: user@olingo.apache.org<ma...@olingo.apache.org> <us...@olingo.apache.org>
Subject: Entity key properties are always added in $select request
You don't often get email from charly.coussot@univ-grenoble-alpes.fr<ma...@univ-grenoble-alpes.fr>. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
Hi Olingo user,
I find that entity key properties are automatically added to $select query. For example request like "http://localhost:8080/v1.1/Datastreams?$select=name" will return elements such as :
{
"@odata.id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
"id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
"name": "Precipitation amount at ALKAMA - Recording raingauge - LOP"
},
I'm fairly new to Odata and I'm wondering why "id" and "@odata.id" properties are added to the response. I can't find the justification from the spec (here<https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptionselect> and here<https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid>).
Any ideas?
Best regards,
Charly
Re: Entity key properties are always added in $select request
Posted by Charly Coussot <ch...@univ-grenoble-alpes.fr>.
Hi Emma,
Thanks for your answer and the pieces of information that help me to
clarify things.
I understand that the key property is needed to address the individual
entity and that this information must somehow be accessible. But the
sentence from the 4.5.8 Control Information: id (odata.id) paragraph
<https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid>
mentions "the id control information" (i.e. odata.id) while, in my
example, Olingo also add the "id" property.
To illustrate, requesting the same url with "metadata=none" returns:
{
"id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
"name": "Precipitation amount at ALKAMA - Recording raingauge - LOP"
}
I found that a similar request on a odata.org example endpoint behave
differently (without adding "ID" property to the
response which is what I expected) :
https://services.odata.org/V3/OData/OData.svc/Products?$select=Name
<https://services.odata.org/V3/OData/OData.svc/Products?$select=Name>
Thanks for your help.
Charly
On 1/15/25 19:27, Sajic, Emma via user wrote:
> Hi Charly,
>
> In the second link you posted to the spec here
> <https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid> 4.5.8
> Control Information: id (odata.id) it mentions that:
>
> "The id control information MUST appear in responses if metadata=full
> <https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_metadatafullodatametadatafull> is
> requested, or if metadata=minimal
> <https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_metadataminimalodatametadataminimal>
> is requested and any of a non-transient entity's key fields are
> omitted from the response"
>
> If your request has a $select list of fields to return, and that list
> doesn't include the field(s) in your OData entity's key, then the
> OData server must still somehow return the key field(s) (OData term
> for the key fields is "key properties") in the response. This is
> because the "key properties" uniquely identify the entity (like a
> primary key on a database record) and are mandatory to "address an
> entity", in other words, be able to make a request to get that
> individual entity.
>
> In my experience, Olingo handles this automatically during serializing
> the response to a $select request as long as the "key properties" are
> populated on the entities being serialized. (I'm not an Olingo expert,
> just a user of Olingo).
>
> So, if you are using Olingo to develop an OData server, when handling
> a $select request, you need to make sure your entities have all their
> "key properties" populated before passing them to the Olingo response
> serializer.
>
> Also see section 4.3 Addressing Entities
> <https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_AddressingEntities> in
> the URL conventions spec and also section 3 Data Model
> <https://docs.oasis-open.org/odata/odata/v4.01/os/part1-protocol/odata-v4.01-os-part1-protocol.html#sec_DataModel> in
> the Protocol spec for more information about the key on the OData entity.
>
> Hope this helps,
> Thanks,
> Emma Sajic
> ------------------------------------------------------------------------
> *From:* Charly Coussot <ch...@univ-grenoble-alpes.fr>
> *Sent:* 15 January 2025 14:21
> *To:* user@olingo.apache.org <us...@olingo.apache.org>
> *Subject:* Entity key properties are always added in $select request
>
>
> You don't often get email from charly.coussot@univ-grenoble-alpes.fr.
> Learn why this is important
> <https://aka.ms/LearnAboutSenderIdentification>
>
>
> Hi Olingo user,
>
> I find that entity key properties are automatically added to $select
> query. For example request like
> /"http://localhost:8080/v1.1/Datastreams?$select=name
> <http://localhost:8080/v1.1/Datastreams?$select=name>/" will return
> elements such as :
> {
> "@odata.id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
> "id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
> "name": "Precipitation amount at ALKAMA - Recording raingauge - LOP"
> },
>
> I'm fairly new to Odata and I'm wondering why "id" and "@odata.id"
> properties are added to the response. I can't find the justification
> from the spec (here
> <https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptionselect>
> and here
> <https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid>).
>
> Any ideas?
>
> Best regards,
>
> Charly
Re: Entity key properties are always added in $select request
Posted by "Sajic, Emma via user" <us...@olingo.apache.org>.
Hi Charly,
In the second link you posted to the spec here<https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid> 4.5.8 Control Information: id (odata.id) it mentions that:
"The id control information MUST appear in responses if metadata=full<https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_metadatafullodatametadatafull> is requested, or if metadata=minimal<https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_metadataminimalodatametadataminimal> is requested and any of a non-transient entity's key fields are omitted from the response"
If your request has a $select list of fields to return, and that list doesn't include the field(s) in your OData entity's key, then the OData server must still somehow return the key field(s) (OData term for the key fields is "key properties") in the response. This is because the "key properties" uniquely identify the entity (like a primary key on a database record) and are mandatory to "address an entity", in other words, be able to make a request to get that individual entity.
In my experience, Olingo handles this automatically during serializing the response to a $select request as long as the "key properties" are populated on the entities being serialized. (I'm not an Olingo expert, just a user of Olingo).
So, if you are using Olingo to develop an OData server, when handling a $select request, you need to make sure your entities have all their "key properties" populated before passing them to the Olingo response serializer.
Also see section 4.3 Addressing Entities<https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_AddressingEntities> in the URL conventions spec and also section 3 Data Model<https://docs.oasis-open.org/odata/odata/v4.01/os/part1-protocol/odata-v4.01-os-part1-protocol.html#sec_DataModel> in the Protocol spec for more information about the key on the OData entity.
Hope this helps,
Thanks,
Emma Sajic
________________________________
From: Charly Coussot <ch...@univ-grenoble-alpes.fr>
Sent: 15 January 2025 14:21
To: user@olingo.apache.org <us...@olingo.apache.org>
Subject: Entity key properties are always added in $select request
You don't often get email from charly.coussot@univ-grenoble-alpes.fr. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
Hi Olingo user,
I find that entity key properties are automatically added to $select query. For example request like "http://localhost:8080/v1.1/Datastreams?$select=name" will return elements such as :
{
"@odata.id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
"id": "CATC_100a8022-525f-336c-811c-3146ed5bf30a",
"name": "Precipitation amount at ALKAMA - Recording raingauge - LOP"
},
I'm fairly new to Odata and I'm wondering why "id" and "@odata.id" properties are added to the response. I can't find the justification from the spec (here<https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptionselect> and here<https://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationidodataid>).
Any ideas?
Best regards,
Charly