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

Function extractEventVariants

scripts/codegen/rust.ts:1066–1113  ·  view source on GitHub ↗
(schema: JSONSchema7)

Source from the content-addressed store, hash-verified

1064}
1065
1066function extractEventVariants(schema: JSONSchema7): EventVariant[] {
1067 const definitionCollections = collectDefinitionCollections(
1068 schema as Record<string, unknown>,
1069 );
1070 const sessionEvent =
1071 resolveSchema(
1072 { $ref: "#/definitions/SessionEvent" },
1073 definitionCollections,
1074 ) ?? resolveSchema({ $ref: "#/$defs/SessionEvent" }, definitionCollections);
1075 if (!sessionEvent?.anyOf)
1076 throw new Error("Schema must have SessionEvent definition with anyOf");
1077
1078 return (sessionEvent.anyOf as JSONSchema7[])
1079 .map((variant) => {
1080 const resolvedVariant =
1081 resolveObjectSchema(variant as JSONSchema7, definitionCollections) ??
1082 resolveSchema(variant as JSONSchema7, definitionCollections) ??
1083 (variant as JSONSchema7);
1084 if (typeof resolvedVariant !== "object" || !resolvedVariant.properties) {
1085 throw new Error("Invalid variant");
1086 }
1087 const typeSchema = resolvedVariant.properties.type as JSONSchema7;
1088 const typeName = typeSchema?.const as string;
1089 if (!typeName) throw new Error("Variant must have type.const");
1090
1091 const dataSchema =
1092 resolveObjectSchema(
1093 resolvedVariant.properties.data as JSONSchema7,
1094 definitionCollections,
1095 ) ??
1096 resolveSchema(
1097 resolvedVariant.properties.data as JSONSchema7,
1098 definitionCollections,
1099 ) ??
1100 ((resolvedVariant.properties.data as JSONSchema7) || {});
1101
1102 return {
1103 typeName,
1104 variantName: toPascalCase(typeName),
1105 dataClassName: `${toPascalCase(typeName)}Data`,
1106 dataSchema,
1107 description: resolvedVariant.description || dataSchema.description,
1108 eventExperimental: isSchemaExperimental(resolvedVariant),
1109 dataExperimental: isSchemaExperimental(dataSchema),
1110 };
1111 })
1112 .filter((v) => !EXCLUDED_EVENT_TYPES.has(v.typeName));
1113}
1114
1115export function generateSessionEventsCode(schema: JSONSchema7): string {
1116 const variants = extractEventVariants(schema);

Callers 1

Calls 5

resolveSchemaFunction · 0.85
resolveObjectSchemaFunction · 0.85
isSchemaExperimentalFunction · 0.85
toPascalCaseFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…