Skip to content

Emit experimental diagnostics in C# clients - #11685

Open
JoshLove-msft wants to merge 2 commits into
microsoft:mainfrom
JoshLove-msft:josh/csharp-experimental-diagnostic-id
Open

Emit experimental diagnostics in C# clients#11685
JoshLove-msft wants to merge 2 commits into
microsoft:mainfrom
JoshLove-msft:josh/csharp-experimental-diagnostic-id

Conversation

@JoshLove-msft

Copy link
Copy Markdown
Contributor

Summary

  • preserve TypeSpec.HttpClient.@experimental diagnostic metadata in the C# input model
  • emit [Experimental("C")] on generated protocol and convenience methods
  • emit scoped warning suppressions for each dependsOn diagnostic in generated method and request bodies
  • keep graduation explicit; the attribute remains until the decorator is removed

Companion to #11684, which adds diagnosticId and dependsOn to the shared decorator contract.

Validation

  • C# emitter build
  • focused emitter, input, and generator tests
  • Cop static-analysis checks
  • generated-library regeneration

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f0e7f0ac-c4b6-47e3-a4fc-430ff8f883c6
@pkg-pr-new

pkg-pr-new Bot commented Aug 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@11685

commit: 06639a1

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

};
}

function isEmitterScopeApplicable(emitterScope: string | undefined): boolean {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Isn't this already handled by TCGC?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TCGC does filter scope, but it currently checks only a top-level decoratorInfo.arguments["scope"]. @experimental receives ClientDecoratorOptions through its options parameter, so this value arrives as decoratorInfo.arguments.options.emitterScope and is not filtered by TCGC. I kept the local check, added a comment explaining the distinction, and retained coverage verifying metadata scoped to another emitter is ignored.

--generated by Copilot

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f0e7f0ac-c4b6-47e3-a4fc-430ff8f883c6
Copilot AI lite review requested due to automatic review settings August 15, 2026 05:26

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.

Pull request overview

This PR propagates TypeSpec.HttpClient.@experimental metadata through the C# emitter input model and uses it during C# client generation to (a) emit ExperimentalAttribute on generated API methods and (b) add scoped warning suppressions for diagnostics listed in dependsOn.

Changes:

  • Extend the emitter/input-model contract to carry experimental: { diagnosticId, dependsOn } for operations, including JSON deserialization support and unit tests.
  • Emit [Experimental("...")] on generated protocol and convenience methods when diagnosticId is present, and add #pragma warning disable/restore for each dependsOn diagnostic on generated methods (including request creation methods).
  • Add emitter-side decorator extraction + tests to ensure @experimental metadata is captured with correct emitter scoping behavior.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/common/InputFactory.cs Adds optional experimental details when creating InputOperation test inputs.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/test/TypeSpecInputConverterTests.cs Adds a deserialization test validating experimental.diagnosticId and experimental.dependsOn.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/InputOperationConverter.cs Deserializes the new experimental payload into InputOperation.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/InputOperation.cs Stores Experimental details on InputOperation and threads it through constructors.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/InputExperimentalDetails.cs Introduces a new input-model type to represent experimental diagnostic metadata.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmMethodProviderCollectionTests.cs Validates attribute emission and dependency suppressions for experimental operations.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Utilities/ExperimentalApiHelpers.cs Centralizes building experimental attributes and dependency suppressions.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs Applies experimental attributes/suppressions to generated protocol and convenience methods.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/RestClientProvider.cs Applies dependency suppressions to generated create-request methods.
packages/http-client-csharp/emitter/test/Unit/experimental-decorator.test.ts Adds unit tests for extracting @experimental diagnostic metadata (including emitter scoping).
packages/http-client-csharp/emitter/src/type/input-operation.ts Extends the TS input operation type to include experimental.
packages/http-client-csharp/emitter/src/options.ts Ensures @experimental is captured via additionalDecorators.
packages/http-client-csharp/emitter/src/lib/operation-converter.ts Populates operation.experimental from decorators during conversion.
packages/http-client-csharp/emitter/src/lib/decorators.ts Adds getExperimentalDetails and emitter-scope filtering for @experimental metadata.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants