Skip to content

Fix C# ClientResult conversions for streaming events - #11858

Merged
JoshLove-msft merged 1 commit into
microsoft:mainfrom
JoshLove-msft:joshlove-msft-fix-streaming-client-results
Sep 8, 2026
Merged

Fix C# ClientResult conversions for streaming events#11858
JoshLove-msft merged 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.

@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.

@JoshLove-msft
JoshLove-msft added this pull request to the merge queue Sep 8, 2026
Merged via the queue into microsoft:main with commit 0bb43ac Sep 8, 2026
29 checks passed
@JoshLove-msft
JoshLove-msft deleted the joshlove-msft-fix-streaming-client-results branch September 8, 2026 16:51
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

4 participants