Skip to content

hsjs: fix handling of optional query/header params#9176

Merged
witemple-msft merged 3 commits intomicrosoft:mainfrom
witemple-msft:witemple-msft/hsjs-hyperparam-optionality
Dec 10, 2025
Merged

hsjs: fix handling of optional query/header params#9176
witemple-msft merged 3 commits intomicrosoft:mainfrom
witemple-msft:witemple-msft/hsjs-hyperparam-optionality

Conversation

@witemple-msft
Copy link
Member

@witemple-msft witemple-msft commented Dec 10, 2025

These use a different codepath in HSJS than JSON properties, and that codepath was mishandling optional parameters by unconditionally passing them into globalThis.Number/globalThis.Boolean, etc. This patch adds an explicit check for undefined and transposes that to undefined instead of calling the parser unconditionally, which will return the default value. For parsers that don't accept undefined as an input, this would have triggered a type error or runtime error.

Closes #9156

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 10, 2025

Open in StackBlitz

npm i https://pkg.pr.new/microsoft/typespec/@typespec/http@9176
npm i https://pkg.pr.new/microsoft/typespec/@typespec/http-server-js@9176

commit: 23764cb

@github-actions
Copy link
Contributor

All changed packages have been documented.

  • @typespec/http-server-js
Show changes

@typespec/http-server-js - fix ✏️

Fixed a bug that caused optional query/header parameters to be improperly converted to primitive types when not provided in a request.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@witemple-msft witemple-msft added this pull request to the merge queue Dec 10, 2025
Merged via the queue into microsoft:main with commit 4a728cb Dec 10, 2025
27 checks passed
@witemple-msft witemple-msft deleted the witemple-msft/hsjs-hyperparam-optionality branch December 10, 2025 19:16
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.

[http-server-js][Bug]: wrong value for optional query parameters

3 participants