Skip to content

feat: new traits merge mechanism - #907

Merged
asyncapi-bot merged 9 commits into
asyncapi:next-major-specfrom
magicmatatjahu:next-major/new-trait-bechaviour
Jul 13, 2023
Merged

asyncapi-bot merged 9 commits into
asyncapi:next-major-specfrom
magicmatatjahu:next-major/new-trait-bechaviour

Conversation

@magicmatatjahu

@magicmatatjahu magicmatatjahu commented Feb 16, 2023 •

Copy link
Copy Markdown
Member

title: "new traits merge mechanism"


Related issue(s):
#505

Note
That PR is based on the #532 Thanks @Fannon for awesome work!

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:

messageId: userSignup
description: A longer description.
payload:
  $ref: '#/components/schemas/userSignupPayload'
traits:
  - name: UserSignup
    title: User signup
    summary: Action to sign a user up.
    description: Description from trait.
  - tags:
      - name: user
      - name: signup
      - name: register

after trait merging should be defined as:

messageId: userSignup
name: UserSignup
title: User signup
summary: Action to sign a user up.
description: A longer description. # it's still description from "main" object
payload:
  $ref: '#/components/schemas/userSignupPayload'
tags:
  - name: user
  - name: signup
  - name: register

That PR doesn't fix problems described in the PR #532, it only change the "main" trait merge mechanism, not JSON Merge Patch mechanism.

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@fmvilas fmvilas left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread spec/asyncapi.md Resolved
Comment thread spec/asyncapi.md Resolved
Comment thread spec/asyncapi.md Resolved
Comment thread spec/asyncapi.md Resolved
Comment thread spec/asyncapi.md Resolved
@jonaslagoni jonaslagoni mentioned this pull request Mar 1, 2023
@jonaslagoni

Copy link
Copy Markdown
Member

@magicmatatjahu am I to understand you champion this for version 3?

@magicmatatjahu

Copy link
Copy Markdown
Member Author

Yeah, I can champion this, but please give me a time to apply changes :)

@smoya

smoya commented Mar 27, 2023

Copy link
Copy Markdown
Member

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!

@smoya

smoya commented Mar 29, 2023

Copy link
Copy Markdown
Member

Concerning my previous comment, @magicmatatjahu do you think you will have time to work on it this week or the next one?
We are actually late on releasing parser v2, and im concerned about the spec v3 release date being compromised (June).
I know you are no longer working full-time on AsyncAPI, so I would say is completely fine if you like to drop this so any other member can pick it up.
It obviously will be amazing if you author it, but again, if you can't make it, which is normal btw, someone else could take it.

Thanks!

@magicmatatjahu

Copy link
Copy Markdown
Member Author

@smoya It should be easy to add in parser :)

Hopefully I will do it in this weekend :)

@magicmatatjahu
magicmatatjahu force-pushed the next-major/new-trait-bechaviour branch from 2ff014b to fdc93d3 Compare April 2, 2023 12:26
@github-advanced-security

Copy link
Copy Markdown

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.

@sonarqubecloud

sonarqubecloud Bot commented Apr 2, 2023

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@magicmatatjahu

magicmatatjahu commented Apr 2, 2023 •

Copy link
Copy Markdown
Member Author

@smoya PR in ParserJS asyncapi/parser-js#744 I also added review suggestions. It can be merged.

@magicmatatjahu
magicmatatjahu requested a review from fmvilas April 3, 2023 08:28
Comment thread spec/asyncapi.md Outdated

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

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

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"

Copy link
Copy Markdown

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 ;)

@magicmatatjahu magicmatatjahu Apr 17, 2023 •

Copy link
Copy Markdown
Member Author

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?

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved

@jonaslagoni

Copy link
Copy Markdown
Member

@magicmatatjahu do you need anything specific to push this forward?

Comment thread spec/asyncapi.md Resolved
Comment thread spec/asyncapi.md Outdated

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

Copy link
Copy Markdown
Contributor

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.

@magicmatatjahu

Copy link
Copy Markdown
Member Author

@jonaslagoni as discussed in DM, go forward with this PR :)

Co-authored-by: Fran Méndez <[email protected]>
fmvilas
fmvilas previously approved these changes Jun 13, 2023

@fmvilas fmvilas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@jonaslagoni

Copy link
Copy Markdown
Member

@Fannon, @smoya, @derberg, @dalelane, @char0n ping ping

Comment thread spec/asyncapi.md Resolved

@smoya smoya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀🌔

@Fannon

Fannon commented Jun 21, 2023

Copy link
Copy Markdown

Thanks for bringing this in, @magicmatatjahu !
I like that this proposal here is very simple in just avoiding the main problem by stating that the target object should never be overwritten.

Comment thread spec/asyncapi.md

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

@Fannon Fannon Jun 21, 2023 •

Copy link
Copy Markdown

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 :)

@smoya smoya Jun 30, 2023 •

Copy link
Copy Markdown
Member

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

cc @jonaslagoni @magicmatatjahu @derberg

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@smoya

smoya commented Jun 30, 2023

Copy link
Copy Markdown
Member

@fmvilas @Fannon a last review round so we can merge? 🙏

@fmvilas fmvilas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@smoya

smoya commented Jul 13, 2023

Copy link
Copy Markdown
Member

/rtm

@asyncapi-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.0.0-next-major-spec.13 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants