-
Notifications
You must be signed in to change notification settings - Fork 576
Helper method to merge additional metadata into requests, results, and notifications #1030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,4 +21,21 @@ private protected NotificationParams() | |
| /// </remarks> | ||
| [JsonPropertyName("_meta")] | ||
| public JsonObject? Meta { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Merges additional metadata into the existing Meta object. | ||
| /// </summary> | ||
| /// <param name="additionalMeta">The additional metadata to merge.</param> | ||
| public void MergeMeta(JsonObject additionalMeta) | ||
| { | ||
| if (Meta == null) | ||
| { | ||
| Meta = new JsonObject(); | ||
| } | ||
|
|
||
| foreach (var kvp in additionalMeta) | ||
| { | ||
| Meta[kvp.Key] = kvp.Value; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we put this logic into an internal shared method? Also, do we want to do a deep merge? For example, // Left
"_meta": {
"a": {
"b": {}
}
}
// Right
"_meta": {
"a": {
"c": {}
}
}
// Deep Merge
"_meta": {
"a": {
"b": {}
"c": {}
}
}With the current shallow merge, the right JsonObject would completely overwrite the left one. This might be the best behavior if we don't think it makes sense for multiple components to configure the same top-level _meta keys, but we should at least clarify this is a shallow merge in the doc comments. |
||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're needing to duplicate this method into each place that has Meta. We're also baking in the overwrite semantics of the additionalMeta always winning, as opposed to an existing value winning. If this is common enough to need a helper for, should we instead expose a static merge method?
@eiriktsarpalis, are we missing something here in STJ? What do you think we should do?