fix: keep params with an empty value - #2299
priyanthants wants to merge 1 commit into
Conversation
`paramParser` split each `--param name=value` input with
`input.split(/=(.+)/, 2)`. The `(.+)` requires at least one character after
`=`, so an input with an empty value such as `name=` did not match and the
param was dropped entirely: `paramParser(['name='])` returned `{}` instead
of `{ name: '' }`. Passing `--param foo=` was therefore silently ignored.
Split on the first `=` with `indexOf` instead, which preserves values that
contain `=` and keeps params whose value is empty.
The existing "trailing equals" test asserted this case but was passing
`name=value` (a non-empty value), so it never exercised the bug. It now
uses `name=` and expects `{ name: '' }`.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
|
There was a problem hiding this comment.
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.
|



Description
paramParser(used byasyncapi generate ... --param name=value) parsed each input with:The
(.+)in that regex requires at least one character after=, so an input with an empty value —name=— does not match the split pattern. The result is that the whole param is dropped:So passing
--param foo=(intentionally setting an empty value, e.g. to blank out a template parameter) is silently ignored, with no error.Fix
Split on the first
=usingindexOf/slice. This keeps values that contain=and preserves params whose value is empty:Tests
The existing test titled "should handle input with trailing equals (no capture after =)" actually passed
name=value(a non-empty value), so it never exercised the case its title described — it gave false confidence while the bug remained. It now passesname=and asserts{ name: '' }.Verified locally: the updated
parseParamssuite passes (20/20), and the new assertion fails against the old implementation ({ 'name=': undefined }), confirming it covers the bug. eslint clean on both changed files.Found by reading the code; no pre-existing issue. Happy to open one to track it if you prefer.
AI disclosure: produced with assistance from Claude (Anthropic), credited via a
Co-authored-by:trailer on the commit. I reviewed, ran, and verified the change myself.