Skip to content

fix(javascript): use proper null check instead of truthiness for required params - #6498

Merged
Fluf22 merged 1 commit into
mainfrom
fix/js-falsy-zero-validation
Jun 12, 2026
Merged

Fluf22 merged 1 commit into
mainfrom
fix/js-falsy-zero-validation

Conversation

@Fluf22

@Fluf22 Fluf22 commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

searchClient.getTask({ indexName, taskID: 0 }) throws:

Error: Parameter `taskID` is required when calling `getTask`.

Because the generated validation used if (!taskID), which treats 0 as falsy/missing in JavaScript. 0 is a valid taskID — for example, POST /3/abtests returns {"abTestID":13743,"taskID":0,"index":"products-2"}.

What changed

The recent validateRequired refactor (#6496) already centralized validation into a helper that correctly checks === null || === undefined. This PR:

  1. Simplifies validateRequired — replaces value === null || value === undefined with the idiomatic value == null (loose equality covers both null and undefined)
  2. Adds a CTS regression test — getTask with taskID: 0 ensures this edge case stays covered

Changes

File Change
packages/client-common/src/validateParam.ts === null || === undefined → == null
tests/CTS/requests/search/getTask.json Add test: getTask with taskID: 0

…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
Fluf22 force-pushed the fix/js-falsy-zero-validation branch from ce19cc3 to 2dfc7a5 Compare June 11, 2026 14:15
@algolia-api-clients-automation-bot

algolia-api-clients-automation-bot Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

✔️ Code generated!

Name Link
🪓 Triggered by f5aa09299c1f8e15c2a828e213f0cfeca4942628
🍃 Generated commit a21cee14565181e76d0a6fd297a5109961d7ffdf
🌲 Generated branch generated/fix/js-falsy-zero-validation
📊 Benchmark results

Benchmarks performed on the method using a mock server, the results might not reflect the real-world performance.

Language Req/s
javascript 2409
go 1872
php 1762
python 1438
csharp 1389
java 1131
ruby 914
swift 679
scala 23

@Fluf22
Fluf22 marked this pull request as ready for review June 11, 2026 15:56
@Fluf22
Fluf22 requested a review from a team as a code owner June 11, 2026 15:56
@Fluf22 Fluf22 self-assigned this Jun 11, 2026
@Fluf22
Fluf22 merged commit 3a0bad1 into main Jun 12, 2026
36 checks passed
@Fluf22
Fluf22 deleted the fix/js-falsy-zero-validation branch June 12, 2026 05:14
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>
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.

2 participants