Skip to content

Commit 7e5dc8d

Browse files
authored
Edburns/ghcp 1573 java ensure zod metadata shows thru (#1591)
* feat(java): emit @deprecated and @APinote from schema stability/deprecated metadata - Add deprecated field to RpcMethod, RpcMethodNode, and EventVariant interfaces - Emit @deprecated annotation on classes/methods where deprecated=true - Emit @APinote Javadoc on event classes, RPC wrapper methods, and params/result classes where stability=experimental - Regenerate all 914 generated files with updated metadata * Move import of JSONSchema7
1 parent 0a25600 commit 7e5dc8d

423 files changed

Lines changed: 343 additions & 125 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

java/scripts/codegen/java.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
*/
99

1010
import fs from "fs/promises";
11+
import type { JSONSchema7 } from "json-schema";
1112
import path from "path";
1213
import { fileURLToPath } from "url";
13-
import type { JSONSchema7 } from "json-schema";
1414

1515
const __filename = fileURLToPath(import.meta.url);
1616
const __dirname = path.dirname(__filename);
@@ -663,6 +663,8 @@ interface EventVariant {
663663
className: string;
664664
dataSchema: JSONSchema7 | null;
665665
description?: string;
666+
stability?: string;
667+
deprecated?: boolean;
666668
}
667669

668670
function extractEventVariants(schema: JSONSchema7): EventVariant[] {
@@ -694,6 +696,8 @@ function extractEventVariants(schema: JSONSchema7): EventVariant[] {
694696
className: `${baseName}Event`,
695697
dataSchema: dataSchema ?? null,
696698
description: resolved.description,
699+
stability: (variant as unknown as Record<string, unknown>).stability as string | undefined,
700+
deprecated: (variant as unknown as Record<string, unknown>).deprecated === true,
697701
};
698702
})
699703
.filter((v) => !EXCLUDED_EVENT_TYPES.has(v.typeName));
@@ -985,15 +989,18 @@ async function generateEventVariantClass(
985989
if (variant.description) {
986990
lines.push(`/**`);
987991
lines.push(` * ${variant.description}`);
988-
lines.push(` *`);
989-
lines.push(` * @since 1.0.0`);
990-
lines.push(` */`);
991992
} else {
992993
lines.push(`/**`);
993994
lines.push(` * The {@code ${variant.typeName}} session event.`);
995+
}
996+
if (variant.stability === "experimental") {
994997
lines.push(` *`);
995-
lines.push(` * @since 1.0.0`);
996-
lines.push(` */`);
998+
lines.push(` * @apiNote This method is experimental and may change in a future version.`);
999+
}
1000+
lines.push(` * @since 1.0.0`);
1001+
lines.push(` */`);
1002+
if (variant.deprecated) {
1003+
lines.push(`@Deprecated`);
9971004
}
9981005
lines.push(`@JsonIgnoreProperties(ignoreUnknown = true)`);
9991006
lines.push(`@JsonInclude(JsonInclude.Include.NON_NULL)`);
@@ -1197,6 +1204,7 @@ interface RpcMethod {
11971204
params: JSONSchema7 | null;
11981205
result: JSONSchema7 | null;
11991206
stability?: string;
1207+
deprecated?: boolean;
12001208
}
12011209

12021210
function isRpcMethod(node: unknown): node is RpcMethod {
@@ -1322,7 +1330,7 @@ async function generateRpcTypes(schemaPath: string): Promise<void> {
13221330
const paramsClassName = `${className}Params`;
13231331
if (!generatedClasses.has(paramsClassName)) {
13241332
generatedClasses.set(paramsClassName, true);
1325-
allFiles.push(await generateRpcDataClass(paramsClassName, paramsSchema, packageName, packageDir, method.rpcMethod, "params"));
1333+
allFiles.push(await generateRpcDataClass(paramsClassName, paramsSchema, packageName, packageDir, method.rpcMethod, "params", method.stability, method.deprecated === true));
13261334
}
13271335
}
13281336

@@ -1336,7 +1344,7 @@ async function generateRpcTypes(schemaPath: string): Promise<void> {
13361344
const resultClassName = `${className}Result`;
13371345
if (!generatedClasses.has(resultClassName)) {
13381346
generatedClasses.set(resultClassName, true);
1339-
allFiles.push(await generateRpcDataClass(resultClassName, resultSchema, packageName, packageDir, method.rpcMethod, "result"));
1347+
allFiles.push(await generateRpcDataClass(resultClassName, resultSchema, packageName, packageDir, method.rpcMethod, "result", method.stability, method.deprecated === true));
13401348
}
13411349
} else if (resultRefName && resultSchema.type === "string" && resultSchema.enum) {
13421350
// String enum → register for standalone generation
@@ -1373,7 +1381,9 @@ async function generateRpcDataClass(
13731381
packageName: string,
13741382
packageDir: string,
13751383
rpcMethod: string,
1376-
kind: "params" | "result"
1384+
kind: "params" | "result",
1385+
stability?: string,
1386+
deprecated?: boolean
13771387
): Promise<string> {
13781388
const nestedTypes = new Map<string, { code: string }>();
13791389
const { code, imports } = generateRpcClass(className, schema, nestedTypes, packageName);
@@ -1403,15 +1413,18 @@ async function generateRpcDataClass(
14031413
if (schema.description) {
14041414
lines.push(`/**`);
14051415
lines.push(` * ${schema.description}`);
1406-
lines.push(` *`);
1407-
lines.push(` * @since 1.0.0`);
1408-
lines.push(` */`);
14091416
} else {
14101417
lines.push(`/**`);
14111418
lines.push(` * ${kind === "params" ? "Request parameters" : "Result"} for the {@code ${rpcMethod}} RPC method.`);
1419+
}
1420+
if (stability === "experimental") {
14121421
lines.push(` *`);
1413-
lines.push(` * @since 1.0.0`);
1414-
lines.push(` */`);
1422+
lines.push(` * @apiNote This method is experimental and may change in a future version.`);
1423+
}
1424+
lines.push(` * @since 1.0.0`);
1425+
lines.push(` */`);
1426+
if (deprecated) {
1427+
lines.push(`@Deprecated`);
14151428
}
14161429
lines.push(GENERATED_ANNOTATION);
14171430
lines.push(code);
@@ -1427,6 +1440,7 @@ async function generateRpcDataClass(
14271440
interface RpcMethodNode {
14281441
rpcMethod: string;
14291442
stability: string;
1443+
deprecated: boolean;
14301444
params: JSONSchema7 | null;
14311445
result: JSONSchema7 | null;
14321446
}
@@ -1447,6 +1461,7 @@ function buildNamespaceTree(node: Record<string, unknown>): NamespaceTree {
14471461
tree.methods.set(key, {
14481462
rpcMethod: String(obj.rpcMethod),
14491463
stability: String(obj.stability ?? "stable"),
1464+
deprecated: obj.deprecated === true,
14501465
params: (obj.params as JSONSchema7) ?? null,
14511466
result: (obj.result as JSONSchema7) ?? null,
14521467
});
@@ -1588,6 +1603,9 @@ function generateApiMethod(
15881603
}
15891604
lines.push(` * @since 1.0.0`);
15901605
lines.push(` */`);
1606+
if (method.deprecated) {
1607+
lines.push(` @Deprecated`);
1608+
}
15911609

15921610
// Signature
15931611
if (hasExtraParams) {

java/src/generated/java/com/github/copilot/generated/AbortEvent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/**
1616
* Session event "abort". Turn abort information including the reason for termination
17-
*
1817
* @since 1.0.0
1918
*/
2019
@JsonIgnoreProperties(ignoreUnknown = true)

java/src/generated/java/com/github/copilot/generated/AssistantIntentEvent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/**
1616
* Session event "assistant.intent". Agent intent description for current activity or plan
17-
*
1817
* @since 1.0.0
1918
*/
2019
@JsonIgnoreProperties(ignoreUnknown = true)

java/src/generated/java/com/github/copilot/generated/AssistantMessageDeltaEvent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/**
1616
* Session event "assistant.message_delta". Streaming assistant message delta for incremental response updates
17-
*
1817
* @since 1.0.0
1918
*/
2019
@JsonIgnoreProperties(ignoreUnknown = true)

java/src/generated/java/com/github/copilot/generated/AssistantMessageEvent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
/**
1717
* Session event "assistant.message". Assistant response containing text content, optional tool requests, and interaction metadata
18-
*
1918
* @since 1.0.0
2019
*/
2120
@JsonIgnoreProperties(ignoreUnknown = true)

java/src/generated/java/com/github/copilot/generated/AssistantMessageStartEvent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/**
1616
* Session event "assistant.message_start". Streaming assistant message start metadata
17-
*
1817
* @since 1.0.0
1918
*/
2019
@JsonIgnoreProperties(ignoreUnknown = true)

java/src/generated/java/com/github/copilot/generated/AssistantReasoningDeltaEvent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/**
1616
* Session event "assistant.reasoning_delta". Streaming reasoning delta for incremental extended thinking updates
17-
*
1817
* @since 1.0.0
1918
*/
2019
@JsonIgnoreProperties(ignoreUnknown = true)

java/src/generated/java/com/github/copilot/generated/AssistantReasoningEvent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/**
1616
* Session event "assistant.reasoning". Assistant reasoning content for timeline display with complete thinking text
17-
*
1817
* @since 1.0.0
1918
*/
2019
@JsonIgnoreProperties(ignoreUnknown = true)

java/src/generated/java/com/github/copilot/generated/AssistantStreamingDeltaEvent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/**
1616
* Session event "assistant.streaming_delta". Streaming response progress with cumulative byte count
17-
*
1817
* @since 1.0.0
1918
*/
2019
@JsonIgnoreProperties(ignoreUnknown = true)

java/src/generated/java/com/github/copilot/generated/AssistantTurnEndEvent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/**
1616
* Session event "assistant.turn_end". Turn completion metadata including the turn identifier
17-
*
1817
* @since 1.0.0
1918
*/
2019
@JsonIgnoreProperties(ignoreUnknown = true)

0 commit comments

Comments
 (0)