@@ -68,6 +68,30 @@ function assertPattern(
|
68 | 68 | throw new Error(`${relativePath}: ${message}`); |
69 | 69 | } |
70 | 70 | |
| 71 | +function stringLiteralUnionValues(schema: unknown): string[] | undefined { |
| 72 | +if (!schema || typeof schema !== "object") { |
| 73 | +return undefined; |
| 74 | +} |
| 75 | +const candidate = schema as { anyOf?: unknown; oneOf?: unknown }; |
| 76 | +const branches = candidate.oneOf ?? candidate.anyOf; |
| 77 | +if (!Array.isArray(branches) || branches.length < 2) { |
| 78 | +return undefined; |
| 79 | +} |
| 80 | + |
| 81 | +const values: string[] = []; |
| 82 | +for (const branch of branches) { |
| 83 | +if (!branch || typeof branch !== "object" || !("const" in branch)) { |
| 84 | +return undefined; |
| 85 | +} |
| 86 | +const value = branch.const; |
| 87 | +if (typeof value !== "string") { |
| 88 | +return undefined; |
| 89 | +} |
| 90 | +values.push(value); |
| 91 | +} |
| 92 | +return new Set(values).size === values.length ? values : undefined; |
| 93 | +} |
| 94 | + |
71 | 95 | describe("native Gateway protocol levels", () => { |
72 | 96 | it("match the TypeScript source of truth", async () => { |
73 | 97 | if (MIN_CLIENT_PROTOCOL_VERSION > PROTOCOL_VERSION) { |
@@ -186,12 +210,8 @@ describe("native Gateway protocol levels", () => {
|
186 | 210 | const swiftGenerated = await readRepoFile(swiftGeneratedPath); |
187 | 211 | |
188 | 212 | for (const [name, schema] of Object.entries(ProtocolSchemas)) { |
189 | | -const branches = schema.anyOf ?? schema.oneOf; |
190 | | -if (!branches || branches.length < 2) { |
191 | | -continue; |
192 | | -} |
193 | | -const values = branches.map((branch) => branch.const); |
194 | | -if (values.some((value) => typeof value !== "string")) { |
| 213 | +const values = stringLiteralUnionValues(schema); |
| 214 | +if (!values) { |
195 | 215 | continue; |
196 | 216 | } |
197 | 217 | |
|