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

Function findRustDiscriminator

scripts/codegen/rust.ts:247–285  ·  view source on GitHub ↗
(variants: RustUnionVariant[])

Source from the content-addressed store, hash-verified

245}
246
247function findRustDiscriminator(variants: RustUnionVariant[]): string | null {
248 const first = variants[0]?.schema;
249 if (!isObjectSchema(first) || !first.properties) return null;
250
251 for (const [propName, propSchema] of Object.entries(first.properties).sort(
252 ([a], [b]) => a.localeCompare(b),
253 )) {
254 if (typeof propSchema !== "object") continue;
255 if ((propSchema as JSONSchema7).const === undefined) continue;
256
257 const values = new Set<string>();
258 let isValid = true;
259 for (const { schema } of variants) {
260 if (!isObjectSchema(schema) || !schema.properties) {
261 isValid = false;
262 break;
263 }
264 const candidate = schema.properties[propName];
265 if (typeof candidate !== "object") {
266 isValid = false;
267 break;
268 }
269 const value = (candidate as JSONSchema7).const;
270 if (value === undefined) {
271 isValid = false;
272 break;
273 }
274 const key = String(value);
275 if (values.has(key)) {
276 isValid = false;
277 break;
278 }
279 values.add(key);
280 }
281 if (isValid) return propName;
282 }
283
284 return null;
285}
286
287function tryEmitRustUnion(
288 schema: JSONSchema7,

Callers 1

tryEmitRustUnionFunction · 0.85

Calls 3

isObjectSchemaFunction · 0.85
StringFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…