( ast: AST.AST, $defs: Record<string, JsonSchema7>, identifier: "handle-identifier" | "ignore-identifier", path: ReadonlyArray<PropertyKey>, options: GoOptions, annotation: "handle-annotation" | "ignore-annotation", errors: "handle-errors" | "ignore-errors" )
| 636 | } |
| 637 | |
| 638 | function go( |
| 639 | ast: AST.AST, |
| 640 | $defs: Record<string, JsonSchema7>, |
| 641 | identifier: "handle-identifier" | "ignore-identifier", |
| 642 | path: ReadonlyArray<PropertyKey>, |
| 643 | options: GoOptions, |
| 644 | annotation: "handle-annotation" | "ignore-annotation", |
| 645 | errors: "handle-errors" | "ignore-errors" |
| 646 | ): JsonSchema7 { |
| 647 | if ( |
| 648 | identifier === "handle-identifier" && |
| 649 | (options.topLevelReferenceStrategy !== "skip" || AST.isSuspend(ast)) |
| 650 | ) { |
| 651 | const id = getIdentifierAnnotation(ast) |
| 652 | if (id !== undefined) { |
| 653 | const escapedId = id.replace(/~/ig, "~0").replace(/\//ig, "~1") |
| 654 | const out = { $ref: options.getRef(escapedId) } |
| 655 | if (!Record.has($defs, id)) { |
| 656 | $defs[id] = out |
| 657 | $defs[id] = go(ast, $defs, "ignore-identifier", path, options, "handle-annotation", errors) |
| 658 | } |
| 659 | return out |
| 660 | } |
| 661 | } |
| 662 | if (annotation === "handle-annotation") { |
| 663 | const hook = AST.getJSONSchemaAnnotation(ast) |
| 664 | if (Option.isSome(hook)) { |
| 665 | const handler = hook.value as JsonSchema7 |
| 666 | if (isOverrideAnnotation(ast, handler)) { |
| 667 | switch (ast._tag) { |
| 668 | case "Declaration": |
| 669 | return addASTAnnotations(handler, ast) |
| 670 | default: |
| 671 | return handler |
| 672 | } |
| 673 | } else { |
| 674 | switch (ast._tag) { |
| 675 | case "Refinement": { |
| 676 | const t = AST.getTransformationFrom(ast) |
| 677 | if (t === undefined) { |
| 678 | return mergeRefinements( |
| 679 | go(ast.from, $defs, identifier, path, options, "handle-annotation", errors), |
| 680 | handler, |
| 681 | ast |
| 682 | ) |
| 683 | } else { |
| 684 | return go(t, $defs, identifier, path, options, "handle-annotation", errors) |
| 685 | } |
| 686 | } |
| 687 | default: |
| 688 | return { |
| 689 | ...go(ast, $defs, identifier, path, options, "ignore-annotation", errors), |
| 690 | ...handler |
| 691 | } as any |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | } |
no test coverage detected