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

Function generateGoSessionEventsCode

scripts/codegen/go.ts:3105–3434  ·  view source on GitHub ↗
(
    schema: JSONSchema7,
    packageName: string,
    externalSchemas?: Record<string, JSONSchema7>
)

Source from the content-addressed store, hash-verified

3103 * Generate the complete Go session-events file content.
3104 */
3105export function generateGoSessionEventsCode(
3106 schema: JSONSchema7,
3107 packageName: string,
3108 externalSchemas?: Record<string, JSONSchema7>
3109): GoGeneratedTypeCode {
3110 const variants = extractGoEventVariants(schema);
3111 const ctx: GoCodegenCtx = {
3112 structs: [],
3113 encoding: [],
3114 enums: [],
3115 enumsByName: new Map(),
3116 discriminatedUnions: new Map(),
3117 generatedNames: new Set(),
3118 definitions: collectDefinitionCollections(schema as Record<string, unknown>),
3119 wrapComments: false,
3120 discriminatedUnionRawVariantSuffix: "",
3121 packageName,
3122 };
3123 registerGoExternalUnionUnmarshalers(schema, ctx, externalSchemas);
3124 const envelopeProperties = getGoSharedEventEnvelopeProperties(schema, ctx);
3125 const sessionEventStructFields = [
3126 ...envelopeProperties.map((property) => ({
3127 fieldName: property.fieldName,
3128 lines: emitGoEnvelopeStructField(property, true, ctx.wrapComments !== false),
3129 })),
3130 {
3131 fieldName: "Data",
3132 lines: [
3133 ...goCommentLines("Typed event payload. Use a type switch to access per-event fields.", "\t", ctx.wrapComments !== false),
3134 `\tData SessionEventData \`json:"-"\``,
3135 ],
3136 },
3137 ].sort((left, right) => compareGoFieldNames(left.fieldName, right.fieldName));
3138 const rawEventUnmarshalFields = [
3139 ...envelopeProperties.map((property) => ({
3140 fieldName: property.fieldName,
3141 lines: emitGoEnvelopeStructField(property, false, ctx.wrapComments !== false),
3142 })),
3143 { fieldName: "Data", lines: [`\tData json.RawMessage \`json:"data"\``] },
3144 { fieldName: "Type", lines: [`\tType SessionEventType \`json:"type"\``] },
3145 ].sort((left, right) => compareGoFieldNames(left.fieldName, right.fieldName));
3146 const rawEventMarshalFields = [
3147 ...envelopeProperties.map((property) => ({
3148 fieldName: property.fieldName,
3149 lines: emitGoEnvelopeStructField(property, false, ctx.wrapComments !== false),
3150 })),
3151 { fieldName: "Data", lines: [`\tData any \`json:"data"\``] },
3152 { fieldName: "Type", lines: [`\tType SessionEventType \`json:"type"\``] },
3153 ].sort((left, right) => compareGoFieldNames(left.fieldName, right.fieldName));
3154
3155 // Generate per-event data structs
3156 const dataStructs: string[] = [];
3157 for (const variant of variants) {
3158 const required = new Set(variant.dataSchema.required || []);
3159 const lines: string[] = [];
3160
3161 if (variant.dataDescription) {
3162 pushGoCommentForContext(lines, variant.dataDescription, ctx);

Callers 2

generateSessionEventsFunction · 0.85

Calls 15

extractGoEventVariantsFunction · 0.85
goCommentLinesFunction · 0.85
compareGoFieldNamesFunction · 0.85
pushGoCommentForContextFunction · 0.85
isSchemaExperimentalFunction · 0.85
sortByGoFieldNameFunction · 0.85
toGoFieldNameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…