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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lsmacedo
Copy link

@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 1062ef0
🔍 Latest deploy log https://app.netlify.com/sites/modelina/deploys/6776fa0e0d5b8a000885dccc

Comment on lines +178 to +180
if (obj[\\"primitiveArrayTest\\"] !== undefined) {
instance.primitiveArrayTest = obj[\\"primitiveArrayTest\\"];
}
Copy link
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.

Copy link

sonarqubecloud bot commented Jan 2, 2025

@@ -162,13 +175,16 @@ exports[`Marshalling preset should render un/marshal code 1`] = `
? null
: obj[\\"arrayTest\\"].map((item: any) => NestedTest.unmarshal(item));
}
Copy link
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant