diff --git a/.chronus/changes/add-workaround-for-test-acceptance-2026-3-15-9-20-0.md b/.chronus/changes/add-workaround-for-test-acceptance-2026-3-15-9-20-0.md new file mode 100644 index 00000000000..4f577e58f0e --- /dev/null +++ b/.chronus/changes/add-workaround-for-test-acceptance-2026-3-15-9-20-0.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-specs" +--- + +Accept `2022-08-26T18:38:00.0000000Z` (7 fractional digit ticks, as emitted by .NET clients) as a valid RFC3339 UTC datetime form in the `ModelWithDatetime` XML scenario. diff --git a/packages/http-specs/specs/payload/xml/mockapi.ts b/packages/http-specs/specs/payload/xml/mockapi.ts index de2d3f85834..cb86927daf4 100644 --- a/packages/http-specs/specs/payload/xml/mockapi.ts +++ b/packages/http-specs/specs/payload/xml/mockapi.ts @@ -146,6 +146,15 @@ const modelWithDatetimeNoMs = ` `; +// Some clients (e.g. .NET) serialize UTC datetimes with 7 fractional digit ticks. +// "2022-08-26T18:38:00.0000000Z" is a valid representation of the same instant; accept it too. +const modelWithDatetimeWindowsMs = ` + + 2022-08-26T18:38:00.0000000Z + Fri, 26 Aug 2022 14:38:00 GMT + +`; + function createServerTests(uri: string, data?: any) { return { get: passOnSuccess({ @@ -280,7 +289,8 @@ Scenarios.Payload_Xml_ModelWithDatetimeValue_put = passOnSuccess({ }, handler: (req: MockRequest) => { req.expect.containsHeader("content-type", "application/xml"); - // Accept both "2022-08-26T18:38:00.000Z" and "2022-08-26T18:38:00Z" as equivalent UTC datetimes. + // Accept "2022-08-26T18:38:00.000Z", "2022-08-26T18:38:00Z", and + // "2022-08-26T18:38:00.0000000Z" as equivalent UTC datetimes. let firstError: unknown; try { req.expect.xmlBodyEquals(modelWithDatetime); @@ -288,7 +298,15 @@ Scenarios.Payload_Xml_ModelWithDatetimeValue_put = passOnSuccess({ firstError = e; } if (firstError !== undefined) { - req.expect.xmlBodyEquals(modelWithDatetimeNoMs); + let secondError: unknown; + try { + req.expect.xmlBodyEquals(modelWithDatetimeNoMs); + } catch (e) { + secondError = e; + } + if (secondError !== undefined) { + req.expect.xmlBodyEquals(modelWithDatetimeWindowsMs); + } } return { status: 204,