Repository navigation
fix(javascript): use proper null check instead of truthiness for required params - #6498
Merged
Merged
Conversation
…ired params
The JS template used `!param` for required parameter validation,
which treats 0 as missing. This breaks calls like
`getTask({ indexName, taskID: 0 })` where 0 is a valid taskID
(e.g. returned by POST /3/abtests).
Fix: use `!param` only for strings (catches null, undefined, and
empty string) and `param === null || param === undefined` for all
other types (numbers, booleans, objects, arrays).
This aligns the JS template with how every other language client
already handles required parameter validation.
Fluf22
force-pushed
the
fix/js-falsy-zero-validation
branch
from
June 11, 2026 14:15
ce19cc3 to
2dfc7a5
Compare
Contributor
✔️ Code generated!
📊 Benchmark resultsBenchmarks performed on the method using a mock server, the results might not reflect the real-world performance.
|
eric-zaharia
approved these changes
Jun 12, 2026
algolia-api-clients-automation-bot Bot
added a commit
that referenced
this pull request
Jun 12, 2026
…ired params (#6498) (generated) [skip ci] Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-javascript
that referenced
this pull request
Jun 12, 2026
…ired params (generated) algolia/api-clients-automation#6498 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
searchClient.getTask({ indexName, taskID: 0 })throws:Because the generated validation used
if (!taskID), which treats0as falsy/missing in JavaScript.0is a validtaskID— for example,POST /3/abtestsreturns{"abTestID":13743,"taskID":0,"index":"products-2"}.What changed
The recent
validateRequiredrefactor (#6496) already centralized validation into a helper that correctly checks=== null || === undefined. This PR:validateRequired— replacesvalue === null || value === undefinedwith the idiomaticvalue == null(loose equality covers bothnullandundefined)getTaskwithtaskID: 0ensures this edge case stays coveredChanges
packages/client-common/src/validateParam.ts=== null || === undefined→== nulltests/CTS/requests/search/getTask.jsongetTaskwithtaskID: 0