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

Function generateApiTypesCode

scripts/codegen/rust.ts:1398–1647  ·  view source on GitHub ↗
(
	apiSchema: ApiSchema,
	nonDefaultableTypes: Iterable<string> = [],
)

Source from the content-addressed store, hash-verified

1396}
1397
1398function generateApiTypesCode(
1399 apiSchema: ApiSchema,
1400 nonDefaultableTypes: Iterable<string> = [],
1401): string {
1402 const definitions = collectDefinitions(apiSchema as Record<string, unknown>);
1403 const defCollections = collectDefinitionCollections(
1404 apiSchema as Record<string, unknown>,
1405 );
1406 const ctx = makeCtx(defCollections, { nonDefaultableTypes });
1407
1408 // Collect all RPC methods before emitting shared definitions so method stability
1409 // can propagate to referenced data types.
1410 const methodEntries: { method: RpcMethod; isSession: boolean }[] = [];
1411 for (const { group, isSession } of [
1412 { group: apiSchema.server, isSession: false },
1413 { group: apiSchema.session, isSession: true },
1414 { group: apiSchema.clientSession, isSession: false },
1415 ]) {
1416 if (group) {
1417 methodEntries.push(
1418 ...collectRpcMethods(group as Record<string, unknown>).map((method) => ({
1419 method,
1420 isSession,
1421 })),
1422 );
1423 }
1424 }
1425 const allMethods = methodEntries.map(({ method }) => method);
1426 const inlineMethodParamSchemas = new Map<string, JSONSchema7>();
1427 const sortedNames = (names: Iterable<string> | undefined): string[] =>
1428 [...(names ?? [])].sort();
1429 const schemaPropertyNames = (schema: JSONSchema7): string[] =>
1430 sortedNames(Object.keys(schema.properties ?? {}));
1431 const shouldPreferMethodParamSchema = (
1432 typeName: string,
1433 paramsSchema: JSONSchema7,
1434 ): boolean => {
1435 const definition = definitions[typeName];
1436 if (typeof definition !== "object" || definition === null) return false;
1437 const definitionSchema = asGeneratedObjectSchema(
1438 definition as JSONSchema7,
1439 defCollections,
1440 );
1441 if (!definitionSchema) return false;
1442
1443 return (
1444 JSON.stringify(schemaPropertyNames(paramsSchema)) !==
1445 JSON.stringify(schemaPropertyNames(definitionSchema)) ||
1446 JSON.stringify(sortedNames(paramsSchema.required)) !==
1447 JSON.stringify(sortedNames(definitionSchema.required))
1448 );
1449 };
1450 for (const { method, isSession } of methodEntries) {
1451 const params = method.params as (JSONSchema7 & { $ref?: string }) | undefined;
1452 if (!params || typeof params.$ref === "string") continue;
1453 const paramsSchema = getMethodParamsObjectSchema(
1454 method,
1455 defCollections,

Callers 1

generateFunction · 0.85

Calls 15

collectDefinitionsFunction · 0.85
makeCtxFunction · 0.85
rustParamsTypeNameFunction · 0.85
asGeneratedObjectSchemaFunction · 0.85
isVoidSchemaFunction · 0.85
rustResultTypeNameFunction · 0.85
emitRustStringEnumFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…