fix(http-client-csharp): honor @protocolAPI(false) by generating protocol method as internal#11215
Merged
Merged
Conversation
…ocol method as internal The ClientModel generator deserialized InputOperation.GenerateProtocolMethod but never used it, so @protocolAPI(false) had no effect. Generate the protocol method as internal (not public) when the flag is false, keeping the method body and the convenience method's delegation intact. The convenience method's accessibility now follows the service method accessibility so it remains public. Fixes microsoft#11211 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the C# http-client generator’s handling of @protocolAPI(false) by ensuring protocol (RequestContent-based) overloads are still generated but are no longer part of the public API surface when the flag is false, while keeping convenience methods public.
Changes:
- Generate protocol methods as
internalwhenInputOperation.GenerateProtocolMethodisfalse. - Decouple convenience-method accessibility from the protocol-method accessibility so convenience methods remain
publicwhen the service method is public. - Add a unit test asserting protocol methods become internal while convenience methods remain public, plus update shared input factory to set
GenerateProtocolMethod.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/common/InputFactory.cs | Extends InputFactory.Operation(...) to allow setting generateProtocolMethod for tests. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmMethodProviderCollectionTests.cs | Adds coverage for GenerateProtocolMethod=false ensuring protocol methods are internal and convenience methods remain public. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs | Implements the accessibility changes for protocol vs convenience methods based on GenerateProtocolMethod and service accessibility. |
| .chronus/changes/honor-protocolapi-false-2026-7-8.md | Adds a Chronus changelog entry for the change. |
The .NET emitter (@typespec/http-client-csharp) is not managed by chronus, so a .chronus changelog entry breaks the preview `chronus version` job. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jorgerangel-msft
approved these changes
Jul 8, 2026
jorgerangel-msft
left a comment
Contributor
There was a problem hiding this comment.
LGTM. I kicked off a regen preview for sanity https://dev.azure.com/azure-sdk/internal/_build/results?buildId=6537081&view=results
Contributor
|
No changes needing a change description found. |
commit: |
|
You can try these changes here
|
The Local/Sample-TypeSpec test project uses @protocolAPI(false) on the internalProtocol and stillConvenient operations. With the fix, their protocol methods are now generated as internal (and the public-only Argument null checks are dropped accordingly), so the checked-in baseline is regenerated to match. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jorgerangel-msft
approved these changes
Jul 8, 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.
Fixes #11211
Problem
The C# emitter ignored
@protocolAPI(false). The emitter emitsgenerateProtocolMethod: false(operation-converter.ts) andInputOperation.GenerateProtocolMethoddeserializes it, but the ClientModel generator never consulted the flag, so the protocol method was always generated aspublic.Fix
In
ScmMethodProviderCollection:BuildProtocolMethod: generate the protocol method asinternal(instead ofpublic) whenGenerateProtocolMethodisfalse. The method and its body are kept (not omitted), so the convenience method still delegates to it.GetConvenienceMethodModifiers: the convenience method's public/internal accessibility now follows the service method's accessibility, decoupled from the protocol method - so the convenience method stayspubliceven when the protocol method isinternal. This is behavior-preserving for existing scenarios (an internal protocol method previously only occurred with a non-public service method).Behavior
With
@protocolAPI(false):Tests
ProtocolMethodIsInternalWhenGenerateProtocolMethodIsFalse(test-first: failed before the fix, passes after).Microsoft.TypeSpec.Generator.ClientModelsuite: 1456 passed, 0 failed.