(typeName: string, schema: JSONSchema7, ctx: GoCodegenCtx, includeWrapper: boolean = false)
| 2763 | } |
| 2764 | |
| 2765 | function planGoUnion(typeName: string, schema: JSONSchema7, ctx: GoCodegenCtx, includeWrapper: boolean = false): GoUnionPlan | undefined { |
| 2766 | const members = goNonNullUnionMembers(schema); |
| 2767 | if (members.length === 0) return undefined; |
| 2768 | |
| 2769 | const description = (schema as JSONSchema7).description; |
| 2770 | const discriminator = findGoDiscriminator(members, ctx, typeName); |
| 2771 | if (discriminator) { |
| 2772 | return { kind: "discriminated", typeName, schema, description, discriminator }; |
| 2773 | } |
| 2774 | |
| 2775 | const primitiveVariants = goPrimitiveUnionVariants(typeName, schema, ctx); |
| 2776 | if (primitiveVariants) { |
| 2777 | return { kind: "primitive", typeName, schema, description, variants: primitiveVariants }; |
| 2778 | } |
| 2779 | |
| 2780 | if (goUnionHasExternalRef(members)) { |
| 2781 | return includeWrapper ? { kind: "wrapper", typeName, schema, description } : undefined; |
| 2782 | } |
| 2783 | |
| 2784 | const requiredFieldDiscriminator = findGoRequiredFieldDiscriminator(members, ctx, typeName); |
| 2785 | if (requiredFieldDiscriminator) { |
| 2786 | return { kind: "requiredFieldDiscriminated", typeName, schema, description, discriminator: requiredFieldDiscriminator }; |
| 2787 | } |
| 2788 | |
| 2789 | const resolvedVariants = members.map((member) => resolveGoUnionMember(member, ctx.definitions)); |
| 2790 | if (canFlattenGoObjectUnion(resolvedVariants, ctx)) { |
| 2791 | return { kind: "flattenedObject", typeName, schema, description, variants: resolvedVariants }; |
| 2792 | } |
| 2793 | |
| 2794 | const untaggedVariants = goUntaggedUnionVariants(typeName, schema, ctx); |
| 2795 | if (untaggedVariants) { |
| 2796 | return { kind: "untagged", typeName, schema, description, variants: untaggedVariants }; |
| 2797 | } |
| 2798 | |
| 2799 | return includeWrapper ? { kind: "wrapper", typeName, schema, description } : undefined; |
| 2800 | } |
| 2801 | |
| 2802 | function emitGoUnionPlan(plan: GoUnionPlan, ctx: GoCodegenCtx): void { |
| 2803 | switch (plan.kind) { |
no test coverage detected
searching dependent graphs…