ditto icon indicating copy to clipboard operation
ditto copied to clipboard

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

Open thjaeckle opened this issue 2 years ago • 4 comments

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".

thjaeckle avatar Oct 31 '23 11:10 thjaeckle

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

sejal-bansal avatar Nov 22 '23 20:11 sejal-bansal

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

thjaeckle avatar Nov 22 '23 20:11 thjaeckle

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

thjaeckle avatar Dec 15 '23 17:12 thjaeckle

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

kulta4 avatar May 08 '24 10:05 kulta4