-
-
Notifications
You must be signed in to change notification settings - Fork 368
fix: correctly detect default values including false in template parameters #1769
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: correctly detect default values including false in template parameters #1769
Conversation
🦋 Changeset detectedLatest commit: 769253c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
What reviewer looks at during PR reviewThe following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.
|
📝 WalkthroughWalkthroughReplaced a truthy check with Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Note: After fixing this and changing the value from the string "false" to the boolean false, the CSS/JS will generate correctly🫡 By using |
|
@lightning-sagar I reviewed the changes you made. Using: We avoid using obj.hasOwnProperty() directly because it can throw errors if the object does not inherit from Object.prototype. So to Avoid crashing and error we can use explicit version of js something like
|
|
yes, that makes sense. your solution is definitely more robust. update: I switched to |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/generator/lib/templates/config/loader.js (1)
48-56: Default detection fix looks correct; consider small cleanup andObject.hasOwnif supportedThe switch to
Object.prototype.hasOwnProperty.call(parameters[key], "default")correctly treats any explicitly declareddefault(includingfalse,0,'',null,undefined) as a default and fixes the originalfalse-is-ignored bug. 👍Two small, optional refinements:
- Normalize
parametersonce to avoid repeating|| {}and slightly tighten the types:function loadDefaultValues(templateConfig, templateParams) { - const parameters = templateConfig.parameters; - const defaultValues = Object.keys(parameters || {}).filter(key => Object.prototype.hasOwnProperty.call(parameters[key],"default")); + const parameters = templateConfig.parameters || {}; + const defaultValues = Object.keys(parameters).filter(key => + Object.prototype.hasOwnProperty.call(parameters[key], 'default') + );
- If your minimum Node/JS runtime supports it and you want to satisfy Sonar, you can switch to
Object.hasOwnin both places:- const defaultValues = Object.keys(parameters).filter(key => - Object.prototype.hasOwnProperty.call(parameters[key], 'default') - ); + const defaultValues = Object.keys(parameters).filter(key => + Object.hasOwn(parameters[key], 'default') + ); - defaultValues.filter(dv => !Object.prototype.hasOwnProperty.call(templateParams, dv)).forEach(dv => + defaultValues.filter(dv => !Object.hasOwn(templateParams, dv)).forEach(dv => Object.defineProperty(templateParams, dv, { enumerable: true, get() { return parameters[dv].default; } }) );Please double‑check that
Object.hasOwnis available in all Node versions you support before adopting this; otherwise the current implementation is fine and you may just want to tune the static‑analysis rule instead.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/generator/lib/templates/config/loader.js(1 hunks)
🧰 Additional context used
🪛 GitHub Check: SonarCloud Code Analysis
apps/generator/lib/templates/config/loader.js
[warning] 49-49: Use 'Object.hasOwn()' instead of 'Object.prototype.hasOwnProperty.call()'.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Test generator as dependency with Node 20
- GitHub Check: Acceptance tests for generated templates
- GitHub Check: Test generator as dependency with Node 18
- GitHub Check: Test NodeJS PR - macos-latest
- GitHub Check: Test NodeJS PR - windows-latest
- GitHub Check: Test NodeJS PR - ubuntu-latest
Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
…S` websocket client (asyncapi#1747) Co-authored-by: Adi-204 <adiboghawala@gmail.com> Co-authored-by: Adi Boghawala <adiboghawala@192.168.1.5> Co-authored-by: Chan <bot+chan@asyncapi.io> Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
…i#1753) Co-authored-by: kartikayy007 <kartikayy6969@gmail.com> Co-authored-by: Adi Boghawala <adiboghawala@gmail.com> Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
…, null, and empty string
a45bc1f to
4046fa5
Compare
derberg
left a comment
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.
@lightning-sagar change is good. Ignore rabbit.
most important is how did you test that it works? solves the html-template error?
did you do some manual testing?
after v5 release we have dedicated node ./test/cli option to run generator test cli locally from local sources against any template, you can also point to template in your local drive
|
Hi @derberg, sorry for the late response... I was testing this manually in two ways:
this confirmed the generator fix works (the default so, there are two possible solution:
let me know which approach should i move forward with? |
|
did you check it with you'd have to verify with docs, and afaik we explain that whatever you pass through CLI, no matter what CLI - it is always |
|
@derberg, yes you are right and I did test this using when the issue only appears when so the flow is:
I agree the generator should not cast values coming from CLI, as that would be a breaking change.... that why we need to update the |
|
ok, then, imho we need to change the default to string: https://github.com/lightning-sagar/html-template/blob/test/template-params/package.json#L93C23-L93C25 please in this PR also explain that if someone uses |
|
we have asyncapi/html-template#757 that we can already use |
|
🚀 Docs preview deployed |
yes, that was exactly my main idea as well.. |
derberg
left a comment
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
@lightning-sagar we can release it, please add changeset. In dev guide there is explanation of release process. We're only releasing @asyncapi/generator.
@Florence-Njeri please look at added docs
|
|
/rtm |




Description
This PR fixes an issue where template parameters with a default value of
false(e.g.,singleFile) were not being applied, causing them to appear asundefinedinside templates.The problem was caused by this check:
Since
falseis falsy, it was incorrectly ignored.The fix updates the condition to properly detect all default values:
How I verified the fix
Patched the generator locally and added simple debug logs in the HTML template:
https://github.com/lightning-sagar/html-template/blob/test/template-params/components/index.js#L48-L49
Ran the generator using:
Output confirmed the fix:
https://github.com/lightning-sagar/html-template/blob/test/template-params/dupa/index.html#L15-L16
(
param: false | computed: false)Related issue(s)
Fixes #1768
Summary by CodeRabbit
Bug Fixes
Documentation
Chores
✏️ Tip: You can customize this high-level summary in your review settings.