(schemaPath: string)
| 1309 | } |
| 1310 | |
| 1311 | async function generateRpcTypes(schemaPath: string): Promise<void> { |
| 1312 | console.log("\n🔌 Generating RPC types..."); |
| 1313 | const schemaContent = await fs.readFile(schemaPath, "utf-8"); |
| 1314 | const schema = normalizeSchemaBrandCasing(JSON.parse(schemaContent)) as Record<string, unknown> & { |
| 1315 | server?: Record<string, unknown>; |
| 1316 | session?: Record<string, unknown>; |
| 1317 | clientSession?: Record<string, unknown>; |
| 1318 | clientGlobal?: Record<string, unknown>; |
| 1319 | definitions?: Record<string, JSONSchema7>; |
| 1320 | }; |
| 1321 | |
| 1322 | // Set module-level definitions for $ref resolution |
| 1323 | currentDefinitions = (schema.definitions ?? {}) as Record<string, JSONSchema7>; |
| 1324 | pendingStandaloneTypes.clear(); |
| 1325 | crossSchemaDefinitions.clear(); |
| 1326 | |
| 1327 | // Load cross-schema definitions (session-events) so that cross-schema $ref values |
| 1328 | // like "session-events.schema.json#/definitions/Foo" can be resolved. |
| 1329 | try { |
| 1330 | const sessionEventsSchemaPath = await getSessionEventsSchemaPath(); |
| 1331 | const sessionEventsContent = await fs.readFile(sessionEventsSchemaPath, "utf-8"); |
| 1332 | const sessionEventsSchema = normalizeSchemaBrandCasing(JSON.parse(sessionEventsContent) as JSONSchema7); |
| 1333 | crossSchemaDefinitions.set("session-events.schema.json", |
| 1334 | (sessionEventsSchema.definitions ?? {}) as Record<string, JSONSchema7>); |
| 1335 | } catch (e) { |
| 1336 | console.warn(`[codegen] Could not load session-events schema for cross-ref resolution: ${e}`); |
| 1337 | } |
| 1338 | |
| 1339 | const packageName = "com.github.copilot.generated.rpc"; |
| 1340 | const packageDir = `src/generated/java/com/github/copilot/generated/rpc`; |
| 1341 | |
| 1342 | // Collect all RPC methods from all sections |
| 1343 | const sections: [string, Record<string, unknown>][] = []; |
| 1344 | if (schema.server) sections.push(["server", schema.server]); |
| 1345 | if (schema.session) sections.push(["session", schema.session]); |
| 1346 | if (schema.clientSession) sections.push(["clientSession", schema.clientSession]); |
| 1347 | if (schema.clientGlobal) sections.push(["clientGlobal", schema.clientGlobal]); |
| 1348 | |
| 1349 | const generatedClasses = new Map<string, boolean>(); |
| 1350 | const allFiles: string[] = []; |
| 1351 | |
| 1352 | for (const [sectionName, sectionNode] of sections) { |
| 1353 | const methods = collectRpcMethods(sectionNode); |
| 1354 | for (const [, method] of methods) { |
| 1355 | const className = rpcMethodToClassName(method.rpcMethod); |
| 1356 | |
| 1357 | // Generate params class — resolve $ref if params is a reference |
| 1358 | let paramsSchema = method.params as JSONSchema7 | null; |
| 1359 | const paramsRefName = extractRefName(paramsSchema); |
| 1360 | if (paramsRefName && sectionName === "clientGlobal") { |
| 1361 | const resolvedParamsSchema = resolveRef(paramsSchema ?? undefined); |
| 1362 | if (resolvedParamsSchema?.type === "object" && resolvedParamsSchema.properties) { |
| 1363 | pendingStandaloneTypes.set(paramsRefName, resolvedParamsSchema); |
| 1364 | } |
| 1365 | paramsSchema = null; |
| 1366 | } else if (paramsSchema?.$ref) { |
| 1367 | paramsSchema = resolveRef(paramsSchema) as JSONSchema7; |
| 1368 | } |
no test coverage detected
searching dependent graphs…