-
-
Notifications
You must be signed in to change notification settings - Fork 279
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
feat: new traits merge mechanism #907
feat: new traits merge mechanism #907
Conversation
Kudos, SonarCloud Quality Gate passed! |
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.
Like it but got some suggestions.
@magicmatatjahu am I to understand you champion this for version 3? |
Yeah, I can champion this, but please give me a time to apply changes :) |
Would you be able to provide an ETA? Please don't take it as me chasing but just want to know if it's gonna be a week, a month, a quarter, etc, so we can decide if it makes sense to move forward, or look for an alternative, etc. Thanks! |
Concerning my previous comment, @magicmatatjahu do you think you will have time to work on it this week or the next one? Thanks! |
@smoya It should be easy to add in parser :) Hopefully I will do it in this weekend :) |
2ff014b
to
fdc93d3
Compare
You have successfully added a new SonarCloud configuration ``. As part of the setup process, we have scanned this repository and found no existing alerts. In the future, you will see all code scanning alerts on the repository Security tab. |
Co-authored-by: Fran Méndez <[email protected]>
Kudos, SonarCloud Quality Gate passed! |
@smoya PR in ParserJS asyncapi/parser-js#744 I also added review suggestions. It can be merged. |
spec/asyncapi.md
Outdated
@@ -2627,6 +2627,31 @@ Message Payload Property | `$message.payload#/messageId` | Correlation ID is set | |||
|
|||
Runtime expressions preserve the type of the referenced value. | |||
|
|||
### <a name="traitsMergeMechanism"></a>Traits Merge Mechanism | |||
|
|||
Traits MUST be merged with the main object using the [JSON Merge Patch](https://tools.ietf.org/html/rfc7386) algorithm in the same order they are defined. A property on a trait MUST NOT override the same property on the main object. |
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.
I would be more explicit on the exception over JSON Merge Patch mechanism on not overriding properties on the target. Like mentioning it is literally an exception
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.
Additionally, I will suggest using wording from JSON Merge Patch RFC, for example calling "target" to what you called "main object"
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.
Target is good, but you need to keep in mind that the whole problem that JSON Merge patch addresses and describes is an inverse situation than merging traits ;)
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.
So how to call it?
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.
Yeah, target
sounds better to me too.
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.
Solved
@magicmatatjahu do you need anything specific to push this forward? |
spec/asyncapi.md
Outdated
@@ -2627,6 +2627,31 @@ Message Payload Property | `$message.payload#/messageId` | Correlation ID is set | |||
|
|||
Runtime expressions preserve the type of the referenced value. | |||
|
|||
### <a name="traitsMergeMechanism"></a>Traits Merge Mechanism | |||
|
|||
Traits MUST be merged with the main object using the [JSON Merge Patch](https://tools.ietf.org/html/rfc7386) algorithm in the same order they are defined. A property on a trait MUST NOT override the same property on the main object. |
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.
Yeah, target
sounds better to me too.
@jonaslagoni as discussed in DM, go forward with this PR :) |
Co-authored-by: Fran Méndez <[email protected]>
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.
🚀
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.
LGTM! 🚀🌔
Thanks for bringing this in, @magicmatatjahu ! |
@@ -2625,6 +2625,32 @@ Message Payload Property | `$message.payload#/messageId` | Correlation ID is set | |||
|
|||
Runtime expressions preserve the type of the referenced value. | |||
|
|||
### <a name="traitsMergeMechanism"></a>Traits Merge Mechanism | |||
|
|||
Traits MUST be merged with the target object using the [JSON Merge Patch](https://tools.ietf.org/html/rfc7386) algorithm in the same order they are defined. A property on a trait MUST NOT override the same property on the target object. |
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.
When implementing this, I think we need to be a bit careful here. The JSON Merge Patch is meant to overwrite the target by design. It's not just making sure that properties are not overridden, also the "null" semantics of JSON Merge Patch is then not applicable, I think.
But I like that this solution is very concise and you avoided defining your own merge algorithm.
Imho, it would be very nice to point to a reference implementation or code snippet how this is to be implemented correctly. As a Dev, I would feel more confident looking at a code example to check my understanding. I like the example, but a simple example cannot cover all the interesting corner cases :)
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.
I created a followup issue for your suggestion @Fannon asyncapi/website#1879
Kudos, SonarCloud Quality Gate passed! |
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.
LGTM 👍
/rtm |
🎉 This PR is included in version 3.0.0-next-major-spec.13 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
title: "new traits merge mechanism"
Related issue(s):
#505
That PR introduces the new traits merge mechanism. In simple words, in the current approach (in
2.x.x
) traits overwrite values defined on the main object. New approach treat main object with higher priority, so Message Object like:after trait merging should be defined as:
That PR doesn't fix problems described in the PR #532, it only change the "main" trait merge mechanism, not JSON Merge Patch mechanism.