Generate ClientSettings and auth constructors for individually-initialized sub-clients#10042
Merged
JoshLove-msft merged 3 commits intomicrosoft:mainfrom Mar 16, 2026
Conversation
- Sub-clients with InitializedBy.Individually now get ClientSettings class - Sub-clients with InitializedBy.Individually now get auth constructors (ApiKeyCredential, AuthenticationTokenProvider) - Internal AuthenticationPolicy constructor always adds auth policy to pipeline - EffectiveClientOptions property on ClientProvider resolves root client's options for sub-clients - Updated test expected files for unsupported-auth pipeline body change Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
Contributor
|
No changes needing a change description found. |
JoshLove-msft
commented
Mar 16, 2026
...nt-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientProvider.cs
Outdated
Show resolved
Hide resolved
JoshLove-msft
commented
Mar 16, 2026
...nt-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientProvider.cs
Show resolved
Hide resolved
c755a3c to
4bfb878
Compare
JoshLove-msft
commented
Mar 16, 2026
...nt-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientProvider.cs
Outdated
Show resolved
Hide resolved
…izedBy - Remove canBeIndividuallyInitialized variable and all ClientOptions null-checks for auth fields and ClientSettings; use only the InitializedBy flag - Add braces to if blocks in constructor builder loops - Update InputFactory.Client default to Individually (matches production) - Update test sub-clients to explicitly set initializedBy: Parent Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4bfb878 to
dcdc8b3
Compare
When authenticationPolicy is null (no-auth clients), the pipeline was including null in the per-retry policies array causing NullReferenceException. Now generates an if/else to only include authenticationPolicy when non-null. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jorgerangel-msft
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the C# generator to produce
ClientSettingsclasses and authentication constructors for sub-clients that haveInitializedBy.Individually(i.e., can be constructed directly by the user, not only via parent client accessors).Changes
ClientProvider.cs
InitializedBy.Individuallynow get_apiKeyAuthFields/_oauth2Fields(previously only root clients had these).AppendSubClientPublicConstructorsnow generates credential-based constructors (ApiKeyCredential,AuthenticationTokenProvider) that chain to the internalAuthenticationPolicyconstructor viathis(...).BuildPrimaryConstructorBodycondition fromauthPolicyParam != null && authFields != nulltoauthPolicyParam != null.EffectiveClientOptionsproperty: Sub-clients resolve the root client'sClientOptionstype viaGetRootClient()?.ClientOptions.GetSubClientInternalConstructorParametersno longer includes credential params.ClientSettingsProvider.cs
_clientProvider.EffectiveClientOptionsinstead of duplicating parent-walking logic.ScmOutputLibrary.cs
ClientSettingsemission decoupled fromClientOptions != null.Test Updates
ClientSettingsProviderTests.cs.Generated Output
Metrics.csnow has auth constructors (ApiKeyCredential,AuthenticationTokenProvider) and auth pipeline.MetricsSettings.cs— new generated settings class for the Metrics sub-client.Testing
Generate.ps1succeeds with no diff beyond expected changes