Fix CanonicalTypeProvider to respect CodeGenMember when categorizing redefined properties#10276
Closed
Fix CanonicalTypeProvider to respect CodeGenMember when categorizing redefined properties#10276
Conversation
…erialization Fix CanonicalTypeProvider.BuildProperties() to use the same _renamedProperties check as TryGetSpecProperty when categorizing custom properties. This ensures that when a property is renamed via CodeGenMember and the original name is redefined as a new custom property, the CodeGenMember property is always preferred for serialization, and the redefined property is correctly treated as a non-spec property in the canonical view. Add XML serialization test for the CanChangePropertyNameAndRedefineOriginal scenario to prevent regression. Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/c29130f0-3438-4d5b-9a35-74add018c73e Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix XML serialization to respect CodeGenMember attributes
Fix CanonicalTypeProvider to respect CodeGenMember when categorizing redefined properties
Apr 6, 2026
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.
When a property is renamed via
[CodeGenMember]and the original name is redefined as a new custom property,CanonicalTypeProvider.BuildProperties()incorrectly categorized the redefined property as a spec property — causing it to silently disappear from the canonical view. The root cause: the property categorization loop at lines 160-171 checked_specPropertiesMapdirectly without consulting_renamedProperties, unlike the existingTryGetSpecProperty()method which already had this guard.Changes
CanonicalTypeProvider.cs: Aligned the custom property categorization logic withTryGetSpecProperty()— properties matching a spec name are now checked against_renamedProperties/_renamedFieldsbefore being treated as spec properties. Redefined properties without[CodeGenMember]are correctly routed tononSpecProperties.ModelCustomizationTests.cs: UpdatedCanChangePropertyNameAndRedefineOriginalto assert the redefined property now appears in the canonical view (without WireInfo, as expected for a non-spec property).XmlSerializationCustomizationTests.cs: AddedCanChangePropertyNameAndRedefineOriginaltest covering the XML serialization path — validates that the[CodeGenMember]property is used for serialization/deserialization, not the redefined wrapper.Example scenario
Before:
StartsOncould incorrectly steal the spec property mapping fromPolicyStartsOn.After:
PolicyStartsOnis always preferred;StartsOnis treated as a non-spec custom property.