Skip to content

fix: required client init parameters should not trigger separate ClientOptions type#10375

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-client-options-bug
Draft

fix: required client init parameters should not trigger separate ClientOptions type#10375
Copilot wants to merge 2 commits intomainfrom
copilot/fix-client-options-bug

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

UseSingletonInstance in ClientOptionsProvider treated all non-standard client parameters as requiring a separate client-specific ClientOptions class. But required parameters (no DefaultValue) never become properties on the options class—they're inlined as constructor parameters on the client. This caused unnecessary per-client options types when using @@clientInitialization with required parameters in multi-client scenarios.

Changes

  • ClientOptionsProvider.cs: Added parameter.DefaultValue != null check in UseSingletonInstance so only optional parameters (which actually become options properties) trigger a separate client-specific options type. This aligns the singleton decision logic with BuildProperties, which already filters on DefaultValue != null.
  • ClientOptionsProviderTests.cs: Added MultipleClientsWithRequiredCustomParametersShareSingletonOptions test covering the multi-client scenario where a required custom parameter should still share the singleton options.

Before/After

// Multi-client scenario with required init parameter
@@clientInitialization(KnowledgeBaseRetrievalClient, {
  parameters: KnowledgeBaseRetrievalClientOptions, // knowledgeBaseName: string (required)
});

Before: Generates KnowledgeBaseRetrievalClientOptions (separate, unnecessary options type)
After: Shares singleton <ServiceName>ClientOptions with other clients in the library

…arate ClientOptions type

In UseSingletonInstance, skip required parameters (those without DefaultValue)
when determining if a client needs a separate client-specific options type.
Required parameters are inlined as constructor parameters on the client and
never become properties on the ClientOptions class, so they should not trigger
the creation of a separate client-specific options type.

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/6c0324cb-28eb-47ca-b77e-05f5375bcea7

Co-authored-by: JonathanCrd <17486462+JonathanCrd@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Apr 14, 2026
Copilot AI changed the title [WIP] Fix bug with unintended ClientOptions generation in C# fix: required client init parameters should not trigger separate ClientOptions type Apr 14, 2026
Copilot AI requested a review from JonathanCrd April 14, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Required client initialization parameters generate unintended ClientOptions in C#

2 participants