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

Function pushGoJSONObjectMatchLines

scripts/codegen/go.ts:1270–1313  ·  view source on GitHub ↗
(
    lines: string[],
    schema: JSONSchema7,
    rawVar: string,
    ctx: GoCodegenCtx,
    indent: string,
    varPrefix: string
)

Source from the content-addressed store, hash-verified

1268}
1269
1270function pushGoJSONObjectMatchLines(
1271 lines: string[],
1272 schema: JSONSchema7,
1273 rawVar: string,
1274 ctx: GoCodegenCtx,
1275 indent: string,
1276 varPrefix: string
1277): void {
1278 const properties = schema.properties || {};
1279 const propertyNames = Object.keys(properties).sort();
1280 const required = [...new Set(schema.required || [])].sort();
1281
1282 for (const requiredProp of required) {
1283 lines.push(`${indent}if _, ok := ${rawVar}[${JSON.stringify(requiredProp)}]; !ok {`);
1284 lines.push(`${indent}\treturn false`);
1285 lines.push(`${indent}}`);
1286 }
1287
1288 if (schema.additionalProperties === false) {
1289 if (propertyNames.length === 0) {
1290 lines.push(`${indent}if len(${rawVar}) != 0 {`);
1291 lines.push(`${indent}\treturn false`);
1292 lines.push(`${indent}}`);
1293 } else {
1294 lines.push(`${indent}for key := range ${rawVar} {`);
1295 lines.push(`${indent}\tswitch key {`);
1296 lines.push(`${indent}\tcase ${propertyNames.map((propertyName) => JSON.stringify(propertyName)).join(", ")}:`);
1297 lines.push(`${indent}\tdefault:`);
1298 lines.push(`${indent}\t\treturn false`);
1299 lines.push(`${indent}\t}`);
1300 lines.push(`${indent}}`);
1301 }
1302 }
1303
1304 for (const [propName, propSchema] of Object.entries(properties).sort(([left], [right]) => left.localeCompare(right))) {
1305 if (typeof propSchema !== "object") continue;
1306 const prop = propSchema as JSONSchema7;
1307 if (!goSchemaNeedsJSONMatch(prop, ctx)) continue;
1308 const valueVar = `${varPrefix}${toGoFieldName(propName)}`;
1309 lines.push(`${indent}if ${valueVar}, ok := ${rawVar}[${JSON.stringify(propName)}]; ok {`);
1310 pushGoJSONSchemaMatchLines(lines, prop, valueVar, ctx, `${indent}\t`, valueVar);
1311 lines.push(`${indent}}`);
1312 }
1313}
1314
1315function pushGoJSONSchemaMatchLines(
1316 lines: string[],

Callers 1

Calls 5

goSchemaNeedsJSONMatchFunction · 0.85
toGoFieldNameFunction · 0.85
joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…