[http-client-csharp] Fix spread model parameter matching to use wire name#10111
Open
JoshLove-msft wants to merge 1 commit intomicrosoft:mainfrom
Open
[http-client-csharp] Fix spread model parameter matching to use wire name#10111JoshLove-msft wants to merge 1 commit intomicrosoft:mainfrom
JoshLove-msft wants to merge 1 commit intomicrosoft:mainfrom
Conversation
commit: |
Contributor
|
No changes needing a change description found. |
When constructing spread models in convenience methods, the parameter matching between convenience method parameters and model constructor parameters used C# names which can diverge due to: - @clientName renames (e.g., 'model' -> 'OverrideModelName') - @Encodedname wire names leaking (e.g., 'tool_resources' vs 'toolResources') - PascalCase vs camelCase differences This caused unmatched parameters to fall back to 'default' (null), leading to NullReferenceException during serialization when Optional.IsCollectionDefined(null) returns true for null collections. Fix: match by the property's wire (serialized) name, which is stable across both the convenience parameter and the model property since they represent the same JSON field. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
875c063 to
6eb86ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When generating convenience methods with spread model construction, parameters were matched between the convenience method and the model constructor by C# name. This fails when:
Unmatched parameters fell back to \default\ (null), causing \NullReferenceException\ during serialization when \Optional.IsCollectionDefined(null)\ returns \ rue\ for null collections.
This was discovered while migrating \Azure.AI.Agents.Persistent\ to the new @azure-typespec/http-client-csharp\ emitter — 172 out of 261 tests failed with NRE in serialization.
Fix
Match spread parameters by their wire (serialized) name (\WireInfo.SerializedName) instead of C# name. Both the convenience parameter and model constructor parameter share the same wire name since they represent the same JSON field. Uses \TryAdd\ to handle potential duplicate wire names gracefully.
Validation