MCPcopy Index your code
hub / github.com/github/copilot-sdk / normalizeSchemaForMatch

Function normalizeSchemaForMatch

scripts/codegen/go.ts:2097–2128  ·  view source on GitHub ↗
(schema: JSONSchema7, ctx: GoCodegenCtx)

Source from the content-addressed store, hash-verified

2095}
2096
2097function 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
2130function dedupeGoSchemasForMatch(schemas: JSONSchema7[], ctx: GoCodegenCtx): JSONSchema7[] {
2131 const seen = new Set<string>();

Callers 2

dedupeGoSchemasForMatchFunction · 0.85

Calls 2

resolveSchemaFunction · 0.85
stableStringifyFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…