* Generate a single variant subclass of a polymorphic result type.
(
className: string,
schema: JSONSchema7,
discriminatorValue: string,
discriminatorProperty: string,
baseClassName: string,
packageName: string,
packageDir: string
)
| 401 | * Generate a single variant subclass of a polymorphic result type. |
| 402 | */ |
| 403 | async function generatePolymorphicVariantClass( |
| 404 | className: string, |
| 405 | schema: JSONSchema7, |
| 406 | discriminatorValue: string, |
| 407 | discriminatorProperty: string, |
| 408 | baseClassName: string, |
| 409 | packageName: string, |
| 410 | packageDir: string |
| 411 | ): Promise<void> { |
| 412 | const allImports = new Set<string>([ |
| 413 | "com.fasterxml.jackson.annotation.JsonIgnoreProperties", |
| 414 | "com.fasterxml.jackson.annotation.JsonInclude", |
| 415 | "com.fasterxml.jackson.annotation.JsonProperty", |
| 416 | "javax.annotation.processing.Generated", |
| 417 | ]); |
| 418 | const nestedTypes = new Map<string, JavaClassDef>(); |
| 419 | |
| 420 | // Collect fields (excluding the discriminator property) |
| 421 | interface FieldInfo { |
| 422 | jsonName: string; |
| 423 | javaName: string; |
| 424 | javaType: string; |
| 425 | description?: string; |
| 426 | } |
| 427 | |
| 428 | const fields: FieldInfo[] = []; |
| 429 | if (schema.properties) { |
| 430 | for (const [propName, propSchema] of Object.entries(schema.properties)) { |
| 431 | if (propName === discriminatorProperty) continue; |
| 432 | if (typeof propSchema !== "object") continue; |
| 433 | const prop = propSchema as JSONSchema7; |
| 434 | const result = schemaTypeToJava(prop, false, className, propName, nestedTypes); |
| 435 | for (const imp of result.imports) allImports.add(imp); |
| 436 | fields.push({ |
| 437 | jsonName: propName, |
| 438 | javaName: toCamelCase(propName), |
| 439 | javaType: result.javaType, |
| 440 | description: prop.description, |
| 441 | }); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | const lines: string[] = []; |
| 446 | lines.push(COPYRIGHT); |
| 447 | lines.push(""); |
| 448 | lines.push(AUTO_GENERATED_HEADER); |
| 449 | lines.push(GENERATED_FROM_API); |
| 450 | lines.push(""); |
| 451 | lines.push(`package ${packageName};`); |
| 452 | lines.push(""); |
| 453 | |
| 454 | // Placeholder for imports |
| 455 | const importPlaceholderIdx = lines.length; |
| 456 | lines.push("__IMPORTS__"); |
| 457 | lines.push(""); |
| 458 | |
| 459 | if (schema.description) { |
| 460 | lines.push(`/**`); |
no test coverage detected
searching dependent graphs…