From 90a392e5e29c595b2536d26513914ffcc2b34547 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 20 Jul 2026 18:16:09 +0000
Subject: [PATCH 1/2] Initial plan
From e9991dbb53b98d6f26b28dffc779922318c740bc Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 20 Jul 2026 18:23:08 +0000
Subject: [PATCH 2/2] fix(spec-api): ignore XML declaration in
validateXmlBodyEquals
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
---
.chronus/changes/spec-api-xml-declaration-fix-2026-7-20.md | 7 +++++++
packages/spec-api/src/request-validations.ts | 2 +-
packages/spector/test/xml-validation.test.ts | 6 ++++++
3 files changed, 14 insertions(+), 1 deletion(-)
create mode 100644 .chronus/changes/spec-api-xml-declaration-fix-2026-7-20.md
diff --git a/.chronus/changes/spec-api-xml-declaration-fix-2026-7-20.md b/.chronus/changes/spec-api-xml-declaration-fix-2026-7-20.md
new file mode 100644
index 00000000000..96ecd21c04f
--- /dev/null
+++ b/.chronus/changes/spec-api-xml-declaration-fix-2026-7-20.md
@@ -0,0 +1,7 @@
+---
+changeKind: fix
+packages:
+ - "@typespec/spec-api"
+---
+
+XML declarations no longer affect semantic body equality in `validateXmlBodyEquals`; both actual and expected XML declarations are ignored during comparison.
diff --git a/packages/spec-api/src/request-validations.ts b/packages/spec-api/src/request-validations.ts
index da170b07aed..1b18b9a65e8 100644
--- a/packages/spec-api/src/request-validations.ts
+++ b/packages/spec-api/src/request-validations.ts
@@ -64,7 +64,7 @@ export const validateXmlBodyEquals = (
throw new ValidationError(BODY_EMPTY_ERROR_MESSAGE, expectedXml, request.rawBody);
}
- const parser = new XMLParser({ parseTagValue: false });
+ const parser = new XMLParser({ parseTagValue: false, ignoreDeclaration: true });
const actualParsed: unknown = parser.parse(request.rawBody);
let expectedParsed: unknown = parser.parse(expectedXml);
diff --git a/packages/spector/test/xml-validation.test.ts b/packages/spector/test/xml-validation.test.ts
index 93e3579506f..a990772368f 100644
--- a/packages/spector/test/xml-validation.test.ts
+++ b/packages/spector/test/xml-validation.test.ts
@@ -35,6 +35,12 @@ describe("with plain string (no matchers)", () => {
).toThrow("Body provided doesn't match expected body");
});
+ it("should accept matching XML when actual has no declaration", () => {
+ expect(() =>
+ validateXmlBodyEquals(makeRequest("1"), "1"),
+ ).not.toThrow();
+ });
+
it("should reject empty body", () => {
expect(() => validateXmlBodyEquals(makeRequest(""), "")).toThrow("Body should exists");
});