Skip to content

Fix C# ClientResult conversions for streaming events - #11858

Open
JoshLove-msft wants to merge 1 commit into
microsoft:mainfrom
JoshLove-msft:joshlove-msft-fix-streaming-client-results
Open

Fix C# ClientResult conversions for streaming events#11858
JoshLove-msft wants to merge 1 commit into
microsoft:mainfrom
JoshLove-msft:joshlove-msft-fix-streaming-client-results

Conversation

@JoshLove-msft

@JoshLove-msft JoshLove-msft commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Streaming event models are never returned as plain ClientResult values, so generating explicit conversions for them adds unusable API surface.

Summary

  • Stop treating streaming payload models as root ClientResult outputs.
  • Preserve conversion operators for models returned by ordinary protocol methods.
  • Add SSE and JSON Lines regression coverage and regenerate streaming fixtures.

Testing

  • npm run build
  • npm run test:generator
  • npm run test:emitter
  • npm run format
  • Targeted oxlint
  • npm run cop

Fixes: #11856

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 4, 2026 00:26
@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 Sep 4, 2026

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.

🟢 Approval recommended

The core logic change aligns with the reported bug and is covered by a targeted regression test; remaining feedback is a non-blocking test-assertion precision improvement.

Pull request overview

This PR adjusts the C# http-client generator’s “root output model” detection so streaming payload/event models are no longer treated as ClientResult-castable outputs, preventing generation of unusable public static explicit operator <Model>(ClientResult) API surface for SSE/JSON Lines streaming scenarios (fix for #11856).

Changes:

  • Stop considering InputStreamingType.ValueType as a root ClientResult output model (so streaming item/event models don’t get ClientResult conversion operators).
  • Add regression coverage ensuring streaming responses do not produce ClientResult explicit operators.
  • Regenerate Spector and local streaming fixtures to reflect the removed operator(s).
File summaries
File Description
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/ScmTypeFactory.cs Removes streaming-type recursion when collecting RootOutputModels, preventing generation of ClientResult conversion operators for streaming payload models.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/DynamicModelSerializationTests.cs Adds a regression test for SSE/JSONL streaming responses to ensure no explicit ClientResult operator is generated.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Models/Info.Serialization.cs Regenerated fixture: removes ClientResult explicit operator for SSE streaming model.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/Models/Info.Serialization.cs Regenerated fixture: removes ClientResult explicit operator for JSONL streaming model.
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/StreamingItem.Serialization.cs Regenerated fixture: removes ClientResult explicit operator for a streaming payload model.
Review details
  • Files reviewed: 2/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1306 to +1310
Assert.That(
serialization!.Methods.Any(m =>
m.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Explicit) &&
m.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Operator)),
Is.False);
@pkg-pr-new

pkg-pr-new Bot commented Sep 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 74b3c90

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

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]: Do not generate ClientResult conversion operators for streaming events

3 participants