Skip to content

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

Draft
timotheeguerin with Copilot wants to merge 2 commits into
mainfrom
copilot/spec-api-fix-xml-validation
Draft

fix(spec-api): ignore XML declaration in validateXmlBodyEquals#11313
timotheeguerin with Copilot wants to merge 2 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: e9991db

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

2 participants