[英]When creating entity with keyValue options, Orion auto data type detection does not infer location attribute correctly
創建實體時,您可以這樣做:
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"
}'
或者沒有 options=KeyValues 參數:
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"
}
}'
在這兩種情況下,實體都是相同的。 但我沒有設法創建一個帶有 options=keyValues 參數的實體和一個具有“位置”屬性的實體:當做
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
]
}
}'
在這種情況下,來自 curl --location --request GET https://my.api/v2/entities/vehicle:WasteManagement:2' 的結果
將會
"location": {
"type": "StructuredValue",
"value": {
"type": "Point",
"coordinates": [
-3.164485592,
40.627851337
]
},
"metadata": {}
},
並且位置的類型是StructuredValue
我的期望是geo:point
或其他 geo:XXX,具體取決於 GeoJSON 的類型,它允許對實體進行地理定位並按位置過濾。
根據NGSIv2 規范部分“部分表示”:
請求中可以省略屬性/元數據
type
。 當在屬性/元數據創建或更新操作中省略時,根據值使用默認值:
- ...
- 如果 value 是 object 或數組,則使用
StructuredValue
。
在請求的情況下
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
]
}
}'
location
屬性符合 NGSIv2 規范的“當 [attribute type] 在屬性/元數據創建或更新操作中省略時” 。 此外,value 是 object,因此“如果 value 是 object 或數組,則使用StructuredValue
” 。 因此,使用StructuredValue
類型創建/更新屬性是正確的。
解決方法非常簡單:如果您需要具有特殊類型的屬性(例如 location 或DateTime
的屬性),請不要使用 keyValues 模式,而是使用規范化模式。
請注意,keyValues 模式被設計為輔助工具,而不是規范化模式的替代品。 keyValues 模式涵蓋了很大程度的規范化模式功能,但並不完全。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.