Skip to content

Commit a112b53

Browse files
committed
Revert "Fix review comments: getRpc() IllegalStateException, UnknownSessionEvent wire type, anyOf heuristic, remove unused var"
This reverts commit ef1de83.
1 parent ef1de83 commit a112b53

File tree

6 files changed

+11
-66
lines changed

6 files changed

+11
-66
lines changed

scripts/codegen/java.ts

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,10 @@ function schemaTypeToJava(
115115
}
116116
// When exactly two non-null types and one of them is string, prefer String
117117
// over Object to avoid unnecessary type erasure on common wire-level unions
118-
// (e.g., string | null, string | boolean). For string | object keep Object
119-
// so downstream code is not forced to cast. For wider unions keep Object.
118+
// (e.g., string | null, string | boolean). For wider unions keep Object.
120119
if (nonNull.length === 2) {
121120
const hasString = nonNull.some((s) => typeof s === "object" && (s as JSONSchema7).type === "string");
122-
const hasObject = nonNull.some((s) => typeof s === "object" && (s as JSONSchema7).type === "object");
123-
if (hasString && !hasObject) {
121+
if (hasString) {
124122
return { javaType: "String", imports };
125123
}
126124
}
@@ -310,7 +308,7 @@ async function generateSessionEventBaseClass(
310308
lines.push(` */`);
311309
lines.push(`@JsonIgnoreProperties(ignoreUnknown = true)`);
312310
lines.push(`@JsonInclude(JsonInclude.Include.NON_NULL)`);
313-
lines.push(`@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true, defaultImpl = UnknownSessionEvent.class)`);
311+
lines.push(`@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = UnknownSessionEvent.class)`);
314312
lines.push(`@JsonSubTypes({`);
315313
for (let i = 0; i < variants.length; i++) {
316314
const v = variants[i];
@@ -380,46 +378,20 @@ async function generateUnknownEventClass(packageName: string, packageDir: string
380378
lines.push("");
381379
lines.push(`package ${packageName};`);
382380
lines.push("");
383-
lines.push(`import com.fasterxml.jackson.annotation.JsonIgnore;`);
384381
lines.push(`import com.fasterxml.jackson.annotation.JsonIgnoreProperties;`);
385-
lines.push(`import com.fasterxml.jackson.annotation.JsonProperty;`);
386382
lines.push(`import javax.annotation.processing.Generated;`);
387383
lines.push("");
388384
lines.push(`/**`);
389385
lines.push(` * Fallback for event types not yet known to this SDK version.`);
390386
lines.push(` *`);
391-
lines.push(` * <p>The {@link #getOriginalType()} method returns the raw event-type discriminator`);
392-
lines.push(` * value received on the wire, which can be used for forward-compatibility`);
393-
lines.push(` * telemetry and handling.`);
394-
lines.push(` *`);
395387
lines.push(` * @since 1.0.0`);
396388
lines.push(` */`);
397389
lines.push(`@JsonIgnoreProperties(ignoreUnknown = true)`);
398390
lines.push(GENERATED_ANNOTATION);
399391
lines.push(`public final class UnknownSessionEvent extends SessionEvent {`);
400392
lines.push("");
401-
lines.push(` @JsonProperty("type")`);
402-
lines.push(` private String originalType;`);
403-
lines.push("");
404-
lines.push(` /**`);
405-
lines.push(` * Returns the raw event-type discriminator string received on the wire,`);
406-
lines.push(` * or {@code "unknown"} if the value was not present in the JSON payload.`);
407-
lines.push(` *`);
408-
lines.push(` * @return the original wire type string, or {@code "unknown"}`);
409-
lines.push(` */`);
410393
lines.push(` @Override`);
411-
lines.push(` @JsonProperty("type")`);
412-
lines.push(` public String getType() { return originalType != null ? originalType : "unknown"; }`);
413-
lines.push("");
414-
lines.push(` /**`);
415-
lines.push(` * Returns the raw event-type discriminator string received on the wire.`);
416-
lines.push(` *`);
417-
lines.push(` * @return the original wire type string, or {@code null} if not present`);
418-
lines.push(` */`);
419-
lines.push(` @JsonIgnore`);
420-
lines.push(` public String getOriginalType() { return originalType; }`);
421-
lines.push("");
422-
lines.push(` public void setOriginalType(String originalType) { this.originalType = originalType; }`);
394+
lines.push(` public String getType() { return "unknown"; }`);
423395
lines.push(`}`);
424396
lines.push("");
425397

@@ -458,6 +430,7 @@ function renderNestedType(nested: JavaClassDef, indentLevel: number, nestedTypes
458430
lines.push(`${ind}}`);
459431
} else if (nested.kind === "class" && nested.schema?.properties) {
460432
const localNestedTypes = new Map<string, JavaClassDef>();
433+
const requiredSet = new Set(nested.schema.required || []);
461434
const fields: { jsonName: string; javaName: string; javaType: string; description?: string }[] = [];
462435

463436
for (const [propName, propSchema] of Object.entries(nested.schema.properties)) {

src/generated/java/com/github/copilot/sdk/generated/SessionEvent.java

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generated/java/com/github/copilot/sdk/generated/UnknownSessionEvent.java

Lines changed: 1 addition & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/github/copilot/sdk/CopilotSession.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ public SessionUiApi getUi() {
299299
*/
300300
public SessionRpc getRpc() {
301301
if (rpc == null) {
302-
throw new IllegalStateException(
303-
"Session is not connected or initialized: getRpc() requires an active session.");
302+
return null;
304303
}
305304
SessionRpc current = sessionRpc;
306305
if (current == null) {

src/test/java/com/github/copilot/sdk/ForwardCompatibilityTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void parse_unknownEventType_returnsUnknownSessionEvent() throws Exception {
5353
SessionEvent result = MAPPER.readValue(json, SessionEvent.class);
5454

5555
assertInstanceOf(UnknownSessionEvent.class, result);
56-
assertEquals("future.feature_from_server", result.getType());
56+
assertEquals("unknown", result.getType());
5757
}
5858

5959
@Test
@@ -69,8 +69,7 @@ void parse_unknownEventType_preservesOriginalType() throws Exception {
6969
SessionEvent result = MAPPER.readValue(json, SessionEvent.class);
7070

7171
assertInstanceOf(UnknownSessionEvent.class, result);
72-
assertEquals("future.feature_from_server", result.getType());
73-
assertEquals("future.feature_from_server", ((UnknownSessionEvent) result).getOriginalType());
72+
assertEquals("unknown", result.getType());
7473
}
7574

7675
@Test

src/test/java/com/github/copilot/sdk/SessionEventDeserializationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ void testParseUnknownEventType() throws Exception {
844844
assertNotNull(event, "Unknown event types should return an UnknownSessionEvent");
845845
assertInstanceOf(com.github.copilot.sdk.generated.UnknownSessionEvent.class, event,
846846
"Unknown event types should return UnknownSessionEvent for forward compatibility");
847-
assertEquals("unknown.event.type", event.getType());
847+
assertEquals("unknown", event.getType());
848848
}
849849

850850
@Test

0 commit comments

Comments
 (0)