Fix XML serialization for model collections#9826
Merged
jorgerangel-msft merged 11 commits intomainfrom Feb 27, 2026
Merged
Conversation
- Add nameHint parameter to WriteObjectValue for XmlWriter - Add XML FromEnumerable overload in BinaryContentHelper with rootNameHint/childNameHint - Update ScmMethodProviderCollection for XML list serialization/deserialization - Add helper methods to detect XML collection operations Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot stopped work on behalf of
jorgerangel-msft due to an error
February 26, 2026 18:42
...ator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/BinaryContentHelperDefinition.cs
Outdated
Show resolved
Hide resolved
...ator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/BinaryContentHelperDefinition.cs
Outdated
Show resolved
Hide resolved
...erator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs
Outdated
Show resolved
Hide resolved
...erator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs
Show resolved
Hide resolved
...erator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs
Outdated
Show resolved
Hide resolved
...erator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs
Outdated
Show resolved
Hide resolved
...or/TestProjects/Local/Sample-TypeSpec/src/Generated/Internal/ModelSerializationExtensions.cs
Outdated
Show resolved
Hide resolved
Copilot stopped work on behalf of
jorgerangel-msft due to an error
February 26, 2026 20:23
Contributor
|
@copilot try fixing the feedback again |
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Contributor
Author
All review feedback addressed in c149c5f:
|
...t.TypeSpec.Generator.ClientModel/src/Providers/ModelSerializationExtensionsDefinition.Xml.cs
Outdated
Show resolved
Hide resolved
...erator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs
Outdated
Show resolved
Hide resolved
...erator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs
Outdated
Show resolved
Hide resolved
.../Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmMethodProviderCollectionTests.cs
Outdated
Show resolved
Hide resolved
Contributor
|
@copilot lets also make |
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Contributor
Author
...hodProviderCollectionTests/ConvenienceMethod_XmlListResponse_UsesXDocumentDeserialization.cs
Show resolved
Hide resolved
...t.TypeSpec.Generator.ClientModel/src/Providers/ModelSerializationExtensionsDefinition.Xml.cs
Outdated
Show resolved
Hide resolved
…tionExtensionsDefinition.Xml Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Contributor
Author
Fixed in 33c80de. The issue was that standalone |
...eSpec.Generator.ClientModel/test/Providers/Definitions/BinaryContentHelperDefinitionTests.cs
Outdated
Show resolved
Hide resolved
...ator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/BinaryContentHelperDefinition.cs
Outdated
Show resolved
Hide resolved
…TypeProviderWriter Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
...eSpec.Generator.ClientModel/test/Providers/Definitions/BinaryContentHelperDefinitionTests.cs
Outdated
Show resolved
Hide resolved
…s1, simplify test to validate only FromEnumerable method Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot stopped work on behalf of
jorgerangel-msft due to an error
February 26, 2026 23:01
jorgerangel-msft
approved these changes
Feb 26, 2026
jsquire
approved these changes
Feb 26, 2026
JoshLove-msft
approved these changes
Feb 26, 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.
nameHintparameter toWriteObjectValueforXmlWriterinModelSerializationExtensionsDefinition.Xml.csModelSerializationExtensionsSnippets.Xml.csto supportnameHintparameterFromEnumerableoverload inBinaryContentHelperDefinition.cswithrootNameHintandchildNameHintBinaryContentHelperSnippets.cswith newFromEnumerableoverload for XMLScmMethodProviderCollection.csserialization path to use XMLFromEnumerablewhen content type is XML and body is listScmMethodProviderCollection.csdeserialization path to use XDocument-based XML deserialization when response content type is XMLBinaryContentHelperDefinitionclass publicAddRangeinModelSerializationExtensionsDefinition.Xml.csFromEnumerableXML method (stream0/writer0/stream1 → stream/writer) and add testeng/scripts/Generate.ps1Original prompt
This section details on the original issue you should resolve
<issue_title>Fix XML Serialization For Model Collections</issue_title>
<issue_description>Consider this operation:
Since the request and response payload bodies are model collections, we cannot use ModelReaderWriter directly to serialize. We need to update our BinaryContentHelper and ModelSerializationExtensions to correctly handle this case.
For BinaryContentHelper, we need to generate this new helper method:
In the generated conv method, we then need to call this helper and pass in the both the serialized name of the collection and the serialized name of it's model elements:
The ModelSerializationExtension's
WriteObjectValuemethod for XML writer will need to be updated to this:For deserialization, we need to update the generated conv method to handle deserializing the payload directly: