(
variant: EventVariant,
packageName: string,
packageDir: string
)
| 955 | } |
| 956 | |
| 957 | async function generateEventVariantClass( |
| 958 | variant: EventVariant, |
| 959 | packageName: string, |
| 960 | packageDir: string |
| 961 | ): Promise<void> { |
| 962 | const lines: string[] = []; |
| 963 | const allImports = new Set<string>([ |
| 964 | "com.fasterxml.jackson.annotation.JsonIgnoreProperties", |
| 965 | "com.fasterxml.jackson.annotation.JsonProperty", |
| 966 | "com.fasterxml.jackson.annotation.JsonInclude", |
| 967 | "javax.annotation.processing.Generated", |
| 968 | ]); |
| 969 | const nestedTypes = new Map<string, JavaClassDef>(); |
| 970 | |
| 971 | // Collect data record fields |
| 972 | interface FieldInfo { |
| 973 | jsonName: string; |
| 974 | javaName: string; |
| 975 | javaType: string; |
| 976 | description?: string; |
| 977 | } |
| 978 | |
| 979 | const dataFields: FieldInfo[] = []; |
| 980 | |
| 981 | if (variant.dataSchema?.properties) { |
| 982 | for (const [propName, propSchema] of Object.entries(variant.dataSchema.properties)) { |
| 983 | if (typeof propSchema !== "object") continue; |
| 984 | const prop = propSchema as JSONSchema7; |
| 985 | // Record components are always boxed (nullable by design). |
| 986 | const result = schemaTypeToJava(prop, false, `${variant.className}Data`, propName, nestedTypes); |
| 987 | for (const imp of result.imports) allImports.add(imp); |
| 988 | dataFields.push({ |
| 989 | jsonName: propName, |
| 990 | javaName: toCamelCase(propName), |
| 991 | javaType: result.javaType, |
| 992 | description: prop.description, |
| 993 | }); |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | // Whether a data record should be emitted (always when dataSchema is present) |
| 998 | const hasDataSchema = variant.dataSchema !== null; |
| 999 | |
| 1000 | // Build the file |
| 1001 | lines.push(COPYRIGHT); |
| 1002 | lines.push(""); |
| 1003 | lines.push(AUTO_GENERATED_HEADER); |
| 1004 | lines.push(GENERATED_FROM_SESSION_EVENTS); |
| 1005 | lines.push(""); |
| 1006 | lines.push(`package ${packageName};`); |
| 1007 | lines.push(""); |
| 1008 | |
| 1009 | // Placeholder for imports |
| 1010 | const importPlaceholderIdx = lines.length; |
| 1011 | lines.push("__IMPORTS__"); |
| 1012 | lines.push(""); |
| 1013 | |
| 1014 | if (variant.description) { |
no test coverage detected
searching dependent graphs…