openapi-typesafe 0.0.0 → 1.0.0-rc.0
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 +42 -0
- package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-config-source.mjs +35 -0
- package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +169 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +167 -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 +145 -0
- package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +139 -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 +204 -0
- package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs.map +1 -0
- package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs +201 -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-enum.cjs +44 -0
- package/dist/api/discriminator-enum.cjs.map +1 -0
- package/dist/api/discriminator-enum.mjs +42 -0
- package/dist/api/discriminator-enum.mjs.map +1 -0
- package/dist/api/discriminator-scan.cjs +168 -0
- package/dist/api/discriminator-scan.cjs.map +1 -0
- package/dist/api/discriminator-scan.mjs +165 -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 +107 -0
- package/dist/api/document-run.cjs.map +1 -0
- package/dist/api/document-run.mjs +101 -0
- package/dist/api/document-run.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/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 +82 -0
- package/dist/api/transform-context.cjs.map +1 -0
- package/dist/api/transform-context.mjs +65 -0
- package/dist/api/transform-context.mjs.map +1 -0
- package/dist/api/transform-schema.cjs +31 -0
- package/dist/api/transform-schema.cjs.map +1 -0
- package/dist/api/transform-schema.mjs +26 -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 +17 -0
- package/dist/api/unsupported-feature-warnings.cjs.map +1 -0
- package/dist/api/unsupported-feature-warnings.mjs +15 -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 +214 -0
- package/dist/application/print/type-printer.cjs.map +1 -0
- package/dist/application/print/type-printer.mjs +210 -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/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/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 +86 -0
- package/dist/application/transform/document/document.cjs.map +1 -0
- package/dist/application/transform/document/document.mjs +83 -0
- package/dist/application/transform/document/document.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/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 +114 -0
- package/dist/application/transform/document/parameters.cjs.map +1 -0
- package/dist/application/transform/document/parameters.mjs +112 -0
- package/dist/application/transform/document/parameters.mjs.map +1 -0
- package/dist/application/transform/document/path-item-conflicts.cjs +51 -0
- package/dist/application/transform/document/path-item-conflicts.cjs.map +1 -0
- package/dist/application/transform/document/path-item-conflicts.mjs +49 -0
- package/dist/application/transform/document/path-item-conflicts.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 +57 -0
- package/dist/application/transform/document/path-key-overlaps.cjs.map +1 -0
- package/dist/application/transform/document/path-key-overlaps.mjs +55 -0
- package/dist/application/transform/document/path-key-overlaps.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 +127 -0
- package/dist/application/transform/document/paths.cjs.map +1 -0
- package/dist/application/transform/document/paths.mjs +125 -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 +69 -0
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -0
- package/dist/application/transform/document/root-type-aliases.mjs +65 -0
- package/dist/application/transform/document/root-type-aliases.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 +88 -0
- package/dist/application/transform/footer/document-footer.cjs.map +1 -0
- package/dist/application/transform/footer/document-footer.mjs +86 -0
- package/dist/application/transform/footer/document-footer.mjs.map +1 -0
- package/dist/application/transform/footer/enum-naming.cjs +121 -0
- package/dist/application/transform/footer/enum-naming.cjs.map +1 -0
- package/dist/application/transform/footer/enum-naming.mjs +115 -0
- package/dist/application/transform/footer/enum-naming.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-type.cjs +57 -0
- package/dist/application/transform/ref-type.cjs.map +1 -0
- package/dist/application/transform/ref-type.mjs +54 -0
- package/dist/application/transform/ref-type.mjs.map +1 -0
- package/dist/application/transform/schema/array-type.cjs +105 -0
- package/dist/application/transform/schema/array-type.cjs.map +1 -0
- package/dist/application/transform/schema/array-type.mjs +103 -0
- package/dist/application/transform/schema/array-type.mjs.map +1 -0
- package/dist/application/transform/schema/composition-type.cjs +107 -0
- package/dist/application/transform/schema/composition-type.cjs.map +1 -0
- package/dist/application/transform/schema/composition-type.mjs +105 -0
- package/dist/application/transform/schema/composition-type.mjs.map +1 -0
- package/dist/application/transform/schema/core-type.cjs +84 -0
- package/dist/application/transform/schema/core-type.cjs.map +1 -0
- package/dist/application/transform/schema/core-type.mjs +82 -0
- package/dist/application/transform/schema/core-type.mjs.map +1 -0
- package/dist/application/transform/schema/discriminator-property.cjs +21 -0
- package/dist/application/transform/schema/discriminator-property.cjs.map +1 -0
- package/dist/application/transform/schema/discriminator-property.mjs +19 -0
- package/dist/application/transform/schema/discriminator-property.mjs.map +1 -0
- package/dist/application/transform/schema/enum-rule.cjs +107 -0
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -0
- package/dist/application/transform/schema/enum-rule.mjs +105 -0
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -0
- package/dist/application/transform/schema/object-type.cjs +173 -0
- package/dist/application/transform/schema/object-type.cjs.map +1 -0
- package/dist/application/transform/schema/object-type.mjs +170 -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/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 +84 -0
- package/dist/application/transform/schema-comment.cjs.map +1 -0
- package/dist/application/transform/schema-comment.mjs +81 -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 +137 -0
- package/dist/cli/cli-arguments.cjs.map +1 -0
- package/dist/cli/cli-arguments.mjs +129 -0
- package/dist/cli/cli-arguments.mjs.map +1 -0
- package/dist/cli/cli-errors.cjs +80 -0
- package/dist/cli/cli-errors.cjs.map +1 -0
- package/dist/cli/cli-errors.mjs +76 -0
- package/dist/cli/cli-errors.mjs.map +1 -0
- package/dist/cli/cli-output.cjs +37 -0
- package/dist/cli/cli-output.cjs.map +1 -0
- package/dist/cli/cli-output.mjs +30 -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 +62 -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 +54 -0
- package/dist/cli/main.mjs.map +1 -0
- package/dist/cli/redocly-apis.cjs +65 -0
- package/dist/cli/redocly-apis.cjs.map +1 -0
- package/dist/cli/redocly-apis.mjs +62 -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 +100 -0
- package/dist/cli/run-cli.cjs.map +1 -0
- package/dist/cli/run-cli.mjs +98 -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 +50 -0
- package/dist/domain/errors.cjs.map +1 -0
- package/dist/domain/errors.mjs +46 -0
- package/dist/domain/errors.mjs.map +1 -0
- package/dist/domain/ir/constructors.cjs +89 -0
- package/dist/domain/ir/constructors.cjs.map +1 -0
- package/dist/domain/ir/constructors.mjs +71 -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/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/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/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 +66 -0
- package/dist/domain/output-fixes.cjs.map +1 -0
- package/dist/domain/output-fixes.mjs +59 -0
- package/dist/domain/output-fixes.mjs.map +1 -0
- package/dist/index.cjs +98 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +812 -0
- package/dist/index.d.mts +812 -0
- package/dist/index.d.ts +812 -0
- package/dist/index.mjs +27 -0
- package/dist/index.mjs.map +1 -0
- package/dist/transform/components-object.cjs +14 -0
- package/dist/transform/components-object.cjs.map +1 -0
- package/dist/transform/components-object.mjs +10 -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 +43 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +246 -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 +220 -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 +280 -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-enum.ts +76 -0
- package/src/api/discriminator-scan.ts +272 -0
- package/src/api/document-declarations.ts +41 -0
- package/src/api/document-refs.ts +71 -0
- package/src/api/document-run.ts +159 -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/schema-callbacks.ts +211 -0
- package/src/api/string-to-ast.ts +27 -0
- package/src/api/transform-context.ts +87 -0
- package/src/api/transform-schema.ts +39 -0
- package/src/api/type-helpers.ts +130 -0
- package/src/api/unsupported-feature-warnings.ts +26 -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 +16 -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 +281 -0
- package/src/application/stack-overflow.ts +54 -0
- package/src/application/transform/document/components.ts +189 -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 +157 -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/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 +200 -0
- package/src/application/transform/document/path-item-conflicts.ts +79 -0
- package/src/application/transform/document/path-item.ts +168 -0
- package/src/application/transform/document/path-key-overlaps.ts +112 -0
- package/src/application/transform/document/paths-enum.ts +127 -0
- package/src/application/transform/document/paths.ts +211 -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 +106 -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 +127 -0
- package/src/application/transform/footer/enum-naming.ts +181 -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-type.ts +97 -0
- package/src/application/transform/schema/array-type.ts +152 -0
- package/src/application/transform/schema/composition-type.ts +183 -0
- package/src/application/transform/schema/core-type.ts +115 -0
- package/src/application/transform/schema/discriminator-property.ts +28 -0
- package/src/application/transform/schema/enum-rule.ts +157 -0
- package/src/application/transform/schema/object-type.ts +271 -0
- package/src/application/transform/schema/presence-members.ts +96 -0
- package/src/application/transform/schema/schema-context.ts +110 -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 +116 -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 +198 -0
- package/src/cli/cli-dependencies.ts +42 -0
- package/src/cli/cli-errors.ts +125 -0
- package/src/cli/cli-output.ts +53 -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 +67 -0
- package/src/cli/redocly-apis.ts +91 -0
- package/src/cli/ref-limits.ts +16 -0
- package/src/cli/run-cli.ts +114 -0
- package/src/domain/assert-never.ts +8 -0
- package/src/domain/errors.ts +74 -0
- package/src/domain/ir/constructors.ts +137 -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 +224 -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/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/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 +30 -0
- package/src/domain/openapi/path-item-object.ts +70 -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 +59 -0
- package/src/domain/openapi/unsupported-features.ts +139 -0
- package/src/domain/output-fixes.ts +95 -0
- package/src/index.ts +67 -0
- package/src/transform/components-object.ts +25 -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 +267 -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,211 @@
|
|
|
1
|
+
import { irIntersection, irObject, irProperty, irRaw } from "../../../domain/ir/constructors.js";
|
|
2
|
+
import type { IrMember, IrType } from "../../../domain/ir/nodes.js";
|
|
3
|
+
import { toPropertyName } from "../../../domain/ir/property-name.js";
|
|
4
|
+
import { escapeTemplateText } from "../../../domain/ir/raw-text-escapes.js";
|
|
5
|
+
import { createRef } from "../../../domain/openapi/json-pointer.js";
|
|
6
|
+
import type { OperationObject } from "../../../domain/openapi/operation-object.js";
|
|
7
|
+
import type {
|
|
8
|
+
ParameterObject,
|
|
9
|
+
ParameterOrReference,
|
|
10
|
+
} from "../../../domain/openapi/parameter-object.js";
|
|
11
|
+
import {
|
|
12
|
+
type PathItemObject,
|
|
13
|
+
type PathsObject,
|
|
14
|
+
pathItemOperations,
|
|
15
|
+
} from "../../../domain/openapi/path-item-object.js";
|
|
16
|
+
import type { ReferenceSchema, SchemaObject } from "../../../domain/openapi/schema-object.js";
|
|
17
|
+
import { documentEntries } from "../document-entries.js";
|
|
18
|
+
import { refType } from "../ref-type.js";
|
|
19
|
+
import type { TransformContext } from "../transform-context.js";
|
|
20
|
+
import { documentMember } from "./document-member.js";
|
|
21
|
+
import { pathItemType } from "./path-item.js";
|
|
22
|
+
import { isCoveredPathItemRejected } from "./path-item-conflicts.js";
|
|
23
|
+
import {
|
|
24
|
+
coveringTemplateKeys,
|
|
25
|
+
type PathKey,
|
|
26
|
+
type PathKeyPart,
|
|
27
|
+
type PathPlaceholder,
|
|
28
|
+
} from "./path-key-overlaps.js";
|
|
29
|
+
|
|
30
|
+
const PATH_PARAMETER_RE = /\{[^}]+\}/g;
|
|
31
|
+
|
|
32
|
+
/** Placeholders by parameter schema type; anything else is a string placeholder. */
|
|
33
|
+
const PLACEHOLDERS: ReadonlyMap<unknown, PathPlaceholder> = new Map([
|
|
34
|
+
["number", "number"],
|
|
35
|
+
["integer", "number"],
|
|
36
|
+
["boolean", "boolean"],
|
|
37
|
+
]);
|
|
38
|
+
const STRING_PLACEHOLDER: PathPlaceholder = "string";
|
|
39
|
+
|
|
40
|
+
/** `${type}`: the text of a template literal type placeholder. */
|
|
41
|
+
function placeholderText(type: PathPlaceholder): string {
|
|
42
|
+
return `\${${type}}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function resolvedParameter(
|
|
46
|
+
parameter: ParameterOrReference,
|
|
47
|
+
context: TransformContext,
|
|
48
|
+
): ParameterObject | undefined {
|
|
49
|
+
return "$ref" in parameter && parameter.$ref
|
|
50
|
+
? (context.refs.resolve(parameter.$ref) as ParameterObject | undefined)
|
|
51
|
+
: (parameter as ParameterObject);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function addPathParameters(
|
|
55
|
+
parameters: readonly ParameterOrReference[],
|
|
56
|
+
byName: Map<string, ParameterObject>,
|
|
57
|
+
context: TransformContext,
|
|
58
|
+
): void {
|
|
59
|
+
for (const parameter of parameters) {
|
|
60
|
+
const resolved = resolvedParameter(parameter, context);
|
|
61
|
+
if (resolved && resolved.in === "path") {
|
|
62
|
+
byName.set(resolved.name, resolved);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Path parameters of the path item and of its operations; later definitions win. */
|
|
68
|
+
function pathParameters(
|
|
69
|
+
pathItem: PathItemObject,
|
|
70
|
+
context: TransformContext,
|
|
71
|
+
): Map<string, ParameterObject> {
|
|
72
|
+
const byName = new Map<string, ParameterObject>();
|
|
73
|
+
addPathParameters(pathItem.parameters ?? [], byName, context);
|
|
74
|
+
for (const { operation: entry } of pathItemOperations(pathItem)) {
|
|
75
|
+
const operation = (entry as ReferenceSchema).$ref
|
|
76
|
+
? (context.refs.resolve((entry as ReferenceSchema).$ref) as OperationObject | undefined)
|
|
77
|
+
: (entry as OperationObject);
|
|
78
|
+
addPathParameters(operation?.parameters ?? [], byName, context);
|
|
79
|
+
}
|
|
80
|
+
return byName;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* `--path-params-as-types`: the URL as template parts, each `{name}` replaced by a placeholder for
|
|
85
|
+
* its parameter's type. Null when the URL has no complete `{…}` placeholder.
|
|
86
|
+
*/
|
|
87
|
+
function pathTemplateParts(
|
|
88
|
+
url: string,
|
|
89
|
+
pathItem: PathItemObject,
|
|
90
|
+
context: TransformContext,
|
|
91
|
+
): PathKeyPart[] | null {
|
|
92
|
+
const matches = url.match(PATH_PARAMETER_RE);
|
|
93
|
+
if (!matches) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const parameters = pathParameters(pathItem, context);
|
|
97
|
+
const placeholders = matches.map((match) => {
|
|
98
|
+
const schema = parameters.get(match.slice(1, -1))?.schema as SchemaObject | undefined;
|
|
99
|
+
return PLACEHOLDERS.get(schema?.type) ?? STRING_PLACEHOLDER;
|
|
100
|
+
});
|
|
101
|
+
return url.split(PATH_PARAMETER_RE).flatMap((text, index): PathKeyPart[] => {
|
|
102
|
+
const type = placeholders[index];
|
|
103
|
+
const textPart: PathKeyPart = { kind: "text", text };
|
|
104
|
+
return type === undefined ? [textPart] : [textPart, { kind: "placeholder", type }];
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The template literal type of the parts. The original escaped only backticks: a backslash or
|
|
110
|
+
* `${` in the URL could end the literal or open a placeholder, and add code to the generated file
|
|
111
|
+
* (intentional fix). So the text parts are escaped.
|
|
112
|
+
*/
|
|
113
|
+
function templateText(parts: readonly PathKeyPart[]): string {
|
|
114
|
+
const text = parts
|
|
115
|
+
.map((part) =>
|
|
116
|
+
part.kind === "text" ? escapeTemplateText(part.text) : placeholderText(part.type),
|
|
117
|
+
)
|
|
118
|
+
.join("");
|
|
119
|
+
return `\`${text}\``;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A path's member, its key and its path item type for the overlap check. */
|
|
123
|
+
interface PathMember {
|
|
124
|
+
readonly member: IrMember;
|
|
125
|
+
readonly key: PathKey;
|
|
126
|
+
readonly type: IrType;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function pathItemMember(
|
|
130
|
+
url: string,
|
|
131
|
+
pathItem: PathItemObject,
|
|
132
|
+
context: TransformContext,
|
|
133
|
+
): PathMember {
|
|
134
|
+
const isReadonly = context.options.immutable;
|
|
135
|
+
const type = pathItemType(pathItem, { path: createRef(["paths", url]) }, context);
|
|
136
|
+
const parts =
|
|
137
|
+
context.options.pathParamsAsTypes && url.includes("{")
|
|
138
|
+
? pathTemplateParts(url, pathItem, context)
|
|
139
|
+
: null;
|
|
140
|
+
if (parts === null) {
|
|
141
|
+
const member = irProperty(toPropertyName(url), type, { isReadonly });
|
|
142
|
+
return { member, key: literalKey(url), type };
|
|
143
|
+
}
|
|
144
|
+
const member: IrMember = {
|
|
145
|
+
kind: "indexSignature",
|
|
146
|
+
parameterName: "path",
|
|
147
|
+
parameterType: irRaw(templateText(parts)),
|
|
148
|
+
type,
|
|
149
|
+
isReadonly,
|
|
150
|
+
comments: [],
|
|
151
|
+
};
|
|
152
|
+
return { member, key: { kind: "template", parts }, type };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function literalKey(url: string): PathKey {
|
|
156
|
+
return { kind: "literal", url };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The members as one object type. When an index signature covers another key, TypeScript checks
|
|
161
|
+
* the covered key's type against it. Where that check surely fails (TS2411, TS2413), each such
|
|
162
|
+
* signature gets an object of its own in an intersection: an intersection does not check its parts
|
|
163
|
+
* against each other, and every key has the type it had in the one object. Output that compiles
|
|
164
|
+
* keeps the one object.
|
|
165
|
+
*/
|
|
166
|
+
function pathsObjectType(paths: readonly PathMember[]): IrType {
|
|
167
|
+
const covering = coveringTemplateKeys(
|
|
168
|
+
paths.map(({ key }) => key),
|
|
169
|
+
(coveringIndex, coveredIndex) => {
|
|
170
|
+
const coveringPath = paths[coveringIndex];
|
|
171
|
+
const coveredPath = paths[coveredIndex];
|
|
172
|
+
return (
|
|
173
|
+
coveringPath !== undefined &&
|
|
174
|
+
coveredPath !== undefined &&
|
|
175
|
+
isCoveredPathItemRejected(coveredPath.type, coveringPath.type)
|
|
176
|
+
);
|
|
177
|
+
},
|
|
178
|
+
);
|
|
179
|
+
if (covering.size === 0) {
|
|
180
|
+
return irObject(paths.map(({ member }) => member));
|
|
181
|
+
}
|
|
182
|
+
const rest = paths.filter((_, index) => !covering.has(index)).map(({ member }) => member);
|
|
183
|
+
const own = paths
|
|
184
|
+
.filter((_, index) => covering.has(index))
|
|
185
|
+
.map(({ member }) => irObject([member]));
|
|
186
|
+
return irIntersection([irObject(rest), ...own]);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The `paths` interface body (OpenAPI 3.1 §4.8.8): one member per path, by URL. */
|
|
190
|
+
export function pathsType(paths: PathsObject, context: TransformContext): IrType {
|
|
191
|
+
const members: PathMember[] = [];
|
|
192
|
+
for (const [url, pathItem] of documentEntries(paths, context.options)) {
|
|
193
|
+
if (!pathItem || typeof pathItem !== "object") {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if ("$ref" in pathItem) {
|
|
197
|
+
const options = { isReadonly: context.options.immutable };
|
|
198
|
+
const member = documentMember(url, refType(pathItem.$ref), pathItem, options);
|
|
199
|
+
members.push({ member, key: literalKey(url), type: member.type });
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const startedAt = context.diagnostics.now();
|
|
203
|
+
const path = pathItemMember(url, pathItem, context);
|
|
204
|
+
members.push(path);
|
|
205
|
+
// The original reports only paths written as properties.
|
|
206
|
+
if (path.member.kind === "property") {
|
|
207
|
+
context.diagnostics.debug(`Transformed path "${url}"`, context.diagnostics.now() - startedAt);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return pathsObjectType(members);
|
|
211
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { irKeyword, irObject, irProperty } from "../../../domain/ir/constructors.js";
|
|
2
|
+
import type { IrMember, IrType } from "../../../domain/ir/nodes.js";
|
|
3
|
+
import { toPropertyName } from "../../../domain/ir/property-name.js";
|
|
4
|
+
import { createRef } from "../../../domain/openapi/json-pointer.js";
|
|
5
|
+
import type { RequestBodyObject } from "../../../domain/openapi/request-body-object.js";
|
|
6
|
+
import { documentEntries } from "../document-entries.js";
|
|
7
|
+
import type { SchemaContext, SchemaLocation } from "../schema/schema-context.js";
|
|
8
|
+
import { documentMember } from "./document-member.js";
|
|
9
|
+
import { contentEntryType, itemContentMember } from "./media-type.js";
|
|
10
|
+
|
|
11
|
+
/** Stands in for the media types of a body that defines none: `"*\/*"?: never`. */
|
|
12
|
+
const ANY_MEDIA_TYPE = "*/*";
|
|
13
|
+
|
|
14
|
+
function contentMembers(
|
|
15
|
+
requestBody: RequestBodyObject,
|
|
16
|
+
location: SchemaLocation,
|
|
17
|
+
context: SchemaContext,
|
|
18
|
+
): IrMember[] {
|
|
19
|
+
const entries = documentEntries(requestBody.content ?? {}, context.options);
|
|
20
|
+
return entries.map(([contentType, entry]) => {
|
|
21
|
+
const path = createRef([location.path, "content", contentType]);
|
|
22
|
+
const type = contentEntryType(entry, { ...location, path }, context);
|
|
23
|
+
return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A request body (OpenAPI 3.2 §4.8.13): `{ content: { [mediaType]: T } }`, and `itemContent` when a
|
|
29
|
+
* media type has an `itemSchema`.
|
|
30
|
+
*/
|
|
31
|
+
export function requestBodyType(
|
|
32
|
+
requestBody: RequestBodyObject,
|
|
33
|
+
location: SchemaLocation,
|
|
34
|
+
context: SchemaContext,
|
|
35
|
+
): IrType {
|
|
36
|
+
const members = contentMembers(requestBody, location, context);
|
|
37
|
+
// The placeholder is never readonly, even with --immutable, as in the original.
|
|
38
|
+
const placeholder = irProperty(toPropertyName(ANY_MEDIA_TYPE), irKeyword("never"), {
|
|
39
|
+
isOptional: true,
|
|
40
|
+
});
|
|
41
|
+
const content = irObject(members.length > 0 ? members : [placeholder]);
|
|
42
|
+
const isReadonly = context.options.immutable;
|
|
43
|
+
const itemContent = itemContentMember(requestBody.content ?? {}, location, context, {
|
|
44
|
+
isReadonly,
|
|
45
|
+
});
|
|
46
|
+
return irObject([
|
|
47
|
+
irProperty(toPropertyName("content"), content, { isReadonly }),
|
|
48
|
+
...(itemContent ? [itemContent] : []),
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
irKeyword,
|
|
3
|
+
irObject,
|
|
4
|
+
irProperty,
|
|
5
|
+
irStringIndexSignature,
|
|
6
|
+
} from "../../../domain/ir/constructors.js";
|
|
7
|
+
import type { IrMember, IrPropertySignature, IrType } from "../../../domain/ir/nodes.js";
|
|
8
|
+
import { toPropertyName } from "../../../domain/ir/property-name.js";
|
|
9
|
+
import { createRef } from "../../../domain/openapi/json-pointer.js";
|
|
10
|
+
import {
|
|
11
|
+
isMediaTypeComponentRef,
|
|
12
|
+
type MediaTypeObject,
|
|
13
|
+
} from "../../../domain/openapi/media-type-object.js";
|
|
14
|
+
import type { ResponseObject } from "../../../domain/openapi/response-object.js";
|
|
15
|
+
import { documentEntries } from "../document-entries.js";
|
|
16
|
+
import { refType } from "../ref-type.js";
|
|
17
|
+
import type { SchemaContext, SchemaLocation } from "../schema/schema-context.js";
|
|
18
|
+
import { UNKNOWN_TYPE } from "../shared-types.js";
|
|
19
|
+
import { documentMember } from "./document-member.js";
|
|
20
|
+
import { headerType } from "./header.js";
|
|
21
|
+
import { contentEntryType, itemContentMember, mediaTypeType } from "./media-type.js";
|
|
22
|
+
|
|
23
|
+
type HeaderEntry = NonNullable<ResponseObject["headers"]>[string];
|
|
24
|
+
|
|
25
|
+
function headerMember(
|
|
26
|
+
name: string,
|
|
27
|
+
header: HeaderEntry,
|
|
28
|
+
location: SchemaLocation,
|
|
29
|
+
context: SchemaContext,
|
|
30
|
+
): IrPropertySignature {
|
|
31
|
+
// A referenced header counts as required: the reference does not say otherwise.
|
|
32
|
+
const isReference = "$ref" in header;
|
|
33
|
+
const type = isReference
|
|
34
|
+
? refType(header.$ref)
|
|
35
|
+
: headerType(
|
|
36
|
+
header,
|
|
37
|
+
{ ...location, path: createRef([location.path, "headers", name]) },
|
|
38
|
+
context,
|
|
39
|
+
);
|
|
40
|
+
return documentMember(name, type, header, {
|
|
41
|
+
isReadonly: context.options.immutable,
|
|
42
|
+
isOptional: !isReference && !header.required,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The listed headers, then `[name: string]: unknown`, because servers may send others. */
|
|
47
|
+
function headersMember(
|
|
48
|
+
response: ResponseObject,
|
|
49
|
+
location: SchemaLocation,
|
|
50
|
+
context: SchemaContext,
|
|
51
|
+
): IrPropertySignature {
|
|
52
|
+
const entries = documentEntries(response.headers ?? {}, context.options);
|
|
53
|
+
const members: IrMember[] = entries.map(([name, header]) =>
|
|
54
|
+
headerMember(name, header, location, context),
|
|
55
|
+
);
|
|
56
|
+
members.push(irStringIndexSignature("name", UNKNOWN_TYPE, context.options.immutable));
|
|
57
|
+
return irProperty(toPropertyName("headers"), irObject(members));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* One media type of a response. The original reads a `$ref` entry as a media type without a
|
|
62
|
+
* schema, so it is `unknown`; a `$ref` to an OpenAPI 3.2 media type component is typed as it.
|
|
63
|
+
*/
|
|
64
|
+
function mediaTypeEntryType(
|
|
65
|
+
entry: NonNullable<ResponseObject["content"]>[string],
|
|
66
|
+
location: SchemaLocation,
|
|
67
|
+
context: SchemaContext,
|
|
68
|
+
): IrType {
|
|
69
|
+
return "$ref" in entry && isMediaTypeComponentRef(entry.$ref)
|
|
70
|
+
? contentEntryType(entry, location, context)
|
|
71
|
+
: mediaTypeType(entry as MediaTypeObject, location, context);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** `content` with one member per media type, or `content?: never` when there are none. */
|
|
75
|
+
function contentMember(
|
|
76
|
+
response: ResponseObject,
|
|
77
|
+
location: SchemaLocation,
|
|
78
|
+
context: SchemaContext,
|
|
79
|
+
): IrPropertySignature {
|
|
80
|
+
const entries = documentEntries(response.content ?? {}, context.options);
|
|
81
|
+
const members = entries.map(([contentType, entry]) => {
|
|
82
|
+
const path = createRef([location.path, "content", contentType]);
|
|
83
|
+
const type = mediaTypeEntryType(entry, { ...location, path }, context);
|
|
84
|
+
return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });
|
|
85
|
+
});
|
|
86
|
+
const name = toPropertyName("content");
|
|
87
|
+
return members.length > 0
|
|
88
|
+
? irProperty(name, irObject(members))
|
|
89
|
+
: irProperty(name, irKeyword("never"), { isOptional: true });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A response (OpenAPI 3.2 §4.8.17): `{ headers: {…}; content: {…} }`, and `itemContent` when a
|
|
94
|
+
* media type has an `itemSchema`. No member is readonly, even with --immutable, as in the original.
|
|
95
|
+
*/
|
|
96
|
+
export function responseType(
|
|
97
|
+
response: ResponseObject,
|
|
98
|
+
location: SchemaLocation,
|
|
99
|
+
context: SchemaContext,
|
|
100
|
+
): IrType {
|
|
101
|
+
const itemContent = itemContentMember(response.content ?? {}, location, context, {
|
|
102
|
+
isReadonly: false,
|
|
103
|
+
});
|
|
104
|
+
return irObject([
|
|
105
|
+
headersMember(response, location, context),
|
|
106
|
+
contentMember(response, location, context),
|
|
107
|
+
...(itemContent ? [itemContent] : []),
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { irKeyword, irObject } from "../../../domain/ir/constructors.js";
|
|
2
|
+
import type { IrType } from "../../../domain/ir/nodes.js";
|
|
3
|
+
import { createRef } from "../../../domain/openapi/json-pointer.js";
|
|
4
|
+
import type { ResponsesObject } from "../../../domain/openapi/response-object.js";
|
|
5
|
+
import { documentEntries } from "../document-entries.js";
|
|
6
|
+
import { refType } from "../ref-type.js";
|
|
7
|
+
import type { SchemaContext, SchemaLocation } from "../schema/schema-context.js";
|
|
8
|
+
import { documentMember } from "./document-member.js";
|
|
9
|
+
import { responseType } from "./response.js";
|
|
10
|
+
|
|
11
|
+
/** Responses by status code (OpenAPI 3.1 §4.8.16), or `never` when there are none. */
|
|
12
|
+
export function responsesType(
|
|
13
|
+
responses: ResponsesObject,
|
|
14
|
+
location: SchemaLocation,
|
|
15
|
+
context: SchemaContext,
|
|
16
|
+
): IrType {
|
|
17
|
+
const members = documentEntries(responses, context.options).map(([code, response]) => {
|
|
18
|
+
const type =
|
|
19
|
+
"$ref" in response
|
|
20
|
+
? refType(response.$ref)
|
|
21
|
+
: responseType(
|
|
22
|
+
response,
|
|
23
|
+
{ ...location, path: createRef([location.path, "responses", code]) },
|
|
24
|
+
context,
|
|
25
|
+
);
|
|
26
|
+
return documentMember(code, type, response, { isReadonly: context.options.immutable });
|
|
27
|
+
});
|
|
28
|
+
return members.length > 0 ? irObject(members) : irKeyword("never");
|
|
29
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { irRaw } from "../../../domain/ir/constructors.js";
|
|
2
|
+
import type { IrDeclaration, IrTypeAliasDeclaration } from "../../../domain/ir/nodes.js";
|
|
3
|
+
import { escapeSingleQuotedText } from "../../../domain/ir/raw-text-escapes.js";
|
|
4
|
+
import type { ComponentKind } from "../../../domain/openapi/components-object.js";
|
|
5
|
+
|
|
6
|
+
/** The `--root-types` aliases: `export type Pet = components['schemas']['Pet'];`. */
|
|
7
|
+
|
|
8
|
+
const REFERENCE_PREFIX = "components['";
|
|
9
|
+
|
|
10
|
+
/** The alias of one component. */
|
|
11
|
+
export function rootTypeAlias(
|
|
12
|
+
name: string,
|
|
13
|
+
kind: ComponentKind,
|
|
14
|
+
item: string,
|
|
15
|
+
): IrTypeAliasDeclaration {
|
|
16
|
+
return {
|
|
17
|
+
kind: "typeAlias",
|
|
18
|
+
name,
|
|
19
|
+
isExported: true,
|
|
20
|
+
// The original writes the reference as text, with single quotes, and did not escape the
|
|
21
|
+
// name: a quote in it could add code to the generated file (intentional fix).
|
|
22
|
+
type: irRaw(`${REFERENCE_PREFIX}${kind}']['${escapeSingleQuotedText(item)}']`),
|
|
23
|
+
comments: [],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isRootTypeAlias(declaration: IrDeclaration): declaration is IrTypeAliasDeclaration {
|
|
28
|
+
return (
|
|
29
|
+
declaration.kind === "typeAlias" &&
|
|
30
|
+
declaration.type.kind === "raw" &&
|
|
31
|
+
declaration.type.text.startsWith(REFERENCE_PREFIX)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The type names the footer declares that an alias must not take: enums, and helper types such as
|
|
37
|
+
* `WithRequired`. Value declarations (`--enum-values` arrays) live in another namespace.
|
|
38
|
+
*/
|
|
39
|
+
function footerTypeNames(declarations: readonly IrDeclaration[]): Set<string> {
|
|
40
|
+
return new Set(
|
|
41
|
+
declarations.flatMap((declaration) => {
|
|
42
|
+
if (declaration.kind === "enum") {
|
|
43
|
+
return [declaration.name];
|
|
44
|
+
}
|
|
45
|
+
return declaration.kind === "rawDeclaration" && declaration.name !== undefined
|
|
46
|
+
? [declaration.name]
|
|
47
|
+
: [];
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function declaredNames(declarations: readonly IrDeclaration[]): Set<string> {
|
|
53
|
+
return new Set(
|
|
54
|
+
declarations.flatMap((declaration) =>
|
|
55
|
+
"name" in declaration && declaration.name !== undefined ? [declaration.name] : [],
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function freeName(name: string, taken: ReadonlySet<string>): string {
|
|
61
|
+
let candidate = `${name}_2`;
|
|
62
|
+
for (let counter = 3; taken.has(candidate); counter++) {
|
|
63
|
+
candidate = `${name}_${counter}`;
|
|
64
|
+
}
|
|
65
|
+
return candidate;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* With the `root-type-numbering` fix (ADR-021, roadmap R13, backlog 30): the aliases that a later
|
|
70
|
+
* schema of one exported name took the name from, numbered `Name_2`, `Name_3`, … in document order
|
|
71
|
+
* with the next free number. The later schema keeps the name, so the fix only adds exports.
|
|
72
|
+
*/
|
|
73
|
+
export function numberDisplacedAliases(
|
|
74
|
+
displaced: readonly IrTypeAliasDeclaration[],
|
|
75
|
+
kept: readonly IrTypeAliasDeclaration[],
|
|
76
|
+
): IrTypeAliasDeclaration[] {
|
|
77
|
+
const taken = new Set(kept.map((alias) => alias.name));
|
|
78
|
+
return displaced.map((alias) => {
|
|
79
|
+
const name = freeName(alias.name, taken);
|
|
80
|
+
taken.add(name);
|
|
81
|
+
return { ...alias, name };
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Rename each root alias whose name an enum or a helper type of the footer also declares, to the
|
|
87
|
+
* next free `Name_2`, `Name_3`, … (the suffix `--root-types` uses for its own conflicts). The
|
|
88
|
+
* footer keeps its names, because the generated types refer to them. Before, both were declared
|
|
89
|
+
* under one name, which does not compile (enums: upstream #2099, #2341, #2206; helpers: a schema
|
|
90
|
+
* named `WithRequired`, roadmap R11). Other declarations are returned unchanged.
|
|
91
|
+
*/
|
|
92
|
+
export function renameAliasesTakenByFooter(
|
|
93
|
+
body: readonly IrDeclaration[],
|
|
94
|
+
footer: readonly IrDeclaration[],
|
|
95
|
+
): IrDeclaration[] {
|
|
96
|
+
const footerNames = footerTypeNames(footer);
|
|
97
|
+
const taken = declaredNames([...body, ...footer]);
|
|
98
|
+
return body.map((declaration) => {
|
|
99
|
+
if (!isRootTypeAlias(declaration) || !footerNames.has(declaration.name)) {
|
|
100
|
+
return declaration;
|
|
101
|
+
}
|
|
102
|
+
const name = freeName(declaration.name, taken);
|
|
103
|
+
taken.add(name);
|
|
104
|
+
return { ...declaration, name };
|
|
105
|
+
});
|
|
106
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { irObject, irProperty } from "../../../domain/ir/constructors.js";
|
|
2
|
+
import type { IrType } from "../../../domain/ir/nodes.js";
|
|
3
|
+
import { toPropertyName } from "../../../domain/ir/property-name.js";
|
|
4
|
+
import { createRef } from "../../../domain/openapi/json-pointer.js";
|
|
5
|
+
import type { PathItemObject, PathsObject } from "../../../domain/openapi/path-item-object.js";
|
|
6
|
+
import { documentEntries } from "../document-entries.js";
|
|
7
|
+
import type { TransformContext } from "../transform-context.js";
|
|
8
|
+
import { pathItemType } from "./path-item.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The `webhooks` interface body (OpenAPI 3.1 §4.8.1): one path item per webhook name. Unlike
|
|
12
|
+
* `paths`, a `$ref` entry is read as a path item (so every method is `never`), as in the original,
|
|
13
|
+
* and members carry no JSDoc.
|
|
14
|
+
*/
|
|
15
|
+
export function webhooksType(webhooks: PathsObject, context: TransformContext): IrType {
|
|
16
|
+
const members = documentEntries(webhooks, context.options).map(([name, pathItem]) => {
|
|
17
|
+
const location = { path: createRef(["webhooks", name]) };
|
|
18
|
+
const type = pathItemType(pathItem as PathItemObject, location, context);
|
|
19
|
+
return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });
|
|
20
|
+
});
|
|
21
|
+
return irObject(members);
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { sortEntriesByKey } from "../../domain/ir/normalize.js";
|
|
2
|
+
import type { SchemaOptions } from "./schema/schema-context.js";
|
|
3
|
+
|
|
4
|
+
/** Whether a document object has `deprecated: true` (`--exclude-deprecated` drops it). */
|
|
5
|
+
export function isDeprecated(value: unknown): boolean {
|
|
6
|
+
return Boolean(value && typeof value === "object" && "deprecated" in value && value.deprecated);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Whether a deprecated entry is still needed, so `--exclude-deprecated` keeps it. */
|
|
10
|
+
export type DeprecatedEntryFilter = (value: unknown) => boolean;
|
|
11
|
+
|
|
12
|
+
const KEEPS_NONE: DeprecatedEntryFilter = () => false;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `Object.entries` of a document map (the original `getEntries`): sorted for `--alphabetize`,
|
|
16
|
+
* without deprecated entries for `--exclude-deprecated`, except those `isKept` names.
|
|
17
|
+
*/
|
|
18
|
+
export function documentEntries<T>(
|
|
19
|
+
record: Readonly<Record<string, T>>,
|
|
20
|
+
options: Pick<SchemaOptions, "alphabetize" | "excludeDeprecated">,
|
|
21
|
+
isKept: DeprecatedEntryFilter = KEEPS_NONE,
|
|
22
|
+
): [string, T][] {
|
|
23
|
+
const entries = Object.entries(record);
|
|
24
|
+
const sorted = options.alphabetize ? sortEntriesByKey(entries) : entries;
|
|
25
|
+
return options.excludeDeprecated
|
|
26
|
+
? sorted.filter(([, value]) => !isDeprecated(value) || isKept(value))
|
|
27
|
+
: sorted;
|
|
28
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { irReference } from "../../../domain/ir/constructors.js";
|
|
2
|
+
import type { IrDeclaration, IrPropertySignature, IrType } from "../../../domain/ir/nodes.js";
|
|
3
|
+
import { HELPER_TYPES, type HelperType } from "../helper-types.js";
|
|
4
|
+
import type {
|
|
5
|
+
EnumDeclarationRequest,
|
|
6
|
+
EnumMemberMetadata,
|
|
7
|
+
EnumValuesRequest,
|
|
8
|
+
} from "../schema/schema-context.js";
|
|
9
|
+
import type { DocumentFooter } from "../transform-context.js";
|
|
10
|
+
import { EnumNaming, enumDeclaration } from "./enum-naming.js";
|
|
11
|
+
|
|
12
|
+
/** Where footer declarations go, in order: the run's `ctx.injectFooter`, open to user code. */
|
|
13
|
+
export interface FooterSink {
|
|
14
|
+
/** Whether a type alias with this name is declared already (by the generator or a user). */
|
|
15
|
+
hasTypeAlias(name: string): boolean;
|
|
16
|
+
add(declaration: IrDeclaration): void;
|
|
17
|
+
/** Add a member to the `operations` interface, declared first if needed; see `DocumentFooter`. */
|
|
18
|
+
addOperation(build: () => IrPropertySignature): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The `--dedupe-enums` key of the original: the values in default sort order, each paired with
|
|
23
|
+
* the metadata at its sorted position (not the value's own metadata), as the original does.
|
|
24
|
+
*/
|
|
25
|
+
function dedupeKey(request: EnumDeclarationRequest): string {
|
|
26
|
+
return [...request.values]
|
|
27
|
+
.sort(compareAsStrings)
|
|
28
|
+
.map((value, index) => metadataKey(String(value), request.metadata[index]))
|
|
29
|
+
.join(",");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** `Array.prototype.sort` without a comparator: compares the values as strings. */
|
|
33
|
+
function compareAsStrings(left: string | number, right: string | number): number {
|
|
34
|
+
const leftText = String(left);
|
|
35
|
+
const rightText = String(right);
|
|
36
|
+
if (leftText === rightText) {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
return leftText < rightText ? -1 : 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function metadataKey(value: string, metadata: EnumMemberMetadata | undefined): string {
|
|
43
|
+
return `${metadata?.name ?? value}:${metadata?.description || ""}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The whole declaration: an equal key means the same enum, member for member. */
|
|
47
|
+
function declarationKey(name: string, request: EnumDeclarationRequest): string {
|
|
48
|
+
return JSON.stringify([name, request.values, request.metadata]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The footer of one run: enums (deduplicated with `--dedupe-enums`), `--enum-values` arrays, the
|
|
53
|
+
* helper types they need, and the `operations` interface. Replaces the original's module-level
|
|
54
|
+
* `enumCache`, so runs no longer share enums (research/legacy-bugs.md, item 3).
|
|
55
|
+
*/
|
|
56
|
+
export class RunFooter implements DocumentFooter {
|
|
57
|
+
private readonly naming = new EnumNaming();
|
|
58
|
+
private readonly enumNamesByKey = new Map<string, string>();
|
|
59
|
+
/** Declarations added already: the same one twice fails with "Duplicate identifier". */
|
|
60
|
+
private readonly declaredEnums = new Set<string>();
|
|
61
|
+
private readonly sink: FooterSink;
|
|
62
|
+
private readonly isDedupingEnums: boolean;
|
|
63
|
+
|
|
64
|
+
constructor(sink: FooterSink, isDedupingEnums: boolean) {
|
|
65
|
+
this.sink = sink;
|
|
66
|
+
this.isDedupingEnums = isDedupingEnums;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
addEnum(request: EnumDeclarationRequest): string {
|
|
70
|
+
// The name is built before the cache lookup: it advances the naming state either way.
|
|
71
|
+
const name = this.naming.enumName(request.name);
|
|
72
|
+
const key = this.isDedupingEnums ? dedupeKey(request) : null;
|
|
73
|
+
const known = key === null ? undefined : this.enumNamesByKey.get(key);
|
|
74
|
+
if (known !== undefined) {
|
|
75
|
+
return known;
|
|
76
|
+
}
|
|
77
|
+
// Only a repeated member fails to compile; two empty declarations merge, so they stay.
|
|
78
|
+
const declared = request.values.length > 0 ? declarationKey(name, request) : null;
|
|
79
|
+
if (declared !== null && this.declaredEnums.has(declared)) {
|
|
80
|
+
return name;
|
|
81
|
+
}
|
|
82
|
+
if (declared !== null) {
|
|
83
|
+
this.declaredEnums.add(declared);
|
|
84
|
+
}
|
|
85
|
+
this.sink.add(enumDeclaration(name, request, this.naming));
|
|
86
|
+
if (key !== null) {
|
|
87
|
+
this.enumNamesByKey.set(key, name);
|
|
88
|
+
}
|
|
89
|
+
return name;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
addEnumValues(request: EnumValuesRequest): void {
|
|
93
|
+
const name = this.naming.arrayName(request.name);
|
|
94
|
+
this.require(HELPER_TYPES.flattenedDeepRequired);
|
|
95
|
+
this.require(HELPER_TYPES.readonlyArray);
|
|
96
|
+
this.sink.add({
|
|
97
|
+
kind: "constArray",
|
|
98
|
+
name,
|
|
99
|
+
isExported: true,
|
|
100
|
+
type: readonlyArrayOf(request.type),
|
|
101
|
+
values: request.values,
|
|
102
|
+
comments: [],
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
requireWithRequired(): void {
|
|
107
|
+
this.require(HELPER_TYPES.withRequired);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
requirePropertyValues(): void {
|
|
111
|
+
this.require(HELPER_TYPES.propertyValues);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
addOperation(build: () => IrPropertySignature): void {
|
|
115
|
+
this.sink.addOperation(build);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private require(helper: HelperType): void {
|
|
119
|
+
if (!this.sink.hasTypeAlias(helper.name)) {
|
|
120
|
+
this.sink.add({ kind: "rawDeclaration", name: helper.name, text: helper.text });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function readonlyArrayOf(type: IrType): IrType {
|
|
126
|
+
return irReference(HELPER_TYPES.readonlyArray.name, [type]);
|
|
127
|
+
}
|