(schema: JSONSchema7, ctx: GoCodegenCtx)
| 2095 | } |
| 2096 | |
| 2097 | function normalizeSchemaForMatch(schema: JSONSchema7, ctx: GoCodegenCtx): unknown { |
| 2098 | const resolved = resolveSchema(schema, ctx.definitions) ?? schema; |
| 2099 | if (Array.isArray(resolved)) { |
| 2100 | return resolved.map((item) => typeof item === "object" && item !== null |
| 2101 | ? normalizeSchemaForMatch(item as JSONSchema7, ctx) |
| 2102 | : item); |
| 2103 | } |
| 2104 | if (!resolved || typeof resolved !== "object") return resolved; |
| 2105 | |
| 2106 | const entries = Object.entries(resolved) |
| 2107 | .filter(([key]) => !["title", "description", "default"].includes(key)) |
| 2108 | .map(([key, value]) => { |
| 2109 | if ((key === "anyOf" || key === "oneOf") && Array.isArray(value)) { |
| 2110 | const members = value |
| 2111 | .map((member) => normalizeSchemaForMatch(member as JSONSchema7, ctx)) |
| 2112 | .sort((left, right) => stableStringify(left).localeCompare(stableStringify(right))); |
| 2113 | return [key, members] as const; |
| 2114 | } |
| 2115 | if (key === "enum" && Array.isArray(value)) { |
| 2116 | return [key, [...value].sort()] as const; |
| 2117 | } |
| 2118 | if (key === "type" && Array.isArray(value)) { |
| 2119 | return [key, [...value].sort()] as const; |
| 2120 | } |
| 2121 | if (value && typeof value === "object") { |
| 2122 | return [key, normalizeSchemaForMatch(value as JSONSchema7, ctx)] as const; |
| 2123 | } |
| 2124 | return [key, value] as const; |
| 2125 | }); |
| 2126 | |
| 2127 | return Object.fromEntries(entries.sort(([left], [right]) => left.localeCompare(right))); |
| 2128 | } |
| 2129 | |
| 2130 | function dedupeGoSchemasForMatch(schemas: JSONSchema7[], ctx: GoCodegenCtx): JSONSchema7[] { |
| 2131 | const seen = new Set<string>(); |
no test coverage detected
searching dependent graphs…