Skip to content

fix(http-client-js): honor custom server option names - #12446

Open
Guishi Wang (guishiw) wants to merge 3 commits into
microsoft:mainfrom
guishiw:fix/12352-js-client-server-options
Open

Guishi Wang (guishiw) wants to merge 3 commits into
microsoft:mainfrom
guishiw:fix/12352-js-client-server-options

Conversation

@guishiw

@guishiw Guishi Wang (guishiw) commented Oct 30, 2026 •

Copy link
Copy Markdown

Fix: #12352

Root cause
The JavaScript client emitter hardcoded an optional endpoint property in the generated client options instead of deriving option properties from the TypeSpec server URL template. As a result, custom optional server parameter names were not represented correctly.

Fix strategy
Generate client option properties from the optional URL-template parameters exposed by the client metadata, applying the emitter naming policy and TypeScript type emission. Update the server scenarios and add coverage for a custom optional parameter name while preserving the expected behavior for required and multiple parameters.

The relevant test suite passes with 247 tests passed and 4 skipped. The package build, lint, Prettier, and diff checks also pass.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change aligning optional server-parameter declarations with their actual names.

No open issues 🎉

What changed in this PR

Fixes #12352 by making the JavaScript client emitter declare optional server parameters using their actual names, keeping client options consistent with endpoint resolution.

Changes:

  • Derive optional server options from client metadata, applying naming and type-emission policies.
  • Add coverage for baseUrl and update required-parameter scenarios to omit the unused endpoint option.
  • Add a package changelog entry.
File Description
packages/​http-client-js/​test/​scenarios/​server/​parametrized-endpoint.md Removes the unused optional endpoint from expected output.
packages/​http-client-js/​test/​scenarios/​server/​multiple-parameters.md Updates expected options for required server parameters.
packages/​http-client-js/​test/​scenarios/​server/​custom-parameter-name.md Tests matching baseUrl declarations and endpoint resolution.
packages/​http-client-js/​src/​components/​client-context/​client-context-options.tsx Emits named, typed options from optional URL-template parameters.
.chronus/​changes/​fix-http-client-js-server-option-name.md Documents the JavaScript emitter fix.

Review effort: Balanced

@pkg-pr-new

pkg-pr-new Bot commented Oct 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/microsoft/typespec/@typespec/http-client-js@12446

commit: cc1213a

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/http-client-js
Show changes

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

Generate client option properties from optional server URL parameters instead of always declaring an endpoint option.

@xirzec Jeff Fisher (xirzec) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, but could you address the below issue that copilot flagged? Thanks!

Comment on lines +22 to +24
const optionalEndpointParameters = $.client
.getUrlTemplate(props.client)
.parameters.filter((parameter) => parameter.optional);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot: @server parameters declared with a default value but without ? (e.g., baseUrl: url = "http://localhost:3000") have parameter.optional === false and parameter.defaultValue !== undefined, which buildClientParameters (packages/http-client-js/src/utils/parameters.tsx:19-28 via buildParameterDescriptor) treats as optional and omits from positional constructor arguments. Consider filtering with parameter.optional || parameter.defaultValue !== undefined here (and in ParametrizedEndpoint at packages/http-client-js/src/components/client-context/parametrized-endpoint.tsx:22-24) so default-valued server parameters without ? are included in *ClientOptions and resolved from options.

Copilot AI balanced review requested due to automatic review settings October 31, 2026 00:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new optional custom-parameter path without a default lacks a test scenario covering both the normalized options member and its resolver access.

1 open issue

Review effort: Balanced

const clientOptions: Map<string, Children> = new Map();
const optionalEndpointParameters = $.client
.getUrlTemplate(props.client)
.parameters.filter((parameter) => parameter.optional || parameter.defaultValue !== undefined);
Copilot AI balanced review requested due to automatic review settings October 31, 2026 00:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the change to derive JavaScript client server options from URL-template parameters.

1 open issue

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:js Issue for the JS client emitter: @typespec/http-client-js

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: http-client-js client options use endpoint when the server parameter has another name

3 participants