* 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, )
| 628 | * side effects into ctx. |
| 629 | */ |
| 630 | function 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", |
no test coverage detected
searching dependent graphs…