Skip to content

Fix nested XML model element name precedence - #5204

Open
Chenjie Shi (tadelesh) wants to merge 12 commits into
Azure:mainfrom
tadelesh:tadelesh/fix-go-xml-nested-element-name
Open

Fix nested XML model element name precedence#5204
Chenjie Shi (tadelesh) wants to merge 12 commits into
Azure:mainfrom
tadelesh:tadelesh/fix-go-xml-nested-element-name

Conversation

@tadelesh

@tadelesh Chenjie Shi (tadelesh) commented Aug 11, 2026

Copy link
Copy Markdown
Member

Summary

  • make generated model MarshalXML methods apply custom model XML names for direct/root serialization
  • route nested model properties and array items through an internal context-aware marshaller so their generated XML tags take precedence
  • handle property names that collide with the Go model name without relying on string comparisons
  • let client requests and fake-server responses use the same model marshalling behavior instead of separate root wrappers
  • enable the existing nested renamed-model Spector PUT regression and add fake-server and emitter snapshot coverage

Testing

  • built and type-checked @azure-tools/typespec-go
  • regenerated azblob and payload/xml
  • ran the direct-root and nested-property azblob tests
  • ran the XML name-precedence unit snapshots and scenario-suite guard
  • ran the targeted fake-server XML tests
  • ran the complete payload/xml Spector Go module uncached, including wrapped and unwrapped model arrays
  • ran repository formatting and linting

Fixes #5179

Preserve property-provided XML element names while retaining custom model names for root serialization.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @azure-tools/typespec-go
Show changes

@azure-tools/typespec-go - fix ✏️

Use model XML names at serialization roots while preserving property and array element names for nested model values.

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

📦 Package size report

2 packages changed size, +565 B (+0.0%) packed overall.

Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
@azure-tools/typespec-python 46.22 KB → 42.20 KB -4.02 KB (-8.7%) 🟢 180.83 KB → 164.85 KB -15.98 KB (-8.8%) 🟢
@azure-tools/typespec-go 249.96 KB → 251.70 KB +1.74 KB (+0.7%) 🔴 1.27 MB → 1.29 MB +11.32 KB (+0.9%) 🔴
11 package(s) with no notable change
Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
@azure-tools/typespec-java 13.51 MB → 13.51 MB +2.94 KB (+0.0%) 15.03 MB → 15.03 MB +4.68 KB (+0.0%)
@azure-tools/typespec-client-generator-core 226.82 KB → 226.69 KB -127 B (-0.1%) 1.22 MB → 1.22 MB -2.38 KB (-0.2%)
@azure-tools/azure-http-specs 146.62 KB → 146.63 KB +9 B (+0.0%) 1.16 MB → 1.16 MB +12 B (+0.0%)
@azure-tools/typespec-autorest 80.93 KB → 80.93 KB 395.06 KB → 395.06 KB
@azure-tools/typespec-autorest-canonical 7.42 KB → 7.42 KB 26.00 KB → 26.00 KB
@azure-tools/typespec-azure-core 129.43 KB → 129.43 KB 702.77 KB → 702.77 KB
@azure-tools/typespec-azure-portal-core 42.40 KB → 42.40 KB 192.91 KB → 192.91 KB
@azure-tools/typespec-azure-resource-manager 171.16 KB → 171.16 KB 1.04 MB → 1.04 MB
@azure-tools/typespec-azure-rulesets 5.16 KB → 5.16 KB 32.09 KB → 32.09 KB
@azure-tools/typespec-metadata 15.91 KB → 15.91 KB 62.26 KB → 62.26 KB
@azure-tools/typespec-ts 527.17 KB → 527.17 KB 2.54 MB → 2.54 MB

Packed = gzipped .tgz published to npm. Unpacked = total extracted size. 🆕 added, 🗑️ removed. Packages from the core/ submodule are not included.
🔴 grew · 🟢 shrank — only changes of at least 512 B and 0.5% are marked.

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Go emitter diff

Baseline gh:7c0c271f206bed1937962ca12b920e555588995e vs this PR.

Diff summary: 8 file(s), +476 / -38

Rendered diff: inline on the run summary, or the emitter-diff-go-html artifact.

Informational check (core/eng/emitter-diff); does not block the PR.

@pkg-pr-new

pkg-pr-new Bot commented Aug 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-go@5204

commit: a8d8ee1

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

Move custom model XML naming to context-aware request and fake response roots while preserving property-provided element names in model marshallers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
@tadelesh
Chenjie Shi (tadelesh) marked this pull request as draft August 11, 2026 08:57
tadelesh and others added 7 commits August 11, 2026 17:02
Emit the shared XML root wrapper once in an existing generated client file instead of creating a dedicated source generator and Go file.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Generate the XML root wrapper in the existing XML helper file alongside additional-properties support.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Keep the existing XML additional-properties generator and emitter plumbing while extending its generated helper file with root serialization support.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Use the general xml-helpers name now that the generator emits both root and additional-properties helpers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Resolve the request-handler conflict by retaining context-aware XML root wrapping in the refactored emitBody path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
@tadelesh
Chenjie Shi (tadelesh) marked this pull request as ready for review August 13, 2026 06:35
tadelesh and others added 3 commits August 17, 2026 10:39
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
@tadelesh

Copy link
Copy Markdown
Member Author

Joel Hendrix (@jhendrixMSFT) I've tried several solutions to handle different naming of root usage vs nested usage for a model. The current one is more general. What do you think?

@jhendrixMSFT

Copy link
Copy Markdown
Member

IMO we need to retool how we model XML info. There were some cases between Autorest and tsp that were different leading to some awkward code. Now that we don't have to share anything with Autorest we can retool it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will retool XML modeling now that autorest is out of the picture.

Also, will wait until after storage tsp migration has landed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:go Issues for @azure-tools/typespec-go emitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[typespec-go] Nested XML model serialization ignores the property element name

2 participants