* Derive the Java result type for an RPC method. * Handles $ref to named definitions (enums, anyOf unions, objects with properties, arrays). * Falls back to Void for null results or schemas with no meaningful type.
(method: RpcMethodNode)
| 1549 | * Falls back to Void for null results or schemas with no meaningful type. |
| 1550 | */ |
| 1551 | function wrapperResultClassName(method: RpcMethodNode): string { |
| 1552 | const originalResult = method.result; |
| 1553 | if (!originalResult) return "Void"; |
| 1554 | |
| 1555 | // If result is a $ref, use the definition name directly |
| 1556 | const refName = extractRefName(originalResult); |
| 1557 | if (refName) { |
| 1558 | const resolved = currentDefinitions[refName]; |
| 1559 | if (resolved) { |
| 1560 | // String enum → use the definition name |
| 1561 | if (resolved.type === "string" && resolved.enum) { |
| 1562 | return refName; |
| 1563 | } |
| 1564 | // anyOf discriminated union → use the definition name |
| 1565 | if (resolved.anyOf && Array.isArray(resolved.anyOf)) { |
| 1566 | const variants = resolveAnyOfVariants(resolved.anyOf as JSONSchema7[]); |
| 1567 | if (variants.length > 1 && findDiscriminator(variants)) { |
| 1568 | return refName; |
| 1569 | } |
| 1570 | } |
| 1571 | // Object with properties → use MethodNameResult |
| 1572 | if (resolved.type === "object" && resolved.properties && Object.keys(resolved.properties).length > 0) { |
| 1573 | return rpcMethodToClassName(method.rpcMethod) + "Result"; |
| 1574 | } |
| 1575 | // Empty object (no properties) that is a named definition → use definition name |
| 1576 | if (resolved.type === "object" && !resolved.properties) { |
| 1577 | return refName; |
| 1578 | } |
| 1579 | // Named array aliases → use the underlying List<T> Java type. |
| 1580 | if (resolved.type === "array") { |
| 1581 | const result = schemaTypeToJava(resolved, false, refName, "item", new Map()); |
| 1582 | return result.javaType; |
| 1583 | } |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | // Inline result schema with properties |
| 1588 | let result = originalResult; |
| 1589 | if (result.$ref) result = resolveRef(result) as JSONSchema7; |
| 1590 | if ( |
| 1591 | result && |
| 1592 | typeof result === "object" && |
| 1593 | result.properties && |
| 1594 | Object.keys(result.properties).length > 0 |
| 1595 | ) { |
| 1596 | return rpcMethodToClassName(method.rpcMethod) + "Result"; |
| 1597 | } |
| 1598 | |
| 1599 | if (result && typeof result === "object" && result.type === "array") { |
| 1600 | const javaResult = schemaTypeToJava(result, false, `${rpcMethodToClassName(method.rpcMethod)}Result`, "item", new Map()); |
| 1601 | return javaResult.javaType; |
| 1602 | } |
| 1603 | |
| 1604 | // Free-form object with additionalProperties (e.g., x-opaque-json) → JsonNode |
| 1605 | if ( |
| 1606 | result && |
| 1607 | typeof result === "object" && |
| 1608 | result.type === "object" && |
no test coverage detected
searching dependent graphs…