openapi-typesafe 0.0.0 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +71 -1
- package/bin/cli.js +4 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +46 -0
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -0
- package/dist/adapters/node-file-system/node-file-system.mjs +40 -0
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -0
- package/dist/adapters/redocly-loader/alias-limit.cjs +16 -0
- package/dist/adapters/redocly-loader/alias-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/alias-limit.mjs +14 -0
- package/dist/adapters/redocly-loader/alias-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/allowed-hosts.cjs +42 -0
- package/dist/adapters/redocly-loader/allowed-hosts.cjs.map +1 -0
- package/dist/adapters/redocly-loader/allowed-hosts.mjs +40 -0
- package/dist/adapters/redocly-loader/allowed-hosts.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +53 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +51 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -0
- package/dist/adapters/redocly-loader/malformed-refs.cjs +41 -0
- package/dist/adapters/redocly-loader/malformed-refs.cjs.map +1 -0
- package/dist/adapters/redocly-loader/malformed-refs.mjs +38 -0
- package/dist/adapters/redocly-loader/malformed-refs.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-config-source.cjs +61 -0
- package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-config-source.mjs +54 -0
- package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +179 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +177 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-access.cjs +107 -0
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-access.mjs +99 -0
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-holders.cjs +31 -0
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-holders.mjs +29 -0
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +60 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.mjs +56 -0
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +87 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +77 -0
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-source.cjs +104 -0
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-source.mjs +98 -0
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -0
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +62 -0
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -0
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +58 -0
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -0
- package/dist/adapters/terminal-logger/terminal-logger.cjs +67 -0
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -0
- package/dist/adapters/terminal-logger/terminal-logger.mjs +59 -0
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/footer-nodes.cjs +21 -0
- package/dist/adapters/type-ast-bridge/footer-nodes.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/footer-nodes.mjs +17 -0
- package/dist/adapters/type-ast-bridge/footer-nodes.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/ir-declarations-to-typescript.cjs +75 -0
- package/dist/adapters/type-ast-bridge/ir-declarations-to-typescript.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/ir-declarations-to-typescript.mjs +71 -0
- package/dist/adapters/type-ast-bridge/ir-declarations-to-typescript.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs +148 -0
- package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +142 -0
- package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/lazy-node.cjs +23 -0
- package/dist/adapters/type-ast-bridge/lazy-node.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/lazy-node.mjs +21 -0
- package/dist/adapters/type-ast-bridge/lazy-node.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/load-typescript.cjs +57 -0
- package/dist/adapters/type-ast-bridge/load-typescript.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/load-typescript.mjs +51 -0
- package/dist/adapters/type-ast-bridge/load-typescript.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/print-typescript.cjs +21 -0
- package/dist/adapters/type-ast-bridge/print-typescript.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/print-typescript.mjs +19 -0
- package/dist/adapters/type-ast-bridge/print-typescript.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/typescript-raw-text.cjs +33 -0
- package/dist/adapters/type-ast-bridge/typescript-raw-text.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/typescript-raw-text.mjs +29 -0
- package/dist/adapters/type-ast-bridge/typescript-raw-text.mjs.map +1 -0
- package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs +210 -0
- package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs +207 -0
- package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs.map +1 -0
- package/dist/api/ast-to-string.cjs +39 -0
- package/dist/api/ast-to-string.cjs.map +1 -0
- package/dist/api/ast-to-string.mjs +37 -0
- package/dist/api/ast-to-string.mjs.map +1 -0
- package/dist/api/comment-header.cjs +11 -0
- package/dist/api/comment-header.cjs.map +1 -0
- package/dist/api/comment-header.mjs +9 -0
- package/dist/api/comment-header.mjs.map +1 -0
- package/dist/api/default-ports.cjs +38 -0
- package/dist/api/default-ports.cjs.map +1 -0
- package/dist/api/default-ports.mjs +28 -0
- package/dist/api/default-ports.mjs.map +1 -0
- package/dist/api/discriminator-conflict-warnings.cjs +25 -0
- package/dist/api/discriminator-conflict-warnings.cjs.map +1 -0
- package/dist/api/discriminator-conflict-warnings.mjs +23 -0
- package/dist/api/discriminator-conflict-warnings.mjs.map +1 -0
- package/dist/api/discriminator-enum-names.cjs +19 -0
- package/dist/api/discriminator-enum-names.cjs.map +1 -0
- package/dist/api/discriminator-enum-names.mjs +17 -0
- package/dist/api/discriminator-enum-names.mjs.map +1 -0
- package/dist/api/discriminator-enum-parent.cjs +59 -0
- package/dist/api/discriminator-enum-parent.cjs.map +1 -0
- package/dist/api/discriminator-enum-parent.mjs +57 -0
- package/dist/api/discriminator-enum-parent.mjs.map +1 -0
- package/dist/api/discriminator-enum.cjs +69 -0
- package/dist/api/discriminator-enum.cjs.map +1 -0
- package/dist/api/discriminator-enum.mjs +66 -0
- package/dist/api/discriminator-enum.mjs.map +1 -0
- package/dist/api/discriminator-other-owners.cjs +67 -0
- package/dist/api/discriminator-other-owners.cjs.map +1 -0
- package/dist/api/discriminator-other-owners.mjs +64 -0
- package/dist/api/discriminator-other-owners.mjs.map +1 -0
- package/dist/api/discriminator-patch.cjs +88 -0
- package/dist/api/discriminator-patch.cjs.map +1 -0
- package/dist/api/discriminator-patch.mjs +82 -0
- package/dist/api/discriminator-patch.mjs.map +1 -0
- package/dist/api/discriminator-scan.cjs +153 -0
- package/dist/api/discriminator-scan.cjs.map +1 -0
- package/dist/api/discriminator-scan.mjs +150 -0
- package/dist/api/discriminator-scan.mjs.map +1 -0
- package/dist/api/document-declarations.cjs +28 -0
- package/dist/api/document-declarations.cjs.map +1 -0
- package/dist/api/document-declarations.mjs +26 -0
- package/dist/api/document-declarations.mjs.map +1 -0
- package/dist/api/document-refs.cjs +53 -0
- package/dist/api/document-refs.cjs.map +1 -0
- package/dist/api/document-refs.mjs +50 -0
- package/dist/api/document-refs.mjs.map +1 -0
- package/dist/api/document-run.cjs +122 -0
- package/dist/api/document-run.cjs.map +1 -0
- package/dist/api/document-run.mjs +116 -0
- package/dist/api/document-run.mjs.map +1 -0
- package/dist/api/enum-values-warnings.cjs +16 -0
- package/dist/api/enum-values-warnings.cjs.map +1 -0
- package/dist/api/enum-values-warnings.mjs +14 -0
- package/dist/api/enum-values-warnings.mjs.map +1 -0
- package/dist/api/footer-entry.cjs +18 -0
- package/dist/api/footer-entry.cjs.map +1 -0
- package/dist/api/footer-entry.mjs +15 -0
- package/dist/api/footer-entry.mjs.map +1 -0
- package/dist/api/footer-sink.cjs +53 -0
- package/dist/api/footer-sink.cjs.map +1 -0
- package/dist/api/footer-sink.mjs +51 -0
- package/dist/api/footer-sink.mjs.map +1 -0
- package/dist/api/legacy-callback-warning.cjs +25 -0
- package/dist/api/legacy-callback-warning.cjs.map +1 -0
- package/dist/api/legacy-callback-warning.mjs +22 -0
- package/dist/api/legacy-callback-warning.mjs.map +1 -0
- package/dist/api/legacy-ts-helpers.cjs +203 -0
- package/dist/api/legacy-ts-helpers.cjs.map +1 -0
- package/dist/api/legacy-ts-helpers.mjs +187 -0
- package/dist/api/legacy-ts-helpers.mjs.map +1 -0
- package/dist/api/legacy-utils.cjs +65 -0
- package/dist/api/legacy-utils.cjs.map +1 -0
- package/dist/api/legacy-utils.mjs +50 -0
- package/dist/api/legacy-utils.mjs.map +1 -0
- package/dist/api/openapi-ts.cjs +40 -0
- package/dist/api/openapi-ts.cjs.map +1 -0
- package/dist/api/openapi-ts.mjs +34 -0
- package/dist/api/openapi-ts.mjs.map +1 -0
- package/dist/api/path-template-warnings.cjs +21 -0
- package/dist/api/path-template-warnings.cjs.map +1 -0
- package/dist/api/path-template-warnings.mjs +19 -0
- package/dist/api/path-template-warnings.mjs.map +1 -0
- package/dist/api/schema-callbacks.cjs +140 -0
- package/dist/api/schema-callbacks.cjs.map +1 -0
- package/dist/api/schema-callbacks.mjs +136 -0
- package/dist/api/schema-callbacks.mjs.map +1 -0
- package/dist/api/string-to-ast.cjs +21 -0
- package/dist/api/string-to-ast.cjs.map +1 -0
- package/dist/api/string-to-ast.mjs +18 -0
- package/dist/api/string-to-ast.mjs.map +1 -0
- package/dist/api/transform-context.cjs +84 -0
- package/dist/api/transform-context.cjs.map +1 -0
- package/dist/api/transform-context.mjs +67 -0
- package/dist/api/transform-context.mjs.map +1 -0
- package/dist/api/transform-schema.cjs +80 -0
- package/dist/api/transform-schema.cjs.map +1 -0
- package/dist/api/transform-schema.mjs +75 -0
- package/dist/api/transform-schema.mjs.map +1 -0
- package/dist/api/type-helpers.cjs +85 -0
- package/dist/api/type-helpers.cjs.map +1 -0
- package/dist/api/type-helpers.mjs +66 -0
- package/dist/api/type-helpers.mjs.map +1 -0
- package/dist/api/unsupported-feature-warnings.cjs +22 -0
- package/dist/api/unsupported-feature-warnings.cjs.map +1 -0
- package/dist/api/unsupported-feature-warnings.mjs +20 -0
- package/dist/api/unsupported-feature-warnings.mjs.map +1 -0
- package/dist/application/print/comment-writer.cjs +95 -0
- package/dist/application/print/comment-writer.cjs.map +1 -0
- package/dist/application/print/comment-writer.mjs +93 -0
- package/dist/application/print/comment-writer.mjs.map +1 -0
- package/dist/application/print/declaration-printer.cjs +83 -0
- package/dist/application/print/declaration-printer.cjs.map +1 -0
- package/dist/application/print/declaration-printer.mjs +81 -0
- package/dist/application/print/declaration-printer.mjs.map +1 -0
- package/dist/application/print/literal-text.cjs +52 -0
- package/dist/application/print/literal-text.cjs.map +1 -0
- package/dist/application/print/literal-text.mjs +48 -0
- package/dist/application/print/literal-text.mjs.map +1 -0
- package/dist/application/print/print-nodes.cjs +38 -0
- package/dist/application/print/print-nodes.cjs.map +1 -0
- package/dist/application/print/print-nodes.mjs +36 -0
- package/dist/application/print/print-nodes.mjs.map +1 -0
- package/dist/application/print/print-options.cjs +6 -0
- package/dist/application/print/print-options.cjs.map +1 -0
- package/dist/application/print/print-options.mjs +4 -0
- package/dist/application/print/print-options.mjs.map +1 -0
- package/dist/application/print/text-writer.cjs +63 -0
- package/dist/application/print/text-writer.cjs.map +1 -0
- package/dist/application/print/text-writer.mjs +60 -0
- package/dist/application/print/text-writer.mjs.map +1 -0
- package/dist/application/print/type-printer.cjs +219 -0
- package/dist/application/print/type-printer.cjs.map +1 -0
- package/dist/application/print/type-printer.mjs +215 -0
- package/dist/application/print/type-printer.mjs.map +1 -0
- package/dist/application/stack-overflow.cjs +36 -0
- package/dist/application/stack-overflow.cjs.map +1 -0
- package/dist/application/stack-overflow.mjs +31 -0
- package/dist/application/stack-overflow.mjs.map +1 -0
- package/dist/application/transform/document/assignability.cjs +144 -0
- package/dist/application/transform/document/assignability.cjs.map +1 -0
- package/dist/application/transform/document/assignability.mjs +138 -0
- package/dist/application/transform/document/assignability.mjs.map +1 -0
- package/dist/application/transform/document/components.cjs +104 -0
- package/dist/application/transform/document/components.cjs.map +1 -0
- package/dist/application/transform/document/components.mjs +102 -0
- package/dist/application/transform/document/components.mjs.map +1 -0
- package/dist/application/transform/document/declared-types.cjs +66 -0
- package/dist/application/transform/document/declared-types.cjs.map +1 -0
- package/dist/application/transform/document/declared-types.mjs +63 -0
- package/dist/application/transform/document/declared-types.mjs.map +1 -0
- package/dist/application/transform/document/defs-root.cjs +18 -0
- package/dist/application/transform/document/defs-root.cjs.map +1 -0
- package/dist/application/transform/document/defs-root.mjs +16 -0
- package/dist/application/transform/document/defs-root.mjs.map +1 -0
- package/dist/application/transform/document/document-member.cjs +13 -0
- package/dist/application/transform/document/document-member.cjs.map +1 -0
- package/dist/application/transform/document/document-member.mjs +11 -0
- package/dist/application/transform/document/document-member.mjs.map +1 -0
- package/dist/application/transform/document/document.cjs +109 -0
- package/dist/application/transform/document/document.cjs.map +1 -0
- package/dist/application/transform/document/document.mjs +106 -0
- package/dist/application/transform/document/document.mjs.map +1 -0
- package/dist/application/transform/document/exploded-query.cjs +46 -0
- package/dist/application/transform/document/exploded-query.cjs.map +1 -0
- package/dist/application/transform/document/exploded-query.mjs +43 -0
- package/dist/application/transform/document/exploded-query.mjs.map +1 -0
- package/dist/application/transform/document/global-type-references.cjs +63 -0
- package/dist/application/transform/document/global-type-references.cjs.map +1 -0
- package/dist/application/transform/document/global-type-references.mjs +61 -0
- package/dist/application/transform/document/global-type-references.mjs.map +1 -0
- package/dist/application/transform/document/header.cjs +27 -0
- package/dist/application/transform/document/header.cjs.map +1 -0
- package/dist/application/transform/document/header.mjs +25 -0
- package/dist/application/transform/document/header.mjs.map +1 -0
- package/dist/application/transform/document/kept-deprecated.cjs +96 -0
- package/dist/application/transform/document/kept-deprecated.cjs.map +1 -0
- package/dist/application/transform/document/kept-deprecated.mjs +94 -0
- package/dist/application/transform/document/kept-deprecated.mjs.map +1 -0
- package/dist/application/transform/document/list-assignability.cjs +54 -0
- package/dist/application/transform/document/list-assignability.cjs.map +1 -0
- package/dist/application/transform/document/list-assignability.mjs +52 -0
- package/dist/application/transform/document/list-assignability.mjs.map +1 -0
- package/dist/application/transform/document/media-type.cjs +42 -0
- package/dist/application/transform/document/media-type.cjs.map +1 -0
- package/dist/application/transform/document/media-type.mjs +38 -0
- package/dist/application/transform/document/media-type.mjs.map +1 -0
- package/dist/application/transform/document/operation.cjs +45 -0
- package/dist/application/transform/document/operation.cjs.map +1 -0
- package/dist/application/transform/document/operation.mjs +43 -0
- package/dist/application/transform/document/operation.mjs.map +1 -0
- package/dist/application/transform/document/parameter.cjs +25 -0
- package/dist/application/transform/document/parameter.cjs.map +1 -0
- package/dist/application/transform/document/parameter.mjs +23 -0
- package/dist/application/transform/document/parameter.mjs.map +1 -0
- package/dist/application/transform/document/parameters.cjs +146 -0
- package/dist/application/transform/document/parameters.cjs.map +1 -0
- package/dist/application/transform/document/parameters.mjs +144 -0
- package/dist/application/transform/document/parameters.mjs.map +1 -0
- package/dist/application/transform/document/path-item.cjs +82 -0
- package/dist/application/transform/document/path-item.cjs.map +1 -0
- package/dist/application/transform/document/path-item.mjs +80 -0
- package/dist/application/transform/document/path-item.mjs.map +1 -0
- package/dist/application/transform/document/path-key-overlaps.cjs +107 -0
- package/dist/application/transform/document/path-key-overlaps.cjs.map +1 -0
- package/dist/application/transform/document/path-key-overlaps.mjs +105 -0
- package/dist/application/transform/document/path-key-overlaps.mjs.map +1 -0
- package/dist/application/transform/document/path-template-replace.cjs +48 -0
- package/dist/application/transform/document/path-template-replace.cjs.map +1 -0
- package/dist/application/transform/document/path-template-replace.mjs +45 -0
- package/dist/application/transform/document/path-template-replace.mjs.map +1 -0
- package/dist/application/transform/document/paths-enum.cjs +75 -0
- package/dist/application/transform/document/paths-enum.cjs.map +1 -0
- package/dist/application/transform/document/paths-enum.mjs +72 -0
- package/dist/application/transform/document/paths-enum.mjs.map +1 -0
- package/dist/application/transform/document/paths.cjs +153 -0
- package/dist/application/transform/document/paths.cjs.map +1 -0
- package/dist/application/transform/document/paths.mjs +149 -0
- package/dist/application/transform/document/paths.mjs.map +1 -0
- package/dist/application/transform/document/request-body.cjs +36 -0
- package/dist/application/transform/document/request-body.cjs.map +1 -0
- package/dist/application/transform/document/request-body.mjs +34 -0
- package/dist/application/transform/document/request-body.mjs.map +1 -0
- package/dist/application/transform/document/response.cjs +59 -0
- package/dist/application/transform/document/response.cjs.map +1 -0
- package/dist/application/transform/document/response.mjs +57 -0
- package/dist/application/transform/document/response.mjs.map +1 -0
- package/dist/application/transform/document/responses.cjs +23 -0
- package/dist/application/transform/document/responses.cjs.map +1 -0
- package/dist/application/transform/document/responses.mjs +21 -0
- package/dist/application/transform/document/responses.mjs.map +1 -0
- package/dist/application/transform/document/root-type-aliases.cjs +70 -0
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -0
- package/dist/application/transform/document/root-type-aliases.mjs +67 -0
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -0
- package/dist/application/transform/document/template-key-match.cjs +128 -0
- package/dist/application/transform/document/template-key-match.cjs.map +1 -0
- package/dist/application/transform/document/template-key-match.mjs +125 -0
- package/dist/application/transform/document/template-key-match.mjs.map +1 -0
- package/dist/application/transform/document/type-assignability.cjs +192 -0
- package/dist/application/transform/document/type-assignability.cjs.map +1 -0
- package/dist/application/transform/document/type-assignability.mjs +190 -0
- package/dist/application/transform/document/type-assignability.mjs.map +1 -0
- package/dist/application/transform/document/type-key.cjs +70 -0
- package/dist/application/transform/document/type-key.cjs.map +1 -0
- package/dist/application/transform/document/type-key.mjs +68 -0
- package/dist/application/transform/document/type-key.mjs.map +1 -0
- package/dist/application/transform/document/type-resolution.cjs +131 -0
- package/dist/application/transform/document/type-resolution.cjs.map +1 -0
- package/dist/application/transform/document/type-resolution.mjs +125 -0
- package/dist/application/transform/document/type-resolution.mjs.map +1 -0
- package/dist/application/transform/document/webhooks.cjs +19 -0
- package/dist/application/transform/document/webhooks.cjs.map +1 -0
- package/dist/application/transform/document/webhooks.mjs +17 -0
- package/dist/application/transform/document/webhooks.mjs.map +1 -0
- package/dist/application/transform/document-entries.cjs +17 -0
- package/dist/application/transform/document-entries.cjs.map +1 -0
- package/dist/application/transform/document-entries.mjs +14 -0
- package/dist/application/transform/document-entries.mjs.map +1 -0
- package/dist/application/transform/footer/document-footer.cjs +150 -0
- package/dist/application/transform/footer/document-footer.cjs.map +1 -0
- package/dist/application/transform/footer/document-footer.mjs +148 -0
- package/dist/application/transform/footer/document-footer.mjs.map +1 -0
- package/dist/application/transform/footer/enum-naming.cjs +138 -0
- package/dist/application/transform/footer/enum-naming.cjs.map +1 -0
- package/dist/application/transform/footer/enum-naming.mjs +131 -0
- package/dist/application/transform/footer/enum-naming.mjs.map +1 -0
- package/dist/application/transform/footer/enum-values-check.cjs +129 -0
- package/dist/application/transform/footer/enum-values-check.cjs.map +1 -0
- package/dist/application/transform/footer/enum-values-check.mjs +127 -0
- package/dist/application/transform/footer/enum-values-check.mjs.map +1 -0
- package/dist/application/transform/footer/evaluation.cjs +33 -0
- package/dist/application/transform/footer/evaluation.cjs.map +1 -0
- package/dist/application/transform/footer/evaluation.mjs +26 -0
- package/dist/application/transform/footer/evaluation.mjs.map +1 -0
- package/dist/application/transform/footer/shared-enum-names.cjs +60 -0
- package/dist/application/transform/footer/shared-enum-names.cjs.map +1 -0
- package/dist/application/transform/footer/shared-enum-names.mjs +57 -0
- package/dist/application/transform/footer/shared-enum-names.mjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.cjs +246 -0
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.mjs +244 -0
- package/dist/application/transform/footer/type-evaluation.mjs.map +1 -0
- package/dist/application/transform/footer/type-rules.cjs +172 -0
- package/dist/application/transform/footer/type-rules.cjs.map +1 -0
- package/dist/application/transform/footer/type-rules.mjs +166 -0
- package/dist/application/transform/footer/type-rules.mjs.map +1 -0
- package/dist/application/transform/helper-types.cjs +68 -0
- package/dist/application/transform/helper-types.cjs.map +1 -0
- package/dist/application/transform/helper-types.mjs +65 -0
- package/dist/application/transform/helper-types.mjs.map +1 -0
- package/dist/application/transform/literal-type.cjs +36 -0
- package/dist/application/transform/literal-type.cjs.map +1 -0
- package/dist/application/transform/literal-type.mjs +34 -0
- package/dist/application/transform/literal-type.mjs.map +1 -0
- package/dist/application/transform/numbered-names.cjs +18 -0
- package/dist/application/transform/numbered-names.cjs.map +1 -0
- package/dist/application/transform/numbered-names.mjs +16 -0
- package/dist/application/transform/numbered-names.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/generated-location.cjs +138 -0
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/generated-location.mjs +136 -0
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/generated-shape.cjs +171 -0
- package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/generated-shape.mjs +162 -0
- package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/inline-cycles.cjs +44 -0
- package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/inline-cycles.mjs +42 -0
- package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/original-index.cjs +62 -0
- package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/original-index.mjs +60 -0
- package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/pointer-type.cjs +60 -0
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/pointer-type.mjs +57 -0
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/pointer-walk.cjs +66 -0
- package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/pointer-walk.mjs +56 -0
- package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/typed-walk.cjs +124 -0
- package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/typed-walk.mjs +122 -0
- package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -0
- package/dist/application/transform/ref-type.cjs +62 -0
- package/dist/application/transform/ref-type.cjs.map +1 -0
- package/dist/application/transform/ref-type.mjs +55 -0
- package/dist/application/transform/ref-type.mjs.map +1 -0
- package/dist/application/transform/schema/access-flags.cjs +38 -0
- package/dist/application/transform/schema/access-flags.cjs.map +1 -0
- package/dist/application/transform/schema/access-flags.mjs +36 -0
- package/dist/application/transform/schema/access-flags.mjs.map +1 -0
- package/dist/application/transform/schema/array-type.cjs +136 -0
- package/dist/application/transform/schema/array-type.cjs.map +1 -0
- package/dist/application/transform/schema/array-type.mjs +134 -0
- package/dist/application/transform/schema/array-type.mjs.map +1 -0
- package/dist/application/transform/schema/composition-type.cjs +142 -0
- package/dist/application/transform/schema/composition-type.cjs.map +1 -0
- package/dist/application/transform/schema/composition-type.mjs +140 -0
- package/dist/application/transform/schema/composition-type.mjs.map +1 -0
- package/dist/application/transform/schema/core-type.cjs +86 -0
- package/dist/application/transform/schema/core-type.cjs.map +1 -0
- package/dist/application/transform/schema/core-type.mjs +84 -0
- package/dist/application/transform/schema/core-type.mjs.map +1 -0
- package/dist/application/transform/schema/discriminated-union.cjs +30 -0
- package/dist/application/transform/schema/discriminated-union.cjs.map +1 -0
- package/dist/application/transform/schema/discriminated-union.mjs +27 -0
- package/dist/application/transform/schema/discriminated-union.mjs.map +1 -0
- package/dist/application/transform/schema/discriminator-property.cjs +22 -0
- package/dist/application/transform/schema/discriminator-property.cjs.map +1 -0
- package/dist/application/transform/schema/discriminator-property.mjs +20 -0
- package/dist/application/transform/schema/discriminator-property.mjs.map +1 -0
- package/dist/application/transform/schema/enum-rule.cjs +163 -0
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -0
- package/dist/application/transform/schema/enum-rule.mjs +160 -0
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -0
- package/dist/application/transform/schema/inherited-discriminator.cjs +29 -0
- package/dist/application/transform/schema/inherited-discriminator.cjs.map +1 -0
- package/dist/application/transform/schema/inherited-discriminator.mjs +26 -0
- package/dist/application/transform/schema/inherited-discriminator.mjs.map +1 -0
- package/dist/application/transform/schema/object-type.cjs +186 -0
- package/dist/application/transform/schema/object-type.cjs.map +1 -0
- package/dist/application/transform/schema/object-type.mjs +182 -0
- package/dist/application/transform/schema/object-type.mjs.map +1 -0
- package/dist/application/transform/schema/presence-members.cjs +59 -0
- package/dist/application/transform/schema/presence-members.cjs.map +1 -0
- package/dist/application/transform/schema/presence-members.mjs +57 -0
- package/dist/application/transform/schema/presence-members.mjs.map +1 -0
- package/dist/application/transform/schema/required-variants.cjs +45 -0
- package/dist/application/transform/schema/required-variants.cjs.map +1 -0
- package/dist/application/transform/schema/required-variants.mjs +42 -0
- package/dist/application/transform/schema/required-variants.mjs.map +1 -0
- package/dist/application/transform/schema/schema-transform.cjs +72 -0
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -0
- package/dist/application/transform/schema/schema-transform.mjs +68 -0
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -0
- package/dist/application/transform/schema/unevaluated-properties.cjs +61 -0
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -0
- package/dist/application/transform/schema/unevaluated-properties.mjs +59 -0
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -0
- package/dist/application/transform/schema-comment.cjs +130 -0
- package/dist/application/transform/schema-comment.cjs.map +1 -0
- package/dist/application/transform/schema-comment.mjs +125 -0
- package/dist/application/transform/schema-comment.mjs.map +1 -0
- package/dist/application/transform/shared-types.cjs +8 -0
- package/dist/application/transform/shared-types.cjs.map +1 -0
- package/dist/application/transform/shared-types.mjs +6 -0
- package/dist/application/transform/shared-types.mjs.map +1 -0
- package/dist/application/transform/type-combinators.cjs +49 -0
- package/dist/application/transform/type-combinators.cjs.map +1 -0
- package/dist/application/transform/type-combinators.mjs +42 -0
- package/dist/application/transform/type-combinators.mjs.map +1 -0
- package/dist/cli/cli-arguments.cjs +145 -0
- package/dist/cli/cli-arguments.cjs.map +1 -0
- package/dist/cli/cli-arguments.mjs +137 -0
- package/dist/cli/cli-arguments.mjs.map +1 -0
- package/dist/cli/cli-errors.cjs +81 -0
- package/dist/cli/cli-errors.cjs.map +1 -0
- package/dist/cli/cli-errors.mjs +77 -0
- package/dist/cli/cli-errors.mjs.map +1 -0
- package/dist/cli/cli-output.cjs +42 -0
- package/dist/cli/cli-output.cjs.map +1 -0
- package/dist/cli/cli-output.mjs +35 -0
- package/dist/cli/cli-output.mjs.map +1 -0
- package/dist/cli/docs-links.cjs +6 -0
- package/dist/cli/docs-links.cjs.map +1 -0
- package/dist/cli/docs-links.mjs +4 -0
- package/dist/cli/docs-links.mjs.map +1 -0
- package/dist/cli/fix-option.cjs +19 -0
- package/dist/cli/fix-option.cjs.map +1 -0
- package/dist/cli/fix-option.mjs +16 -0
- package/dist/cli/fix-option.mjs.map +1 -0
- package/dist/cli/help-text.cjs +44 -0
- package/dist/cli/help-text.cjs.map +1 -0
- package/dist/cli/help-text.mjs +42 -0
- package/dist/cli/help-text.mjs.map +1 -0
- package/dist/cli/main.cjs +67 -0
- package/dist/cli/main.cjs.map +1 -0
- package/dist/cli/main.d.cts +2 -0
- package/dist/cli/main.d.mts +2 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.mjs +59 -0
- package/dist/cli/main.mjs.map +1 -0
- package/dist/cli/redocly-apis.cjs +69 -0
- package/dist/cli/redocly-apis.cjs.map +1 -0
- package/dist/cli/redocly-apis.mjs +66 -0
- package/dist/cli/redocly-apis.mjs.map +1 -0
- package/dist/cli/ref-limits.cjs +14 -0
- package/dist/cli/ref-limits.cjs.map +1 -0
- package/dist/cli/ref-limits.mjs +12 -0
- package/dist/cli/ref-limits.mjs.map +1 -0
- package/dist/cli/run-cli.cjs +113 -0
- package/dist/cli/run-cli.cjs.map +1 -0
- package/dist/cli/run-cli.mjs +111 -0
- package/dist/cli/run-cli.mjs.map +1 -0
- package/dist/domain/assert-never.cjs +8 -0
- package/dist/domain/assert-never.cjs.map +1 -0
- package/dist/domain/assert-never.mjs +6 -0
- package/dist/domain/assert-never.mjs.map +1 -0
- package/dist/domain/errors.cjs +52 -0
- package/dist/domain/errors.cjs.map +1 -0
- package/dist/domain/errors.mjs +48 -0
- package/dist/domain/errors.mjs.map +1 -0
- package/dist/domain/ir/constructors.cjs +93 -0
- package/dist/domain/ir/constructors.cjs.map +1 -0
- package/dist/domain/ir/constructors.mjs +74 -0
- package/dist/domain/ir/constructors.mjs.map +1 -0
- package/dist/domain/ir/identifier-text.cjs +29 -0
- package/dist/domain/ir/identifier-text.cjs.map +1 -0
- package/dist/domain/ir/identifier-text.mjs +25 -0
- package/dist/domain/ir/identifier-text.mjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs +109 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.mjs +106 -0
- package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -0
- package/dist/domain/ir/normalize.cjs +32 -0
- package/dist/domain/ir/normalize.cjs.map +1 -0
- package/dist/domain/ir/normalize.mjs +29 -0
- package/dist/domain/ir/normalize.mjs.map +1 -0
- package/dist/domain/ir/property-name.cjs +19 -0
- package/dist/domain/ir/property-name.cjs.map +1 -0
- package/dist/domain/ir/property-name.mjs +16 -0
- package/dist/domain/ir/property-name.mjs.map +1 -0
- package/dist/domain/ir/raw-text-escapes.cjs +25 -0
- package/dist/domain/ir/raw-text-escapes.cjs.map +1 -0
- package/dist/domain/ir/raw-text-escapes.mjs +22 -0
- package/dist/domain/ir/raw-text-escapes.mjs.map +1 -0
- package/dist/domain/openapi/admitted-values.cjs +75 -0
- package/dist/domain/openapi/admitted-values.cjs.map +1 -0
- package/dist/domain/openapi/admitted-values.mjs +72 -0
- package/dist/domain/openapi/admitted-values.mjs.map +1 -0
- package/dist/domain/openapi/alias-expansion.cjs +50 -0
- package/dist/domain/openapi/alias-expansion.cjs.map +1 -0
- package/dist/domain/openapi/alias-expansion.mjs +45 -0
- package/dist/domain/openapi/alias-expansion.mjs.map +1 -0
- package/dist/domain/openapi/binary-content.cjs +48 -0
- package/dist/domain/openapi/binary-content.cjs.map +1 -0
- package/dist/domain/openapi/binary-content.mjs +45 -0
- package/dist/domain/openapi/binary-content.mjs.map +1 -0
- package/dist/domain/openapi/components-object.cjs +29 -0
- package/dist/domain/openapi/components-object.cjs.map +1 -0
- package/dist/domain/openapi/components-object.mjs +24 -0
- package/dist/domain/openapi/components-object.mjs.map +1 -0
- package/dist/domain/openapi/discriminated-union.cjs +68 -0
- package/dist/domain/openapi/discriminated-union.cjs.map +1 -0
- package/dist/domain/openapi/discriminated-union.mjs +62 -0
- package/dist/domain/openapi/discriminated-union.mjs.map +1 -0
- package/dist/domain/openapi/discriminator-conflicts.cjs +143 -0
- package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -0
- package/dist/domain/openapi/discriminator-conflicts.mjs +141 -0
- package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -0
- package/dist/domain/openapi/json-pointer.cjs +31 -0
- package/dist/domain/openapi/json-pointer.cjs.map +1 -0
- package/dist/domain/openapi/json-pointer.mjs +27 -0
- package/dist/domain/openapi/json-pointer.mjs.map +1 -0
- package/dist/domain/openapi/media-type-object.cjs +14 -0
- package/dist/domain/openapi/media-type-object.cjs.map +1 -0
- package/dist/domain/openapi/media-type-object.mjs +11 -0
- package/dist/domain/openapi/media-type-object.mjs.map +1 -0
- package/dist/domain/openapi/parameter-object.cjs +13 -0
- package/dist/domain/openapi/parameter-object.cjs.map +1 -0
- package/dist/domain/openapi/parameter-object.mjs +10 -0
- package/dist/domain/openapi/parameter-object.mjs.map +1 -0
- package/dist/domain/openapi/path-item-object.cjs +35 -0
- package/dist/domain/openapi/path-item-object.cjs.map +1 -0
- package/dist/domain/openapi/path-item-object.mjs +30 -0
- package/dist/domain/openapi/path-item-object.mjs.map +1 -0
- package/dist/domain/openapi/path-templates.cjs +23 -0
- package/dist/domain/openapi/path-templates.cjs.map +1 -0
- package/dist/domain/openapi/path-templates.mjs +21 -0
- package/dist/domain/openapi/path-templates.mjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.cjs +87 -0
- package/dist/domain/openapi/unsupported-features.cjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.mjs +84 -0
- package/dist/domain/openapi/unsupported-features.mjs.map +1 -0
- package/dist/domain/output-fixes.cjs +101 -0
- package/dist/domain/output-fixes.cjs.map +1 -0
- package/dist/domain/output-fixes.mjs +94 -0
- package/dist/domain/output-fixes.mjs.map +1 -0
- package/dist/domain/warnings.cjs +15 -0
- package/dist/domain/warnings.cjs.map +1 -0
- package/dist/domain/warnings.mjs +12 -0
- package/dist/domain/warnings.mjs.map +1 -0
- package/dist/index.cjs +98 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +841 -0
- package/dist/index.d.mts +841 -0
- package/dist/index.d.ts +841 -0
- package/dist/index.mjs +27 -0
- package/dist/index.mjs.map +1 -0
- package/dist/transform/components-object.cjs +15 -0
- package/dist/transform/components-object.cjs.map +1 -0
- package/dist/transform/components-object.mjs +11 -0
- package/dist/transform/components-object.mjs.map +1 -0
- package/dist/transform/header-object.cjs +12 -0
- package/dist/transform/header-object.cjs.map +1 -0
- package/dist/transform/header-object.mjs +10 -0
- package/dist/transform/header-object.mjs.map +1 -0
- package/dist/transform/media-type-object.cjs +12 -0
- package/dist/transform/media-type-object.cjs.map +1 -0
- package/dist/transform/media-type-object.mjs +10 -0
- package/dist/transform/media-type-object.mjs.map +1 -0
- package/dist/transform/operation-object.cjs +26 -0
- package/dist/transform/operation-object.cjs.map +1 -0
- package/dist/transform/operation-object.mjs +21 -0
- package/dist/transform/operation-object.mjs.map +1 -0
- package/dist/transform/parameter-object.cjs +12 -0
- package/dist/transform/parameter-object.cjs.map +1 -0
- package/dist/transform/parameter-object.mjs +10 -0
- package/dist/transform/parameter-object.mjs.map +1 -0
- package/dist/transform/path-item-object.cjs +12 -0
- package/dist/transform/path-item-object.cjs.map +1 -0
- package/dist/transform/path-item-object.mjs +10 -0
- package/dist/transform/path-item-object.mjs.map +1 -0
- package/dist/transform/paths-object.cjs +11 -0
- package/dist/transform/paths-object.cjs.map +1 -0
- package/dist/transform/paths-object.mjs +9 -0
- package/dist/transform/paths-object.mjs.map +1 -0
- package/dist/transform/request-body-object.cjs +12 -0
- package/dist/transform/request-body-object.cjs.map +1 -0
- package/dist/transform/request-body-object.mjs +10 -0
- package/dist/transform/request-body-object.mjs.map +1 -0
- package/dist/transform/response-object.cjs +12 -0
- package/dist/transform/response-object.cjs.map +1 -0
- package/dist/transform/response-object.mjs +10 -0
- package/dist/transform/response-object.mjs.map +1 -0
- package/dist/transform/responses-object.cjs +12 -0
- package/dist/transform/responses-object.cjs.map +1 -0
- package/dist/transform/responses-object.mjs +10 -0
- package/dist/transform/responses-object.mjs.map +1 -0
- package/dist/transform/schema-object.cjs +21 -0
- package/dist/transform/schema-object.cjs.map +1 -0
- package/dist/transform/schema-object.mjs +16 -0
- package/dist/transform/schema-object.mjs.map +1 -0
- package/package.json +115 -4
- package/src/adapters/node-file-system/node-file-system.ts +44 -0
- package/src/adapters/redocly-loader/alias-limit.ts +20 -0
- package/src/adapters/redocly-loader/allowed-hosts.ts +62 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +65 -0
- package/src/adapters/redocly-loader/malformed-refs.ts +61 -0
- package/src/adapters/redocly-loader/redocly-config-source.ts +78 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +262 -0
- package/src/adapters/redocly-loader/ref-access.ts +146 -0
- package/src/adapters/redocly-loader/ref-holders.ts +43 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +104 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +124 -0
- package/src/adapters/redocly-loader/schema-source.ts +151 -0
- package/src/adapters/redocly-loader/unsupported-keys.ts +102 -0
- package/src/adapters/terminal-logger/terminal-logger.ts +98 -0
- package/src/adapters/type-ast-bridge/footer-nodes.ts +38 -0
- package/src/adapters/type-ast-bridge/ir-declarations-to-typescript.ts +100 -0
- package/src/adapters/type-ast-bridge/ir-to-typescript.ts +223 -0
- package/src/adapters/type-ast-bridge/lazy-node.ts +24 -0
- package/src/adapters/type-ast-bridge/load-typescript.ts +84 -0
- package/src/adapters/type-ast-bridge/print-typescript.ts +33 -0
- package/src/adapters/type-ast-bridge/typescript-raw-text.ts +49 -0
- package/src/adapters/type-ast-bridge/typescript-to-ir.ts +294 -0
- package/src/adapters/type-ast-bridge/typescript-types.ts +8 -0
- package/src/api/ast-to-string.ts +59 -0
- package/src/api/comment-header.ts +7 -0
- package/src/api/default-ports.ts +44 -0
- package/src/api/discriminator-conflict-warnings.ts +43 -0
- package/src/api/discriminator-enum-names.ts +26 -0
- package/src/api/discriminator-enum-parent.ts +129 -0
- package/src/api/discriminator-enum.ts +115 -0
- package/src/api/discriminator-other-owners.ts +97 -0
- package/src/api/discriminator-patch.ts +147 -0
- package/src/api/discriminator-scan.ts +260 -0
- package/src/api/document-declarations.ts +41 -0
- package/src/api/document-refs.ts +71 -0
- package/src/api/document-run.ts +177 -0
- package/src/api/enum-values-warnings.ts +21 -0
- package/src/api/footer-entry.ts +23 -0
- package/src/api/footer-sink.ts +67 -0
- package/src/api/legacy-callback-warning.ts +29 -0
- package/src/api/legacy-ts-helpers.ts +311 -0
- package/src/api/legacy-utils.ts +118 -0
- package/src/api/openapi-ts.ts +62 -0
- package/src/api/path-template-warnings.ts +27 -0
- package/src/api/schema-callbacks.ts +211 -0
- package/src/api/string-to-ast.ts +27 -0
- package/src/api/transform-context.ts +93 -0
- package/src/api/transform-schema.ts +123 -0
- package/src/api/type-helpers.ts +130 -0
- package/src/api/unsupported-feature-warnings.ts +33 -0
- package/src/application/ports/file-system.ts +12 -0
- package/src/application/ports/logger.ts +16 -0
- package/src/application/ports/redocly-config-source.ts +20 -0
- package/src/application/ports/schema-loader.ts +32 -0
- package/src/application/print/comment-writer.ts +91 -0
- package/src/application/print/declaration-printer.ts +100 -0
- package/src/application/print/literal-text.ts +62 -0
- package/src/application/print/print-nodes.ts +62 -0
- package/src/application/print/print-options.ts +11 -0
- package/src/application/print/text-writer.ts +83 -0
- package/src/application/print/type-printer.ts +287 -0
- package/src/application/stack-overflow.ts +54 -0
- package/src/application/transform/document/assignability.ts +203 -0
- package/src/application/transform/document/components.ts +189 -0
- package/src/application/transform/document/declared-types.ts +93 -0
- package/src/application/transform/document/defs-root.ts +25 -0
- package/src/application/transform/document/document-member.ts +20 -0
- package/src/application/transform/document/document.ts +215 -0
- package/src/application/transform/document/exploded-query.ts +91 -0
- package/src/application/transform/document/global-type-references.ts +78 -0
- package/src/application/transform/document/header.ts +34 -0
- package/src/application/transform/document/kept-deprecated.ts +135 -0
- package/src/application/transform/document/list-assignability.ts +87 -0
- package/src/application/transform/document/media-type.ts +78 -0
- package/src/application/transform/document/operation.ts +64 -0
- package/src/application/transform/document/parameter.ts +45 -0
- package/src/application/transform/document/parameters.ts +265 -0
- package/src/application/transform/document/path-item.ts +168 -0
- package/src/application/transform/document/path-key-overlaps.ts +201 -0
- package/src/application/transform/document/path-template-replace.ts +90 -0
- package/src/application/transform/document/paths-enum.ts +127 -0
- package/src/application/transform/document/paths.ts +273 -0
- package/src/application/transform/document/request-body.ts +50 -0
- package/src/application/transform/document/response.ts +109 -0
- package/src/application/transform/document/responses.ts +29 -0
- package/src/application/transform/document/root-type-aliases.ts +107 -0
- package/src/application/transform/document/template-key-match.ts +183 -0
- package/src/application/transform/document/type-assignability.ts +268 -0
- package/src/application/transform/document/type-key.ts +80 -0
- package/src/application/transform/document/type-resolution.ts +163 -0
- package/src/application/transform/document/webhooks.ts +22 -0
- package/src/application/transform/document-entries.ts +28 -0
- package/src/application/transform/footer/document-footer.ts +212 -0
- package/src/application/transform/footer/enum-naming.ts +210 -0
- package/src/application/transform/footer/enum-values-check.ts +171 -0
- package/src/application/transform/footer/evaluation.ts +47 -0
- package/src/application/transform/footer/shared-enum-names.ts +86 -0
- package/src/application/transform/footer/type-evaluation.ts +294 -0
- package/src/application/transform/footer/type-rules.ts +269 -0
- package/src/application/transform/helper-types.ts +92 -0
- package/src/application/transform/literal-type.ts +54 -0
- package/src/application/transform/numbered-names.ts +20 -0
- package/src/application/transform/ref-pointer/generated-location.ts +211 -0
- package/src/application/transform/ref-pointer/generated-shape.ts +275 -0
- package/src/application/transform/ref-pointer/inline-cycles.ts +56 -0
- package/src/application/transform/ref-pointer/original-index.ts +95 -0
- package/src/application/transform/ref-pointer/pointer-type.ts +92 -0
- package/src/application/transform/ref-pointer/pointer-walk.ts +96 -0
- package/src/application/transform/ref-pointer/typed-walk.ts +192 -0
- package/src/application/transform/ref-type.ts +102 -0
- package/src/application/transform/schema/access-flags.ts +63 -0
- package/src/application/transform/schema/array-type.ts +213 -0
- package/src/application/transform/schema/composition-type.ts +255 -0
- package/src/application/transform/schema/core-type.ts +119 -0
- package/src/application/transform/schema/discriminated-union.ts +58 -0
- package/src/application/transform/schema/discriminator-property.ts +33 -0
- package/src/application/transform/schema/enum-rule.ts +280 -0
- package/src/application/transform/schema/inherited-discriminator.ts +54 -0
- package/src/application/transform/schema/object-type.ts +289 -0
- package/src/application/transform/schema/presence-members.ts +96 -0
- package/src/application/transform/schema/required-variants.ts +88 -0
- package/src/application/transform/schema/schema-context.ts +136 -0
- package/src/application/transform/schema/schema-rule.ts +29 -0
- package/src/application/transform/schema/schema-transform.ts +99 -0
- package/src/application/transform/schema/unevaluated-properties.ts +105 -0
- package/src/application/transform/schema-comment.ts +196 -0
- package/src/application/transform/shared-types.ts +9 -0
- package/src/application/transform/transform-context.ts +51 -0
- package/src/application/transform/type-combinators.ts +57 -0
- package/src/cli/cli-arguments.ts +208 -0
- package/src/cli/cli-dependencies.ts +47 -0
- package/src/cli/cli-errors.ts +127 -0
- package/src/cli/cli-output.ts +67 -0
- package/src/cli/docs-links.ts +6 -0
- package/src/cli/fix-option.ts +29 -0
- package/src/cli/help-text.ts +52 -0
- package/src/cli/main.ts +73 -0
- package/src/cli/redocly-apis.ts +95 -0
- package/src/cli/ref-limits.ts +16 -0
- package/src/cli/run-cli.ts +131 -0
- package/src/domain/assert-never.ts +8 -0
- package/src/domain/errors.ts +76 -0
- package/src/domain/ir/constructors.ts +142 -0
- package/src/domain/ir/identifier-text.ts +49 -0
- package/src/domain/ir/newer-identifier-ranges.ts +109 -0
- package/src/domain/ir/nodes.ts +225 -0
- package/src/domain/ir/normalize.ts +51 -0
- package/src/domain/ir/property-name.ts +28 -0
- package/src/domain/ir/raw-text-escapes.ts +37 -0
- package/src/domain/openapi/admitted-values.ts +113 -0
- package/src/domain/openapi/alias-expansion.ts +72 -0
- package/src/domain/openapi/binary-content.ts +74 -0
- package/src/domain/openapi/components-object.ts +52 -0
- package/src/domain/openapi/discriminated-union.ts +109 -0
- package/src/domain/openapi/discriminator-conflicts.ts +251 -0
- package/src/domain/openapi/document-object.ts +12 -0
- package/src/domain/openapi/header-object.ts +9 -0
- package/src/domain/openapi/json-pointer.ts +46 -0
- package/src/domain/openapi/media-type-object.ts +26 -0
- package/src/domain/openapi/operation-object.ts +13 -0
- package/src/domain/openapi/parameter-object.ts +34 -0
- package/src/domain/openapi/path-item-object.ts +70 -0
- package/src/domain/openapi/path-templates.ts +31 -0
- package/src/domain/openapi/request-body-object.ts +7 -0
- package/src/domain/openapi/response-object.ts +14 -0
- package/src/domain/openapi/schema-object.ts +61 -0
- package/src/domain/openapi/unsupported-features.ts +139 -0
- package/src/domain/output-fixes.ts +136 -0
- package/src/domain/warnings.ts +20 -0
- package/src/index.ts +67 -0
- package/src/transform/components-object.ts +27 -0
- package/src/transform/header-object.ts +19 -0
- package/src/transform/media-type-object.ts +19 -0
- package/src/transform/operation-object.ts +36 -0
- package/src/transform/parameter-object.ts +19 -0
- package/src/transform/parameters-array.ts +19 -0
- package/src/transform/path-item-object.ts +22 -0
- package/src/transform/paths-enum.ts +8 -0
- package/src/transform/paths-object.ts +15 -0
- package/src/transform/request-body-object.ts +19 -0
- package/src/transform/response-object.ts +19 -0
- package/src/transform/responses-object.ts +19 -0
- package/src/transform/schema-object.ts +36 -0
- package/src/transform/webhooks-object.ts +15 -0
- package/src/types/generator-options.ts +278 -0
- package/src/types/openapi-common.ts +100 -0
- package/src/types/openapi-document.ts +196 -0
- package/src/types/openapi-path-item.ts +130 -0
- package/src/types/openapi-request.ts +209 -0
- package/src/types/openapi-response.ts +81 -0
- package/src/types/openapi-schema.ts +169 -0
- package/src/types/openapi-security.ts +116 -0
- package/src/types.ts +12 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsonPointer = require('../domain/openapi/json-pointer.cjs');
|
|
4
|
+
|
|
5
|
+
const PROPERTIES_KEYWORD = "properties";
|
|
6
|
+
const ROOT_SEGMENTS = 3;
|
|
7
|
+
function typedAt(ref) {
|
|
8
|
+
const segments = jsonPointer.parseRefPointer(ref);
|
|
9
|
+
const nested = segments.slice(ROOT_SEGMENTS).filter((segment) => segment !== PROPERTIES_KEYWORD);
|
|
10
|
+
return jsonPointer.createRef([...segments.slice(0, ROOT_SEGMENTS), ...nested]);
|
|
11
|
+
}
|
|
12
|
+
function isSchemaObject(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function ownProperty(item, ref, name) {
|
|
16
|
+
const property = ("properties" in item ? item.properties : void 0)?.[name];
|
|
17
|
+
return property === void 0 ? void 0 : { property, path: jsonPointer.createRef([ref, name]) };
|
|
18
|
+
}
|
|
19
|
+
function declaredProperty(ref, name, resolve, visited) {
|
|
20
|
+
const schema = resolve(ref);
|
|
21
|
+
if (visited.has(ref) || !isSchemaObject(schema)) {
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
visited.add(ref);
|
|
25
|
+
for (const item of [schema, ...schema.allOf ?? []]) {
|
|
26
|
+
if (!isSchemaObject(item)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const found = "$ref" in item ? declaredProperty(item.$ref, name, resolve, visited) : ownProperty(item, ref, name);
|
|
30
|
+
if (found !== void 0) {
|
|
31
|
+
return found;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
function inheritedProperty(ref, name, resolve) {
|
|
37
|
+
const schema = resolve(ref);
|
|
38
|
+
const visited = /* @__PURE__ */ new Set([ref]);
|
|
39
|
+
for (const item of isSchemaObject(schema) ? schema.allOf ?? [] : []) {
|
|
40
|
+
const found = isSchemaObject(item) && "$ref" in item ? declaredProperty(item.$ref, name, resolve, visited) : void 0;
|
|
41
|
+
if (found !== void 0) {
|
|
42
|
+
return found;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
function enumParentOf(patch, resolve) {
|
|
48
|
+
const name = patch.discriminator.propertyName;
|
|
49
|
+
const declared = declaredProperty(patch.discriminatorRef, name, resolve, /* @__PURE__ */ new Set()) ?? (patch.ref === void 0 ? void 0 : inheritedProperty(patch.ref, name, resolve));
|
|
50
|
+
if (declared === void 0 || !isSchemaObject(declared.property)) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
const ref = declared.property.$ref;
|
|
54
|
+
const parent = typeof ref === "string" ? { schema: resolve(ref), path: typedAt(ref) } : { schema: declared.property, path: declared.path };
|
|
55
|
+
return isSchemaObject(parent.schema) && Array.isArray(parent.schema.enum) ? { schema: parent.schema, path: parent.path } : void 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.enumParentOf = enumParentOf;
|
|
59
|
+
//# sourceMappingURL=discriminator-enum-parent.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-enum-parent.cjs","sources":["../../src/api/discriminator-enum-parent.ts"],"sourcesContent":["import { createRef, parseRefPointer } from \"../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../types.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\n\n/**\n * The `discriminator-values` fix (#1700). With `--enum`, the enum the scan adds to a member\n * (`petType: \"Cat\"`) is declared as an enum of its own (`CatPetType`), which is not assignable to\n * the parent's enum (`PetType`). The parent's enum is found here, so the member's property can be\n * typed with its members (`PetType.Cat`).\n */\n\n/** The parent's enum schema and the location it is typed at, which gives the enum its name. */\nexport interface EnumParent {\n readonly schema: SchemaObject;\n readonly path: string;\n}\n\ntype ResolveSchemaRef = (ref: string) => unknown;\n\n/** A declared property schema and the location the transformer types it at. */\ninterface DeclaredProperty {\n readonly property: unknown;\n readonly path: string;\n}\n\nconst PROPERTIES_KEYWORD = \"properties\";\n/** `components`, `schemas` and the schema name: the segments before the schema's own keywords. */\nconst ROOT_SEGMENTS = 3;\n\n/** The location a `$ref` is typed at: object properties are nested without `properties`. */\nfunction typedAt(ref: string): string {\n const segments = parseRefPointer(ref);\n const nested = segments.slice(ROOT_SEGMENTS).filter((segment) => segment !== PROPERTIES_KEYWORD);\n return createRef([...segments.slice(0, ROOT_SEGMENTS), ...nested]);\n}\n\nfunction isSchemaObject(value: unknown): value is SchemaObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The property `name` of a schema object typed at `ref`. */\nfunction ownProperty(item: SchemaObject, ref: string, name: string): DeclaredProperty | undefined {\n const property = (\"properties\" in item ? item.properties : undefined)?.[name];\n return property === undefined ? undefined : { property, path: createRef([ref, name]) };\n}\n\n/** The property `name` of the schema at `ref`, its own or from an `allOf` item, depth first. */\nfunction declaredProperty(\n ref: string,\n name: string,\n resolve: ResolveSchemaRef,\n visited: Set<string>,\n): DeclaredProperty | undefined {\n const schema = resolve(ref);\n if (visited.has(ref) || !isSchemaObject(schema)) {\n return undefined;\n }\n visited.add(ref);\n // An inline `allOf` item is typed at its parent's location, so both share the path.\n for (const item of [schema, ...(schema.allOf ?? [])]) {\n if (!isSchemaObject(item)) {\n continue;\n }\n const found =\n \"$ref\" in item\n ? declaredProperty(item.$ref as string, name, resolve, visited)\n : ownProperty(item, ref, name);\n if (found !== undefined) {\n return found;\n }\n }\n return undefined;\n}\n\n/**\n * A discriminator and the `$ref` of the schema that declares its property; `ref` is the member\n * whose value the discriminator gives, where there is one.\n */\nexport type DiscriminatorOwner = Pick<EnumPatch, \"discriminator\" | \"discriminatorRef\"> &\n Partial<Pick<EnumPatch, \"ref\">>;\n\n/**\n * The property `name` that the member at `ref` inherits through its `allOf` `$ref`s. Its own\n * keywords and inline items are left out: the scan writes the added value there.\n */\nfunction inheritedProperty(\n ref: string,\n name: string,\n resolve: ResolveSchemaRef,\n): DeclaredProperty | undefined {\n const schema = resolve(ref);\n const visited = new Set([ref]);\n for (const item of isSchemaObject(schema) ? (schema.allOf ?? []) : []) {\n const found =\n isSchemaObject(item) && \"$ref\" in item\n ? declaredProperty(item.$ref as string, name, resolve, visited)\n : undefined;\n if (found !== undefined) {\n return found;\n }\n }\n return undefined;\n}\n\n/**\n * The enum of the property that the discriminator owner declares, if it is one. An owner that\n * declares no such property (a `oneOf` with a mapping) leaves the member's type to the property\n * the member inherits, so that property's enum is the one.\n */\nexport function enumParentOf(\n patch: DiscriminatorOwner,\n resolve: ResolveSchemaRef,\n): EnumParent | undefined {\n const name = patch.discriminator.propertyName;\n const declared =\n declaredProperty(patch.discriminatorRef, name, resolve, new Set()) ??\n (patch.ref === undefined ? undefined : inheritedProperty(patch.ref, name, resolve));\n if (declared === undefined || !isSchemaObject(declared.property)) {\n return undefined;\n }\n const ref = (declared.property as { readonly $ref?: unknown }).$ref;\n const parent =\n typeof ref === \"string\"\n ? { schema: resolve(ref), path: typedAt(ref) }\n : { schema: declared.property, path: declared.path };\n return isSchemaObject(parent.schema) && Array.isArray(parent.schema.enum)\n ? { schema: parent.schema, path: parent.path }\n : undefined;\n}\n"],"names":["parseRefPointer","createRef"],"mappings":";;;;AAyBA,MAAM,kBAAA,GAAqB,YAAA;AAE3B,MAAM,aAAA,GAAgB,CAAA;AAGtB,SAAS,QAAQ,GAAA,EAAqB;AACpC,EAAA,MAAM,QAAA,GAAWA,4BAAgB,GAAG,CAAA;AACpC,EAAA,MAAM,MAA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AA,MAAM,MAAA,GACJ,OAAO,GAAA,KAAQ,QAAA,GACX,EAAE,MAAA,EAAQ,OAAA,CAAQ,GAAG,CAAA,EAAG,IAAA,EAAM,QAAQ,GAAG,CAAA,KACzC,EAAE,MAAA,EAAQ,SAAS,QAAA,EAAU,IAAA,EAAM,SAAS,IAAA,EAAK;AACvD,EAAA,OAAO,eAAe,MAAA,CAAO,MAAM,CAAA,IAAK,KAAA,CAAM,QAAQ,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA,GACpE,EAAE,MAAA,EAAQ,MAAA,CAAO,QAAQ,IAAA,EAAM,MAAA,CAAO,MAAK,GAC3C,MAAA;AACN;;"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { parseRefPointer, createRef } from '../domain/openapi/json-pointer.mjs';
|
|
2
|
+
|
|
3
|
+
const PROPERTIES_KEYWORD = "properties";
|
|
4
|
+
const ROOT_SEGMENTS = 3;
|
|
5
|
+
function typedAt(ref) {
|
|
6
|
+
const segments = parseRefPointer(ref);
|
|
7
|
+
const nested = segments.slice(ROOT_SEGMENTS).filter((segment) => segment !== PROPERTIES_KEYWORD);
|
|
8
|
+
return createRef([...segments.slice(0, ROOT_SEGMENTS), ...nested]);
|
|
9
|
+
}
|
|
10
|
+
function isSchemaObject(value) {
|
|
11
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
function ownProperty(item, ref, name) {
|
|
14
|
+
const property = ("properties" in item ? item.properties : void 0)?.[name];
|
|
15
|
+
return property === void 0 ? void 0 : { property, path: createRef([ref, name]) };
|
|
16
|
+
}
|
|
17
|
+
function declaredProperty(ref, name, resolve, visited) {
|
|
18
|
+
const schema = resolve(ref);
|
|
19
|
+
if (visited.has(ref) || !isSchemaObject(schema)) {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
visited.add(ref);
|
|
23
|
+
for (const item of [schema, ...schema.allOf ?? []]) {
|
|
24
|
+
if (!isSchemaObject(item)) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const found = "$ref" in item ? declaredProperty(item.$ref, name, resolve, visited) : ownProperty(item, ref, name);
|
|
28
|
+
if (found !== void 0) {
|
|
29
|
+
return found;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
function inheritedProperty(ref, name, resolve) {
|
|
35
|
+
const schema = resolve(ref);
|
|
36
|
+
const visited = /* @__PURE__ */ new Set([ref]);
|
|
37
|
+
for (const item of isSchemaObject(schema) ? schema.allOf ?? [] : []) {
|
|
38
|
+
const found = isSchemaObject(item) && "$ref" in item ? declaredProperty(item.$ref, name, resolve, visited) : void 0;
|
|
39
|
+
if (found !== void 0) {
|
|
40
|
+
return found;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
function enumParentOf(patch, resolve) {
|
|
46
|
+
const name = patch.discriminator.propertyName;
|
|
47
|
+
const declared = declaredProperty(patch.discriminatorRef, name, resolve, /* @__PURE__ */ new Set()) ?? (patch.ref === void 0 ? void 0 : inheritedProperty(patch.ref, name, resolve));
|
|
48
|
+
if (declared === void 0 || !isSchemaObject(declared.property)) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
const ref = declared.property.$ref;
|
|
52
|
+
const parent = typeof ref === "string" ? { schema: resolve(ref), path: typedAt(ref) } : { schema: declared.property, path: declared.path };
|
|
53
|
+
return isSchemaObject(parent.schema) && Array.isArray(parent.schema.enum) ? { schema: parent.schema, path: parent.path } : void 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { enumParentOf };
|
|
57
|
+
//# sourceMappingURL=discriminator-enum-parent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-enum-parent.mjs","sources":["../../src/api/discriminator-enum-parent.ts"],"sourcesContent":["import { createRef, parseRefPointer } from \"../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../types.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\n\n/**\n * The `discriminator-values` fix (#1700). With `--enum`, the enum the scan adds to a member\n * (`petType: \"Cat\"`) is declared as an enum of its own (`CatPetType`), which is not assignable to\n * the parent's enum (`PetType`). The parent's enum is found here, so the member's property can be\n * typed with its members (`PetType.Cat`).\n */\n\n/** The parent's enum schema and the location it is typed at, which gives the enum its name. */\nexport interface EnumParent {\n readonly schema: SchemaObject;\n readonly path: string;\n}\n\ntype ResolveSchemaRef = (ref: string) => unknown;\n\n/** A declared property schema and the location the transformer types it at. */\ninterface DeclaredProperty {\n readonly property: unknown;\n readonly path: string;\n}\n\nconst PROPERTIES_KEYWORD = \"properties\";\n/** `components`, `schemas` and the schema name: the segments before the schema's own keywords. */\nconst ROOT_SEGMENTS = 3;\n\n/** The location a `$ref` is typed at: object properties are nested without `properties`. */\nfunction typedAt(ref: string): string {\n const segments = parseRefPointer(ref);\n const nested = segments.slice(ROOT_SEGMENTS).filter((segment) => segment !== PROPERTIES_KEYWORD);\n return createRef([...segments.slice(0, ROOT_SEGMENTS), ...nested]);\n}\n\nfunction isSchemaObject(value: unknown): value is SchemaObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The property `name` of a schema object typed at `ref`. */\nfunction ownProperty(item: SchemaObject, ref: string, name: string): DeclaredProperty | undefined {\n const property = (\"properties\" in item ? item.properties : undefined)?.[name];\n return property === undefined ? undefined : { property, path: createRef([ref, name]) };\n}\n\n/** The property `name` of the schema at `ref`, its own or from an `allOf` item, depth first. */\nfunction declaredProperty(\n ref: string,\n name: string,\n resolve: ResolveSchemaRef,\n visited: Set<string>,\n): DeclaredProperty | undefined {\n const schema = resolve(ref);\n if (visited.has(ref) || !isSchemaObject(schema)) {\n return undefined;\n }\n visited.add(ref);\n // An inline `allOf` item is typed at its parent's location, so both share the path.\n for (const item of [schema, ...(schema.allOf ?? [])]) {\n if (!isSchemaObject(item)) {\n continue;\n }\n const found =\n \"$ref\" in item\n ? declaredProperty(item.$ref as string, name, resolve, visited)\n : ownProperty(item, ref, name);\n if (found !== undefined) {\n return found;\n }\n }\n return undefined;\n}\n\n/**\n * A discriminator and the `$ref` of the schema that declares its property; `ref` is the member\n * whose value the discriminator gives, where there is one.\n */\nexport type DiscriminatorOwner = Pick<EnumPatch, \"discriminator\" | \"discriminatorRef\"> &\n Partial<Pick<EnumPatch, \"ref\">>;\n\n/**\n * The property `name` that the member at `ref` inherits through its `allOf` `$ref`s. Its own\n * keywords and inline items are left out: the scan writes the added value there.\n */\nfunction inheritedProperty(\n ref: string,\n name: string,\n resolve: ResolveSchemaRef,\n): DeclaredProperty | undefined {\n const schema = resolve(ref);\n const visited = new Set([ref]);\n for (const item of isSchemaObject(schema) ? (schema.allOf ?? []) : []) {\n const found =\n isSchemaObject(item) && \"$ref\" in item\n ? declaredProperty(item.$ref as string, name, resolve, visited)\n : undefined;\n if (found !== undefined) {\n return found;\n }\n }\n return undefined;\n}\n\n/**\n * The enum of the property that the discriminator owner declares, if it is one. An owner that\n * declares no such property (a `oneOf` with a mapping) leaves the member's type to the property\n * the member inherits, so that property's enum is the one.\n */\nexport function enumParentOf(\n patch: DiscriminatorOwner,\n resolve: ResolveSchemaRef,\n): EnumParent | undefined {\n const name = patch.discriminator.propertyName;\n const declared =\n declaredProperty(patch.discriminatorRef, name, resolve, new Set()) ??\n (patch.ref === undefined ? undefined : inheritedProperty(patch.ref, name, resolve));\n if (declared === undefined || !isSchemaObject(declared.property)) {\n return undefined;\n }\n const ref = (declared.property as { readonly $ref?: unknown }).$ref;\n const parent =\n typeof ref === \"string\"\n ? { schema: resolve(ref), path: typedAt(ref) }\n : { schema: declared.property, path: declared.path };\n return isSchemaObject(parent.schema) && Array.isArray(parent.schema.enum)\n ? { schema: parent.schema, path: parent.path }\n : undefined;\n}\n"],"names":[],"mappings":";;AAyBA,MAAM,kBAAA,GAAqB,YAAA;AAE3B,MAAM,aAAA,GAAgB,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A,EAAG;AAChE,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,MAAM,GAAA,GAAO,SAAS,QAAA,CAAyC,IAAA;AAC/D,EAAA,MAAM,MAAA,GACJ,OAAO,GAAA,KAAQ,QAAA,GACX,EAAE,MAAA,EAAQ,OAAA,CAAQ,GAAG,CAAA,EAAG,IAAA,EAAM,QAAQ,GAAG,CAAA,KACzC,EAAE,MAAA,EAAQ,SAAS,QAAA,EAAU,IAAA,EAAM,SAAS,IAAA,EAAK;AACvD,EAAA,OAAO,eAAe,MAAA,CAAO,MAAM,CAAA,IAAK,KAAA,CAAM,QAAQ,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA,GACpE,EAAE,MAAA,EAAQ,MAAA,CAAO,QAAQ,IAAA,EAAM,MAAA,CAAO,MAAK,GAC3C,MAAA;AACN;;"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function discriminatorEnum(values, previous) {
|
|
4
|
+
return {
|
|
5
|
+
type: "string",
|
|
6
|
+
enum: values,
|
|
7
|
+
description: previous?.description ? `${previous.description} (enum property replaced by openapi-typesafe)` : "discriminator enum property added by openapi-typesafe"
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function patchAllOf(allOf, patch) {
|
|
11
|
+
const added = discriminatorEnum(patch.values);
|
|
12
|
+
allOf.push({
|
|
13
|
+
type: "object",
|
|
14
|
+
required: [patch.discriminator.propertyName],
|
|
15
|
+
properties: { [patch.discriminator.propertyName]: added }
|
|
16
|
+
});
|
|
17
|
+
return added;
|
|
18
|
+
}
|
|
19
|
+
function patchObjectSchema(schema, patch) {
|
|
20
|
+
const name = patch.discriminator.propertyName;
|
|
21
|
+
if (!schema.properties) {
|
|
22
|
+
schema.properties = {};
|
|
23
|
+
}
|
|
24
|
+
if (!schema.required) {
|
|
25
|
+
schema.required = [name];
|
|
26
|
+
} else if (!schema.required.includes(name)) {
|
|
27
|
+
schema.required.push(name);
|
|
28
|
+
}
|
|
29
|
+
const added = discriminatorEnum(patch.values, schema.properties[name]);
|
|
30
|
+
schema.properties[name] = added;
|
|
31
|
+
return added;
|
|
32
|
+
}
|
|
33
|
+
function isObjectSchema(schema) {
|
|
34
|
+
return typeof schema === "object" && schema !== null && "type" in schema && schema.type === "object";
|
|
35
|
+
}
|
|
36
|
+
function listedValues(property) {
|
|
37
|
+
if (typeof property !== "object" || property === null) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const { const: constant, enum: values } = property;
|
|
41
|
+
if (constant !== void 0) {
|
|
42
|
+
return [constant];
|
|
43
|
+
}
|
|
44
|
+
return Array.isArray(values) ? values : null;
|
|
45
|
+
}
|
|
46
|
+
function requiresValues(schema, name, values) {
|
|
47
|
+
if (typeof schema !== "object" || schema === null || "$ref" in schema) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const { required, properties } = schema;
|
|
51
|
+
const listed = listedValues(properties?.[name]);
|
|
52
|
+
return Boolean(required?.includes(name)) && listed !== null && listed.length === values.length && values.every((value) => listed.includes(value));
|
|
53
|
+
}
|
|
54
|
+
function declaresValues(schema, patch) {
|
|
55
|
+
const name = patch.discriminator.propertyName;
|
|
56
|
+
return [schema, ...schema?.allOf ?? []].some(
|
|
57
|
+
(item) => requiresValues(item, name, patch.values)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
function addEnumProperty(schema, patch) {
|
|
61
|
+
if (schema?.allOf) {
|
|
62
|
+
return patchAllOf(schema.allOf, patch);
|
|
63
|
+
}
|
|
64
|
+
return isObjectSchema(schema) ? patchObjectSchema(schema, patch) : null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.addEnumProperty = addEnumProperty;
|
|
68
|
+
exports.declaresValues = declaresValues;
|
|
69
|
+
//# sourceMappingURL=discriminator-enum.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-enum.cjs","sources":["../../src/api/discriminator-enum.ts"],"sourcesContent":["import type {\n DiscriminatorObject,\n ObjectSubtype,\n ReferenceObject,\n SchemaObject,\n} from \"../types.js\";\n\n/**\n * The in-place patch of the discriminator pre-pass: a mapped schema gets a required enum property\n * with its discriminator values, so that TypeScript can narrow the generated union.\n */\n\n/** One mapped schema to patch: `ref` is the schema; `discriminatorRef` owns the discriminator. */\nexport interface EnumPatch {\n readonly ref: string;\n readonly values: string[];\n readonly discriminator: DiscriminatorObject;\n readonly discriminatorRef: string;\n}\n\nfunction discriminatorEnum(values: string[], previous?: SchemaObject): SchemaObject {\n return {\n type: \"string\",\n enum: values,\n description: previous?.description\n ? `${previous.description} (enum property replaced by openapi-typesafe)`\n : \"discriminator enum property added by openapi-typesafe\",\n };\n}\n\n/** An `allOf` schema gets one more item that holds the required enum property. */\nfunction patchAllOf(allOf: (SchemaObject | ReferenceObject)[], patch: EnumPatch): SchemaObject {\n const added = discriminatorEnum(patch.values);\n allOf.push({\n type: \"object\",\n required: [patch.discriminator.propertyName],\n properties: { [patch.discriminator.propertyName]: added },\n });\n return added;\n}\n\n/** An object schema gets the enum property, which is always required, added or replaced. */\nfunction patchObjectSchema(schema: SchemaObject & ObjectSubtype, patch: EnumPatch): SchemaObject {\n const name = patch.discriminator.propertyName;\n if (!schema.properties) {\n schema.properties = {};\n }\n if (!schema.required) {\n schema.required = [name];\n } else if (!schema.required.includes(name)) {\n schema.required.push(name);\n }\n const added = discriminatorEnum(patch.values, schema.properties[name] as SchemaObject);\n schema.properties[name] = added;\n return added;\n}\n\nfunction isObjectSchema(schema: unknown): schema is SchemaObject & ObjectSubtype {\n return (\n typeof schema === \"object\" && schema !== null && \"type\" in schema && schema.type === \"object\"\n );\n}\n\n/** The values a property schema allows, from `const` or `enum`; null when it lists none. */\nfunction listedValues(property: unknown): readonly unknown[] | null {\n if (typeof property !== \"object\" || property === null) {\n return null;\n }\n const { const: constant, enum: values } = property as SchemaObject;\n if (constant !== undefined) {\n return [constant];\n }\n return Array.isArray(values) ? values : null;\n}\n\n/** Whether one schema object requires the property and allows exactly the values. */\nfunction requiresValues(schema: unknown, name: string, values: readonly string[]): boolean {\n if (typeof schema !== \"object\" || schema === null || \"$ref\" in schema) {\n return false;\n }\n const { required, properties } = schema as SchemaObject & ObjectSubtype;\n const listed = listedValues(properties?.[name]);\n return (\n Boolean(required?.includes(name)) &&\n listed !== null &&\n listed.length === values.length &&\n values.every((value) => listed.includes(value))\n );\n}\n\n/**\n * Whether `schema`, or an inline `allOf` item of it, already requires the discriminator property\n * with exactly the patch's values (the `discriminator-values` fix). Then a patch would\n * only repeat it (#2124).\n */\nexport function declaresValues(schema: SchemaObject | undefined, patch: EnumPatch): boolean {\n const name = patch.discriminator.propertyName;\n return [schema, ...(schema?.allOf ?? [])].some((item) =>\n requiresValues(item, name, patch.values),\n );\n}\n\n/**\n * Add or replace the enum property in `schema`, an `allOf` or object schema. Returns the added\n * enum schema, or null for another kind of schema, which is left as it is.\n */\nexport function addEnumProperty(\n schema: SchemaObject | undefined,\n patch: EnumPatch,\n): SchemaObject | null {\n if (schema?.allOf) {\n return patchAllOf(schema.allOf, patch);\n }\n return isObjectSchema(schema) ? patchObjectSchema(schema, patch) : null;\n}\n"],"names":[],"mappings":";;AAoBA,SAAS,iBAAA,CAAkB,QAAkB,QAAA,EAAuC;AAClF,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,QAAA;AAAA,IACN,IAAA,EAAM,MAAA;AAAA,IACN,aAAa,QAAA,EAAU,WAAA,GACnB,CAAA,EAAG,QAAA,CAAS,WAAW,CAAA,6CAAA,CAAA,GACvB;AAAA,GACN;AACF;AAGA,SAAS,UAAA,CAAW,OAA2C,KAAA,EAAgC;AAC7F,EAAA,MAAM,KAAA,GAAQ,iBAAA,CAAkB,KAAA,CAAM,MAAM,CAAA;AAC5C,EAAA,KAAA,CAAM,IAAA,CAAK;AAAA,IACT,IAAA,EAAM,QAAA;AAAA,IACN,QAAA,EAAU,CAAC,KAAA,CAAM,aAAA,CAAc,YAAY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um: values,
|
|
5
|
+
description: previous?.description ? `${previous.description} (enum property replaced by openapi-typesafe)` : "discriminator enum property added by openapi-typesafe"
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function patchAllOf(allOf, patch) {
|
|
9
|
+
const added = discriminatorEnum(patch.values);
|
|
10
|
+
allOf.push({
|
|
11
|
+
type: "object",
|
|
12
|
+
required: [patch.discriminator.propertyName],
|
|
13
|
+
properties: { [patch.discriminator.propertyName]: added }
|
|
14
|
+
});
|
|
15
|
+
return added;
|
|
16
|
+
}
|
|
17
|
+
function patchObjectSchema(schema, patch) {
|
|
18
|
+
const name = patch.discriminator.propertyName;
|
|
19
|
+
if (!schema.properties) {
|
|
20
|
+
schema.properties = {};
|
|
21
|
+
}
|
|
22
|
+
if (!schema.required) {
|
|
23
|
+
schema.required = [name];
|
|
24
|
+
} else if (!schema.required.includes(name)) {
|
|
25
|
+
schema.required.push(name);
|
|
26
|
+
}
|
|
27
|
+
const added = discriminatorEnum(patch.values, schema.properties[name]);
|
|
28
|
+
schema.properties[name] = added;
|
|
29
|
+
return added;
|
|
30
|
+
}
|
|
31
|
+
function isObjectSchema(schema) {
|
|
32
|
+
return typeof schema === "object" && schema !== null && "type" in schema && schema.type === "object";
|
|
33
|
+
}
|
|
34
|
+
function listedValues(property) {
|
|
35
|
+
if (typeof property !== "object" || property === null) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const { const: constant, enum: values } = property;
|
|
39
|
+
if (constant !== void 0) {
|
|
40
|
+
return [constant];
|
|
41
|
+
}
|
|
42
|
+
return Array.isArray(values) ? values : null;
|
|
43
|
+
}
|
|
44
|
+
function requiresValues(schema, name, values) {
|
|
45
|
+
if (typeof schema !== "object" || schema === null || "$ref" in schema) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const { required, properties } = schema;
|
|
49
|
+
const listed = listedValues(properties?.[name]);
|
|
50
|
+
return Boolean(required?.includes(name)) && listed !== null && listed.length === values.length && values.every((value) => listed.includes(value));
|
|
51
|
+
}
|
|
52
|
+
function declaresValues(schema, patch) {
|
|
53
|
+
const name = patch.discriminator.propertyName;
|
|
54
|
+
return [schema, ...schema?.allOf ?? []].some(
|
|
55
|
+
(item) => requiresValues(item, name, patch.values)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
function addEnumProperty(schema, patch) {
|
|
59
|
+
if (schema?.allOf) {
|
|
60
|
+
return patchAllOf(schema.allOf, patch);
|
|
61
|
+
}
|
|
62
|
+
return isObjectSchema(schema) ? patchObjectSchema(schema, patch) : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { addEnumProperty, declaresValues };
|
|
66
|
+
//# sourceMappingURL=discriminator-enum.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-enum.mjs","sources":["../../src/api/discriminator-enum.ts"],"sourcesContent":["import type {\n DiscriminatorObject,\n ObjectSubtype,\n ReferenceObject,\n SchemaObject,\n} from \"../types.js\";\n\n/**\n * The in-place patch of the discriminator pre-pass: a mapped schema gets a required enum property\n * with its discriminator values, so that TypeScript can narrow the generated union.\n */\n\n/** One mapped schema to patch: `ref` is the schema; `discriminatorRef` owns the discriminator. */\nexport interface EnumPatch {\n readonly ref: string;\n readonly values: string[];\n readonly discriminator: DiscriminatorObject;\n readonly discriminatorRef: string;\n}\n\nfunction discriminatorEnum(values: string[], previous?: SchemaObject): SchemaObject {\n return {\n type: \"string\",\n enum: values,\n description: previous?.description\n ? `${previous.description} (enum property replaced by openapi-typesafe)`\n : \"discriminator enum property added by openapi-typesafe\",\n };\n}\n\n/** An `allOf` schema gets one more item that holds the required enum property. */\nfunction patchAllOf(allOf: (SchemaObject | ReferenceObject)[], patch: EnumPatch): SchemaObject {\n const added = discriminatorEnum(patch.values);\n allOf.push({\n type: \"object\",\n required: [patch.discriminator.propertyName],\n properties: { [patch.discriminator.propertyName]: added },\n });\n return added;\n}\n\n/** An object schema gets the enum property, which is always required, added or replaced. */\nfunction patchObjectSchema(schema: SchemaObject & ObjectSubtype, patch: EnumPatch): SchemaObject {\n const name = patch.discriminator.propertyName;\n if (!schema.properties) {\n schema.properties = {};\n }\n if (!schema.required) {\n schema.required = [name];\n } else if (!schema.required.includes(name)) {\n schema.required.push(name);\n }\n const added = discriminatorEnum(patch.values, schema.properties[name] as SchemaObject);\n schema.properties[name] = added;\n return added;\n}\n\nfunction isObjectSchema(schema: unknown): schema is SchemaObject & ObjectSubtype {\n return (\n typeof schema === \"object\" && schema !== null && \"type\" in schema && schema.type === \"object\"\n );\n}\n\n/** The values a property schema allows, from `const` or `enum`; null when it lists none. */\nfunction listedValues(property: unknown): readonly unknown[] | null {\n if (typeof property !== \"object\" || property === null) {\n return null;\n }\n const { const: constant, enum: values } = property as SchemaObject;\n if (constant !== undefined) {\n return [constant];\n }\n return Array.isArray(values) ? values : null;\n}\n\n/** Whether one schema object requires the property and allows exactly the values. */\nfunction requiresValues(schema: unknown, name: string, values: readonly string[]): boolean {\n if (typeof schema !== \"object\" || schema === null || \"$ref\" in schema) {\n return false;\n }\n const { required, properties } = schema as SchemaObject & ObjectSubtype;\n const listed = listedValues(properties?.[name]);\n return (\n Boolean(required?.includes(name)) &&\n listed !== null &&\n listed.length === values.length &&\n values.every((value) => listed.includes(value))\n );\n}\n\n/**\n * Whether `schema`, or an inline `allOf` item of it, already requires the discriminator property\n * with exactly the patch's values (the `discriminator-values` fix). Then a patch would\n * only repeat it (#2124).\n */\nexport function declaresValues(schema: SchemaObject | undefined, patch: EnumPatch): boolean {\n const name = patch.discriminator.propertyName;\n return [schema, ...(schema?.allOf ?? [])].some((item) =>\n requiresValues(item, name, patch.values),\n );\n}\n\n/**\n * Add or replace the enum property in `schema`, an `allOf` or object schema. Returns the added\n * enum schema, or null for another kind of schema, which is left as it is.\n */\nexport function addEnumProperty(\n schema: SchemaObject | undefined,\n patch: EnumPatch,\n): SchemaObject | null {\n if (schema?.allOf) {\n return patchAllOf(schema.allOf, patch);\n }\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AAO,CAAC,MAAA,EAAQ,GAAI,QAAQ,KAAA,IAAS,EAAG,CAAA,CAAE,IAAA;AAAA,IAAK,CAAC,IAAA,KAC9C,cAAA,CAAe,IAAA,EAAM,IAAA,EAAM,MAAM,MAAM;AAAA,GACzC;AACF;AAMO,SAAS,eAAA,CACd,QACA,KAAA,EACqB;AACrB,EAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,IAAA,OAAO,UAAA,CAAW,MAAA,CAAO,KAAA,EAAO,KAAK,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,eAAe,MAAM,CAAA,GAAI,iBAAA,CAAkB,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AACrE;;"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const discriminatorPatch = require('./discriminator-patch.cjs');
|
|
4
|
+
const documentRefs = require('./document-refs.cjs');
|
|
5
|
+
|
|
6
|
+
function allOfRefs(state, ref) {
|
|
7
|
+
const { silent, logger } = state;
|
|
8
|
+
const schema = documentRefs.resolveDocumentRef(state.schema, ref, { silent, logger });
|
|
9
|
+
const items = schema?.allOf ?? [];
|
|
10
|
+
return items.flatMap(
|
|
11
|
+
(item) => "$ref" in item && typeof item.$ref === "string" ? [item.$ref] : []
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
function otherOwners(state, parentRef) {
|
|
15
|
+
const own = state.objects[parentRef]?.propertyName;
|
|
16
|
+
const found = /* @__PURE__ */ new Map();
|
|
17
|
+
const visited = /* @__PURE__ */ new Set();
|
|
18
|
+
const queue = [parentRef];
|
|
19
|
+
for (let ref = queue.shift(); ref !== void 0; ref = queue.shift()) {
|
|
20
|
+
if (visited.has(ref)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
visited.add(ref);
|
|
24
|
+
const discriminator = state.owners.has(ref) ? state.objects[ref] : void 0;
|
|
25
|
+
const name = discriminator?.propertyName;
|
|
26
|
+
if (discriminator && name !== void 0 && name !== own && !found.has(name)) {
|
|
27
|
+
found.set(name, { discriminator, ownerRef: ref });
|
|
28
|
+
}
|
|
29
|
+
queue.push(...allOfRefs(state, ref));
|
|
30
|
+
}
|
|
31
|
+
return [...found.values()];
|
|
32
|
+
}
|
|
33
|
+
function recordOtherProperty(state, ref, propertyName) {
|
|
34
|
+
const names = state.otherProperties[ref] ?? [];
|
|
35
|
+
if (!names.includes(propertyName)) {
|
|
36
|
+
names.push(propertyName);
|
|
37
|
+
}
|
|
38
|
+
state.otherProperties[ref] = names;
|
|
39
|
+
}
|
|
40
|
+
function inheritOtherOwners(state, parentRef, ref) {
|
|
41
|
+
const childProperty = state.objects[ref]?.propertyName;
|
|
42
|
+
for (const { discriminator, ownerRef } of otherOwners(state, parentRef)) {
|
|
43
|
+
if (discriminator.propertyName === childProperty) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
recordOtherProperty(state, ref, discriminator.propertyName);
|
|
47
|
+
const mapped = Object.entries(discriminator.mapping ?? {}).filter(([, target]) => target === ref).map(([value]) => value);
|
|
48
|
+
const name = ref.slice(ref.lastIndexOf("/") + 1);
|
|
49
|
+
const patch = { ref, values: mapped, discriminator, discriminatorRef: ownerRef };
|
|
50
|
+
if (mapped.length > 0) {
|
|
51
|
+
discriminatorPatch.patchDiscriminatorEnum(state, patch);
|
|
52
|
+
} else {
|
|
53
|
+
state.otherInferredPatches.push({ ...patch, values: [name] });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function applyOtherInferredPatches(state, mapped) {
|
|
58
|
+
for (const patch of state.otherInferredPatches) {
|
|
59
|
+
if (!mapped.has(discriminatorPatch.enumKey(patch))) {
|
|
60
|
+
discriminatorPatch.patchDiscriminatorEnum(state, patch);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.applyOtherInferredPatches = applyOtherInferredPatches;
|
|
66
|
+
exports.inheritOtherOwners = inheritOtherOwners;
|
|
67
|
+
//# sourceMappingURL=discriminator-other-owners.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-other-owners.cjs","sources":["../../src/api/discriminator-other-owners.ts"],"sourcesContent":["import type { DiscriminatorObject, ReferenceObject, SchemaObject } from \"../types.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\nimport { enumKey, patchDiscriminatorEnum, type ScanState } from \"./discriminator-patch.js\";\nimport { resolveDocumentRef } from \"./document-refs.js\";\n\n/**\n * The `discriminator-values` fix: a schema inherits one discriminator per property. A schema that\n * owns a discriminator keeps its own (#2200), so the scan does not record the one it inherits for\n * another property (`Content` owns `subtype` and `allOf`s `Element`, which owns `contentType`).\n * Its members (`Video`) still get a value of that property, found here from the owners above.\n */\n\n/** A discriminator and the schema that defines it. */\ninterface OtherOwner {\n readonly discriminator: DiscriminatorObject;\n readonly ownerRef: string;\n}\n\n/** The `$ref`s of a schema's `allOf` items. */\nfunction allOfRefs(state: ScanState, ref: string): string[] {\n const { silent, logger } = state;\n const schema = resolveDocumentRef<SchemaObject>(state.schema, ref, { silent, logger });\n const items = (schema?.allOf ?? []) as (SchemaObject | ReferenceObject)[];\n return items.flatMap((item) =>\n \"$ref\" in item && typeof item.$ref === \"string\" ? [item.$ref] : [],\n );\n}\n\n/**\n * The owners' discriminators that the schema at `parentRef` and its `allOf` parents define, the\n * nearest one per property, except the property of `parentRef`'s own discriminator.\n */\nfunction otherOwners(state: ScanState, parentRef: string): OtherOwner[] {\n const own = state.objects[parentRef]?.propertyName;\n const found = new Map<string, OtherOwner>();\n const visited = new Set<string>();\n const queue = [parentRef];\n for (let ref = queue.shift(); ref !== undefined; ref = queue.shift()) {\n if (visited.has(ref)) {\n continue;\n }\n visited.add(ref);\n const discriminator = state.owners.has(ref) ? state.objects[ref] : undefined;\n const name = discriminator?.propertyName;\n if (discriminator && name !== undefined && name !== own && !found.has(name)) {\n found.set(name, { discriminator, ownerRef: ref });\n }\n queue.push(...allOfRefs(state, ref));\n }\n return [...found.values()];\n}\n\n/**\n * The child redefines this property, so its `allOf` items omit it: a parent may have a value of\n * its own, as `Content` has when `Element`'s mapping names it.\n */\nfunction recordOtherProperty(state: ScanState, ref: string, propertyName: string): void {\n const names = state.otherProperties[ref] ?? [];\n if (!names.includes(propertyName)) {\n names.push(propertyName);\n }\n state.otherProperties[ref] = names;\n}\n\n/**\n * The child at `ref` of the schema at `parentRef` gets a value of each other property: a mapped\n * one at once, else its schema name after both passes, where no mapping gives one. The schema's\n * own discriminator property is still added, so these patches do not mark it handled.\n */\nexport function inheritOtherOwners(state: ScanState, parentRef: string, ref: string): void {\n const childProperty = state.objects[ref]?.propertyName;\n for (const { discriminator, ownerRef } of otherOwners(state, parentRef)) {\n if (discriminator.propertyName === childProperty) {\n continue;\n }\n recordOtherProperty(state, ref, discriminator.propertyName);\n const mapped = Object.entries(discriminator.mapping ?? {})\n .filter(([, target]) => target === ref)\n .map(([value]) => value);\n const name = ref.slice(ref.lastIndexOf(\"/\") + 1);\n const patch: EnumPatch = { ref, values: mapped, discriminator, discriminatorRef: ownerRef };\n if (mapped.length > 0) {\n patchDiscriminatorEnum(state, patch);\n } else {\n state.otherInferredPatches.push({ ...patch, values: [name] });\n }\n }\n}\n\n/** The deferred schema-name values of other properties; see `inheritOtherOwners`. */\nexport function applyOtherInferredPatches(state: ScanState, mapped: ReadonlySet<string>): void {\n for (const patch of state.otherInferredPatches) {\n if (!mapped.has(enumKey(patch))) {\n patchDiscriminatorEnum(state, patch);\n }\n }\n}\n"],"names":["resolveDocumentRef","patchDiscriminatorEnum","enumKey"],"mappings":";;;;;AAmBA,SAAS,SAAA,CAAU,OAAkB,GAAA,EAAuB;AAC1D,EAAA,MAAM,EAAE,MAAA,EAAQ,MAAA,EAAO,GAAI,KAAA;AAC3B,EAAA,MAAM,MAAA,GAASA,gCAAiC,KAAA,CAAM,MAAA,EAAQ,KAAK,EAAE,MAAA,EAAQ,QAAQ,CAAA;AACrF,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AAAC,yCAAA,CAAuB,OAAO,KAAK,CAAA;AAAA,IACrC,CAAA,MAAO;AACL,MAAA,KAAA,CAAM,oBAAA,CAAqB,KAAK,EAAE,GAAG,OAAO,MAAA,EAAQ,CAAC,IAAI,CAAA,EAAG,CAAA;AAAA,IAC9D;AAAA,EACF;AACF;AAGO,SAAS,yBAAA,CAA0B,OAAkB,MAAA,EAAmC;AAC7F,EAAA,KAAA,MAAW,KAAA,IAAS,MAAM,oBAAA,EAAsB;AAC9C,IAAA,IAAI,CAAC,MAAA,CAAO,GAAA,CAAIC,0BAAA,CAAQ,KAAK,CAAC,CAAA,EAAG;AAC/B,MAAAD,yCAAA,CAAuB,OAAO,KAAK,CAAA;AAAA,IACrC;AAAA,EACF;AACF;;;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { enumKey, patchDiscriminatorEnum } from './discriminator-patch.mjs';
|
|
2
|
+
import { resolveDocumentRef } from './document-refs.mjs';
|
|
3
|
+
|
|
4
|
+
function allOfRefs(state, ref) {
|
|
5
|
+
const { silent, logger } = state;
|
|
6
|
+
const schema = resolveDocumentRef(state.schema, ref, { silent, logger });
|
|
7
|
+
const items = schema?.allOf ?? [];
|
|
8
|
+
return items.flatMap(
|
|
9
|
+
(item) => "$ref" in item && typeof item.$ref === "string" ? [item.$ref] : []
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
function otherOwners(state, parentRef) {
|
|
13
|
+
const own = state.objects[parentRef]?.propertyName;
|
|
14
|
+
const found = /* @__PURE__ */ new Map();
|
|
15
|
+
const visited = /* @__PURE__ */ new Set();
|
|
16
|
+
const queue = [parentRef];
|
|
17
|
+
for (let ref = queue.shift(); ref !== void 0; ref = queue.shift()) {
|
|
18
|
+
if (visited.has(ref)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
visited.add(ref);
|
|
22
|
+
const discriminator = state.owners.has(ref) ? state.objects[ref] : void 0;
|
|
23
|
+
const name = discriminator?.propertyName;
|
|
24
|
+
if (discriminator && name !== void 0 && name !== own && !found.has(name)) {
|
|
25
|
+
found.set(name, { discriminator, ownerRef: ref });
|
|
26
|
+
}
|
|
27
|
+
queue.push(...allOfRefs(state, ref));
|
|
28
|
+
}
|
|
29
|
+
return [...found.values()];
|
|
30
|
+
}
|
|
31
|
+
function recordOtherProperty(state, ref, propertyName) {
|
|
32
|
+
const names = state.otherProperties[ref] ?? [];
|
|
33
|
+
if (!names.includes(propertyName)) {
|
|
34
|
+
names.push(propertyName);
|
|
35
|
+
}
|
|
36
|
+
state.otherProperties[ref] = names;
|
|
37
|
+
}
|
|
38
|
+
function inheritOtherOwners(state, parentRef, ref) {
|
|
39
|
+
const childProperty = state.objects[ref]?.propertyName;
|
|
40
|
+
for (const { discriminator, ownerRef } of otherOwners(state, parentRef)) {
|
|
41
|
+
if (discriminator.propertyName === childProperty) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
recordOtherProperty(state, ref, discriminator.propertyName);
|
|
45
|
+
const mapped = Object.entries(discriminator.mapping ?? {}).filter(([, target]) => target === ref).map(([value]) => value);
|
|
46
|
+
const name = ref.slice(ref.lastIndexOf("/") + 1);
|
|
47
|
+
const patch = { ref, values: mapped, discriminator, discriminatorRef: ownerRef };
|
|
48
|
+
if (mapped.length > 0) {
|
|
49
|
+
patchDiscriminatorEnum(state, patch);
|
|
50
|
+
} else {
|
|
51
|
+
state.otherInferredPatches.push({ ...patch, values: [name] });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function applyOtherInferredPatches(state, mapped) {
|
|
56
|
+
for (const patch of state.otherInferredPatches) {
|
|
57
|
+
if (!mapped.has(enumKey(patch))) {
|
|
58
|
+
patchDiscriminatorEnum(state, patch);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { applyOtherInferredPatches, inheritOtherOwners };
|
|
64
|
+
//# sourceMappingURL=discriminator-other-owners.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-other-owners.mjs","sources":["../../src/api/discriminator-other-owners.ts"],"sourcesContent":["import type { DiscriminatorObject, ReferenceObject, SchemaObject } from \"../types.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\nimport { enumKey, patchDiscriminatorEnum, type ScanState } from \"./discriminator-patch.js\";\nimport { resolveDocumentRef } from \"./document-refs.js\";\n\n/**\n * The `discriminator-values` fix: a schema inherits one discriminator per property. A schema that\n * owns a discriminator keeps its own (#2200), so the scan does not record the one it inherits for\n * another property (`Content` owns `subtype` and `allOf`s `Element`, which owns `contentType`).\n * Its members (`Video`) still get a value of that property, found here from the owners above.\n */\n\n/** A discriminator and the schema that defines it. */\ninterface OtherOwner {\n readonly discriminator: DiscriminatorObject;\n readonly ownerRef: string;\n}\n\n/** The `$ref`s of a schema's `allOf` items. */\nfunction allOfRefs(state: ScanState, ref: string): string[] {\n const { silent, logger } = state;\n const schema = resolveDocumentRef<SchemaObject>(state.schema, ref, { silent, logger });\n const items = (schema?.allOf ?? []) as (SchemaObject | ReferenceObject)[];\n return items.flatMap((item) =>\n \"$ref\" in item && typeof item.$ref === \"string\" ? [item.$ref] : [],\n );\n}\n\n/**\n * The owners' discriminators that the schema at `parentRef` and its `allOf` parents define, the\n * nearest one per property, except the property of `parentRef`'s own discriminator.\n */\nfunction otherOwners(state: ScanState, parentRef: string): OtherOwner[] {\n const own = state.objects[parentRef]?.propertyName;\n const found = new Map<string, OtherOwner>();\n const visited = new Set<string>();\n const queue = [parentRef];\n for (let ref = queue.shift(); ref !== undefined; ref = queue.shift()) {\n if (visited.has(ref)) {\n continue;\n }\n visited.add(ref);\n const discriminator = state.owners.has(ref) ? state.objects[ref] : undefined;\n const name = discriminator?.propertyName;\n if (discriminator && name !== undefined && name !== own && !found.has(name)) {\n found.set(name, { discriminator, ownerRef: ref });\n }\n queue.push(...allOfRefs(state, ref));\n }\n return [...found.values()];\n}\n\n/**\n * The child redefines this property, so its `allOf` items omit it: a parent may have a value of\n * its own, as `Content` has when `Element`'s mapping names it.\n */\nfunction recordOtherProperty(state: ScanState, ref: string, propertyName: string): void {\n const names = state.otherProperties[ref] ?? [];\n if (!names.includes(propertyName)) {\n names.push(propertyName);\n }\n state.otherProperties[ref] = names;\n}\n\n/**\n * The child at `ref` of the schema at `parentRef` gets a value of each other property: a mapped\n * one at once, else its schema name after both passes, where no mapping gives one. The schema's\n * own discriminator property is still added, so these patches do not mark it handled.\n */\nexport function inheritOtherOwners(state: ScanState, parentRef: string, ref: string): void {\n const childProperty = state.objects[ref]?.propertyName;\n for (const { discriminator, ownerRef } of otherOwners(state, parentRef)) {\n if (discriminator.propertyName === childProperty) {\n continue;\n }\n recordOtherProperty(state, ref, discriminator.propertyName);\n const mapped = Object.entries(discriminator.mapping ?? {})\n .filter(([, target]) => target === ref)\n .map(([value]) => value);\n const name = ref.slice(ref.lastIndexOf(\"/\") + 1);\n const patch: EnumPatch = { ref, values: mapped, discriminator, discriminatorRef: ownerRef };\n if (mapped.length > 0) {\n patchDiscriminatorEnum(state, patch);\n } else {\n state.otherInferredPatches.push({ ...patch, values: [name] });\n }\n }\n}\n\n/** The deferred schema-name values of other properties; see `inheritOtherOwners`. */\nexport function applyOtherInferredPatches(state: ScanState, mapped: ReadonlySet<string>): void {\n for (const patch of state.otherInferredPatches) {\n if (!mapped.has(enumKey(patch))) {\n patchDiscriminatorEnum(state, patch);\n }\n }\n}\n"],"names":[],"mappings":";;;AAmBA,SAAS,SAAA,CAAU,OAAkB,GAAA,EAAuB;AAC1D,EAAA,MAAM,EAAE,MAAA,EAAQ,MAAA,EAAO,GAAI,KAAA;AAC3B,EAAA,MAAM,MAAA,GAAS,mBAAiC,KAAA,CAAM,MAAA,EAAQ,KAAK,EAAE,MAAA,EAAQ,QAAQ,CAAA;AACrF,EAAA,MAAM,KAAA,GAAS,MAAA,EAAQ,KAAA,IAAS,EAAC;AACjC,EAAA,OAAO,KAAA,CAAM,OAAA;AA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AqB,KAAK,EAAE,GAAG,OAAO,MAAA,EAAQ,CAAC,IAAI,CAAA,EAAG,CAAA;AAAA,IAC9D;AAAA,EACF;AACF;AAGO,SAAS,yBAAA,CAA0B,OAAkB,MAAA,EAAmC;AAC7F,EAAA,KAAA,MAAW,KAAA,IAAS,MAAM,oBAAA,EAAsB;AAC9C,IAAA,IAAI,CAAC,MAAA,CAAO,GAAA,CAAI,OAAA,CAAQ,KAAK,CAAC,CAAA,EAAG;AAC/B,MAAA,sBAAA,CAAuB,OAAO,KAAK,CAAA;AAAA,IACrC;AAAA,EACF;AACF;;"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const outputFixes = require('../domain/output-fixes.cjs');
|
|
4
|
+
const discriminatorEnum = require('./discriminator-enum.cjs');
|
|
5
|
+
const discriminatorEnumParent = require('./discriminator-enum-parent.cjs');
|
|
6
|
+
const documentRefs = require('./document-refs.cjs');
|
|
7
|
+
|
|
8
|
+
function mergesValues(state) {
|
|
9
|
+
return state.fixes.has(outputFixes.OutputFix.DISCRIMINATOR_VALUES);
|
|
10
|
+
}
|
|
11
|
+
function patchedSchema(state, patch) {
|
|
12
|
+
const { silent, logger } = state;
|
|
13
|
+
return documentRefs.resolveDocumentRef(state.schema, patch.ref, { silent, logger });
|
|
14
|
+
}
|
|
15
|
+
function isDeclared(state, patch) {
|
|
16
|
+
return state.fixes.has(outputFixes.OutputFix.DISCRIMINATOR_VALUES) && discriminatorEnum.declaresValues(patchedSchema(state, patch), patch);
|
|
17
|
+
}
|
|
18
|
+
function recordEnumParent(state, owner, key) {
|
|
19
|
+
if (!state.fixes.has(outputFixes.OutputFix.DISCRIMINATOR_VALUES)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const { silent, logger } = state;
|
|
23
|
+
const parent = discriminatorEnumParent.enumParentOf(
|
|
24
|
+
owner,
|
|
25
|
+
(ref) => documentRefs.resolveDocumentRef(state.schema, ref, { silent, logger })
|
|
26
|
+
);
|
|
27
|
+
if (parent !== void 0) {
|
|
28
|
+
state.enumParents.set(key, parent);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function addDiscriminatorEnum(state, patch) {
|
|
32
|
+
const added = discriminatorEnum.addEnumProperty(patchedSchema(state, patch), patch);
|
|
33
|
+
if (added === null) {
|
|
34
|
+
warnInvalidMapping(patch, state.logger);
|
|
35
|
+
} else {
|
|
36
|
+
recordEnumParent(state, patch, added);
|
|
37
|
+
}
|
|
38
|
+
return added;
|
|
39
|
+
}
|
|
40
|
+
function enumKey(patch) {
|
|
41
|
+
return `${patch.ref}
|
|
42
|
+
${patch.discriminator.propertyName}`;
|
|
43
|
+
}
|
|
44
|
+
function mergeIntoPatchedEnum(state, key, values) {
|
|
45
|
+
const patched = state.patchedEnums.get(key);
|
|
46
|
+
if (patched === void 0) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const merged = patched.enum;
|
|
50
|
+
merged.push(...values.filter((value) => !merged.includes(value)));
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
function patchDiscriminatorEnum(state, patch) {
|
|
54
|
+
if (isDeclared(state, patch)) {
|
|
55
|
+
state.declaredKeys.add(enumKey(patch));
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (!mergesValues(state)) {
|
|
59
|
+
return addDiscriminatorEnum(state, patch) !== null;
|
|
60
|
+
}
|
|
61
|
+
const key = enumKey(patch);
|
|
62
|
+
if (mergeIntoPatchedEnum(state, key, patch.values)) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
const added = addDiscriminatorEnum(state, patch);
|
|
66
|
+
if (added !== null) {
|
|
67
|
+
state.patchedEnums.set(key, added);
|
|
68
|
+
}
|
|
69
|
+
return added !== null;
|
|
70
|
+
}
|
|
71
|
+
function markHandled(state, ref) {
|
|
72
|
+
if (!state.refsHandled.includes(ref)) {
|
|
73
|
+
state.refsHandled.push(ref);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function warnInvalidMapping(patch, logger) {
|
|
77
|
+
const mapped = `${patch.ref} => ${patch.values.join(", ")}`;
|
|
78
|
+
logger.warn(
|
|
79
|
+
`Discriminator mapping has an invalid schema (neither an object schema nor an allOf array): ${mapped} (Discriminator: ${patch.discriminatorRef})`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
exports.enumKey = enumKey;
|
|
84
|
+
exports.markHandled = markHandled;
|
|
85
|
+
exports.mergesValues = mergesValues;
|
|
86
|
+
exports.patchDiscriminatorEnum = patchDiscriminatorEnum;
|
|
87
|
+
exports.recordEnumParent = recordEnumParent;
|
|
88
|
+
//# sourceMappingURL=discriminator-patch.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-patch.cjs","sources":["../../src/api/discriminator-patch.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport { OutputFix } from \"../domain/output-fixes.js\";\nimport type { DiscriminatorObject, OpenAPI3, SchemaObject } from \"../types.js\";\nimport { addEnumProperty, declaresValues, type EnumPatch } from \"./discriminator-enum.js\";\nimport {\n type DiscriminatorOwner,\n type EnumParent,\n enumParentOf,\n} from \"./discriminator-enum-parent.js\";\nimport { resolveDocumentRef } from \"./document-refs.js\";\n\n/**\n * The state of the discriminator pre-pass and the in-place patch of a mapped schema: the enum\n * property that the generated union narrows by. Two discriminators of one property may patch one\n * schema; how they combine is the `discriminator-values` fix (ADR-021, roadmap R12).\n */\n\n/** How to scan: the warnings, and the output fixes of the run (ADR-021). */\nexport interface DiscriminatorScanOptions {\n readonly silent: boolean;\n readonly logger: Logger;\n readonly fixes: ReadonlySet<OutputFix>;\n}\n\n/** What the two passes share: the document they patch and what they found so far. */\nexport interface ScanState extends DiscriminatorScanOptions {\n readonly schema: OpenAPI3;\n readonly objects: Record<string, DiscriminatorObject>;\n /** The schemas that define a discriminator themselves (pass 1), not by inheritance. */\n readonly owners: Set<string>;\n readonly refsHandled: string[];\n /** With the fix: the enum added to each schema, by schema and property, so values merge. */\n readonly patchedEnums: Map<string, SchemaObject>;\n /** With the fix: schema-name values, applied after both passes where no mapping names one. */\n readonly inferredPatches: EnumPatch[];\n /** With the fix: schema-name values of other properties (`inheritOtherOwners`). */\n readonly otherInferredPatches: EnumPatch[];\n /** With the fix: the other properties each schema got a value of (`inheritOtherOwners`). */\n readonly otherProperties: Record<string, string[]>;\n /** With `discriminator-values`: the enum keys that a schema declares itself. */\n readonly declaredKeys: Set<string>;\n /** With `discriminator-values`: the owner's enum of each added enum, by that enum. */\n readonly enumParents: Map<object, EnumParent>;\n}\n\n/** Whether `discriminator-values` is on: values of two discriminators merge into one enum. */\nexport function mergesValues(state: ScanState): boolean {\n return state.fixes.has(OutputFix.DISCRIMINATOR_VALUES);\n}\n\nfunction patchedSchema(state: ScanState, patch: EnumPatch): SchemaObject | undefined {\n const { silent, logger } = state;\n return resolveDocumentRef<SchemaObject>(state.schema, patch.ref, { silent, logger });\n}\n\n/**\n * With `discriminator-values`: the schema at `patch.ref` requires the property with\n * exactly these values already, so a patch would only repeat it (#2124).\n */\nfunction isDeclared(state: ScanState, patch: EnumPatch): boolean {\n return (\n state.fixes.has(OutputFix.DISCRIMINATOR_VALUES) &&\n declaresValues(patchedSchema(state, patch), patch)\n );\n}\n\n/**\n * With `discriminator-values`: the enum of the owner's property, for `key`: an enum the scan\n * added, or a discriminator object that a schema inherited.\n */\nexport function recordEnumParent(state: ScanState, owner: DiscriminatorOwner, key: object): void {\n if (!state.fixes.has(OutputFix.DISCRIMINATOR_VALUES)) {\n return;\n }\n const { silent, logger } = state;\n const parent = enumParentOf(owner, (ref) =>\n resolveDocumentRef(state.schema, ref, { silent, logger }),\n );\n if (parent !== undefined) {\n state.enumParents.set(key, parent);\n }\n}\n\n/** The enum the schema at `patch.ref` gets, or null (with a warning) for another kind of schema. */\nfunction addDiscriminatorEnum(state: ScanState, patch: EnumPatch): SchemaObject | null {\n const added = addEnumProperty(patchedSchema(state, patch), patch);\n if (added === null) {\n warnInvalidMapping(patch, state.logger);\n } else {\n recordEnumParent(state, patch, added);\n }\n return added;\n}\n\n/** One schema and discriminator property; two discriminators of one property share an enum. */\nexport function enumKey(patch: EnumPatch): string {\n return `${patch.ref}\\n${patch.discriminator.propertyName}`;\n}\n\n/** With the fix, a second discriminator of the same property adds its values to the first enum. */\nfunction mergeIntoPatchedEnum(state: ScanState, key: string, values: readonly string[]): boolean {\n const patched = state.patchedEnums.get(key);\n if (patched === undefined) {\n return false;\n }\n const merged = patched.enum as unknown[];\n merged.push(...values.filter((value) => !merged.includes(value)));\n return true;\n}\n\n/**\n * Add or replace the discriminator enum in the schema at `patch.ref`. Returns false, with a\n * warning, when that schema is neither an `allOf` nor an object schema. Without the fix every\n * patch adds a property, so two discriminators with different values intersect to `never`.\n */\nexport function patchDiscriminatorEnum(state: ScanState, patch: EnumPatch): boolean {\n if (isDeclared(state, patch)) {\n state.declaredKeys.add(enumKey(patch));\n return true;\n }\n if (!mergesValues(state)) {\n return addDiscriminatorEnum(state, patch) !== null;\n }\n const key = enumKey(patch);\n if (mergeIntoPatchedEnum(state, key, patch.values)) {\n return true;\n }\n const added = addDiscriminatorEnum(state, patch);\n if (added !== null) {\n state.patchedEnums.set(key, added);\n }\n return added !== null;\n}\n\nexport function markHandled(state: ScanState, ref: string): void {\n if (!state.refsHandled.includes(ref)) {\n state.refsHandled.push(ref);\n }\n}\n\nfunction warnInvalidMapping(patch: EnumPatch, logger: Logger): void {\n const mapped = `${patch.ref} => ${patch.values.join(\", \")}`;\n logger.warn(\n \"Discriminator mapping has an invalid schema (neither an object schema nor an allOf array): \" +\n `${mapped} (Discriminator: ${patch.discriminatorRef})`,\n );\n}\n"],"names":["OutputFix","resolveDocumentRef","declaresValues","enumParentOf","addEnumProperty"],"mappings":";;;;;;;AA8CO,SAAS,aAAa,KAAA,EAA2B;AACtD,EAAA,OAAO,KAAA,CAAM,KAAA,CAAM,GAA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