MCPcopy Index your code
hub / github.com/github/copilot-sdk / planGoUnion

Function planGoUnion

scripts/codegen/go.ts:2765–2800  ·  view source on GitHub ↗
(typeName: string, schema: JSONSchema7, ctx: GoCodegenCtx, includeWrapper: boolean = false)

Source from the content-addressed store, hash-verified

2763}
2764
2765function 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
2802function emitGoUnionPlan(plan: GoUnionPlan, ctx: GoCodegenCtx): void {
2803 switch (plan.kind) {

Callers 4

resolveGoPropertyTypeFunction · 0.85
emitGoUnionStructFunction · 0.85
emitGoRpcDefinitionFunction · 0.85

Calls 8

goNonNullUnionMembersFunction · 0.85
findGoDiscriminatorFunction · 0.85
goPrimitiveUnionVariantsFunction · 0.85
goUnionHasExternalRefFunction · 0.85
resolveGoUnionMemberFunction · 0.85
canFlattenGoObjectUnionFunction · 0.85
goUntaggedUnionVariantsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…