2
votes

When creating an entity you could do it like this :

curl --location --request POST 'https://my.api/v2/entities/?options=keyValues' --header 'Content-Type: application/json' --data-raw '{
   "id":"vehicle:WasteManagement:1",
   "type":"WasteManagement",
   "vehicleType":"lorry"
}'

Or without the options=KeyValues parameter :

curl --location --request POST 'https://my.api/v2/entities/' --header 'Content-Type: application/json' --data-raw '{
   "id":"vehicle:WasteManagement:2",
   "type":"WasteManagement",
   "vehicleType":{
        "value": "lorry"
    }
}'

And in both case the entity is the same. But I don't manage to create an entity with a options=keyValues parameter with an entity that has a 'location' attribute : when doing

curl --location --request POST 'https://my.api/v2/entities/' --header 'Content-Type: application/json' --data-raw '{
   "id":"vehicle:WasteManagement:3",
   "type":"WasteManagement",
   "vehicleType":"lorry",
    "location": {
        "type": "Point",
        "coordinates": [
            -0.56832066,
            47.49576
        ]
    }
}'

In this case, the result from curl --location --request GET https://my.api/v2/entities/vehicle:WasteManagement:2'

Would be

"location": {
    "type": "StructuredValue",
    "value": {
        "type": "Point",
        "coordinates": [
            -3.164485592,
            40.627851337
        ]
    },
    "metadata": {}
},

And the type of location is StructuredValue

My expectation would be geo:point or other geo:XXX depending of the type of the GeoJSON which allow the entity to be geolocalized and filter by location.

1
It seems third culr has a typo. It should include ?options=keyValues. Otherwise Orion returns: {"error":"BadRequest","description":"attribute must be a JSON object, unless keyValues option is used"}. I'd recommend to edit the question post to fix it.fgalan

1 Answers

0
votes

According to the NGSIv2 specification section "Partial Representations":

Attribute/metadata type may be omitted in requests. When omitted in attribute/metadata creation or in update operations, a default is used for the type depending on the value:

  • ...
  • If value is an object or array, then StructuredValue is used.

In the case of request

curl --location --request POST 'https://my.api/v2/entities/?options=keyValue' --header 'Content-Type: application/json' --data-raw '{
   "id":"vehicle:WasteManagement:3",
   "type":"WasteManagement",
   "vehicleType":"lorry",
    "location": {
        "type": "Point",
        "coordinates": [
            -0.56832066,
            47.49576
        ]
    }
}'

the location attribute fulfills with the "when [attribute type] omitted in attribute/metadata creation or in update operations" of the NGSIv2 spec. In addition, value is an object so "If value is an object or array, then StructuredValue is used" applys. Thus, it is correct that the attribute is created/updated with type StructuredValue.

The workaround is pretty easy: don't use the keyValues mode if you need attributes with a special type (as the ones for a location or DateTime) and use the normalized mode instead.

Note that the keyValues mode has been designed as a helper not as a replacement of the normalized mode. The keyValues mode covers a great degree of the normalized mode functionality, but not fully.