openapi-typesafe 1.0.0-rc.2 → 1.0.0-rc.4
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/CHANGELOG.md +1831 -0
- package/dist/adapters/node-deprecations/node-deprecations.cjs +14 -0
- package/dist/adapters/node-deprecations/node-deprecations.cjs.map +1 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs +12 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.cjs +105 -0
- package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.mjs +95 -0
- package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.cjs +82 -0
- package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.mjs +74 -0
- package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +90 -14
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +90 -14
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +75 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +72 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -1
- package/dist/adapters/redocly-loader/loaded-documents.cjs +28 -0
- package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +14 -15
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +12 -13
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.cjs +2 -2
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.mjs +3 -3
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
- package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +47 -0
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +44 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +11 -7
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +12 -8
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/default-ports.cjs +19 -2
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +19 -3
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.mjs +2 -2
- package/dist/api/discriminator-conflict-warnings.mjs.map +1 -1
- package/dist/api/discriminator-enum-parent.cjs +2 -2
- package/dist/api/discriminator-enum-parent.cjs.map +1 -1
- package/dist/api/discriminator-enum-parent.mjs +3 -3
- package/dist/api/discriminator-enum-parent.mjs.map +1 -1
- package/dist/api/discriminator-other-owners.cjs +5 -3
- package/dist/api/discriminator-other-owners.cjs.map +1 -1
- package/dist/api/discriminator-other-owners.mjs +5 -3
- package/dist/api/discriminator-other-owners.mjs.map +1 -1
- package/dist/api/discriminator-patch.cjs +8 -4
- package/dist/api/discriminator-patch.cjs.map +1 -1
- package/dist/api/discriminator-patch.mjs +9 -5
- package/dist/api/discriminator-patch.mjs.map +1 -1
- package/dist/api/discriminator-scan.cjs +17 -10
- package/dist/api/discriminator-scan.cjs.map +1 -1
- package/dist/api/discriminator-scan.mjs +18 -11
- package/dist/api/discriminator-scan.mjs.map +1 -1
- package/dist/api/document-run.cjs +4 -3
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +4 -3
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-callback-warning.cjs +7 -4
- package/dist/api/legacy-callback-warning.cjs.map +1 -1
- package/dist/api/legacy-callback-warning.mjs +8 -5
- package/dist/api/legacy-callback-warning.mjs.map +1 -1
- package/dist/api/legacy-utils.cjs.map +1 -1
- package/dist/api/legacy-utils.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +9 -5
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +10 -7
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/schema-callbacks.cjs +36 -12
- package/dist/api/schema-callbacks.cjs.map +1 -1
- package/dist/api/schema-callbacks.mjs +36 -12
- package/dist/api/schema-callbacks.mjs.map +1 -1
- package/dist/api/string-to-ast.cjs +7 -9
- package/dist/api/string-to-ast.cjs.map +1 -1
- package/dist/api/string-to-ast.mjs +8 -9
- package/dist/api/string-to-ast.mjs.map +1 -1
- package/dist/api/transform-context.cjs +7 -3
- package/dist/api/transform-context.cjs.map +1 -1
- package/dist/api/transform-context.mjs +7 -3
- package/dist/api/transform-context.mjs.map +1 -1
- package/dist/api/transform-schema.cjs +42 -12
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +44 -14
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/print/text-writer.cjs +10 -3
- package/dist/application/print/text-writer.cjs.map +1 -1
- package/dist/application/print/text-writer.mjs +10 -3
- package/dist/application/print/text-writer.mjs.map +1 -1
- package/dist/application/stack-overflow.cjs +2 -1
- package/dist/application/stack-overflow.cjs.map +1 -1
- package/dist/application/stack-overflow.mjs +2 -1
- package/dist/application/stack-overflow.mjs.map +1 -1
- package/dist/application/transform/document/components.cjs +2 -2
- package/dist/application/transform/document/components.cjs.map +1 -1
- package/dist/application/transform/document/components.mjs +4 -4
- package/dist/application/transform/document/components.mjs.map +1 -1
- package/dist/application/transform/document/declared-type-names.cjs +23 -0
- package/dist/application/transform/document/declared-type-names.cjs.map +1 -0
- package/dist/application/transform/document/declared-type-names.mjs +20 -0
- package/dist/application/transform/document/declared-type-names.mjs.map +1 -0
- package/dist/application/transform/document/defs-root.cjs +1 -1
- package/dist/application/transform/document/defs-root.cjs.map +1 -1
- package/dist/application/transform/document/defs-root.mjs +2 -2
- package/dist/application/transform/document/defs-root.mjs.map +1 -1
- package/dist/application/transform/document/document.cjs +4 -1
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +3 -2
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
- package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
- package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
- package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
- package/dist/application/transform/document/global-type-references.cjs +1 -0
- package/dist/application/transform/document/global-type-references.cjs.map +1 -1
- package/dist/application/transform/document/global-type-references.mjs +1 -1
- package/dist/application/transform/document/global-type-references.mjs.map +1 -1
- package/dist/application/transform/document/media-type.cjs +2 -2
- package/dist/application/transform/document/media-type.cjs.map +1 -1
- package/dist/application/transform/document/media-type.mjs +3 -3
- package/dist/application/transform/document/media-type.mjs.map +1 -1
- package/dist/application/transform/document/operation-keys-written.cjs +26 -0
- package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
- package/dist/application/transform/document/operation-keys-written.mjs +24 -0
- package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
- package/dist/application/transform/document/operation.cjs +1 -1
- package/dist/application/transform/document/operation.cjs.map +1 -1
- package/dist/application/transform/document/operation.mjs +2 -2
- package/dist/application/transform/document/operation.mjs.map +1 -1
- package/dist/application/transform/document/parameter-entries.cjs +34 -0
- package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
- package/dist/application/transform/document/parameter-entries.mjs +30 -0
- package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
- package/dist/application/transform/document/parameter.cjs +12 -4
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +13 -5
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +7 -30
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +8 -31
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +11 -14
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +12 -16
- package/dist/application/transform/document/path-item.mjs.map +1 -1
- package/dist/application/transform/document/paths-enum.cjs +1 -0
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +1 -1
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +6 -2
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +8 -4
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/referenced-parameter.cjs +80 -0
- package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
- package/dist/application/transform/document/referenced-parameter.mjs +78 -0
- package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
- package/dist/application/transform/document/request-body.cjs +1 -1
- package/dist/application/transform/document/request-body.cjs.map +1 -1
- package/dist/application/transform/document/request-body.mjs +2 -2
- package/dist/application/transform/document/request-body.mjs.map +1 -1
- package/dist/application/transform/document/response.cjs +2 -2
- package/dist/application/transform/document/response.cjs.map +1 -1
- package/dist/application/transform/document/response.mjs +3 -3
- package/dist/application/transform/document/response.mjs.map +1 -1
- package/dist/application/transform/document/responses.cjs +1 -1
- package/dist/application/transform/document/responses.cjs.map +1 -1
- package/dist/application/transform/document/responses.mjs +2 -2
- package/dist/application/transform/document/responses.mjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.cjs +8 -23
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.mjs +8 -24
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
- package/dist/application/transform/document/type-resolution.cjs +3 -1
- package/dist/application/transform/document/type-resolution.cjs.map +1 -1
- package/dist/application/transform/document/type-resolution.mjs +3 -1
- package/dist/application/transform/document/type-resolution.mjs.map +1 -1
- package/dist/application/transform/document/webhooks.cjs +1 -1
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +2 -2
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +10 -2
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +10 -2
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
- package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
- package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
- package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.cjs +23 -0
- package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.mjs +21 -0
- package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.cjs +4 -4
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
- package/dist/application/transform/footer/type-evaluation.mjs +4 -4
- package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
- package/dist/application/transform/helper-types.cjs +1 -1
- package/dist/application/transform/helper-types.cjs.map +1 -1
- package/dist/application/transform/helper-types.mjs +1 -1
- package/dist/application/transform/helper-types.mjs.map +1 -1
- package/dist/application/transform/numbered-names.cjs +9 -0
- package/dist/application/transform/numbered-names.cjs.map +1 -1
- package/dist/application/transform/numbered-names.mjs +9 -1
- package/dist/application/transform/numbered-names.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +2 -2
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs +2 -2
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
- package/dist/application/transform/ref-type.cjs +2 -1
- package/dist/application/transform/ref-type.cjs.map +1 -1
- package/dist/application/transform/ref-type.mjs +2 -1
- package/dist/application/transform/ref-type.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs +2 -2
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/array-type.cjs +2 -2
- package/dist/application/transform/schema/array-type.cjs.map +1 -1
- package/dist/application/transform/schema/array-type.mjs +3 -3
- package/dist/application/transform/schema/array-type.mjs.map +1 -1
- package/dist/application/transform/schema/composition-type.cjs +4 -4
- package/dist/application/transform/schema/composition-type.cjs.map +1 -1
- package/dist/application/transform/schema/composition-type.mjs +6 -6
- package/dist/application/transform/schema/composition-type.mjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.cjs +4 -6
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.mjs +6 -8
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
- package/dist/application/transform/schema/object-type.cjs +3 -3
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +4 -4
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/presence-members.cjs +1 -1
- package/dist/application/transform/schema/presence-members.cjs.map +1 -1
- package/dist/application/transform/schema/presence-members.mjs +2 -2
- package/dist/application/transform/schema/presence-members.mjs.map +1 -1
- package/dist/application/transform/schema/ref-siblings.cjs +47 -0
- package/dist/application/transform/schema/ref-siblings.cjs.map +1 -0
- package/dist/application/transform/schema/ref-siblings.mjs +45 -0
- package/dist/application/transform/schema/ref-siblings.mjs.map +1 -0
- package/dist/application/transform/schema/required-variants.cjs +2 -2
- package/dist/application/transform/schema/required-variants.cjs.map +1 -1
- package/dist/application/transform/schema/required-variants.mjs +3 -3
- package/dist/application/transform/schema/required-variants.mjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.cjs +4 -2
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +4 -2
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.mjs +2 -2
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
- package/dist/application/transform/schema-comment.cjs +6 -2
- package/dist/application/transform/schema-comment.cjs.map +1 -1
- package/dist/application/transform/schema-comment.mjs +7 -3
- package/dist/application/transform/schema-comment.mjs.map +1 -1
- package/dist/cli/api-settings.cjs +62 -6
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +60 -7
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +72 -0
- package/dist/cli/api-writes.cjs.map +1 -0
- package/dist/cli/api-writes.mjs +69 -0
- package/dist/cli/api-writes.mjs.map +1 -0
- package/dist/cli/cli-errors.cjs +12 -1
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +12 -1
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +106 -1
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +99 -2
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +5 -1
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +6 -2
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +82 -36
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +85 -39
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +13 -7
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +14 -8
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/append-all.cjs +10 -0
- package/dist/domain/append-all.cjs.map +1 -0
- package/dist/domain/append-all.mjs +8 -0
- package/dist/domain/append-all.mjs.map +1 -0
- package/dist/domain/cause-secrets.cjs +37 -0
- package/dist/domain/cause-secrets.cjs.map +1 -0
- package/dist/domain/cause-secrets.mjs +35 -0
- package/dist/domain/cause-secrets.mjs.map +1 -0
- package/dist/domain/deprecations.cjs +11 -0
- package/dist/domain/deprecations.cjs.map +1 -0
- package/dist/domain/deprecations.mjs +9 -0
- package/dist/domain/deprecations.mjs.map +1 -0
- package/dist/domain/errors.cjs +9 -3
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +9 -3
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/identifier-text.cjs.map +1 -1
- package/dist/domain/ir/identifier-text.mjs +1 -1
- package/dist/domain/ir/identifier-text.mjs.map +1 -1
- package/dist/domain/ir/ir-shape.cjs +187 -0
- package/dist/domain/ir/ir-shape.cjs.map +1 -0
- package/dist/domain/ir/ir-shape.mjs +184 -0
- package/dist/domain/ir/ir-shape.mjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
- package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.cjs +3 -1
- package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.mjs +3 -1
- package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.cjs +3 -3
- package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.mjs +4 -4
- package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
- package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
- package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
- package/dist/domain/openapi/json-pointer.cjs +43 -1
- package/dist/domain/openapi/json-pointer.cjs.map +1 -1
- package/dist/domain/openapi/json-pointer.mjs +40 -2
- package/dist/domain/openapi/json-pointer.mjs.map +1 -1
- package/dist/domain/openapi/schema-dialect.cjs +15 -0
- package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
- package/dist/domain/openapi/schema-dialect.mjs +12 -0
- package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.cjs +1 -1
- package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
- package/dist/domain/openapi/unsupported-features.mjs +2 -2
- package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
- package/dist/domain/output-fixes.cjs +25 -14
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +25 -13
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/url-secrets.cjs +48 -0
- package/dist/domain/url-secrets.cjs.map +1 -0
- package/dist/domain/url-secrets.mjs +45 -0
- package/dist/domain/url-secrets.mjs.map +1 -0
- package/dist/domain/warnings.cjs +0 -1
- package/dist/domain/warnings.cjs.map +1 -1
- package/dist/domain/warnings.mjs +0 -1
- package/dist/domain/warnings.mjs.map +1 -1
- package/dist/index.cjs +2 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -20
- package/dist/index.d.mts +57 -20
- package/dist/index.d.ts +57 -20
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -6
- package/src/adapters/node-deprecations/node-deprecations.ts +14 -0
- package/src/adapters/node-file-system/file-claims.ts +138 -0
- package/src/adapters/node-file-system/file-identity.ts +137 -0
- package/src/adapters/node-file-system/node-file-system.ts +145 -18
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +95 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
- package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +18 -24
- package/src/adapters/redocly-loader/ref-access.ts +37 -3
- package/src/adapters/redocly-loader/ref-holders.ts +3 -3
- package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +74 -11
- package/src/adapters/redocly-loader/remote-node-limit.ts +62 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
- package/src/adapters/redocly-loader/schema-source.ts +20 -8
- package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
- package/src/adapters/terminal-logger/terminal-logger.ts +10 -5
- package/src/api/default-ports.ts +40 -4
- package/src/api/discriminator-conflict-warnings.ts +2 -2
- package/src/api/discriminator-enum-parent.ts +3 -3
- package/src/api/discriminator-other-owners.ts +5 -3
- package/src/api/discriminator-patch.ts +9 -6
- package/src/api/discriminator-scan.ts +19 -11
- package/src/api/document-run.ts +9 -3
- package/src/api/legacy-callback-warning.ts +13 -6
- package/src/api/legacy-utils.ts +5 -1
- package/src/api/openapi-ts.ts +26 -7
- package/src/api/run-context.ts +6 -0
- package/src/api/schema-callbacks.ts +60 -17
- package/src/api/string-to-ast.ts +11 -15
- package/src/api/transform-context.ts +7 -3
- package/src/api/transform-schema.ts +67 -15
- package/src/application/ports/deprecation-reporter.ts +9 -0
- package/src/application/ports/file-system.ts +39 -0
- package/src/application/ports/schema-loader.ts +11 -1
- package/src/application/print/text-writer.ts +10 -3
- package/src/application/stack-overflow.ts +9 -5
- package/src/application/transform/document/components.ts +4 -4
- package/src/application/transform/document/declared-type-names.ts +36 -0
- package/src/application/transform/document/defs-root.ts +2 -2
- package/src/application/transform/document/document.ts +4 -3
- package/src/application/transform/document/enum-names-given-back.ts +91 -0
- package/src/application/transform/document/global-type-references.ts +1 -1
- package/src/application/transform/document/media-type.ts +4 -3
- package/src/application/transform/document/operation-keys-written.ts +27 -0
- package/src/application/transform/document/operation.ts +2 -2
- package/src/application/transform/document/parameter-entries.ts +70 -0
- package/src/application/transform/document/parameter.ts +21 -9
- package/src/application/transform/document/parameters.ts +13 -58
- package/src/application/transform/document/path-item.ts +13 -31
- package/src/application/transform/document/paths-enum.ts +1 -1
- package/src/application/transform/document/paths.ts +8 -4
- package/src/application/transform/document/referenced-parameter.ts +146 -0
- package/src/application/transform/document/request-body.ts +2 -2
- package/src/application/transform/document/response.ts +3 -3
- package/src/application/transform/document/responses.ts +2 -2
- package/src/application/transform/document/root-type-aliases.ts +17 -38
- package/src/application/transform/document/type-resolution.ts +2 -1
- package/src/application/transform/document/webhooks.ts +2 -2
- package/src/application/transform/footer/document-footer.ts +18 -1
- package/src/application/transform/footer/enum-name-claims.ts +62 -0
- package/src/application/transform/footer/operation-keys.ts +28 -0
- package/src/application/transform/footer/type-evaluation.ts +4 -4
- package/src/application/transform/helper-types.ts +6 -5
- package/src/application/transform/numbered-names.ts +15 -0
- package/src/application/transform/ref-pointer/generated-location.ts +2 -2
- package/src/application/transform/ref-pointer/pointer-type.ts +2 -4
- package/src/application/transform/ref-type.ts +2 -1
- package/src/application/transform/schema/access-flags.ts +2 -2
- package/src/application/transform/schema/array-type.ts +3 -5
- package/src/application/transform/schema/composition-type.ts +6 -6
- package/src/application/transform/schema/enum-rule.ts +10 -8
- package/src/application/transform/schema/object-type.ts +4 -4
- package/src/application/transform/schema/presence-members.ts +2 -2
- package/src/application/transform/schema/ref-siblings.ts +76 -0
- package/src/application/transform/schema/required-variants.ts +3 -3
- package/src/application/transform/schema/schema-context.ts +3 -0
- package/src/application/transform/schema/schema-transform.ts +4 -2
- package/src/application/transform/schema/unevaluated-properties.ts +2 -2
- package/src/application/transform/schema-comment.ts +7 -3
- package/src/application/transform/transform-context.ts +5 -0
- package/src/cli/api-settings.ts +82 -7
- package/src/cli/api-writes.ts +117 -0
- package/src/cli/cli-dependencies.ts +21 -4
- package/src/cli/cli-errors.ts +20 -1
- package/src/cli/cli-output.ts +186 -7
- package/src/cli/main.ts +6 -3
- package/src/cli/redocly-apis.ts +153 -48
- package/src/cli/run-cli.ts +37 -8
- package/src/domain/append-all.ts +10 -0
- package/src/domain/cause-secrets.ts +52 -0
- package/src/domain/deprecations.ts +15 -0
- package/src/domain/errors.ts +22 -7
- package/src/domain/ir/identifier-text.ts +6 -5
- package/src/domain/ir/ir-shape.ts +299 -0
- package/src/domain/ir/newer-identifier-ranges.ts +183 -30
- package/src/domain/openapi/alias-expansion.ts +4 -1
- package/src/domain/openapi/discriminated-union.ts +6 -4
- package/src/domain/openapi/discriminator-conflicts.ts +21 -7
- package/src/domain/openapi/document-object.ts +2 -0
- package/src/domain/openapi/json-pointer.ts +96 -7
- package/src/domain/openapi/schema-dialect.ts +22 -0
- package/src/domain/openapi/unsupported-features.ts +2 -2
- package/src/domain/output-fixes.ts +37 -18
- package/src/domain/url-secrets.ts +72 -0
- package/src/domain/warnings.ts +0 -1
- package/src/index.ts +2 -6
- package/src/types/generator-options.ts +1 -1
- package/dist/cli/main.d.cts +0 -2
- package/dist/cli/main.d.mts +0 -2
- package/dist/cli/main.d.ts +0 -2
- package/dist/domain/url-credentials.cjs +0 -10
- package/dist/domain/url-credentials.cjs.map +0 -1
- package/dist/domain/url-credentials.mjs +0 -8
- package/dist/domain/url-credentials.mjs.map +0 -1
- package/src/domain/url-credentials.ts +0 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-load-errors.cjs","sources":["../../../src/adapters/redocly-loader/schema-load-errors.ts"],"sourcesContent":["import { assertNever } from \"../../domain/assert-never.js\";\nimport { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport { redactUrlCredentials } from \"../../domain/url-credentials.js\";\n\n/**\n * The typed errors of loading, validating and bundling a document (ADR-011). Messages are the\n * original messages, so Node API users who match on them keep working; URLs in them and in the\n * details never show user info.\n */\n\n/** No source was given, or the source is empty. */\nexport function sourceEmptyError(message: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({ code: ERROR_CODES.SCHEMA_SOURCE_EMPTY, message });\n}\n\n/** The source is neither a URL, text, buffer, stream nor plain object. */\nexport function sourceInvalidError(source: unknown): OpenAPITypesafeError {\n const received = Array.isArray(source) ? \"Array\" : typeof source;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message: `Expected string, object, or Buffer. Got ${received}`,\n details: { received },\n });\n}\n\nfunction causeMessage(cause: unknown): string {\n return cause instanceof Error ? cause.message : String(cause);\n}\n\n/** Enough of a source string to recognise it in the message. */\nconst SOURCE_TEXT_IN_MESSAGE = 200;\n\n/**\n * A string source is document text, so a file path parses as a YAML string scalar, not as a\n * document (docs/node.md). The message says how to load the file instead.\n */\nexport function pathStringError(text: string): OpenAPITypesafeError {\n const shown =\n text.length > SOURCE_TEXT_IN_MESSAGE ? `${text.slice(0, SOURCE_TEXT_IN_MESSAGE)}…` : text;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message:\n `The string \"${shown}\" was parsed as YAML text, not loaded as a file. ` +\n \"To load a file, pass a URL: openapiTS(pathToFileURL(path)) from node:url.\",\n details: { reason: \"path\", received: \"string\" },\n });\n}\n\n/** Reading the document from a file or URL failed; the message is the reader's message. */\nexport function loadFailedError(absoluteRef: string, cause: unknown): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_LOAD_FAILED,\n message: causeMessage(cause),\n details: { source: redactUrlCredentials(absoluteRef) },\n cause,\n });\n}\n\n/** The document text is not valid JSON or YAML; the message is the parser's message. */\nexport function parseFailedError(\n format: \"json\" | \"yaml\",\n absoluteRef: string,\n cause: unknown,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_PARSE_FAILED,\n message: causeMessage(cause),\n details: { format, source: redactUrlCredentials(absoluteRef) },\n cause,\n });\n}\n\n/** The document is not OpenAPI 3.x. */\nexport function versionUnsupportedError(\n message: string,\n parsed: Readonly<Record<string, unknown>>,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_VERSION_UNSUPPORTED,\n message,\n details: { openapi: parsed.openapi, swagger: parsed.swagger },\n });\n}\n\n/**\n * Linting or bundling found errors. The message is the last error, as in the original; all error\n * messages are in `details.problems`.\n */\nexport function schemaInvalidError(problems: readonly string[]): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_INVALID,\n message: problems.at(-1) ?? \"\",\n details: { problems: problems.map(redactUrlCredentials) },\n });\n}\n\n/** A `$ref` chain points back to itself with no schema in between (`A: $ref B`, `B: $ref A`). */\nexport function refCycleError(cause: Error): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: cause.message,\n details: { reason: \"cycle\" },\n cause,\n });\n}\n\nfunction hostListText(hosts: readonly string[]): string {\n return hosts.length === 0 ? \"none\" : hosts.join(\", \");\n}\n\n/** Why a `$ref` document was refused, with the limit it broke (ADR-017). */\nexport type RefRefusalDetails =\n | { readonly reason: \"outside-local-root\"; readonly localRoot: string }\n | { readonly reason: \"host-not-allowed\"; readonly allowedHosts: readonly string[] }\n | { readonly reason: \"local-ref-from-remote\"; readonly base: string }\n | { readonly reason: \"too-many-remote-documents\"; readonly maxDocuments: number };\n\nfunction limitText(details: RefRefusalDetails): string {\n switch (details.reason) {\n case \"outside-local-root\":\n return `it is outside the local $ref root ${details.localRoot}`;\n case \"host-not-allowed\": {\n const hosts = hostListText(details.allowedHosts);\n return `its host is not in the allowed remote $ref hosts (${hosts})`;\n }\n case \"local-ref-from-remote\":\n return `it is not an http(s) URL, and the $ref is in the remote document ${details.base}`;\n case \"too-many-remote-documents\":\n return `the document refers to more than ${details.maxDocuments} remote documents`;\n default:\n return assertNever(details);\n }\n}\n\n/**\n * A `$ref` is outside the local root, its host is not allowed (threat model R1, R2), a remote\n * document refers to a local file (T3), or there are too many remote documents (T2).\n */\nexport function refForbiddenError(ref: string, details: RefRefusalDetails): OpenAPITypesafeError {\n const limit = limitText(details);\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_FORBIDDEN,\n message: `Refused to load ${ref}: ${limit}`,\n details: { ref: redactUrlCredentials(ref), ...details },\n });\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","redactUrlCredentials","assertNever"],"mappings":";;;;;;AAWO,SAAS,iBAAiB,OAAA,EAAuC;AACtE,EAAA,OAAO,IAAIA,2BAAA,CAAqB,EAAE,MAAMC,kBAAA,CAAY,mBAAA,EAAqB,SAAS,CAAA;AACpF;AAGO,SAAS,mBAAmB,MAAA,EAAuC;AACxE,EAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAI,UAAU,OAAO,MAAA;AAC1D,EAAA,OAAO,IAAID,2BAAA,CAAqB;AAAA,IAC9B,MAAMC,kBAAA,CAAY,qBAAA;AAAA,IAClB,OAAA,EAAS,2CAA2C,QAAQ,CAAA,CAAA;AAAA,IAC5D,OAAA,EAAS,EAAE,QAAA;AAAS,GACrB,CAAA;AACH;AAEA,SAAS,aAAa,KAAA,EAAwB;AAC5C,EAAA,OAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAC9D;AAGA,MAAM,sBAAA,GAAyB,GAAA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AAA,CAAkB,KAAa,OAAA,EAAkD;AAC/F,EAAA,MAAM,KAAA,GAAQ,UAAU,OAAO,CAAA;AAC/B,EAAA,OAAO,IAAIH,2BAAA,CAAqB;AAAA,IAC9B,MAAMC,kBAAA,CAAY,oBAAA;AAAA,IAClB,OAAA,EAAS,CAAA,gBAAA,EAAmB,GAAG,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA;AAAA,IACzC,SAAS,EAAE,GAAA,EAAKC,oCAAqB,GAAG,CAAA,EAAG,GAAG,OAAA;AAAQ,GACvD,CAAA;AACH;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"schema-load-errors.cjs","sources":["../../../src/adapters/redocly-loader/schema-load-errors.ts"],"sourcesContent":["import { assertNever } from \"../../domain/assert-never.js\";\nimport { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport { redactUnparsedUrl, redactUrlSecrets } from \"../../domain/url-secrets.js\";\n\n/**\n * The typed errors of loading, validating and bundling a document (ADR-011). Messages are the\n * original messages, so Node API users who match on them keep working; URLs in them and in the\n * details never show user info.\n */\n\n/** No source was given, or the source is empty. */\nexport function sourceEmptyError(message: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({ code: ERROR_CODES.SCHEMA_SOURCE_EMPTY, message });\n}\n\n/** The source is neither a URL, text, buffer, stream nor plain object. */\nexport function sourceInvalidError(source: unknown): OpenAPITypesafeError {\n const received = Array.isArray(source) ? \"Array\" : typeof source;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message: `Expected string, object, or Buffer. Got ${received}`,\n details: { received },\n });\n}\n\n/** A source string starts with a URL scheme but does not parse as a URL. */\nexport function urlInvalidError(text: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message: `The string ${redactUnparsedUrl(text)} starts like a URL but is not a valid URL`,\n details: { reason: \"url\", received: \"string\" },\n });\n}\n\nfunction causeMessage(cause: unknown): string {\n return cause instanceof Error ? cause.message : String(cause);\n}\n\n/** Enough of a source string to recognise it in the message. */\nconst SOURCE_TEXT_IN_MESSAGE = 200;\n\n/** Where document text that is only a YAML string came from. */\nexport type TextOrigin = \"string\" | \"stream\";\n\nconst LOAD_FILE_ADVICE =\n \"To load a file, pass a URL: openapiTS(pathToFileURL(path)) from node:url.\";\n\n/**\n * A string source is document text, so a file path parses as a YAML string scalar, not as a\n * document (docs/node.md). The message says how to load the file instead. Text read from a\n * stream (stdin in the CLI) is named as such; `details.text` lets the CLI give its own advice.\n */\nexport function pathStringError(text: string, origin: TextOrigin): OpenAPITypesafeError {\n const shown =\n text.length > SOURCE_TEXT_IN_MESSAGE ? `${text.slice(0, SOURCE_TEXT_IN_MESSAGE)}…` : text;\n const message =\n origin === \"string\"\n ? `The string \"${shown}\" was parsed as YAML text, not loaded as a file. ${LOAD_FILE_ADVICE}`\n : `The stream held only the YAML string \"${shown}\", not an OpenAPI document. ` +\n LOAD_FILE_ADVICE;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message,\n details: { reason: \"path\", received: origin, text: shown },\n });\n}\n\n/** Reading the document from a file or URL failed; the message is the reader's message. */\nexport function loadFailedError(absoluteRef: string, cause: unknown): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_LOAD_FAILED,\n message: causeMessage(cause),\n details: { source: redactUrlSecrets(absoluteRef) },\n cause,\n });\n}\n\n/** The document text is not valid JSON or YAML; the message is the parser's message. */\nexport function parseFailedError(\n format: \"json\" | \"yaml\",\n absoluteRef: string,\n cause: unknown,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_PARSE_FAILED,\n message: causeMessage(cause),\n details: { format, source: redactUrlSecrets(absoluteRef) },\n cause,\n });\n}\n\n/** The document is not OpenAPI 3.x. */\nexport function versionUnsupportedError(\n message: string,\n parsed: Readonly<Record<string, unknown>>,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_VERSION_UNSUPPORTED,\n message,\n details: { openapi: parsed.openapi, swagger: parsed.swagger },\n });\n}\n\n/**\n * Linting or bundling found errors. The message is the last error, as in the original; all error\n * messages are in `details.problems`.\n */\nexport function schemaInvalidError(problems: readonly string[]): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_INVALID,\n message: problems.at(-1) ?? \"\",\n details: { problems: problems.map(redactUrlSecrets) },\n });\n}\n\n/** A `$ref` chain points back to itself with no schema in between (`A: $ref B`, `B: $ref A`). */\nexport function refCycleError(cause: Error): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: cause.message,\n details: { reason: \"cycle\" },\n cause,\n });\n}\n\nfunction hostListText(hosts: readonly string[]): string {\n return hosts.length === 0 ? \"none\" : hosts.join(\", \");\n}\n\n/** Why a `$ref` document was refused, with the limit it broke (ADR-017). */\nexport type RefRefusalDetails =\n | { readonly reason: \"outside-local-root\"; readonly localRoot: string }\n | { readonly reason: \"host-not-allowed\"; readonly allowedHosts: readonly string[] }\n | { readonly reason: \"local-ref-from-remote\"; readonly base: string }\n | { readonly reason: \"too-many-remote-documents\"; readonly maxDocuments: number }\n | { readonly reason: \"remote-document-too-large\"; readonly maxDocumentBytes: number }\n | { readonly reason: \"remote-documents-too-large\"; readonly maxTotalBytes: number }\n | { readonly reason: \"remote-documents-too-many-nodes\"; readonly maxNodes: number };\n\nconst BYTES_PER_MEBIBYTE = 1024 * 1024;\n\n/** A byte count in MiB, as the limits are chosen: `256 MiB`; a smaller limit in bytes. */\nfunction sizeText(bytes: number): string {\n return bytes % BYTES_PER_MEBIBYTE === 0 ? `${bytes / BYTES_PER_MEBIBYTE} MiB` : `${bytes} bytes`;\n}\n\nfunction limitText(details: RefRefusalDetails): string {\n switch (details.reason) {\n case \"outside-local-root\":\n return `it is outside the local $ref root ${details.localRoot}`;\n case \"host-not-allowed\": {\n const hosts = hostListText(details.allowedHosts);\n return `its host is not in the allowed remote $ref hosts (${hosts})`;\n }\n case \"local-ref-from-remote\":\n return `it is not an http(s) URL, and the $ref is in the remote document ${details.base}`;\n case \"too-many-remote-documents\":\n return `the document refers to more than ${details.maxDocuments} remote documents`;\n case \"remote-document-too-large\":\n return `its body is larger than ${sizeText(details.maxDocumentBytes)} once decoded`;\n case \"remote-documents-too-large\": {\n const limit = sizeText(details.maxTotalBytes);\n return `the remote documents of this run are larger than ${limit} together once decoded`;\n }\n case \"remote-documents-too-many-nodes\": {\n const limit = details.maxNodes;\n return `the remote documents of this run parse into more than ${limit} nodes together`;\n }\n default:\n return assertNever(details);\n }\n}\n\n/**\n * A `$ref` is outside the local root, its host is not allowed (threat model R1, R2), a remote\n * document refers to a local file (T3), or there are too many or too large remote documents (T2).\n */\nexport function refForbiddenError(ref: string, details: RefRefusalDetails): OpenAPITypesafeError {\n const limit = limitText(details);\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_FORBIDDEN,\n message: `Refused to load ${ref}: ${limit}`,\n details: { ref: redactUrlSecrets(ref), ...details },\n });\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","redactUnparsedUrl","redactUrlSecrets","assertNever"],"mappings":";;;;;;AAWO,SAAS,iBAAiB,OAAA,EAAuC;AACtE,EAAA,OAAO,IAAIA,2BAAA,CAAqB,EAAE,MAAMC,kBAAA,CAAY,mBAAA,EAAqB,SAAS,CAAA;AACpF;AAGO,SAAS,mBAAmB,MAAA,EAAuC;AACxE,EAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAI,UAAU,OAAO,MAAA;AAC1D,EAAA,OAAO,IAAID,2BAAA,CAAqB;AAAA,IAC9B,MAAMC,kBAAA,CAAY,qBAAA;AAAA,IAClB,OAAA,EAAS,2CAA2C,QAAQ,CAAA,CAAA;AAAA,IAC5D,OAAA,EAAS,EAAE,QAAA;AA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;AACE,MAAA,OAAOG,wBAAY,OAAO,CAAA;AAAA;AAEhC;AAMO,SAAS,iBAAA,CAAkB,KAAa,OAAA,EAAkD;AAC/F,EAAA,MAAM,KAAA,GAAQ,UAAU,OAAO,CAAA;AAC/B,EAAA,OAAO,IAAIJ,2BAAA,CAAqB;AAAA,IAC9B,MAAMC,kBAAA,CAAY,oBAAA;AAAA,IAClB,OAAA,EAAS,CAAA,gBAAA,EAAmB,GAAG,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA;AAAA,IACzC,SAAS,EAAE,GAAA,EAAKE,4BAAiB,GAAG,CAAA,EAAG,GAAG,OAAA;AAAQ,GACnD,CAAA;AACH;;;;;;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assertNever } from '../../domain/assert-never.mjs';
|
|
2
2
|
import { OpenAPITypesafeError, ERROR_CODES } from '../../domain/errors.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { redactUrlSecrets, redactUnparsedUrl } from '../../domain/url-secrets.mjs';
|
|
4
4
|
|
|
5
5
|
function sourceEmptyError(message) {
|
|
6
6
|
return new OpenAPITypesafeError({ code: ERROR_CODES.SCHEMA_SOURCE_EMPTY, message });
|
|
@@ -13,23 +13,32 @@ function sourceInvalidError(source) {
|
|
|
13
13
|
details: { received }
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
+
function urlInvalidError(text) {
|
|
17
|
+
return new OpenAPITypesafeError({
|
|
18
|
+
code: ERROR_CODES.SCHEMA_SOURCE_INVALID,
|
|
19
|
+
message: `The string ${redactUnparsedUrl(text)} starts like a URL but is not a valid URL`,
|
|
20
|
+
details: { reason: "url", received: "string" }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
16
23
|
function causeMessage(cause) {
|
|
17
24
|
return cause instanceof Error ? cause.message : String(cause);
|
|
18
25
|
}
|
|
19
26
|
const SOURCE_TEXT_IN_MESSAGE = 200;
|
|
20
|
-
|
|
27
|
+
const LOAD_FILE_ADVICE = "To load a file, pass a URL: openapiTS(pathToFileURL(path)) from node:url.";
|
|
28
|
+
function pathStringError(text, origin) {
|
|
21
29
|
const shown = text.length > SOURCE_TEXT_IN_MESSAGE ? `${text.slice(0, SOURCE_TEXT_IN_MESSAGE)}\u2026` : text;
|
|
30
|
+
const message = origin === "string" ? `The string "${shown}" was parsed as YAML text, not loaded as a file. ${LOAD_FILE_ADVICE}` : `The stream held only the YAML string "${shown}", not an OpenAPI document. ` + LOAD_FILE_ADVICE;
|
|
22
31
|
return new OpenAPITypesafeError({
|
|
23
32
|
code: ERROR_CODES.SCHEMA_SOURCE_INVALID,
|
|
24
|
-
message
|
|
25
|
-
details: { reason: "path", received:
|
|
33
|
+
message,
|
|
34
|
+
details: { reason: "path", received: origin, text: shown }
|
|
26
35
|
});
|
|
27
36
|
}
|
|
28
37
|
function loadFailedError(absoluteRef, cause) {
|
|
29
38
|
return new OpenAPITypesafeError({
|
|
30
39
|
code: ERROR_CODES.SCHEMA_LOAD_FAILED,
|
|
31
40
|
message: causeMessage(cause),
|
|
32
|
-
details: { source:
|
|
41
|
+
details: { source: redactUrlSecrets(absoluteRef) },
|
|
33
42
|
cause
|
|
34
43
|
});
|
|
35
44
|
}
|
|
@@ -37,7 +46,7 @@ function parseFailedError(format, absoluteRef, cause) {
|
|
|
37
46
|
return new OpenAPITypesafeError({
|
|
38
47
|
code: ERROR_CODES.SCHEMA_PARSE_FAILED,
|
|
39
48
|
message: causeMessage(cause),
|
|
40
|
-
details: { format, source:
|
|
49
|
+
details: { format, source: redactUrlSecrets(absoluteRef) },
|
|
41
50
|
cause
|
|
42
51
|
});
|
|
43
52
|
}
|
|
@@ -52,7 +61,7 @@ function schemaInvalidError(problems) {
|
|
|
52
61
|
return new OpenAPITypesafeError({
|
|
53
62
|
code: ERROR_CODES.SCHEMA_INVALID,
|
|
54
63
|
message: problems.at(-1) ?? "",
|
|
55
|
-
details: { problems: problems.map(
|
|
64
|
+
details: { problems: problems.map(redactUrlSecrets) }
|
|
56
65
|
});
|
|
57
66
|
}
|
|
58
67
|
function refCycleError(cause) {
|
|
@@ -66,6 +75,10 @@ function refCycleError(cause) {
|
|
|
66
75
|
function hostListText(hosts) {
|
|
67
76
|
return hosts.length === 0 ? "none" : hosts.join(", ");
|
|
68
77
|
}
|
|
78
|
+
const BYTES_PER_MEBIBYTE = 1024 * 1024;
|
|
79
|
+
function sizeText(bytes) {
|
|
80
|
+
return bytes % BYTES_PER_MEBIBYTE === 0 ? `${bytes / BYTES_PER_MEBIBYTE} MiB` : `${bytes} bytes`;
|
|
81
|
+
}
|
|
69
82
|
function limitText(details) {
|
|
70
83
|
switch (details.reason) {
|
|
71
84
|
case "outside-local-root":
|
|
@@ -78,6 +91,16 @@ function limitText(details) {
|
|
|
78
91
|
return `it is not an http(s) URL, and the $ref is in the remote document ${details.base}`;
|
|
79
92
|
case "too-many-remote-documents":
|
|
80
93
|
return `the document refers to more than ${details.maxDocuments} remote documents`;
|
|
94
|
+
case "remote-document-too-large":
|
|
95
|
+
return `its body is larger than ${sizeText(details.maxDocumentBytes)} once decoded`;
|
|
96
|
+
case "remote-documents-too-large": {
|
|
97
|
+
const limit = sizeText(details.maxTotalBytes);
|
|
98
|
+
return `the remote documents of this run are larger than ${limit} together once decoded`;
|
|
99
|
+
}
|
|
100
|
+
case "remote-documents-too-many-nodes": {
|
|
101
|
+
const limit = details.maxNodes;
|
|
102
|
+
return `the remote documents of this run parse into more than ${limit} nodes together`;
|
|
103
|
+
}
|
|
81
104
|
default:
|
|
82
105
|
return assertNever(details);
|
|
83
106
|
}
|
|
@@ -87,9 +110,9 @@ function refForbiddenError(ref, details) {
|
|
|
87
110
|
return new OpenAPITypesafeError({
|
|
88
111
|
code: ERROR_CODES.SCHEMA_REF_FORBIDDEN,
|
|
89
112
|
message: `Refused to load ${ref}: ${limit}`,
|
|
90
|
-
details: { ref:
|
|
113
|
+
details: { ref: redactUrlSecrets(ref), ...details }
|
|
91
114
|
});
|
|
92
115
|
}
|
|
93
116
|
|
|
94
|
-
export { loadFailedError, parseFailedError, pathStringError, refCycleError, refForbiddenError, schemaInvalidError, sourceEmptyError, sourceInvalidError, versionUnsupportedError };
|
|
117
|
+
export { loadFailedError, parseFailedError, pathStringError, refCycleError, refForbiddenError, schemaInvalidError, sourceEmptyError, sourceInvalidError, urlInvalidError, versionUnsupportedError };
|
|
95
118
|
//# sourceMappingURL=schema-load-errors.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-load-errors.mjs","sources":["../../../src/adapters/redocly-loader/schema-load-errors.ts"],"sourcesContent":["import { assertNever } from \"../../domain/assert-never.js\";\nimport { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport { redactUrlCredentials } from \"../../domain/url-credentials.js\";\n\n/**\n * The typed errors of loading, validating and bundling a document (ADR-011). Messages are the\n * original messages, so Node API users who match on them keep working; URLs in them and in the\n * details never show user info.\n */\n\n/** No source was given, or the source is empty. */\nexport function sourceEmptyError(message: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({ code: ERROR_CODES.SCHEMA_SOURCE_EMPTY, message });\n}\n\n/** The source is neither a URL, text, buffer, stream nor plain object. */\nexport function sourceInvalidError(source: unknown): OpenAPITypesafeError {\n const received = Array.isArray(source) ? \"Array\" : typeof source;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message: `Expected string, object, or Buffer. Got ${received}`,\n details: { received },\n });\n}\n\nfunction causeMessage(cause: unknown): string {\n return cause instanceof Error ? cause.message : String(cause);\n}\n\n/** Enough of a source string to recognise it in the message. */\nconst SOURCE_TEXT_IN_MESSAGE = 200;\n\n/**\n * A string source is document text, so a file path parses as a YAML string scalar, not as a\n * document (docs/node.md). The message says how to load the file instead.\n */\nexport function pathStringError(text: string): OpenAPITypesafeError {\n const shown =\n text.length > SOURCE_TEXT_IN_MESSAGE ? `${text.slice(0, SOURCE_TEXT_IN_MESSAGE)}…` : text;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message:\n `The string \"${shown}\" was parsed as YAML text, not loaded as a file. ` +\n \"To load a file, pass a URL: openapiTS(pathToFileURL(path)) from node:url.\",\n details: { reason: \"path\", received: \"string\" },\n });\n}\n\n/** Reading the document from a file or URL failed; the message is the reader's message. */\nexport function loadFailedError(absoluteRef: string, cause: unknown): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_LOAD_FAILED,\n message: causeMessage(cause),\n details: { source: redactUrlCredentials(absoluteRef) },\n cause,\n });\n}\n\n/** The document text is not valid JSON or YAML; the message is the parser's message. */\nexport function parseFailedError(\n format: \"json\" | \"yaml\",\n absoluteRef: string,\n cause: unknown,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_PARSE_FAILED,\n message: causeMessage(cause),\n details: { format, source: redactUrlCredentials(absoluteRef) },\n cause,\n });\n}\n\n/** The document is not OpenAPI 3.x. */\nexport function versionUnsupportedError(\n message: string,\n parsed: Readonly<Record<string, unknown>>,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_VERSION_UNSUPPORTED,\n message,\n details: { openapi: parsed.openapi, swagger: parsed.swagger },\n });\n}\n\n/**\n * Linting or bundling found errors. The message is the last error, as in the original; all error\n * messages are in `details.problems`.\n */\nexport function schemaInvalidError(problems: readonly string[]): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_INVALID,\n message: problems.at(-1) ?? \"\",\n details: { problems: problems.map(redactUrlCredentials) },\n });\n}\n\n/** A `$ref` chain points back to itself with no schema in between (`A: $ref B`, `B: $ref A`). */\nexport function refCycleError(cause: Error): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: cause.message,\n details: { reason: \"cycle\" },\n cause,\n });\n}\n\nfunction hostListText(hosts: readonly string[]): string {\n return hosts.length === 0 ? \"none\" : hosts.join(\", \");\n}\n\n/** Why a `$ref` document was refused, with the limit it broke (ADR-017). */\nexport type RefRefusalDetails =\n | { readonly reason: \"outside-local-root\"; readonly localRoot: string }\n | { readonly reason: \"host-not-allowed\"; readonly allowedHosts: readonly string[] }\n | { readonly reason: \"local-ref-from-remote\"; readonly base: string }\n | { readonly reason: \"too-many-remote-documents\"; readonly maxDocuments: number };\n\nfunction limitText(details: RefRefusalDetails): string {\n switch (details.reason) {\n case \"outside-local-root\":\n return `it is outside the local $ref root ${details.localRoot}`;\n case \"host-not-allowed\": {\n const hosts = hostListText(details.allowedHosts);\n return `its host is not in the allowed remote $ref hosts (${hosts})`;\n }\n case \"local-ref-from-remote\":\n return `it is not an http(s) URL, and the $ref is in the remote document ${details.base}`;\n case \"too-many-remote-documents\":\n return `the document refers to more than ${details.maxDocuments} remote documents`;\n default:\n return assertNever(details);\n }\n}\n\n/**\n * A `$ref` is outside the local root, its host is not allowed (threat model R1, R2), a remote\n * document refers to a local file (T3), or there are too many remote documents (T2).\n */\nexport function refForbiddenError(ref: string, details: RefRefusalDetails): OpenAPITypesafeError {\n const limit = limitText(details);\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_FORBIDDEN,\n message: `Refused to load ${ref}: ${limit}`,\n details: { ref: redactUrlCredentials(ref), ...details },\n });\n}\n"],"names":[],"mappings":";;;;AAWO,SAAS,iBAAiB,OAAA,EAAuC;AACtE,EAAA,OAAO,IAAI,oBAAA,CAAqB,EAAE,MAAM,WAAA,CAAY,mBAAA,EAAqB,SAAS,CAAA;AACpF;AAGO,SAAS,mBAAmB,MAAA,EAAuC;AACxE,EAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAI,UAAU,OAAO,MAAA;AAC1D,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9B,MAAM,WAAA,CAAY,qBAAA;AAAA,IAClB,OAAA,EAAS,2CAA2C,QAAQ,CAAA,CAA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oE,QAAQ,IAAI,CAAA,CAAA;AAAA,IACzF,KAAK,2BAAA;AACH,MAAA,OAAO,CAAA,iCAAA,EAAoC,QAAQ,YAAY,CAAA,iBAAA,CAAA;AAAA,IACjE;AACE,MAAA,OAAO,YAAY,OAAO,CAAA;AAAA;AAEhC;AAMO,SAAS,iBAAA,CAAkB,KAAa,OAAA,EAAkD;AAC/F,EAAA,MAAM,KAAA,GAAQ,UAAU,OAAO,CAAA;AAC/B,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9B,MAAM,WAAA,CAAY,oBAAA;AAAA,IAClB,OAAA,EAAS,CAAA,gBAAA,EAAmB,GAAG,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA;AAAA,IACzC,SAAS,EAAE,GAAA,EAAK,qBAAqB,GAAG,CAAA,EAAG,GAAG,OAAA;AAAQ,GACvD,CAAA;AACH;;"}
|
|
1
|
+
{"version":3,"file":"schema-load-errors.mjs","sources":["../../../src/adapters/redocly-loader/schema-load-errors.ts"],"sourcesContent":["import { assertNever } from \"../../domain/assert-never.js\";\nimport { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport { redactUnparsedUrl, redactUrlSecrets } from \"../../domain/url-secrets.js\";\n\n/**\n * The typed errors of loading, validating and bundling a document (ADR-011). Messages are the\n * original messages, so Node API users who match on them keep working; URLs in them and in the\n * details never show user info.\n */\n\n/** No source was given, or the source is empty. */\nexport function sourceEmptyError(message: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({ code: ERROR_CODES.SCHEMA_SOURCE_EMPTY, message });\n}\n\n/** The source is neither a URL, text, buffer, stream nor plain object. */\nexport function sourceInvalidError(source: unknown): OpenAPITypesafeError {\n const received = Array.isArray(source) ? \"Array\" : typeof source;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message: `Expected string, object, or Buffer. Got ${received}`,\n details: { received },\n });\n}\n\n/** A source string starts with a URL scheme but does not parse as a URL. */\nexport function urlInvalidError(text: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message: `The string ${redactUnparsedUrl(text)} starts like a URL but is not a valid URL`,\n details: { reason: \"url\", received: \"string\" },\n });\n}\n\nfunction causeMessage(cause: unknown): string {\n return cause instanceof Error ? cause.message : String(cause);\n}\n\n/** Enough of a source string to recognise it in the message. */\nconst SOURCE_TEXT_IN_MESSAGE = 200;\n\n/** Where document text that is only a YAML string came from. */\nexport type TextOrigin = \"string\" | \"stream\";\n\nconst LOAD_FILE_ADVICE =\n \"To load a file, pass a URL: openapiTS(pathToFileURL(path)) from node:url.\";\n\n/**\n * A string source is document text, so a file path parses as a YAML string scalar, not as a\n * document (docs/node.md). The message says how to load the file instead. Text read from a\n * stream (stdin in the CLI) is named as such; `details.text` lets the CLI give its own advice.\n */\nexport function pathStringError(text: string, origin: TextOrigin): OpenAPITypesafeError {\n const shown =\n text.length > SOURCE_TEXT_IN_MESSAGE ? `${text.slice(0, SOURCE_TEXT_IN_MESSAGE)}…` : text;\n const message =\n origin === \"string\"\n ? `The string \"${shown}\" was parsed as YAML text, not loaded as a file. ${LOAD_FILE_ADVICE}`\n : `The stream held only the YAML string \"${shown}\", not an OpenAPI document. ` +\n LOAD_FILE_ADVICE;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message,\n details: { reason: \"path\", received: origin, text: shown },\n });\n}\n\n/** Reading the document from a file or URL failed; the message is the reader's message. */\nexport function loadFailedError(absoluteRef: string, cause: unknown): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_LOAD_FAILED,\n message: causeMessage(cause),\n details: { source: redactUrlSecrets(absoluteRef) },\n cause,\n });\n}\n\n/** The document text is not valid JSON or YAML; the message is the parser's message. */\nexport function parseFailedError(\n format: \"json\" | \"yaml\",\n absoluteRef: string,\n cause: unknown,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_PARSE_FAILED,\n message: causeMessage(cause),\n details: { format, source: redactUrlSecrets(absoluteRef) },\n cause,\n });\n}\n\n/** The document is not OpenAPI 3.x. */\nexport function versionUnsupportedError(\n message: string,\n parsed: Readonly<Record<string, unknown>>,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_VERSION_UNSUPPORTED,\n message,\n details: { openapi: parsed.openapi, swagger: parsed.swagger },\n });\n}\n\n/**\n * Linting or bundling found errors. The message is the last error, as in the original; all error\n * messages are in `details.problems`.\n */\nexport function schemaInvalidError(problems: readonly string[]): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_INVALID,\n message: problems.at(-1) ?? \"\",\n details: { problems: problems.map(redactUrlSecrets) },\n });\n}\n\n/** A `$ref` chain points back to itself with no schema in between (`A: $ref B`, `B: $ref A`). */\nexport function refCycleError(cause: Error): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: cause.message,\n details: { reason: \"cycle\" },\n cause,\n });\n}\n\nfunction hostListText(hosts: readonly string[]): string {\n return hosts.length === 0 ? \"none\" : hosts.join(\", \");\n}\n\n/** Why a `$ref` document was refused, with the limit it broke (ADR-017). */\nexport type RefRefusalDetails =\n | { readonly reason: \"outside-local-root\"; readonly localRoot: string }\n | { readonly reason: \"host-not-allowed\"; readonly allowedHosts: readonly string[] }\n | { readonly reason: \"local-ref-from-remote\"; readonly base: string }\n | { readonly reason: \"too-many-remote-documents\"; readonly maxDocuments: number }\n | { readonly reason: \"remote-document-too-large\"; readonly maxDocumentBytes: number }\n | { readonly reason: \"remote-documents-too-large\"; readonly maxTotalBytes: number }\n | { readonly reason: \"remote-documents-too-many-nodes\"; readonly maxNodes: number };\n\nconst BYTES_PER_MEBIBYTE = 1024 * 1024;\n\n/** A byte count in MiB, as the limits are chosen: `256 MiB`; a smaller limit in bytes. */\nfunction sizeText(bytes: number): string {\n return bytes % BYTES_PER_MEBIBYTE === 0 ? `${bytes / BYTES_PER_MEBIBYTE} MiB` : `${bytes} bytes`;\n}\n\nfunction limitText(details: RefRefusalDetails): string {\n switch (details.reason) {\n case \"outside-local-root\":\n return `it is outside the local $ref root ${details.localRoot}`;\n case \"host-not-allowed\": {\n const hosts = hostListText(details.allowedHosts);\n return `its host is not in the allowed remote $ref hosts (${hosts})`;\n }\n case \"local-ref-from-remote\":\n return `it is not an http(s) URL, and the $ref is in the remote document ${details.base}`;\n case \"too-many-remote-documents\":\n return `the document refers to more than ${details.maxDocuments} remote documents`;\n case \"remote-document-too-large\":\n return `its body is larger than ${sizeText(details.maxDocumentBytes)} once decoded`;\n case \"remote-documents-too-large\": {\n const limit = sizeText(details.maxTotalBytes);\n return `the remote documents of this run are larger than ${limit} together once decoded`;\n }\n case \"remote-documents-too-many-nodes\": {\n const limit = details.maxNodes;\n return `the remote documents of this run parse into more than ${limit} nodes together`;\n }\n default:\n return assertNever(details);\n }\n}\n\n/**\n * A `$ref` is outside the local root, its host is not allowed (threat model R1, R2), a remote\n * document refers to a local file (T3), or there are too many or too large remote documents (T2).\n */\nexport function refForbiddenError(ref: string, details: RefRefusalDetails): OpenAPITypesafeError {\n const limit = limitText(details);\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_FORBIDDEN,\n message: `Refused to load ${ref}: ${limit}`,\n details: { ref: redactUrlSecrets(ref), ...details },\n });\n}\n"],"names":[],"mappings":";;;;AAWO,SAAS,iBAAiB,OAAA,EAAuC;AACtE,EAAA,OAAO,IAAI,oBAAA,CAAqB,EAAE,MAAM,WAAA,CAAY,mBAAA,EAAqB,SAAS,CAAA;AACpF;AAGO,SAAS,mBAAmB,MAAA,EAAuC;AACxE,EAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAI,UAAU,OAAO,MAAA;AAC1D,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9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Q,OAAA,CAAQ,QAAA;AACtB,MAAA,OAAO,yDAAyD,KAAK,CAAA,eAAA,CAAA;AAAA,IACvE;AAAA,IACA;AACE,MAAA,OAAO,YAAY,OAAO,CAAA;AAAA;AAEhC;AAMO,SAAS,iBAAA,CAAkB,KAAa,OAAA,EAAkD;AAC/F,EAAA,MAAM,KAAA,GAAQ,UAAU,OAAO,CAAA;AAC/B,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9B,MAAM,WAAA,CAAY,oBAAA;AAAA,IAClB,OAAA,EAAS,CAAA,gBAAA,EAAmB,GAAG,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA;AAAA,IACzC,SAAS,EAAE,GAAA,EAAK,iBAAiB,GAAG,CAAA,EAAG,GAAG,OAAA;AAAQ,GACnD,CAAA;AACH;;"}
|
|
@@ -19,14 +19,17 @@ async function readStream(stream, absoluteRef) {
|
|
|
19
19
|
throw schemaLoadErrors.loadFailedError(absoluteRef, error);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
const
|
|
22
|
+
const URL_PREFIX_RE = /^(?:https?|file):\/\//i;
|
|
23
23
|
function parseSchemaText(schema, options) {
|
|
24
|
-
if (
|
|
25
|
-
const url =
|
|
24
|
+
if (URL_PREFIX_RE.test(schema)) {
|
|
25
|
+
const url = URL.parse(schema);
|
|
26
|
+
if (url === null) {
|
|
27
|
+
throw schemaLoadErrors.urlInvalidError(schema);
|
|
28
|
+
}
|
|
26
29
|
const absoluteRef = url.protocol === "file:" ? node_url.fileURLToPath(url) : url.href;
|
|
27
30
|
return parseSchema(url, { absoluteRef, resolver: options.resolver });
|
|
28
31
|
}
|
|
29
|
-
return schema[0] === "{" ? parseJsonText(schema, options.absoluteRef) : parseYamlText(schema, options.absoluteRef);
|
|
32
|
+
return schema[0] === "{" ? parseJsonText(schema, options.absoluteRef) : parseYamlText(schema, options.absoluteRef, options.textOrigin ?? "string");
|
|
30
33
|
}
|
|
31
34
|
function parseJsonText(text2, absoluteRef) {
|
|
32
35
|
try {
|
|
@@ -35,7 +38,7 @@ function parseJsonText(text2, absoluteRef) {
|
|
|
35
38
|
throw schemaLoadErrors.parseFailedError("json", absoluteRef, cause);
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
|
-
function parseYamlText(text2, absoluteRef) {
|
|
41
|
+
function parseYamlText(text2, absoluteRef, origin) {
|
|
39
42
|
let document;
|
|
40
43
|
try {
|
|
41
44
|
document = openapiCore.makeDocumentFromString(text2, absoluteRef);
|
|
@@ -43,7 +46,7 @@ function parseYamlText(text2, absoluteRef) {
|
|
|
43
46
|
throw schemaLoadErrors.parseFailedError("yaml", absoluteRef, cause);
|
|
44
47
|
}
|
|
45
48
|
if (typeof document.parsed === "string") {
|
|
46
|
-
throw schemaLoadErrors.pathStringError(text2);
|
|
49
|
+
throw schemaLoadErrors.pathStringError(text2, origin);
|
|
47
50
|
}
|
|
48
51
|
const failure = aliasLimit.aliasExpansionFailure(document.parsed);
|
|
49
52
|
if (failure !== void 0) {
|
|
@@ -89,7 +92,8 @@ async function parseSchema(schema, options) {
|
|
|
89
92
|
return resolveSchemaURL(options);
|
|
90
93
|
}
|
|
91
94
|
if (schema instanceof node_stream.Readable) {
|
|
92
|
-
|
|
95
|
+
const text2 = await readStream(schema, options.absoluteRef);
|
|
96
|
+
return parseSchema(text2, { ...options, textOrigin: "stream" });
|
|
93
97
|
}
|
|
94
98
|
if (schema instanceof Buffer) {
|
|
95
99
|
return parseSchema(schema.toString("utf8"), options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-source.cjs","sources":["../../../src/adapters/redocly-loader/schema-source.ts"],"sourcesContent":["import { Readable } from \"node:stream\";\nimport { text } from \"node:stream/consumers\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n type BaseResolver,\n type Document,\n makeDocumentFromString,\n ResolveError,\n Source,\n YamlParseError,\n} from \"@redocly/openapi-core\";\nimport parseJson from \"parse-json\";\nimport { aliasExpansionFailure } from \"./alias-limit.js\";\nimport {\n loadFailedError,\n parseFailedError,\n pathStringError,\n sourceEmptyError,\n sourceInvalidError,\n} from \"./schema-load-errors.js\";\n\n/** Parse a schema source of any supported type into a Redocly document (ENGINEERING_PLAN 4.5). */\n\nexport interface ParseSchemaOptions {\n absoluteRef: string;\n resolver: BaseResolver;\n}\n\n/**\n * Read a stream to the end as UTF-8 text, trimmed. A stream that fails rejects with\n * SCHEMA_LOAD_FAILED; listening only for `data` and `end` left the promise pending forever.\n */\nasync function readStream(stream: Readable, absoluteRef: string): Promise<string> {\n try {\n return (await text(stream)).trim();\n } catch (error) {\n throw loadFailedError(absoluteRef, error);\n }\n}\n\
|
|
1
|
+
{"version":3,"file":"schema-source.cjs","sources":["../../../src/adapters/redocly-loader/schema-source.ts"],"sourcesContent":["import { Readable } from \"node:stream\";\nimport { text } from \"node:stream/consumers\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n type BaseResolver,\n type Document,\n makeDocumentFromString,\n ResolveError,\n Source,\n YamlParseError,\n} from \"@redocly/openapi-core\";\nimport parseJson from \"parse-json\";\nimport { aliasExpansionFailure } from \"./alias-limit.js\";\nimport {\n loadFailedError,\n parseFailedError,\n pathStringError,\n sourceEmptyError,\n sourceInvalidError,\n type TextOrigin,\n urlInvalidError,\n} from \"./schema-load-errors.js\";\n\n/** Parse a schema source of any supported type into a Redocly document (ENGINEERING_PLAN 4.5). */\n\nexport interface ParseSchemaOptions {\n absoluteRef: string;\n resolver: BaseResolver;\n /** Where document text came from, for the message of text that is only a string. */\n textOrigin?: TextOrigin;\n}\n\n/**\n * Read a stream to the end as UTF-8 text, trimmed. A stream that fails rejects with\n * SCHEMA_LOAD_FAILED; listening only for `data` and `end` left the promise pending forever.\n */\nasync function readStream(stream: Readable, absoluteRef: string): Promise<string> {\n try {\n return (await text(stream)).trim();\n } catch (error) {\n throw loadFailedError(absoluteRef, error);\n }\n}\n\n/** A URL source string; a scheme is the same in any case (RFC 3986, section 3.1). */\nconst URL_PREFIX_RE = /^(?:https?|file):\\/\\//i;\n\n/**\n * A string is a URL, JSON (starts with `{`) or YAML. A string that starts like a URL but does not\n * parse as one fails with `SCHEMA_SOURCE_INVALID`, not the parser's `TypeError`.\n */\nfunction parseSchemaText(\n schema: string,\n options: ParseSchemaOptions,\n): Promise<Document> | Document {\n if (URL_PREFIX_RE.test(schema)) {\n const url = URL.parse(schema);\n if (url === null) {\n throw urlInvalidError(schema);\n }\n const absoluteRef = url.protocol === \"file:\" ? fileURLToPath(url) : url.href;\n return parseSchema(url, { absoluteRef, resolver: options.resolver });\n }\n return schema[0] === \"{\"\n ? parseJsonText(schema, options.absoluteRef)\n : parseYamlText(schema, options.absoluteRef, options.textOrigin ?? \"string\");\n}\n\nfunction parseJsonText(text: string, absoluteRef: string): Document {\n try {\n return { source: new Source(absoluteRef, text, \"application/json\"), parsed: parseJson(text) };\n } catch (cause) {\n throw parseFailedError(\"json\", absoluteRef, cause);\n }\n}\n\nfunction parseYamlText(text: string, absoluteRef: string, origin: TextOrigin): Document {\n let document: Document;\n try {\n document = makeDocumentFromString(text, absoluteRef);\n } catch (cause) {\n throw parseFailedError(\"yaml\", absoluteRef, cause);\n }\n // Text that is only a YAML string scalar, such as \"./openapi.yaml\", was meant as a file path.\n if (typeof document.parsed === \"string\") {\n throw pathStringError(text, origin);\n }\n const failure = aliasExpansionFailure(document.parsed);\n if (failure !== undefined) {\n throw parseFailedError(\"yaml\", absoluteRef, failure);\n }\n return document;\n}\n\n/** The resolver throws for some failures (a missing file) and returns an error for others. */\nasync function resolveSchemaURL(options: ParseSchemaOptions): Promise<Document> {\n const result = await options.resolver\n .resolveDocument(null, options.absoluteRef, true)\n .catch((cause: unknown) => {\n throw cause instanceof YamlParseError\n ? fileParseFailedError(options.absoluteRef, cause)\n : loadFailedError(options.absoluteRef, readerError(cause));\n });\n if (\"parsed\" in result) {\n return result;\n }\n throw loadFailedError(options.absoluteRef, readerError(result));\n}\n\n/**\n * Redocly wraps a failed read in `ResolveError`, which keeps the reader's error in\n * `originalError`, not in `cause`. Unwrapped, the cause keeps the network reason (refused, DNS).\n */\nfunction readerError(error: unknown): unknown {\n let current = error;\n while (current instanceof ResolveError) {\n current = current.originalError;\n }\n return current;\n}\n\n/**\n * The resolver parses JSON files with its YAML parser too, so the format comes from the file\n * name. Some parser messages (a second YAML document) do not name the file; the error adds it.\n */\nfunction fileParseFailedError(absoluteRef: string, error: YamlParseError): Error {\n const format = absoluteRef.toLowerCase().endsWith(\".json\") ? \"json\" : \"yaml\";\n const cause = error.message.includes(absoluteRef)\n ? error\n : new Error(`${error.message} in \"${absoluteRef}\"`, { cause: error });\n return parseFailedError(format, absoluteRef, cause);\n}\n\nfunction parseSchemaObject(schema: unknown, absoluteRef: string): Document {\n if (typeof schema === \"object\" && !Array.isArray(schema)) {\n return {\n source: new Source(absoluteRef, JSON.stringify(schema), \"application/json\"),\n parsed: schema,\n };\n }\n throw sourceInvalidError(schema);\n}\n\n/** Parse any supported source: URL, stream, buffer, URL or document text, or a plain object. */\nexport async function parseSchema(schema: unknown, options: ParseSchemaOptions): Promise<Document> {\n if (!schema) {\n throw sourceEmptyError(\"Can’t parse empty schema\");\n }\n if (schema instanceof URL) {\n return resolveSchemaURL(options);\n }\n if (schema instanceof Readable) {\n const text = await readStream(schema, options.absoluteRef);\n return parseSchema(text, { ...options, textOrigin: \"stream\" });\n }\n if (schema instanceof Buffer) {\n return parseSchema(schema.toString(\"utf8\"), options);\n }\n if (typeof schema === \"string\") {\n return parseSchemaText(schema, options);\n }\n return parseSchemaObject(schema, options.absoluteRef);\n}\n"],"names":["text","loadFailedError","urlInvalidError","fileURLToPath","Source","parseJson","parseFailedError","makeDocumentFromString","pathStringError","aliasExpansionFailure","YamlParseError","ResolveError","sourceInvalidError","sourceEmptyError","Readable"],"mappings":";;;;;;;;;;;;;;AAoCA,eAAe,UAAA,CAAW,QAAkB,WAAA,EAAsC;AAChF,EAAA,IAAI;AACF,IAAA,OAAA,CAAQ,MAAMA,cAAA,CAAK,MAAM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AU,CAAA;AAAA,EAC/D;AACA,EAAA,IAAI,kBAAkB,MAAA,EAAQ;AAC5B,IAAA,OAAO,WAAA,CAAY,MAAA,CAAO,QAAA,CAAS,MAAM,GAAG,OAAO,CAAA;AAAA,EACrD;AACA,EAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC9B,IAAA,OAAO,eAAA,CAAgB,QAAQ,OAAO,CAAA;AAAA,EACxC;AACA,EAAA,OAAO,iBAAA,CAAkB,MAAA,EAAQ,OAAA,CAAQ,WAAW,CAAA;AACtD;;"}
|
|
@@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
4
4
|
import { YamlParseError, Source, ResolveError, makeDocumentFromString } from '@redocly/openapi-core';
|
|
5
5
|
import parseJson from 'parse-json';
|
|
6
6
|
import { aliasExpansionFailure } from './alias-limit.mjs';
|
|
7
|
-
import { sourceEmptyError, loadFailedError, sourceInvalidError, parseFailedError, pathStringError } from './schema-load-errors.mjs';
|
|
7
|
+
import { sourceEmptyError, loadFailedError, urlInvalidError, sourceInvalidError, parseFailedError, pathStringError } from './schema-load-errors.mjs';
|
|
8
8
|
|
|
9
9
|
async function readStream(stream, absoluteRef) {
|
|
10
10
|
try {
|
|
@@ -13,14 +13,17 @@ async function readStream(stream, absoluteRef) {
|
|
|
13
13
|
throw loadFailedError(absoluteRef, error);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
const
|
|
16
|
+
const URL_PREFIX_RE = /^(?:https?|file):\/\//i;
|
|
17
17
|
function parseSchemaText(schema, options) {
|
|
18
|
-
if (
|
|
19
|
-
const url =
|
|
18
|
+
if (URL_PREFIX_RE.test(schema)) {
|
|
19
|
+
const url = URL.parse(schema);
|
|
20
|
+
if (url === null) {
|
|
21
|
+
throw urlInvalidError(schema);
|
|
22
|
+
}
|
|
20
23
|
const absoluteRef = url.protocol === "file:" ? fileURLToPath(url) : url.href;
|
|
21
24
|
return parseSchema(url, { absoluteRef, resolver: options.resolver });
|
|
22
25
|
}
|
|
23
|
-
return schema[0] === "{" ? parseJsonText(schema, options.absoluteRef) : parseYamlText(schema, options.absoluteRef);
|
|
26
|
+
return schema[0] === "{" ? parseJsonText(schema, options.absoluteRef) : parseYamlText(schema, options.absoluteRef, options.textOrigin ?? "string");
|
|
24
27
|
}
|
|
25
28
|
function parseJsonText(text2, absoluteRef) {
|
|
26
29
|
try {
|
|
@@ -29,7 +32,7 @@ function parseJsonText(text2, absoluteRef) {
|
|
|
29
32
|
throw parseFailedError("json", absoluteRef, cause);
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
|
-
function parseYamlText(text2, absoluteRef) {
|
|
35
|
+
function parseYamlText(text2, absoluteRef, origin) {
|
|
33
36
|
let document;
|
|
34
37
|
try {
|
|
35
38
|
document = makeDocumentFromString(text2, absoluteRef);
|
|
@@ -37,7 +40,7 @@ function parseYamlText(text2, absoluteRef) {
|
|
|
37
40
|
throw parseFailedError("yaml", absoluteRef, cause);
|
|
38
41
|
}
|
|
39
42
|
if (typeof document.parsed === "string") {
|
|
40
|
-
throw pathStringError(text2);
|
|
43
|
+
throw pathStringError(text2, origin);
|
|
41
44
|
}
|
|
42
45
|
const failure = aliasExpansionFailure(document.parsed);
|
|
43
46
|
if (failure !== void 0) {
|
|
@@ -83,7 +86,8 @@ async function parseSchema(schema, options) {
|
|
|
83
86
|
return resolveSchemaURL(options);
|
|
84
87
|
}
|
|
85
88
|
if (schema instanceof Readable) {
|
|
86
|
-
|
|
89
|
+
const text2 = await readStream(schema, options.absoluteRef);
|
|
90
|
+
return parseSchema(text2, { ...options, textOrigin: "stream" });
|
|
87
91
|
}
|
|
88
92
|
if (schema instanceof Buffer) {
|
|
89
93
|
return parseSchema(schema.toString("utf8"), options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-source.mjs","sources":["../../../src/adapters/redocly-loader/schema-source.ts"],"sourcesContent":["import { Readable } from \"node:stream\";\nimport { text } from \"node:stream/consumers\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n type BaseResolver,\n type Document,\n makeDocumentFromString,\n ResolveError,\n Source,\n YamlParseError,\n} from \"@redocly/openapi-core\";\nimport parseJson from \"parse-json\";\nimport { aliasExpansionFailure } from \"./alias-limit.js\";\nimport {\n loadFailedError,\n parseFailedError,\n pathStringError,\n sourceEmptyError,\n sourceInvalidError,\n} from \"./schema-load-errors.js\";\n\n/** Parse a schema source of any supported type into a Redocly document (ENGINEERING_PLAN 4.5). */\n\nexport interface ParseSchemaOptions {\n absoluteRef: string;\n resolver: BaseResolver;\n}\n\n/**\n * Read a stream to the end as UTF-8 text, trimmed. A stream that fails rejects with\n * SCHEMA_LOAD_FAILED; listening only for `data` and `end` left the promise pending forever.\n */\nasync function readStream(stream: Readable, absoluteRef: string): Promise<string> {\n try {\n return (await text(stream)).trim();\n } catch (error) {\n throw loadFailedError(absoluteRef, error);\n }\n}\n\
|
|
1
|
+
{"version":3,"file":"schema-source.mjs","sources":["../../../src/adapters/redocly-loader/schema-source.ts"],"sourcesContent":["import { Readable } from \"node:stream\";\nimport { text } from \"node:stream/consumers\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n type BaseResolver,\n type Document,\n makeDocumentFromString,\n ResolveError,\n Source,\n YamlParseError,\n} from \"@redocly/openapi-core\";\nimport parseJson from \"parse-json\";\nimport { aliasExpansionFailure } from \"./alias-limit.js\";\nimport {\n loadFailedError,\n parseFailedError,\n pathStringError,\n sourceEmptyError,\n sourceInvalidError,\n type TextOrigin,\n urlInvalidError,\n} from \"./schema-load-errors.js\";\n\n/** Parse a schema source of any supported type into a Redocly document (ENGINEERING_PLAN 4.5). */\n\nexport interface ParseSchemaOptions {\n absoluteRef: string;\n resolver: BaseResolver;\n /** Where document text came from, for the message of text that is only a string. */\n textOrigin?: TextOrigin;\n}\n\n/**\n * Read a stream to the end as UTF-8 text, trimmed. A stream that fails rejects with\n * SCHEMA_LOAD_FAILED; listening only for `data` and `end` left the promise pending forever.\n */\nasync function readStream(stream: Readable, absoluteRef: string): Promise<string> {\n try {\n return (await text(stream)).trim();\n } catch (error) {\n throw loadFailedError(absoluteRef, error);\n }\n}\n\n/** A URL source string; a scheme is the same in any case (RFC 3986, section 3.1). */\nconst URL_PREFIX_RE = /^(?:https?|file):\\/\\//i;\n\n/**\n * A string is a URL, JSON (starts with `{`) or YAML. A string that starts like a URL but does not\n * parse as one fails with `SCHEMA_SOURCE_INVALID`, not the parser's `TypeError`.\n */\nfunction parseSchemaText(\n schema: string,\n options: ParseSchemaOptions,\n): Promise<Document> | Document {\n if (URL_PREFIX_RE.test(schema)) {\n const url = URL.parse(schema);\n if (url === null) {\n throw urlInvalidError(schema);\n }\n const absoluteRef = url.protocol === \"file:\" ? fileURLToPath(url) : url.href;\n return parseSchema(url, { absoluteRef, resolver: options.resolver });\n }\n return schema[0] === \"{\"\n ? parseJsonText(schema, options.absoluteRef)\n : parseYamlText(schema, options.absoluteRef, options.textOrigin ?? \"string\");\n}\n\nfunction parseJsonText(text: string, absoluteRef: string): Document {\n try {\n return { source: new Source(absoluteRef, text, \"application/json\"), parsed: parseJson(text) };\n } catch (cause) {\n throw parseFailedError(\"json\", absoluteRef, cause);\n }\n}\n\nfunction parseYamlText(text: string, absoluteRef: string, origin: TextOrigin): Document {\n let document: Document;\n try {\n document = makeDocumentFromString(text, absoluteRef);\n } catch (cause) {\n throw parseFailedError(\"yaml\", absoluteRef, cause);\n }\n // Text that is only a YAML string scalar, such as \"./openapi.yaml\", was meant as a file path.\n if (typeof document.parsed === \"string\") {\n throw pathStringError(text, origin);\n }\n const failure = aliasExpansionFailure(document.parsed);\n if (failure !== undefined) {\n throw parseFailedError(\"yaml\", absoluteRef, failure);\n }\n return document;\n}\n\n/** The resolver throws for some failures (a missing file) and returns an error for others. */\nasync function resolveSchemaURL(options: ParseSchemaOptions): Promise<Document> {\n const result = await options.resolver\n .resolveDocument(null, options.absoluteRef, true)\n .catch((cause: unknown) => {\n throw cause instanceof YamlParseError\n ? fileParseFailedError(options.absoluteRef, cause)\n : loadFailedError(options.absoluteRef, readerError(cause));\n });\n if (\"parsed\" in result) {\n return result;\n }\n throw loadFailedError(options.absoluteRef, readerError(result));\n}\n\n/**\n * Redocly wraps a failed read in `ResolveError`, which keeps the reader's error in\n * `originalError`, not in `cause`. Unwrapped, the cause keeps the network reason (refused, DNS).\n */\nfunction readerError(error: unknown): unknown {\n let current = error;\n while (current instanceof ResolveError) {\n current = current.originalError;\n }\n return current;\n}\n\n/**\n * The resolver parses JSON files with its YAML parser too, so the format comes from the file\n * name. Some parser messages (a second YAML document) do not name the file; the error adds it.\n */\nfunction fileParseFailedError(absoluteRef: string, error: YamlParseError): Error {\n const format = absoluteRef.toLowerCase().endsWith(\".json\") ? \"json\" : \"yaml\";\n const cause = error.message.includes(absoluteRef)\n ? error\n : new Error(`${error.message} in \"${absoluteRef}\"`, { cause: error });\n return parseFailedError(format, absoluteRef, cause);\n}\n\nfunction parseSchemaObject(schema: unknown, absoluteRef: string): Document {\n if (typeof schema === \"object\" && !Array.isArray(schema)) {\n return {\n source: new Source(absoluteRef, JSON.stringify(schema), \"application/json\"),\n parsed: schema,\n };\n }\n throw sourceInvalidError(schema);\n}\n\n/** Parse any supported source: URL, stream, buffer, URL or document text, or a plain object. */\nexport async function parseSchema(schema: unknown, options: ParseSchemaOptions): Promise<Document> {\n if (!schema) {\n throw sourceEmptyError(\"Can’t parse empty schema\");\n }\n if (schema instanceof URL) {\n return resolveSchemaURL(options);\n }\n if (schema instanceof Readable) {\n const text = await readStream(schema, options.absoluteRef);\n return parseSchema(text, { ...options, textOrigin: \"stream\" });\n }\n if (schema instanceof Buffer) {\n return parseSchema(schema.toString(\"utf8\"), options);\n }\n if (typeof schema === \"string\") {\n return parseSchemaText(schema, options);\n }\n return parseSchemaObject(schema, options.absoluteRef);\n}\n"],"names":["text"],"mappings":";;;;;;;;AAoCA,eAAe,UAAA,CAAW,QAAkB,WAAA,EAAsC;AAChF,EAAA,IAAI;AACF,IAAA,OAAA,CAAQ,MAAM,IAAA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ACA,EAAA,IAAI,kBAAkB,MAAA,EAAQ;AAC5B,IAAA,OAAO,WAAA,CAAY,MAAA,CAAO,QAAA,CAAS,MAAM,GAAG,OAAO,CAAA;AAAA,EACrD;AACA,EAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC9B,IAAA,OAAO,eAAA,CAAgB,QAAQ,OAAO,CAAA;AAAA,EACxC;AACA,EAAA,OAAO,iBAAA,CAAkB,MAAA,EAAQ,OAAA,CAAQ,WAAW,CAAA;AACtD;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const errors = require('../../domain/errors.cjs');
|
|
4
|
+
const jsonPointer = require('../../domain/openapi/json-pointer.cjs');
|
|
4
5
|
|
|
5
6
|
const UNSUPPORTED_KEYS = /* @__PURE__ */ new Set([
|
|
6
7
|
"hasOwnProperty",
|
|
@@ -22,9 +23,6 @@ function isUnsupportedEntry(key, value) {
|
|
|
22
23
|
return key === CONSTRUCTOR_KEY && typeof value === "object" && typeof name === "string";
|
|
23
24
|
}
|
|
24
25
|
const KEYS_IN_MESSAGE = 5;
|
|
25
|
-
function escapePointerSegment(segment) {
|
|
26
|
-
return segment.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
27
|
-
}
|
|
28
26
|
function unsupportedKeysOf(document) {
|
|
29
27
|
const found = [];
|
|
30
28
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
@@ -35,10 +33,10 @@ function unsupportedKeysOf(document) {
|
|
|
35
33
|
pending.push({ value, pointer });
|
|
36
34
|
}
|
|
37
35
|
};
|
|
38
|
-
enqueue(document.parsed,
|
|
36
|
+
enqueue(document.parsed, jsonPointer.ROOT_POINTER);
|
|
39
37
|
for (let node = pending.pop(); node !== void 0; node = pending.pop()) {
|
|
40
38
|
for (const [key, child] of Object.entries(node.value)) {
|
|
41
|
-
const pointer =
|
|
39
|
+
const pointer = jsonPointer.childPointer(node.pointer, key);
|
|
42
40
|
if (isUnsupportedEntry(key, child)) {
|
|
43
41
|
found.push({ key, pointer, source: document.source });
|
|
44
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unsupported-keys.cjs","sources":["../../../src/adapters/redocly-loader/unsupported-keys.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\n\n/**\n * Keys Redocly 1.34 cannot walk. It looks up the type of every key with `type.properties[key]`,\n * which also finds inherited `Object.prototype` members; it then calls a found function with no\n * `this`, and these methods throw a `TypeError` for that. Redocly 2.x looks up own keys only\n * (ADR-005 keeps 1.34). `toString` does not throw, and loads as it should.\n *\n * Redocly does not walk every value (`default` and `const` are data), so a document with such a\n * key is not rejected up front: the loader looks for them only after Redocly threw a `TypeError`.\n */\nexport const UNSUPPORTED_KEYS: ReadonlySet<string> = new Set([\n \"hasOwnProperty\",\n \"isPrototypeOf\",\n \"propertyIsEnumerable\",\n \"toLocaleString\",\n \"valueOf\",\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n]);\n\n/**\n * `constructor` finds `Object`, which returns the value it is called with. Redocly then takes the\n * value for a node type when it has a string `name` (a security scheme, a header with a `name`),\n * and fails reading the type's fields. Any other `constructor` key loads.\n */\nconst CONSTRUCTOR_KEY = \"constructor\";\n\nfunction isUnsupportedEntry(key: string, value: unknown): boolean {\n if (UNSUPPORTED_KEYS.has(key)) {\n return true;\n }\n const name = (value as { name?: unknown } | null | undefined)?.name;\n return key === CONSTRUCTOR_KEY && typeof value === \"object\" && typeof name === \"string\";\n}\n\n/** Enough found keys in the message to act on; `details.keys` has all of them. */\nconst KEYS_IN_MESSAGE = 5;\n\n/** A parsed document and where it was loaded from. */\nexport interface LoadedDocument {\n readonly source: string;\n readonly parsed: unknown;\n}\n\n/** An unsupported key: its JSON pointer and the document that has it. */\nexport interface UnsupportedKey {\n readonly key: string;\n readonly pointer: string;\n readonly source: string;\n}\n\ninterface PendingNode {\n readonly value: object;\n readonly pointer: string;\n}\n\n
|
|
1
|
+
{"version":3,"file":"unsupported-keys.cjs","sources":["../../../src/adapters/redocly-loader/unsupported-keys.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport { childPointer, ROOT_POINTER } from \"../../domain/openapi/json-pointer.js\";\n\n/**\n * Keys Redocly 1.34 cannot walk. It looks up the type of every key with `type.properties[key]`,\n * which also finds inherited `Object.prototype` members; it then calls a found function with no\n * `this`, and these methods throw a `TypeError` for that. Redocly 2.x looks up own keys only\n * (ADR-005 keeps 1.34). `toString` does not throw, and loads as it should.\n *\n * Redocly does not walk every value (`default` and `const` are data), so a document with such a\n * key is not rejected up front: the loader looks for them only after Redocly threw a `TypeError`.\n */\nexport const UNSUPPORTED_KEYS: ReadonlySet<string> = new Set([\n \"hasOwnProperty\",\n \"isPrototypeOf\",\n \"propertyIsEnumerable\",\n \"toLocaleString\",\n \"valueOf\",\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n]);\n\n/**\n * `constructor` finds `Object`, which returns the value it is called with. Redocly then takes the\n * value for a node type when it has a string `name` (a security scheme, a header with a `name`),\n * and fails reading the type's fields. Any other `constructor` key loads.\n */\nconst CONSTRUCTOR_KEY = \"constructor\";\n\nfunction isUnsupportedEntry(key: string, value: unknown): boolean {\n if (UNSUPPORTED_KEYS.has(key)) {\n return true;\n }\n const name = (value as { name?: unknown } | null | undefined)?.name;\n return key === CONSTRUCTOR_KEY && typeof value === \"object\" && typeof name === \"string\";\n}\n\n/** Enough found keys in the message to act on; `details.keys` has all of them. */\nconst KEYS_IN_MESSAGE = 5;\n\n/** A parsed document and where it was loaded from. */\nexport interface LoadedDocument {\n readonly source: string;\n readonly parsed: unknown;\n}\n\n/** An unsupported key: its JSON pointer and the document that has it. */\nexport interface UnsupportedKey {\n readonly key: string;\n readonly pointer: string;\n readonly source: string;\n}\n\ninterface PendingNode {\n readonly value: object;\n readonly pointer: string;\n}\n\n/**\n * The unsupported keys of one parsed document. The walk uses its own stack, so a deeply nested\n * document is checked without running out of call stack; nodes shared by YAML aliases are checked\n * once.\n */\nfunction unsupportedKeysOf(document: LoadedDocument): UnsupportedKey[] {\n const found: UnsupportedKey[] = [];\n const visited = new WeakSet<object>();\n const pending: PendingNode[] = [];\n const enqueue = (value: unknown, pointer: string): void => {\n if (typeof value === \"object\" && value !== null && !visited.has(value)) {\n visited.add(value);\n pending.push({ value, pointer });\n }\n };\n enqueue(document.parsed, ROOT_POINTER);\n for (let node = pending.pop(); node !== undefined; node = pending.pop()) {\n for (const [key, child] of Object.entries(node.value)) {\n const pointer = childPointer(node.pointer, key);\n if (isUnsupportedEntry(key, child)) {\n found.push({ key, pointer, source: document.source });\n }\n enqueue(child, pointer);\n }\n }\n return found;\n}\n\n/** Every unsupported key of the given documents. */\nexport function findUnsupportedKeys(documents: readonly LoadedDocument[]): UnsupportedKey[] {\n return documents.flatMap(unsupportedKeysOf);\n}\n\nfunction describeKey(found: UnsupportedKey): string {\n return `\"${found.key}\" at ${found.pointer} in ${found.source}`;\n}\n\n/** The typed error for the keys the schema loader failed on; `cause` is Redocly's `TypeError`. */\nexport function unsupportedKeysError(\n keys: readonly UnsupportedKey[],\n cause: unknown,\n): OpenAPITypesafeError {\n const listed = keys.slice(0, KEYS_IN_MESSAGE).map(describeKey);\n const more = keys.length > KEYS_IN_MESSAGE ? ` and ${keys.length - KEYS_IN_MESSAGE} more` : \"\";\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_KEY_UNSUPPORTED,\n message:\n \"The schema loader (Redocly 1.x) failed on a key named like a built-in object method. \" +\n `Rename it: ${listed.join(\", \")}${more}.`,\n details: { keys: keys.map((found) => ({ ...found })) },\n cause,\n });\n}\n"],"names":["ROOT_POINTER","childPointer","OpenAPITypesafeError","ERROR_CODES"],"mappings":";;;;;AAYO,MAAM,gBAAA,uBAA4C,GAAA,CAAI;AAAA,EAC3D,gBAAA;AAAA,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|
1
1
|
import { OpenAPITypesafeError, ERROR_CODES } from '../../domain/errors.mjs';
|
|
2
|
+
import { childPointer, ROOT_POINTER } from '../../domain/openapi/json-pointer.mjs';
|
|
2
3
|
|
|
3
4
|
const UNSUPPORTED_KEYS = /* @__PURE__ */ new Set([
|
|
4
5
|
"hasOwnProperty",
|
|
@@ -20,9 +21,6 @@ function isUnsupportedEntry(key, value) {
|
|
|
20
21
|
return key === CONSTRUCTOR_KEY && typeof value === "object" && typeof name === "string";
|
|
21
22
|
}
|
|
22
23
|
const KEYS_IN_MESSAGE = 5;
|
|
23
|
-
function escapePointerSegment(segment) {
|
|
24
|
-
return segment.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
25
|
-
}
|
|
26
24
|
function unsupportedKeysOf(document) {
|
|
27
25
|
const found = [];
|
|
28
26
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
@@ -33,10 +31,10 @@ function unsupportedKeysOf(document) {
|
|
|
33
31
|
pending.push({ value, pointer });
|
|
34
32
|
}
|
|
35
33
|
};
|
|
36
|
-
enqueue(document.parsed,
|
|
34
|
+
enqueue(document.parsed, ROOT_POINTER);
|
|
37
35
|
for (let node = pending.pop(); node !== void 0; node = pending.pop()) {
|
|
38
36
|
for (const [key, child] of Object.entries(node.value)) {
|
|
39
|
-
const pointer =
|
|
37
|
+
const pointer = childPointer(node.pointer, key);
|
|
40
38
|
if (isUnsupportedEntry(key, child)) {
|
|
41
39
|
found.push({ key, pointer, source: document.source });
|
|
42
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unsupported-keys.mjs","sources":["../../../src/adapters/redocly-loader/unsupported-keys.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\n\n/**\n * Keys Redocly 1.34 cannot walk. It looks up the type of every key with `type.properties[key]`,\n * which also finds inherited `Object.prototype` members; it then calls a found function with no\n * `this`, and these methods throw a `TypeError` for that. Redocly 2.x looks up own keys only\n * (ADR-005 keeps 1.34). `toString` does not throw, and loads as it should.\n *\n * Redocly does not walk every value (`default` and `const` are data), so a document with such a\n * key is not rejected up front: the loader looks for them only after Redocly threw a `TypeError`.\n */\nexport const UNSUPPORTED_KEYS: ReadonlySet<string> = new Set([\n \"hasOwnProperty\",\n \"isPrototypeOf\",\n \"propertyIsEnumerable\",\n \"toLocaleString\",\n \"valueOf\",\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n]);\n\n/**\n * `constructor` finds `Object`, which returns the value it is called with. Redocly then takes the\n * value for a node type when it has a string `name` (a security scheme, a header with a `name`),\n * and fails reading the type's fields. Any other `constructor` key loads.\n */\nconst CONSTRUCTOR_KEY = \"constructor\";\n\nfunction isUnsupportedEntry(key: string, value: unknown): boolean {\n if (UNSUPPORTED_KEYS.has(key)) {\n return true;\n }\n const name = (value as { name?: unknown } | null | undefined)?.name;\n return key === CONSTRUCTOR_KEY && typeof value === \"object\" && typeof name === \"string\";\n}\n\n/** Enough found keys in the message to act on; `details.keys` has all of them. */\nconst KEYS_IN_MESSAGE = 5;\n\n/** A parsed document and where it was loaded from. */\nexport interface LoadedDocument {\n readonly source: string;\n readonly parsed: unknown;\n}\n\n/** An unsupported key: its JSON pointer and the document that has it. */\nexport interface UnsupportedKey {\n readonly key: string;\n readonly pointer: string;\n readonly source: string;\n}\n\ninterface PendingNode {\n readonly value: object;\n readonly pointer: string;\n}\n\n
|
|
1
|
+
{"version":3,"file":"unsupported-keys.mjs","sources":["../../../src/adapters/redocly-loader/unsupported-keys.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport { childPointer, ROOT_POINTER } from \"../../domain/openapi/json-pointer.js\";\n\n/**\n * Keys Redocly 1.34 cannot walk. It looks up the type of every key with `type.properties[key]`,\n * which also finds inherited `Object.prototype` members; it then calls a found function with no\n * `this`, and these methods throw a `TypeError` for that. Redocly 2.x looks up own keys only\n * (ADR-005 keeps 1.34). `toString` does not throw, and loads as it should.\n *\n * Redocly does not walk every value (`default` and `const` are data), so a document with such a\n * key is not rejected up front: the loader looks for them only after Redocly threw a `TypeError`.\n */\nexport const UNSUPPORTED_KEYS: ReadonlySet<string> = new Set([\n \"hasOwnProperty\",\n \"isPrototypeOf\",\n \"propertyIsEnumerable\",\n \"toLocaleString\",\n \"valueOf\",\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n]);\n\n/**\n * `constructor` finds `Object`, which returns the value it is called with. Redocly then takes the\n * value for a node type when it has a string `name` (a security scheme, a header with a `name`),\n * and fails reading the type's fields. Any other `constructor` key loads.\n */\nconst CONSTRUCTOR_KEY = \"constructor\";\n\nfunction isUnsupportedEntry(key: string, value: unknown): boolean {\n if (UNSUPPORTED_KEYS.has(key)) {\n return true;\n }\n const name = (value as { name?: unknown } | null | undefined)?.name;\n return key === CONSTRUCTOR_KEY && typeof value === \"object\" && typeof name === \"string\";\n}\n\n/** Enough found keys in the message to act on; `details.keys` has all of them. */\nconst KEYS_IN_MESSAGE = 5;\n\n/** A parsed document and where it was loaded from. */\nexport interface LoadedDocument {\n readonly source: string;\n readonly parsed: unknown;\n}\n\n/** An unsupported key: its JSON pointer and the document that has it. */\nexport interface UnsupportedKey {\n readonly key: string;\n readonly pointer: string;\n readonly source: string;\n}\n\ninterface PendingNode {\n readonly value: object;\n readonly pointer: string;\n}\n\n/**\n * The unsupported keys of one parsed document. The walk uses its own stack, so a deeply nested\n * document is checked without running out of call stack; nodes shared by YAML aliases are checked\n * once.\n */\nfunction unsupportedKeysOf(document: LoadedDocument): UnsupportedKey[] {\n const found: UnsupportedKey[] = [];\n const visited = new WeakSet<object>();\n const pending: PendingNode[] = [];\n const enqueue = (value: unknown, pointer: string): void => {\n if (typeof value === \"object\" && value !== null && !visited.has(value)) {\n visited.add(value);\n pending.push({ value, pointer });\n }\n };\n enqueue(document.parsed, ROOT_POINTER);\n for (let node = pending.pop(); node !== undefined; node = pending.pop()) {\n for (const [key, child] of Object.entries(node.value)) {\n const pointer = childPointer(node.pointer, key);\n if (isUnsupportedEntry(key, child)) {\n found.push({ key, pointer, source: document.source });\n }\n enqueue(child, pointer);\n }\n }\n return found;\n}\n\n/** Every unsupported key of the given documents. */\nexport function findUnsupportedKeys(documents: readonly LoadedDocument[]): UnsupportedKey[] {\n return documents.flatMap(unsupportedKeysOf);\n}\n\nfunction describeKey(found: UnsupportedKey): string {\n return `\"${found.key}\" at ${found.pointer} in ${found.source}`;\n}\n\n/** The typed error for the keys the schema loader failed on; `cause` is Redocly's `TypeError`. */\nexport function unsupportedKeysError(\n keys: readonly UnsupportedKey[],\n cause: unknown,\n): OpenAPITypesafeError {\n const listed = keys.slice(0, KEYS_IN_MESSAGE).map(describeKey);\n const more = keys.length > KEYS_IN_MESSAGE ? ` and ${keys.length - KEYS_IN_MESSAGE} more` : \"\";\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_KEY_UNSUPPORTED,\n message:\n \"The schema loader (Redocly 1.x) failed on a key named like a built-in object method. \" +\n `Rename it: ${listed.join(\", \")}${more}.`,\n details: { keys: keys.map((found) => ({ ...found })) },\n cause,\n });\n}\n"],"names":[],"mappings":";;;AAYO,MAAM,gBAAA,uBAA4C,GAAA,CAAI;AAAA,EAC3D,gBAAA;AAAA,EACA,eAAA;AAAA,EACA,sBAAA;AAAA,EACA,gBAAA;AAAA,EACA,SAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAC;AAOD,MAAM,eAAA,GAAkB,aAAA;AAExB,SAAS,kBAAA,CAAmB,KAAa,KAAA,EAAyB;AAChE,EAAA,IAAI,gBAAA,CAAiB,GAAA,CAAI,GAAG,CAAA,EAAG;AAC7B,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,OAAQ,KAAA,EAAiD,IAAA;AAC/D,EAAA,OAAO,QAAQ,eAAA,IAAmB,OAAO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U,QAAQ,iBAAiB,CAAA;AAC5C;AAEA,SAAS,YAAY,KAAA,EAA+B;AAClD,EAAA,OAAO,CAAA,CAAA,EAAI,MAAM,GAAG,CAAA,KAAA,EAAQ,MAAM,OAAO,CAAA,IAAA,EAAO,MAAM,MAAM,CAAA,CAAA;AAC9D;AAGO,SAAS,oBAAA,CACd,MACA,KAAA,EACsB;AACtB,EAAA,MAAM,SAAS,IAAA,CAAK,KAAA,CAAM,GAAG,eAAe,CAAA,CAAE,IAAI,WAAW,CAAA;AAC7D,EAAA,MAAM,IAAA,GAAO,KAAK,MAAA,GAAS,eAAA,GAAkB,QAAQ,IAAA,CAAK,MAAA,GAAS,eAAe,CAAA,KAAA,CAAA,GAAU,EAAA;AAC5F,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9B,MAAM,WAAA,CAAY,sBAAA;AAAA,IAClB,SACE,CAAA,gGAAA,EACc,MAAA,CAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAA,CAAA,CAAA;AAAA,IACxC,OAAA,EAAS,EAAE,IAAA,EAAM,IAAA,CAAK,GAAA,CAAI,CAAC,KAAA,MAAW,EAAE,GAAG,KAAA,EAAM,CAAE,CAAA,EAAE;AAAA,IACrD;AAAA,GACD,CAAA;AACH;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const colors = require('ansi-colors');
|
|
4
|
-
const
|
|
4
|
+
const urlSecrets = require('../../domain/url-secrets.cjs');
|
|
5
5
|
|
|
6
6
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
7
7
|
|
|
@@ -47,16 +47,18 @@ class TerminalLogger {
|
|
|
47
47
|
}
|
|
48
48
|
const name = groupColor(this.#palette, group)(`openapi-ts:${group ?? "info"}`);
|
|
49
49
|
const time = durationMs === void 0 ? " " : this.#palette.green(` ${formatDuration(durationMs)} `);
|
|
50
|
-
const text =
|
|
50
|
+
const text = urlSecrets.redactUrlSecrets(message);
|
|
51
51
|
this.#options.sink.debug(` ${this.#palette.bold(name)}${time}${text}`);
|
|
52
52
|
}
|
|
53
53
|
warn(message) {
|
|
54
54
|
if (!this.#options.silent) {
|
|
55
|
-
this.#options.sink.warn(this.#palette.yellow(` \u26A0 ${
|
|
55
|
+
this.#options.sink.warn(this.#palette.yellow(` \u26A0 ${urlSecrets.redactUrlSecrets(message)}`));
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
error(message) {
|
|
59
|
-
this.#options.
|
|
59
|
+
if (!this.#options.silent) {
|
|
60
|
+
this.#options.sink.error(this.#palette.red(` \u2718 ${urlSecrets.redactUrlSecrets(message)}`));
|
|
61
|
+
}
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
function createTerminalLogger(options) {
|