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

Function collectGoSharedSessionEventAliasNames

scripts/codegen/go.ts:3514–3559  ·  view source on GitHub ↗
(
    sharedDefinitionNames: Iterable<string>,
    apiSchema: ApiSchema
)

Source from the content-addressed store, hash-verified

3512}
3513
3514function collectGoSharedSessionEventAliasNames(
3515 sharedDefinitionNames: Iterable<string>,
3516 apiSchema: ApiSchema
3517): { typeNames: string[]; constNames: string[] } {
3518 const apiDefinitions = collectDefinitionCollections(apiSchema as Record<string, unknown>);
3519 const definitions = { ...apiDefinitions.$defs, ...apiDefinitions.definitions };
3520 const typeNames = new Set<string>();
3521 const constNames = new Set<string>();
3522
3523 for (const definitionName of sharedDefinitionNames) {
3524 const typeName = toGoFieldName(definitionName);
3525 typeNames.add(typeName);
3526
3527 const definition = definitions[definitionName];
3528 if (!definition || typeof definition !== "object" || Array.isArray(definition)) continue;
3529
3530 const schema = definition as JSONSchema7;
3531 const values = isStringEnumDefinition(schema)
3532 ? schema.enum
3533 : typeof schema.const === "string"
3534 ? [schema.const]
3535 : undefined;
3536 for (const value of values ?? []) {
3537 constNames.add(`${typeName}${goEnumConstSuffix(value)}`);
3538 }
3539
3540 // Detect anyOf unions with a string-const discriminator property. The
3541 // api/rpc generator synthesizes an enum (named `<TypeName><DiscProp>`)
3542 // and per-variant consts for these (e.g. `Attachment` → `AttachmentType`
3543 // + `AttachmentTypeFile`, ...). They aren't top-level $defs, so we have
3544 // to surface them explicitly here so the public `copilot` alias file
3545 // re-exports them alongside the union and its variant structs.
3546 const synthesized = collectGoSharedAnyOfDiscriminatorAliasNames(typeName, schema, definitions);
3547 if (synthesized) {
3548 typeNames.add(synthesized.enumName);
3549 for (const constName of synthesized.constNames) {
3550 constNames.add(constName);
3551 }
3552 }
3553 }
3554
3555 return {
3556 typeNames: [...typeNames].sort(compareGoTypeNames),
3557 constNames: [...constNames].sort(compareGoTypeNames),
3558 };
3559}
3560
3561/**
3562 * For a shared definition that is an `anyOf` discriminated union with a

Callers 1

generateSessionEventsFunction · 0.85

Calls 6

toGoFieldNameFunction · 0.85
isStringEnumDefinitionFunction · 0.85
goEnumConstSuffixFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…