eclipse-ditto / ditto

Eclipse Ditto™: Digital Twin framework of Eclipse IoT - main repository
https://eclipse.dev/ditto/
Eclipse Public License 2.0
679 stars 222 forks source link

Using wildcard in "put-metadata" header for PATCH / MergeThing command adds the metadata also for non-affected fields #1790

Open thjaeckle opened 11 months ago

thjaeckle commented 11 months ago

When e.g. using the following put-metadata header:

[{"key":"*/createdAt","value": "now!"}]

On a HTTP request:

PATCH /api/2/things/my:thing-1

E.g. sending the payload:

{
  "attributes": {
    "only-one": 2
  }
}

Will also lead to all existing fields in the Thing getting the metadata, e.g. as in:

{
  "_metadata": {
    "thingId": {
        "createdAt": "now!"
    },
    "policyId": {
        "createdAt": "now!"
    },
    "attributes": {
        "only-one": {
            "createdAt": "now!"
        }
    }
  }
}

That is unexpected and should instead only modify the metadata of the provided fields to "PATCH".

sejal-bansal commented 10 months ago

@thjaeckle I would like to work on this issue. Could you please assign it to me?

thjaeckle commented 10 months ago

@sejal-bansal cool, thanks This however is probably not trivial to fix, I would assume.

thjaeckle commented 10 months ago

@sejal-bansal any update here? Do you work on this or shall I unassign the issue again?

kulta4 commented 5 months ago

Hi @thjaeckle, @sejal-bansal! I tried UpdateTwinWithLiveResponse mapper, [{"key":"/updated-via","value":"device-live-response"}] in put-metadata. I am facing error "message": "The wildcard expression '//updated-via' in header 'put-metadata' is not valid.", how to fix this and I want to get the detailed implementation to achieve this in doc i have seen { "dittoHeadersForMerge": { "if-match": "", "response-required": false, "put-metadata": [ {"key":"/updated-by","value":"{{ request:subjectId }}"}, {"key":"/updated-via","value":"device-live-response"}, {"key":"/update-hint","value":"{{ header:some-custom-hint }}"}, {"key":"*/updated-at","value":"{{ time:now }}"} ] } } this much config example was there. can anyone help to do this properly