diff --git a/packages/gateway-protocol/src/native-protocol-levels.guard.test.ts b/packages/gateway-protocol/src/native-protocol-levels.guard.test.ts index fbfa664d2e37..46ce7feac56a 100644 --- a/packages/gateway-protocol/src/native-protocol-levels.guard.test.ts +++ b/packages/gateway-protocol/src/native-protocol-levels.guard.test.ts @@ -19,6 +19,10 @@ type ProtocolLevels = { max: number; }; +type LiteralUnionBranch = { + readonly const?: unknown; +}; + const expectedLevels: ProtocolLevels = { min: MIN_CLIENT_PROTOCOL_VERSION, max: PROTOCOL_VERSION, @@ -68,6 +72,25 @@ function assertPattern( throw new Error(`${relativePath}: ${message}`); } +function literalUnionBranches(schema: unknown): readonly LiteralUnionBranch[] | undefined { + if (!schema || typeof schema !== "object") { + return undefined; + } + const unionSchema = schema as { + readonly anyOf?: unknown; + readonly oneOf?: unknown; + }; + const branches = Array.isArray(unionSchema.anyOf) + ? unionSchema.anyOf + : Array.isArray(unionSchema.oneOf) + ? unionSchema.oneOf + : undefined; + if (!branches || branches.length < 2) { + return undefined; + } + return branches as readonly LiteralUnionBranch[]; +} + describe("native Gateway protocol levels", () => { it("match the TypeScript source of truth", async () => { if (MIN_CLIENT_PROTOCOL_VERSION > PROTOCOL_VERSION) { @@ -186,8 +209,8 @@ describe("native Gateway protocol levels", () => { const swiftGenerated = await readRepoFile(swiftGeneratedPath); for (const [name, schema] of Object.entries(ProtocolSchemas)) { - const branches = schema.anyOf ?? schema.oneOf; - if (!branches || branches.length < 2) { + const branches = literalUnionBranches(schema); + if (!branches) { continue; } const values = branches.map((branch) => branch.const);