Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

The apiVersion parameter in client initialization was incorrectly marked as required (optional: false) even when a default value exists.

Changes

  • clients.ts: Set optional: true for all apiVersion parameters at client level when isApiVersionParam is true
    • Endpoint template parameters (server URL parameters)
    • Multi-service client scenarios
    • Single-service client scenarios
  • Test updates: Updated assertions to expect optional: true for client-level apiVersion parameters in params.test.ts and structure.test.ts, including multi-service test cases
  • Changeset: Added changeset file documenting the fix

Before:

{
  name: "apiVersion",
  isApiVersionParam: true,
  clientDefaultValue: "2022-12-01",
  optional: false,  // ❌ Required despite having default
  onClient: true
}

After:

{
  name: "apiVersion",
  isApiVersionParam: true,
  clientDefaultValue: "2022-12-01",
  optional: true,   // ✅ Optional when at client level
  onClient: true
}

The fix ensures that apiVersion parameters are always optional at the client level across all scenarios, including both single-service and multi-service clients.

Original prompt

This section details on the original issue you should resolve

<issue_title>[TCGC] The apiVersion parameter should be optional at the client</issue_title>
<issue_description>The apiVersion parameter in the clientInitalization should be optional when the client has a default apiVersion value or all operations have default apiVersion values.

Image</issue_description>

<agent_instructions>The client level api version should always be optional.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Copilot AI changed the title [WIP] Make apiVersion parameter optional at client initialization Make apiVersion parameter optional at client initialization Jan 20, 2026
Copilot AI requested a review from tadelesh January 20, 2026 06:38
@tadelesh
Copy link
Member

@copilot You need also to check the multiple service cases. You must make sure all TCGC tests pass and use pnpm -w change add to add changeset.

…eset

Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 20, 2026

@copilot You need also to check the multiple service cases. You must make sure all TCGC tests pass and use pnpm -w change add to add changeset.

I've updated the code to handle multiple service cases explicitly. The changes ensure that apiVersion parameters are always optional: true at the client level in all scenarios:

  1. Endpoint template parameters (server URL params)
  2. Multi-service clients (line 265 in clients.ts)
  3. Single-service clients (line 269 in clients.ts)

I've also added test assertions for multiple service cases and created a changeset file. Commit: a0126dc

Note: I couldn't run the full TCGC test suite locally due to missing TypeSpec core dependencies in the build environment, but the code changes are syntactically correct and follow the same patterns as existing code.

@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Jan 26, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 26, 2026

Open in StackBlitz

npm i https://pkg.pr.new/Azure/typespec-azure/@azure-tools/typespec-client-generator-core@3806

commit: 491f344

@tadelesh tadelesh marked this pull request as ready for review January 26, 2026 06:15
@azure-sdk
Copy link
Collaborator

All changed packages have been documented.

  • @azure-tools/typespec-client-generator-core
Show changes

@azure-tools/typespec-client-generator-core - fix ✏️

The apiVersion parameter in client initialization is now correctly marked as optional: true for all client-level API version parameters, including both single-service and multi-service scenarios.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website

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

Labels

lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TCGC] The apiVersion parameter should be optional at the client

3 participants