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

Function resolveRustType

scripts/codegen/rust.ts:630–842  ·  view source on GitHub ↗

* Map a JSON Schema to a Rust type string. Emits nested type definitions as * side effects into ctx.

(
	propSchema: JSONSchema7,
	parentTypeName: string,
	jsonPropName: string,
	isRequired: boolean,
	ctx: RustCodegenCtx,
)

Source from the content-addressed store, hash-verified

628 * side effects into ctx.
629 */
630function resolveRustType(
631 propSchema: JSONSchema7,
632 parentTypeName: string,
633 jsonPropName: string,
634 isRequired: boolean,
635 ctx: RustCodegenCtx,
636): string {
637 const nestedName = parentTypeName + toPascalCase(jsonPropName);
638
639 // $ref — resolve and recurse
640 if (propSchema.$ref && typeof propSchema.$ref === "string") {
641 recordExternalRustTypeRef(propSchema.$ref, ctx);
642 const typeName = rustRefTypeName(propSchema.$ref, ctx.definitions);
643 const resolved = resolveRef(propSchema.$ref, ctx.definitions);
644 if (resolved) {
645 if (resolved.enum) {
646 emitRustStringEnum(
647 typeName,
648 resolved.enum as string[],
649 ctx,
650 resolved.description,
651 getEnumValueDescriptions(resolved),
652 isSchemaExperimental(resolved),
653 );
654 return wrapOption(typeName, isRequired);
655 }
656 if (isObjectSchema(resolved)) {
657 emitRustStruct(typeName, resolved, ctx);
658 return wrapOption(typeName, isRequired);
659 }
660 return resolveRustType(
661 resolved,
662 parentTypeName,
663 jsonPropName,
664 isRequired,
665 ctx,
666 );
667 }
668 return wrapOption(typeName, isRequired);
669 }
670
671 // anyOf — nullable pattern or union
672 if (propSchema.anyOf) {
673 const unionType = tryEmitRustUnion(
674 propSchema,
675 parentTypeName,
676 jsonPropName,
677 ctx,
678 );
679 if (unionType) {
680 return wrapOption(unionType, isRequired);
681 }
682
683 const nonNull = (propSchema.anyOf as JSONSchema7[]).filter(
684 (s) => s.type !== "null",
685 );
686 const hasNull = (propSchema.anyOf as JSONSchema7[]).some(
687 (s) => s.type === "null",

Callers 3

rustArrayTypeFunction · 0.85
rustMapValueTypeFunction · 0.85
emitRustStructFunction · 0.85

Calls 15

rustRefTypeNameFunction · 0.85
emitRustStringEnumFunction · 0.85
getEnumValueDescriptionsFunction · 0.85
isSchemaExperimentalFunction · 0.85
wrapOptionFunction · 0.85
isObjectSchemaFunction · 0.85
emitRustStructFunction · 0.85
tryEmitRustUnionFunction · 0.85
resolveObjectSchemaFunction · 0.85
emitRustConstStringEnumFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…