Skip to content

[http-client-csharp] Preserve reader options when deserializing external models - #11917

Open
JoshLove-msft with Copilot wants to merge 3 commits into
mainfrom
copilot/preserve-reader-options
Open

[http-client-csharp] Preserve reader options when deserializing external models#11917
JoshLove-msft with Copilot wants to merge 3 commits into
mainfrom
copilot/preserve-reader-options

Conversation

Copilot AI commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Generated deserializers force wire options when reading external models, dropping unknown nested JSON properties during persistence round-trips.

  • Options propagation: Pass the enclosing ModelReaderWriterOptions to fallback ModelReaderWriter.Read calls instead of hardcoding WireOptions. JSON mode retains unknown properties; wire behavior remains unchanged.
  • Regression coverage: Cover external models in scalar, list, and dictionary properties across JSON/wire read-write combinations, and update the generated-method baseline.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@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 9, 2026
Copilot AI changed the title [WIP] Preserve reader options when deserializing external models [http-client-csharp] Preserve reader options when deserializing external models Sep 9, 2026
Copilot AI requested a review from JoshLove-msft September 9, 2026 20:34
@JoshLove-msft
JoshLove-msft marked this pull request as ready for review September 10, 2026 20:07
Copilot AI lite review requested due to automatic review settings September 10, 2026 20:07
@pkg-pr-new

pkg-pr-new Bot commented Sep 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: c66cfa8

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 change directly addresses the reported option-propagation bug with targeted regression coverage for external models across relevant property shapes and formats.

Pull request overview

Fixes a C# http-client generator bug where deserialization of external model types forced WireOptions, causing unknown JSON properties to be dropped during JSON round-trips. The change forwards the caller’s ModelReaderWriterOptions into the ModelReaderWriter.Read(...) fallback path, and adds a regression test that executes generated code to validate behavior across scalar/list/dictionary external-model properties and JSON/wire combinations.

Changes:

  • Forward mrwOptions (instead of WireOptions) to ModelReaderWriterSnippets.Read(...) in the MRW deserialization fallback.
  • Add a compilation+execution regression test validating unknown-property preservation only for JSON read+write (J/J) with external model properties (scalar/list/dictionary).
  • Update the existing generated-method baseline and add test-only context shims to support the new scenario.
File summaries
File Description
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs Fixes the fallback ModelReaderWriter.Read call to propagate the caller’s reader options (mrwOptions).
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationTypeDefinitionTests.cs Adds an execution-based regression test covering external models and updates an existing baseline assertion to compare the emitted method text.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/GetUtf8BytesIsUsedForMrwFallback.cs Updates the expected generated deserializer text to reflect option propagation and the new assertion shape.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/ExternalModelPropertiesPreserveReaderOptions(Context).cs Adds test-only context/extension shims used by the regression scenario’s compilation.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

… baseline comparison

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>

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 change is a targeted bug fix aligned with the linked issue and is covered by generator-output regression tests verifying the corrected options propagation in the emitted deserializers.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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.

[http-client-csharp] Preserve reader options when deserializing external models

4 participants