[http-client-csharp] Preserve reader options when deserializing external models - #11917
[http-client-csharp] Preserve reader options when deserializing external models#11917JoshLove-msft with Copilot wants to merge 3 commits into
Conversation
|
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>
commit: |
There was a problem hiding this comment.
🟢 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 ofWireOptions) toModelReaderWriterSnippets.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>
There was a problem hiding this comment.
🟢 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
Generated deserializers force wire options when reading external models, dropping unknown nested JSON properties during persistence round-trips.
ModelReaderWriterOptionsto fallbackModelReaderWriter.Readcalls instead of hardcodingWireOptions. JSON mode retains unknown properties; wire behavior remains unchanged.