Fix XML serialization/deserialization of additionalProperties#3781
Open
joheredi wants to merge 2 commits intoAzure:mainfrom
Open
Fix XML serialization/deserialization of additionalProperties#3781joheredi wants to merge 2 commits intoAzure:mainfrom
additionalProperties#3781joheredi wants to merge 2 commits intoAzure:mainfrom
Conversation
Models with additionalProperties (Record spread) were not correctly handled in XML serialization and deserialization: - XML deserializers ignored undeclared XML elements, returning empty objects for models like BlobMetadata - XML object serializer incorrectly spread the entire client model instead of just the additionalProperties Record entries - XML string serializer silently dropped all additional properties Changes: - Add XmlAdditionalPropertiesConfig interface to xml-helpers.ts - Extend deserializeXmlObject/deserializeFromXml to collect undeclared XML elements into the additionalProperties field - Extend serializeModelToXml/serializeToXml to emit additionalProperties entries as sibling XML elements - Fix buildXmlObjectModelSerializer to spread item["additionalProperties"] instead of ...item - Update buildXmlModelSerializer/buildXmlModelDeserializer/ buildXmlObjectModelDeserializer generators to pass config when model has additional properties - Register XmlAdditionalPropertiesConfig in static-helpers-metadata.ts Fixes Azure#3779 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Fixes #3779
Problem
Models with
additionalProperties(e.g.,BlobMetadatawhich uses...Record<string>) were not correctly handled in XML serialization/deserialization:<Metadata><a>c</a></Metadata>would deserialize to{}instead of{ additionalProperties: { a: "c" } }....item) instead of just theadditionalPropertiesRecord entries, producing malformed XML output.The JSON deserializer handled this correctly via
serializeRecord(), but the XML path had no equivalent logic.Solution
Introduced
XmlAdditionalPropertiesConfig— a metadata-driven approach consistent with the existing XML serialization patterns (arrays, dicts, dates, etc.):Changes
Runtime helpers (static/static-helpers/serialization/xml-helpers.ts):
Code generator (src/modular/serialization/buildXmlSerializerFunction.ts):
Tests: