Skip to content
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

fix: preventing unmarshal on primitive types #2144

Merged

Conversation

lsmacedo
Copy link
Contributor

@lsmacedo lsmacedo commented Jan 2, 2025

Description

There's currently a bug on 3.10.0 where calls to unmarshal are made on arrays of primitive type. Here's an example of the generated code:

image

This PR prevents the issue by adding new checks.

Related Issue

N/A

Checklist

  • The code follows the project's coding standards and is properly linted (npm run lint).
  • Tests have been added or updated to cover the changes.
  • Documentation has been updated to reflect the changes.
  • All tests pass successfully locally.(npm run test).

Additional Notes

By the way, noticed that version 4.0.0 doesn't include unmarshalling array items, and that might be an issue (at least for my use cases). Just letting you know so you can keep track of this, in case it's not expected.

@lsmacedo lsmacedo requested a review from Samridhi-98 as a code owner January 2, 2025 20:41
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

Copy link

netlify bot commented Jan 2, 2025

Deploy Preview for modelina canceled.

Name Link
🔨 Latest commit 0bc8502
🔍 Latest deploy log https://app.netlify.com/sites/modelina/deploys/679394351e7dbd00081e5cbc

Comment on lines +178 to +180
if (obj[\\"primitiveArrayTest\\"] !== undefined) {
instance.primitiveArrayTest = obj[\\"primitiveArrayTest\\"];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's evidence that the code doesn't try to call unmarshal anymore for the array of primitive items.

@@ -162,13 +175,16 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
? null
: obj[\\"arrayTest\\"].map((item: any) => NestedTest.unmarshal(item));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's evidence that for an array of objects, unmarshal is still called.

@lsmacedo lsmacedo changed the title fix: preventing unmarshall on primitive types fix: preventing unmarshal on primitive types Jan 2, 2025
@jonaslagoni
Copy link
Member

/rtm

@coveralls
Copy link

Pull Request Test Coverage Report for Build 12950503043

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 92.321%

Totals Coverage Status
Change from base Build 12950496189: 0.002%
Covered Lines: 6004
Relevant Lines: 6335

💛 - Coveralls

@jonaslagoni jonaslagoni merged commit e101bb6 into asyncapi:master Jan 24, 2025
17 of 18 checks passed
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 3.10.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants