Skip to content

fix(spec-api): ignore XML declaration in validateXmlBodyEquals#11313

Merged
timotheeguerin merged 3 commits into
mainfrom
copilot/spec-api-fix-xml-validation
Jul 22, 2026
Merged

fix(spec-api): ignore XML declaration in validateXmlBodyEquals#11313
timotheeguerin merged 3 commits into
mainfrom
copilot/spec-api-fix-xml-validation

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Since the migration from xml2js to fast-xml-parser (#10239), validateXmlBodyEquals prepends <?xml version='1.0' encoding='UTF-8'?> to plain expected strings, and fast-xml-parser (unlike xml2js) preserves that declaration as a ?xml node in the parsed output. This causes comparison failures when the actual request body omits the declaration.

Changes

  • packages/spec-api/src/request-validations.ts — Add ignoreDeclaration: true to XMLParser options so declarations are stripped from both sides before comparison, restoring the semantic-equality behavior of xml2js.
  • packages/spector/test/xml-validation.test.ts — Add test for the inverse path: actual body without a declaration matching an expected string (the exact scenario failing in Spector).
// Previously threw ValidationError; now passes
validateXmlBodyEquals(
  { rawBody: "<Root><a>1</a></Root>" },
  "<Root><a>1</a></Root>",
);

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix XML validation to handle declaration correctly fix(spec-api): ignore XML declaration in validateXmlBodyEquals Jul 20, 2026
Copilot AI requested a review from timotheeguerin July 20, 2026 18:23
@microsoft-github-policy-service microsoft-github-policy-service Bot added the spector Issues related to spector and the spec sets label Jul 20, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/spec-api@11313
npm i https://pkg.pr.new/@typespec/spector@11313

commit: 217163d

@timotheeguerin
timotheeguerin marked this pull request as ready for review July 22, 2026 14:44
@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/spec-api
Show changes

@typespec/spec-api - fix ✏️

XML declarations no longer affect semantic body equality in validateXmlBodyEquals; both actual and expected XML declarations are ignored during comparison.

@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@timotheeguerin
timotheeguerin enabled auto-merge July 22, 2026 15:33
@timotheeguerin
timotheeguerin added this pull request to the merge queue Jul 22, 2026
Merged via the queue into main with commit 886385b Jul 22, 2026
38 of 40 checks passed
@timotheeguerin
timotheeguerin deleted the copilot/spec-api-fix-xml-validation branch July 22, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spector Issues related to spector and the spec sets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[spec-api] XML validation treats the declaration as body content

3 participants