@@ -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 ) ) {
0 commit comments