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

Function goUntaggedUnionVariant

scripts/codegen/go.ts:2634–2690  ·  view source on GitHub ↗
(typeName: string, member: JSONSchema7, ctx: GoCodegenCtx)

Source from the content-addressed store, hash-verified

2632}
2633
2634function goUntaggedUnionVariant(typeName: string, member: JSONSchema7, ctx: GoCodegenCtx): GoUntaggedUnionVariant | undefined {
2635 const jsonKind = goSchemaJSONKind(member, ctx);
2636 if (!jsonKind) return undefined;
2637
2638 const resolved = resolveGoUnionMember(member, ctx.definitions);
2639 if (member.$ref && typeof member.$ref === "string") {
2640 const definitionName = refTypeName(member.$ref, ctx.definitions);
2641 const variantTypeName = goDefinitionName(definitionName);
2642 emitGoRpcDefinition(definitionName, resolved, ctx);
2643 return {
2644 typeName: variantTypeName,
2645 goType: variantTypeName,
2646 jsonKind,
2647 returnExpr: goObjectUnionMemberSchema(member, ctx) ? "&value" : "value",
2648 };
2649 }
2650
2651 if (resolved.enum && Array.isArray(resolved.enum)) {
2652 const enumType = getOrCreateGoEnum((resolved.title as string) || `${typeName}Enum`, resolved.enum as string[], ctx, resolved.description, getEnumValueDescriptions(resolved), isSchemaDeprecated(resolved));
2653 return { typeName: enumType, goType: enumType, jsonKind, returnExpr: "value" };
2654 }
2655
2656 const primitiveValueName = goPrimitiveUnionValueName(member, ctx);
2657 const primitiveGoType = goPrimitiveUnionGoType(member, ctx);
2658 if (primitiveValueName && primitiveGoType) {
2659 const variantTypeName = goPrimitiveUnionVariantTypeName(typeName, primitiveValueName);
2660 return {
2661 typeName: variantTypeName,
2662 goType: primitiveGoType,
2663 jsonKind,
2664 typeDefinition: `type ${variantTypeName} ${primitiveGoType}`,
2665 returnExpr: `${variantTypeName}(value)`,
2666 };
2667 }
2668
2669 if (jsonKind === "object" && resolved.type === "object" && resolved.additionalProperties && !resolved.properties) {
2670 const fieldName = goUnionFieldName(resolved, ctx);
2671 const variantTypeName = `${typeName}${fieldName}`;
2672 const goType = resolveGoPropertyType(resolved, typeName, fieldName, true, ctx);
2673 if (!goTypeIsMap(goType)) return undefined;
2674 return {
2675 typeName: variantTypeName,
2676 goType: variantTypeName,
2677 jsonKind,
2678 typeDefinition: `type ${variantTypeName} ${goType}`,
2679 returnExpr: "value",
2680 };
2681 }
2682
2683 if (jsonKind === "object" && (resolved.properties || resolved.additionalProperties === false)) {
2684 const variantTypeName = (resolved.title as string) || `${typeName}Object`;
2685 emitGoStruct(variantTypeName, resolved, ctx);
2686 return { typeName: variantTypeName, goType: variantTypeName, jsonKind, returnExpr: "&value" };
2687 }
2688
2689 return undefined;
2690}
2691

Callers 1

goUntaggedUnionVariantsFunction · 0.85

Calls 15

goSchemaJSONKindFunction · 0.85
resolveGoUnionMemberFunction · 0.85
refTypeNameFunction · 0.85
goDefinitionNameFunction · 0.85
emitGoRpcDefinitionFunction · 0.85
getOrCreateGoEnumFunction · 0.85
getEnumValueDescriptionsFunction · 0.85
isSchemaDeprecatedFunction · 0.85
goPrimitiveUnionGoTypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…