openapi-typesafe 1.0.0-rc.4 → 1.0.0-rc.6
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 +214 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +7 -0
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +7 -0
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs +19 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs.map +1 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs +17 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +5 -32
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +6 -33
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -1
- package/dist/adapters/redocly-loader/component-schemas.cjs +17 -0
- package/dist/adapters/redocly-loader/component-schemas.cjs.map +1 -0
- package/dist/adapters/redocly-loader/component-schemas.mjs +14 -0
- package/dist/adapters/redocly-loader/component-schemas.mjs.map +1 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.cjs +22 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.cjs.map +1 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.mjs +20 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.mjs.map +1 -0
- package/dist/adapters/redocly-loader/query-document-names.cjs +50 -0
- package/dist/adapters/redocly-loader/query-document-names.cjs.map +1 -0
- package/dist/adapters/redocly-loader/query-document-names.mjs +48 -0
- package/dist/adapters/redocly-loader/query-document-names.mjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs +129 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs +126 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-config-source.cjs +3 -0
- package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-config-source.mjs +4 -1
- package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +39 -18
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +40 -19
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +25 -4
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +26 -5
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.cjs +52 -10
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.mjs +52 -11
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.cjs +20 -3
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +20 -4
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +17 -3
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +17 -3
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +7 -2
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +8 -3
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +7 -3
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +7 -3
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/cwd-option.cjs +58 -0
- package/dist/api/cwd-option.cjs.map +1 -0
- package/dist/api/cwd-option.mjs +52 -0
- package/dist/api/cwd-option.mjs.map +1 -0
- package/dist/api/default-ports.cjs +15 -7
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +14 -8
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/document-refs.cjs +16 -1
- package/dist/api/document-refs.cjs.map +1 -1
- package/dist/api/document-refs.mjs +16 -1
- package/dist/api/document-refs.mjs.map +1 -1
- package/dist/api/document-run.cjs +6 -26
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +5 -21
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-utils.cjs +1 -1
- package/dist/api/legacy-utils.cjs.map +1 -1
- package/dist/api/legacy-utils.mjs +1 -1
- package/dist/api/legacy-utils.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +1 -2
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +2 -3
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/option-errors.cjs +24 -0
- package/dist/api/option-errors.cjs.map +1 -0
- package/dist/api/option-errors.mjs +21 -0
- package/dist/api/option-errors.mjs.map +1 -0
- package/dist/api/ref-limit-options.cjs +58 -0
- package/dist/api/ref-limit-options.cjs.map +1 -0
- package/dist/api/ref-limit-options.mjs +52 -0
- package/dist/api/ref-limit-options.mjs.map +1 -0
- package/dist/api/transform-schema.cjs +12 -5
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +12 -5
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/transform/declared-value-types.cjs +36 -0
- package/dist/application/transform/declared-value-types.cjs.map +1 -0
- package/dist/application/transform/declared-value-types.mjs +34 -0
- package/dist/application/transform/declared-value-types.mjs.map +1 -0
- package/dist/application/transform/document/document.cjs +3 -1
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +3 -1
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/exploded-query-values.cjs +63 -0
- package/dist/application/transform/document/exploded-query-values.cjs.map +1 -0
- package/dist/application/transform/document/exploded-query-values.mjs +59 -0
- package/dist/application/transform/document/exploded-query-values.mjs.map +1 -0
- package/dist/application/transform/document/header.cjs +11 -3
- package/dist/application/transform/document/header.cjs.map +1 -1
- package/dist/application/transform/document/header.mjs +10 -2
- package/dist/application/transform/document/header.mjs.map +1 -1
- package/dist/application/transform/document/parameter.cjs +1 -1
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +1 -1
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +23 -5
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +23 -5
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +4 -3
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +4 -4
- package/dist/application/transform/document/path-item.mjs.map +1 -1
- package/dist/application/transform/document/path-template-key.cjs +84 -0
- package/dist/application/transform/document/path-template-key.cjs.map +1 -0
- package/dist/application/transform/document/path-template-key.mjs +79 -0
- package/dist/application/transform/document/path-template-key.mjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.cjs +80 -0
- package/dist/application/transform/document/path-template-refs.cjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.mjs +77 -0
- package/dist/application/transform/document/path-template-refs.mjs.map +1 -0
- package/dist/application/transform/document/paths-enum.cjs +7 -6
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +7 -6
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +38 -66
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +36 -66
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/webhooks.cjs +10 -3
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +9 -2
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +6 -3
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +6 -3
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/helper-types.cjs +3 -3
- package/dist/application/transform/helper-types.cjs.map +1 -1
- package/dist/application/transform/helper-types.mjs +3 -3
- package/dist/application/transform/helper-types.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +4 -4
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.cjs +63 -64
- package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.mjs +57 -53
- package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.cjs +2 -2
- package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.mjs +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/located-node.cjs +23 -0
- package/dist/application/transform/ref-pointer/located-node.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/located-node.mjs +18 -0
- package/dist/application/transform/ref-pointer/located-node.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/original-index.cjs +69 -14
- package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/original-index.mjs +71 -16
- package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs +2 -2
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-walk.cjs +54 -13
- package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-walk.mjs +46 -7
- package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/property-shape.cjs +57 -0
- package/dist/application/transform/ref-pointer/property-shape.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs +49 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/typed-walk.cjs +90 -22
- package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/typed-walk.mjs +87 -19
- package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/index-signature-type.cjs +21 -0
- package/dist/application/transform/schema/index-signature-type.cjs.map +1 -0
- package/dist/application/transform/schema/index-signature-type.mjs +19 -0
- package/dist/application/transform/schema/index-signature-type.mjs.map +1 -0
- package/dist/application/transform/schema/input-location.cjs +23 -0
- package/dist/application/transform/schema/input-location.cjs.map +1 -0
- package/dist/application/transform/schema/input-location.mjs +21 -0
- package/dist/application/transform/schema/input-location.mjs.map +1 -0
- package/dist/application/transform/schema/object-type.cjs +15 -5
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +15 -5
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.cjs +2 -1
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +2 -1
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs +2 -30
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.mjs +3 -31
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
- package/dist/cli/api-logger.cjs +13 -0
- package/dist/cli/api-logger.cjs.map +1 -0
- package/dist/cli/api-logger.mjs +11 -0
- package/dist/cli/api-logger.mjs.map +1 -0
- package/dist/cli/api-settings.cjs +10 -17
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +10 -17
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +7 -1
- package/dist/cli/api-writes.cjs.map +1 -1
- package/dist/cli/api-writes.mjs +7 -1
- package/dist/cli/api-writes.mjs.map +1 -1
- package/dist/cli/cli-arguments.cjs +32 -74
- package/dist/cli/cli-arguments.cjs.map +1 -1
- package/dist/cli/cli-arguments.mjs +28 -70
- package/dist/cli/cli-arguments.mjs.map +1 -1
- package/dist/cli/cli-errors.cjs +18 -0
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +18 -1
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-flag-names.cjs +77 -0
- package/dist/cli/cli-flag-names.cjs.map +1 -0
- package/dist/cli/cli-flag-names.mjs +64 -0
- package/dist/cli/cli-flag-names.mjs.map +1 -0
- package/dist/cli/cli-output.cjs +13 -6
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +14 -7
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +11 -5
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +11 -5
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +33 -12
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +35 -14
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/ref-limits.cjs +15 -1
- package/dist/cli/ref-limits.cjs.map +1 -1
- package/dist/cli/ref-limits.mjs +15 -2
- package/dist/cli/ref-limits.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +24 -7
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +25 -8
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/cli/written-flags.cjs +83 -0
- package/dist/cli/written-flags.cjs.map +1 -0
- package/dist/cli/written-flags.mjs +77 -0
- package/dist/cli/written-flags.mjs.map +1 -0
- package/dist/domain/cause-secrets.cjs +31 -16
- package/dist/domain/cause-secrets.cjs.map +1 -1
- package/dist/domain/cause-secrets.mjs +31 -16
- package/dist/domain/cause-secrets.mjs.map +1 -1
- package/dist/domain/errors.cjs +3 -0
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +3 -0
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/location-text.cjs +15 -0
- package/dist/domain/location-text.cjs.map +1 -0
- package/dist/domain/location-text.mjs +13 -0
- package/dist/domain/location-text.mjs.map +1 -0
- package/dist/domain/openapi/document-places.cjs +55 -0
- package/dist/domain/openapi/document-places.cjs.map +1 -0
- package/dist/domain/openapi/document-places.mjs +53 -0
- package/dist/domain/openapi/document-places.mjs.map +1 -0
- package/dist/domain/output-fixes.cjs +8 -2
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +8 -2
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/terminal-text.cjs +31 -0
- package/dist/domain/terminal-text.cjs.map +1 -0
- package/dist/domain/terminal-text.mjs +29 -0
- package/dist/domain/terminal-text.mjs.map +1 -0
- package/dist/domain/warnings.cjs +1 -0
- package/dist/domain/warnings.cjs.map +1 -1
- package/dist/domain/warnings.mjs +1 -0
- package/dist/domain/warnings.mjs.map +1 -1
- package/dist/index.d.cts +29 -18
- package/dist/index.d.mts +29 -18
- package/dist/index.d.ts +29 -18
- package/package.json +1 -1
- package/src/adapters/node-file-system/node-file-system.ts +14 -1
- package/src/adapters/pipe-safe-writer/pipe-safe-writer.ts +29 -0
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +7 -42
- package/src/adapters/redocly-loader/component-schemas.ts +19 -0
- package/src/adapters/redocly-loader/mapping-schema-names.ts +25 -0
- package/src/adapters/redocly-loader/query-document-names.ts +79 -0
- package/src/adapters/redocly-loader/query-named-components.ts +200 -0
- package/src/adapters/redocly-loader/redocly-config-source.ts +11 -1
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +63 -17
- package/src/adapters/redocly-loader/ref-access.ts +32 -5
- package/src/adapters/redocly-loader/ref-holders.ts +75 -14
- package/src/adapters/redocly-loader/remote-fetch.ts +37 -2
- package/src/adapters/redocly-loader/remote-node-limit.ts +44 -4
- package/src/adapters/redocly-loader/schema-source.ts +15 -3
- package/src/adapters/terminal-logger/terminal-logger.ts +10 -4
- package/src/api/cwd-option.ts +76 -0
- package/src/api/default-ports.ts +33 -10
- package/src/api/document-refs.ts +29 -1
- package/src/api/document-run.ts +7 -32
- package/src/api/legacy-utils.ts +1 -1
- package/src/api/openapi-ts.ts +20 -4
- package/src/api/option-errors.ts +22 -0
- package/src/api/ref-limit-options.ts +69 -0
- package/src/api/transform-schema.ts +20 -5
- package/src/application/ports/file-system.ts +8 -0
- package/src/application/ports/redocly-config-source.ts +5 -0
- package/src/application/transform/declared-value-types.ts +42 -0
- package/src/application/transform/document/document.ts +4 -2
- package/src/application/transform/document/exploded-query-values.ts +88 -0
- package/src/application/transform/document/header.ts +25 -5
- package/src/application/transform/document/parameter.ts +4 -4
- package/src/application/transform/document/parameters.ts +45 -10
- package/src/application/transform/document/path-item.ts +3 -3
- package/src/application/transform/document/path-template-key.ts +152 -0
- package/src/application/transform/document/path-template-refs.ts +127 -0
- package/src/application/transform/document/paths-enum.ts +23 -9
- package/src/application/transform/document/paths.ts +53 -123
- package/src/application/transform/document/webhooks.ts +18 -5
- package/src/application/transform/footer/document-footer.ts +18 -8
- package/src/application/transform/helper-types.ts +4 -4
- package/src/application/transform/ref-pointer/generated-location.ts +1 -1
- package/src/application/transform/ref-pointer/generated-shape.ts +115 -83
- package/src/application/transform/ref-pointer/inline-cycles.ts +1 -1
- package/src/application/transform/ref-pointer/located-node.ts +38 -0
- package/src/application/transform/ref-pointer/original-index.ts +106 -20
- package/src/application/transform/ref-pointer/pointer-type.ts +1 -1
- package/src/application/transform/ref-pointer/pointer-walk.ts +82 -8
- package/src/application/transform/ref-pointer/property-shape.ts +106 -0
- package/src/application/transform/ref-pointer/typed-walk.ts +143 -29
- package/src/application/transform/schema/access-flags.ts +5 -2
- package/src/application/transform/schema/index-signature-type.ts +31 -0
- package/src/application/transform/schema/input-location.ts +35 -0
- package/src/application/transform/schema/object-type.ts +18 -8
- package/src/application/transform/schema/schema-transform.ts +2 -1
- package/src/application/transform/schema/unevaluated-properties.ts +4 -44
- package/src/cli/api-logger.ts +17 -0
- package/src/cli/api-settings.ts +12 -20
- package/src/cli/api-writes.ts +11 -3
- package/src/cli/cli-arguments.ts +57 -92
- package/src/cli/cli-dependencies.ts +7 -2
- package/src/cli/cli-errors.ts +23 -0
- package/src/cli/cli-flag-names.ts +99 -0
- package/src/cli/cli-output.ts +31 -16
- package/src/cli/main.ts +12 -5
- package/src/cli/redocly-apis.ts +56 -20
- package/src/cli/ref-limits.ts +21 -2
- package/src/cli/run-cli.ts +39 -7
- package/src/cli/written-flags.ts +131 -0
- package/src/domain/cause-secrets.ts +59 -25
- package/src/domain/errors.ts +3 -0
- package/src/domain/location-text.ts +27 -0
- package/src/domain/openapi/document-places.ts +78 -0
- package/src/domain/output-fixes.ts +9 -2
- package/src/domain/terminal-text.ts +44 -0
- package/src/domain/warnings.ts +1 -0
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,22 @@ import { Config } from '@redocly/openapi-core';
|
|
|
4
4
|
import * as TypeScript from 'typescript';
|
|
5
5
|
import colors from 'ansi-colors';
|
|
6
6
|
|
|
7
|
+
/** The debug groups of the original `DEBUG=openapi-ts:<group>` output. */
|
|
8
|
+
type DebugGroup = "redoc" | "lint" | "bundle" | "ts";
|
|
9
|
+
/**
|
|
10
|
+
* Where the generator reports progress and problems (ENGINEERING_PLAN 4.5). Whether warnings are
|
|
11
|
+
* printed (`silent`) and debug output (`DEBUG`) is decided by the adapter, when it is created.
|
|
12
|
+
*/
|
|
13
|
+
interface Logger {
|
|
14
|
+
/**
|
|
15
|
+
* A debug line, with how long the step took when it was measured. A line without a group is
|
|
16
|
+
* written whenever debug output is on.
|
|
17
|
+
*/
|
|
18
|
+
debug(message: string, group?: DebugGroup, durationMs?: number): void;
|
|
19
|
+
warn(message: string): void;
|
|
20
|
+
error(message: string): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
7
23
|
/**
|
|
8
24
|
* Type IR: the closed set of immutable nodes that describes the TypeScript types and declarations
|
|
9
25
|
* the generator emits (ENGINEERING_PLAN §4.2, ADR-002). Nodes are plain readonly data with a `kind`
|
|
@@ -268,6 +284,11 @@ declare const FIX: {
|
|
|
268
284
|
readonly ARRAY_LENGTH_TUPLES: "array-length-tuples";
|
|
269
285
|
/** `--dedupe-enums` names a shared enum by all of its schemas, not by the first one. */
|
|
270
286
|
readonly DEDUPE_ENUM_NAMES: "dedupe-enum-names";
|
|
287
|
+
/**
|
|
288
|
+
* `--default-non-nullable` finds parameters and request bodies by the document's structure, not
|
|
289
|
+
* by the words `parameters` and `requestBody` anywhere in a schema's location.
|
|
290
|
+
*/
|
|
291
|
+
readonly DEFAULT_INPUT_LOCATIONS: "default-input-locations";
|
|
271
292
|
/** `required` next to an `allOf` `$ref` to a discriminator member still gives `WithRequired`. */
|
|
272
293
|
readonly DISCRIMINATOR_MEMBER_REQUIRED: "discriminator-member-required";
|
|
273
294
|
/**
|
|
@@ -280,8 +301,8 @@ declare const FIX: {
|
|
|
280
301
|
readonly EXPLODED_QUERY_OBJECTS: "exploded-query-objects";
|
|
281
302
|
/** `--enum` declares an enum that lists `null` without it, and the type adds `| null`. */
|
|
282
303
|
readonly NULLABLE_ENUMS: "nullable-enums";
|
|
283
|
-
/** A parameter with `content
|
|
284
|
-
readonly
|
|
304
|
+
/** A parameter or header with `content`, not `schema`, is typed by its media type's schema. */
|
|
305
|
+
readonly PARAMETER_HEADER_CONTENT: "parameter-header-content";
|
|
285
306
|
/** `--path-params-as-types` gives each `{name}` its placeholder, `{number}` included. */
|
|
286
307
|
readonly PATH_PARAM_TYPE_NAMES: "path-param-type-names";
|
|
287
308
|
/** A `prefixItems` tuple is open unless `items` or `unevaluatedItems` closes it (2020-12). */
|
|
@@ -1474,22 +1495,6 @@ declare const DEPRECATION_CODES: {
|
|
|
1474
1495
|
};
|
|
1475
1496
|
type DeprecationCode = (typeof DEPRECATION_CODES)[keyof typeof DEPRECATION_CODES];
|
|
1476
1497
|
|
|
1477
|
-
/** The debug groups of the original `DEBUG=openapi-ts:<group>` output. */
|
|
1478
|
-
type DebugGroup = "redoc" | "lint" | "bundle" | "ts";
|
|
1479
|
-
/**
|
|
1480
|
-
* Where the generator reports progress and problems (ENGINEERING_PLAN 4.5). Whether warnings are
|
|
1481
|
-
* printed (`silent`) and debug output (`DEBUG`) is decided by the adapter, when it is created.
|
|
1482
|
-
*/
|
|
1483
|
-
interface Logger {
|
|
1484
|
-
/**
|
|
1485
|
-
* A debug line, with how long the step took when it was measured. A line without a group is
|
|
1486
|
-
* written whenever debug output is on.
|
|
1487
|
-
*/
|
|
1488
|
-
debug(message: string, group?: DebugGroup, durationMs?: number): void;
|
|
1489
|
-
warn(message: string): void;
|
|
1490
|
-
error(message: string): void;
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
1498
|
/**
|
|
1494
1499
|
* Convert an OpenAPI schema to TypeScript declarations (IR nodes; print them with `astToString`)
|
|
1495
1500
|
* @param {string|URL|object|Readable} source OpenAPI schema source:
|
|
@@ -1498,6 +1503,8 @@ interface Logger {
|
|
|
1498
1503
|
* - URL: URL to a YAML or JSON file (local or remote)
|
|
1499
1504
|
* - Readable: Readable stream of YAML or JSON
|
|
1500
1505
|
*/
|
|
1506
|
+
declare function openapiTS(source: SchemaSource, options?: OpenAPITSOptions): Promise<IrDeclaration[]>;
|
|
1507
|
+
/** Convert an OpenAPI schema to IR declarations, with either form of the options. */
|
|
1501
1508
|
declare function openapiTS(source: SchemaSource, options?: GeneratorOptions): Promise<IrDeclaration[]>;
|
|
1502
1509
|
|
|
1503
1510
|
/**
|
|
@@ -1526,14 +1533,17 @@ declare const ERROR_CODES: {
|
|
|
1526
1533
|
readonly ENUM_NAME_EMPTY: "ENUM_NAME_EMPTY";
|
|
1527
1534
|
readonly CALLBACK_RESULT_UNREADABLE: "CALLBACK_RESULT_UNREADABLE";
|
|
1528
1535
|
readonly OPTION_FIX_UNKNOWN: "OPTION_FIX_UNKNOWN";
|
|
1536
|
+
readonly OPTION_INVALID: "OPTION_INVALID";
|
|
1529
1537
|
readonly TYPESCRIPT_NOT_FOUND: "TYPESCRIPT_NOT_FOUND";
|
|
1530
1538
|
readonly CLI_FLAG_REMOVED: "CLI_FLAG_REMOVED";
|
|
1539
|
+
readonly CLI_FLAG_INVALID: "CLI_FLAG_INVALID";
|
|
1531
1540
|
readonly CLI_GLOB_UNSUPPORTED: "CLI_GLOB_UNSUPPORTED";
|
|
1532
1541
|
readonly CLI_CONFIG_NOT_FOUND: "CLI_CONFIG_NOT_FOUND";
|
|
1533
1542
|
readonly CLI_CONFIG_INVALID: "CLI_CONFIG_INVALID";
|
|
1534
1543
|
readonly CLI_CONFIG_OUTPUT_MISSING: "CLI_CONFIG_OUTPUT_MISSING";
|
|
1535
1544
|
readonly CLI_CHECK_OUTPUT_MISSING: "CLI_CHECK_OUTPUT_MISSING";
|
|
1536
1545
|
readonly CLI_INPUT_MISSING: "CLI_INPUT_MISSING";
|
|
1546
|
+
readonly CLI_INPUT_EXTRA: "CLI_INPUT_EXTRA";
|
|
1537
1547
|
readonly CLI_OUTPUT_IS_INPUT: "CLI_OUTPUT_IS_INPUT";
|
|
1538
1548
|
readonly CLI_OUTPUT_DUPLICATE: "CLI_OUTPUT_DUPLICATE";
|
|
1539
1549
|
readonly CLI_OUTPUT_INVALID: "CLI_OUTPUT_INVALID";
|
|
@@ -1849,6 +1859,7 @@ declare function transformSchema(schema: OpenAPI3, ctx: GlobalContext): IrDeclar
|
|
|
1849
1859
|
/** Every warning code. */
|
|
1850
1860
|
declare const WARNING_CODES: {
|
|
1851
1861
|
readonly CLI_INPUT_IGNORED: "CLI_INPUT_IGNORED";
|
|
1862
|
+
readonly CLI_OUTPUT_IGNORED: "CLI_OUTPUT_IGNORED";
|
|
1852
1863
|
readonly CONFIG_SETTING_UNKNOWN: "CONFIG_SETTING_UNKNOWN";
|
|
1853
1864
|
readonly DISCRIMINATOR_MAPPING_INVALID: "DISCRIMINATOR_MAPPING_INVALID";
|
|
1854
1865
|
readonly DISCRIMINATOR_VALUE_NOT_ALLOWED: "DISCRIMINATOR_VALUE_NOT_ALLOWED";
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,22 @@ import { Config } from '@redocly/openapi-core';
|
|
|
4
4
|
import * as TypeScript from 'typescript';
|
|
5
5
|
import colors from 'ansi-colors';
|
|
6
6
|
|
|
7
|
+
/** The debug groups of the original `DEBUG=openapi-ts:<group>` output. */
|
|
8
|
+
type DebugGroup = "redoc" | "lint" | "bundle" | "ts";
|
|
9
|
+
/**
|
|
10
|
+
* Where the generator reports progress and problems (ENGINEERING_PLAN 4.5). Whether warnings are
|
|
11
|
+
* printed (`silent`) and debug output (`DEBUG`) is decided by the adapter, when it is created.
|
|
12
|
+
*/
|
|
13
|
+
interface Logger {
|
|
14
|
+
/**
|
|
15
|
+
* A debug line, with how long the step took when it was measured. A line without a group is
|
|
16
|
+
* written whenever debug output is on.
|
|
17
|
+
*/
|
|
18
|
+
debug(message: string, group?: DebugGroup, durationMs?: number): void;
|
|
19
|
+
warn(message: string): void;
|
|
20
|
+
error(message: string): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
7
23
|
/**
|
|
8
24
|
* Type IR: the closed set of immutable nodes that describes the TypeScript types and declarations
|
|
9
25
|
* the generator emits (ENGINEERING_PLAN §4.2, ADR-002). Nodes are plain readonly data with a `kind`
|
|
@@ -268,6 +284,11 @@ declare const FIX: {
|
|
|
268
284
|
readonly ARRAY_LENGTH_TUPLES: "array-length-tuples";
|
|
269
285
|
/** `--dedupe-enums` names a shared enum by all of its schemas, not by the first one. */
|
|
270
286
|
readonly DEDUPE_ENUM_NAMES: "dedupe-enum-names";
|
|
287
|
+
/**
|
|
288
|
+
* `--default-non-nullable` finds parameters and request bodies by the document's structure, not
|
|
289
|
+
* by the words `parameters` and `requestBody` anywhere in a schema's location.
|
|
290
|
+
*/
|
|
291
|
+
readonly DEFAULT_INPUT_LOCATIONS: "default-input-locations";
|
|
271
292
|
/** `required` next to an `allOf` `$ref` to a discriminator member still gives `WithRequired`. */
|
|
272
293
|
readonly DISCRIMINATOR_MEMBER_REQUIRED: "discriminator-member-required";
|
|
273
294
|
/**
|
|
@@ -280,8 +301,8 @@ declare const FIX: {
|
|
|
280
301
|
readonly EXPLODED_QUERY_OBJECTS: "exploded-query-objects";
|
|
281
302
|
/** `--enum` declares an enum that lists `null` without it, and the type adds `| null`. */
|
|
282
303
|
readonly NULLABLE_ENUMS: "nullable-enums";
|
|
283
|
-
/** A parameter with `content
|
|
284
|
-
readonly
|
|
304
|
+
/** A parameter or header with `content`, not `schema`, is typed by its media type's schema. */
|
|
305
|
+
readonly PARAMETER_HEADER_CONTENT: "parameter-header-content";
|
|
285
306
|
/** `--path-params-as-types` gives each `{name}` its placeholder, `{number}` included. */
|
|
286
307
|
readonly PATH_PARAM_TYPE_NAMES: "path-param-type-names";
|
|
287
308
|
/** A `prefixItems` tuple is open unless `items` or `unevaluatedItems` closes it (2020-12). */
|
|
@@ -1474,22 +1495,6 @@ declare const DEPRECATION_CODES: {
|
|
|
1474
1495
|
};
|
|
1475
1496
|
type DeprecationCode = (typeof DEPRECATION_CODES)[keyof typeof DEPRECATION_CODES];
|
|
1476
1497
|
|
|
1477
|
-
/** The debug groups of the original `DEBUG=openapi-ts:<group>` output. */
|
|
1478
|
-
type DebugGroup = "redoc" | "lint" | "bundle" | "ts";
|
|
1479
|
-
/**
|
|
1480
|
-
* Where the generator reports progress and problems (ENGINEERING_PLAN 4.5). Whether warnings are
|
|
1481
|
-
* printed (`silent`) and debug output (`DEBUG`) is decided by the adapter, when it is created.
|
|
1482
|
-
*/
|
|
1483
|
-
interface Logger {
|
|
1484
|
-
/**
|
|
1485
|
-
* A debug line, with how long the step took when it was measured. A line without a group is
|
|
1486
|
-
* written whenever debug output is on.
|
|
1487
|
-
*/
|
|
1488
|
-
debug(message: string, group?: DebugGroup, durationMs?: number): void;
|
|
1489
|
-
warn(message: string): void;
|
|
1490
|
-
error(message: string): void;
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
1498
|
/**
|
|
1494
1499
|
* Convert an OpenAPI schema to TypeScript declarations (IR nodes; print them with `astToString`)
|
|
1495
1500
|
* @param {string|URL|object|Readable} source OpenAPI schema source:
|
|
@@ -1498,6 +1503,8 @@ interface Logger {
|
|
|
1498
1503
|
* - URL: URL to a YAML or JSON file (local or remote)
|
|
1499
1504
|
* - Readable: Readable stream of YAML or JSON
|
|
1500
1505
|
*/
|
|
1506
|
+
declare function openapiTS(source: SchemaSource, options?: OpenAPITSOptions): Promise<IrDeclaration[]>;
|
|
1507
|
+
/** Convert an OpenAPI schema to IR declarations, with either form of the options. */
|
|
1501
1508
|
declare function openapiTS(source: SchemaSource, options?: GeneratorOptions): Promise<IrDeclaration[]>;
|
|
1502
1509
|
|
|
1503
1510
|
/**
|
|
@@ -1526,14 +1533,17 @@ declare const ERROR_CODES: {
|
|
|
1526
1533
|
readonly ENUM_NAME_EMPTY: "ENUM_NAME_EMPTY";
|
|
1527
1534
|
readonly CALLBACK_RESULT_UNREADABLE: "CALLBACK_RESULT_UNREADABLE";
|
|
1528
1535
|
readonly OPTION_FIX_UNKNOWN: "OPTION_FIX_UNKNOWN";
|
|
1536
|
+
readonly OPTION_INVALID: "OPTION_INVALID";
|
|
1529
1537
|
readonly TYPESCRIPT_NOT_FOUND: "TYPESCRIPT_NOT_FOUND";
|
|
1530
1538
|
readonly CLI_FLAG_REMOVED: "CLI_FLAG_REMOVED";
|
|
1539
|
+
readonly CLI_FLAG_INVALID: "CLI_FLAG_INVALID";
|
|
1531
1540
|
readonly CLI_GLOB_UNSUPPORTED: "CLI_GLOB_UNSUPPORTED";
|
|
1532
1541
|
readonly CLI_CONFIG_NOT_FOUND: "CLI_CONFIG_NOT_FOUND";
|
|
1533
1542
|
readonly CLI_CONFIG_INVALID: "CLI_CONFIG_INVALID";
|
|
1534
1543
|
readonly CLI_CONFIG_OUTPUT_MISSING: "CLI_CONFIG_OUTPUT_MISSING";
|
|
1535
1544
|
readonly CLI_CHECK_OUTPUT_MISSING: "CLI_CHECK_OUTPUT_MISSING";
|
|
1536
1545
|
readonly CLI_INPUT_MISSING: "CLI_INPUT_MISSING";
|
|
1546
|
+
readonly CLI_INPUT_EXTRA: "CLI_INPUT_EXTRA";
|
|
1537
1547
|
readonly CLI_OUTPUT_IS_INPUT: "CLI_OUTPUT_IS_INPUT";
|
|
1538
1548
|
readonly CLI_OUTPUT_DUPLICATE: "CLI_OUTPUT_DUPLICATE";
|
|
1539
1549
|
readonly CLI_OUTPUT_INVALID: "CLI_OUTPUT_INVALID";
|
|
@@ -1849,6 +1859,7 @@ declare function transformSchema(schema: OpenAPI3, ctx: GlobalContext): IrDeclar
|
|
|
1849
1859
|
/** Every warning code. */
|
|
1850
1860
|
declare const WARNING_CODES: {
|
|
1851
1861
|
readonly CLI_INPUT_IGNORED: "CLI_INPUT_IGNORED";
|
|
1862
|
+
readonly CLI_OUTPUT_IGNORED: "CLI_OUTPUT_IGNORED";
|
|
1852
1863
|
readonly CONFIG_SETTING_UNKNOWN: "CONFIG_SETTING_UNKNOWN";
|
|
1853
1864
|
readonly DISCRIMINATOR_MAPPING_INVALID: "DISCRIMINATOR_MAPPING_INVALID";
|
|
1854
1865
|
readonly DISCRIMINATOR_VALUE_NOT_ALLOWED: "DISCRIMINATOR_VALUE_NOT_ALLOWED";
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url";
|
|
|
3
3
|
import type {
|
|
4
4
|
ClaimedFile,
|
|
5
5
|
DirectoryCheck,
|
|
6
|
+
FileCheck,
|
|
6
7
|
FileClaims,
|
|
7
8
|
FileIdentity,
|
|
8
9
|
FileReader,
|
|
@@ -110,7 +111,9 @@ function typedWrite<T>(file: URL, step: () => T): T {
|
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
class NodeFileSystem
|
|
114
|
+
class NodeFileSystem
|
|
115
|
+
implements FileReader, FileWriter, FileIdentity, DirectoryCheck, FileCheck, FileClaims
|
|
116
|
+
{
|
|
114
117
|
readText(file: URL): string {
|
|
115
118
|
try {
|
|
116
119
|
return fs.readFileSync(file, "utf8");
|
|
@@ -144,6 +147,15 @@ class NodeFileSystem implements FileReader, FileWriter, FileIdentity, DirectoryC
|
|
|
144
147
|
}
|
|
145
148
|
}
|
|
146
149
|
|
|
150
|
+
isFile(file: URL): boolean {
|
|
151
|
+
try {
|
|
152
|
+
return fs.statSync(file).isFile();
|
|
153
|
+
} catch {
|
|
154
|
+
// Missing or unreadable: no file; the read that follows reports a failure.
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
147
159
|
isSameFile(left: URL, right: URL): boolean {
|
|
148
160
|
const leftPath = fileURLToPath(left);
|
|
149
161
|
const rightPath = fileURLToPath(right);
|
|
@@ -166,6 +178,7 @@ export function createNodeFileSystem(): FileReader &
|
|
|
166
178
|
FileWriter &
|
|
167
179
|
FileIdentity &
|
|
168
180
|
DirectoryCheck &
|
|
181
|
+
FileCheck &
|
|
169
182
|
FileClaims {
|
|
170
183
|
return new NodeFileSystem();
|
|
171
184
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Writable } from "node:stream";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A writer for the CLI's stdout that stops when the reader closes the pipe (`| head`): the write
|
|
5
|
+
* fails with `EPIPE`, which Node raises as an unhandled `error` event and a crash with exit code
|
|
6
|
+
* 1. The reader has all it wanted, so the rest is dropped and the run ends as it would have.
|
|
7
|
+
* Every other write error is thrown again, as before.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const BROKEN_PIPE = "EPIPE";
|
|
11
|
+
|
|
12
|
+
function isBrokenPipe(error: Error): boolean {
|
|
13
|
+
return (error as NodeJS.ErrnoException).code === BROKEN_PIPE;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The text writer of the stream. After `EPIPE` the stream is destroyed, so later writes are
|
|
18
|
+
* dropped by the stream itself and raise no second error.
|
|
19
|
+
*/
|
|
20
|
+
export function createPipeSafeWriter(stream: Writable): (text: string) => void {
|
|
21
|
+
stream.on("error", (error: Error) => {
|
|
22
|
+
if (!isBrokenPipe(error)) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return (text) => {
|
|
27
|
+
stream.write(text);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { childPointer
|
|
2
|
-
import {
|
|
1
|
+
import { childPointer } from "../../domain/openapi/json-pointer.js";
|
|
2
|
+
import { type ComponentSchemas, componentSchemasOf, SCHEMAS_POINTER } from "./component-schemas.js";
|
|
3
|
+
import { findMappings, findRefHolders } from "./ref-holders.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Redocly 1.x bundles every discriminator `mapping` value as if it were an external `$ref`: it
|
|
@@ -11,27 +12,13 @@ import { findRefHolders } from "./ref-holders.js";
|
|
|
11
12
|
* and the mapping values and `$ref`s that name it point at the original.
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
|
-
type Schemas = Record<string, unknown>;
|
|
15
|
-
|
|
16
|
-
const SCHEMAS_POINTER = childPointer(childPointer(ROOT_POINTER, "components"), "schemas");
|
|
17
|
-
|
|
18
|
-
function isContainer(value: unknown): value is Record<string, unknown> {
|
|
19
|
-
return typeof value === "object" && value !== null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function schemasOf(document: unknown): Schemas | undefined {
|
|
23
|
-
const components = isContainer(document) ? document.components : undefined;
|
|
24
|
-
const schemas = isContainer(components) ? components.schemas : undefined;
|
|
25
|
-
return isContainer(schemas) ? schemas : undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
15
|
/** The keys of `components.schemas` before bundling: the bundle edits the document in place. */
|
|
29
16
|
export function schemaKeysOf(document: unknown): ReadonlySet<string> {
|
|
30
|
-
return new Set(Object.keys(
|
|
17
|
+
return new Set(Object.keys(componentSchemasOf(document) ?? {}));
|
|
31
18
|
}
|
|
32
19
|
|
|
33
20
|
/** Each key the bundle added as a copy, with the pointer of the schema it copies. */
|
|
34
|
-
function copiesIn(schemas:
|
|
21
|
+
function copiesIn(schemas: ComponentSchemas, keysBefore: ReadonlySet<string>): Map<string, string> {
|
|
35
22
|
const originals = new Map<unknown, string>();
|
|
36
23
|
for (const key of keysBefore) {
|
|
37
24
|
if (Object.hasOwn(schemas, key) && !originals.has(schemas[key])) {
|
|
@@ -49,39 +36,17 @@ function copiesIn(schemas: Schemas, keysBefore: ReadonlySet<string>): Map<string
|
|
|
49
36
|
return copies;
|
|
50
37
|
}
|
|
51
38
|
|
|
52
|
-
/** Every `discriminator.mapping` object of the document; the walk has its own stack. */
|
|
53
|
-
function mappingsOf(document: unknown): Record<string, unknown>[] {
|
|
54
|
-
const mappings: Record<string, unknown>[] = [];
|
|
55
|
-
const visited = new WeakSet<object>();
|
|
56
|
-
const pending: unknown[] = [document];
|
|
57
|
-
for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
|
|
58
|
-
if (!isContainer(next) || visited.has(next)) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
visited.add(next);
|
|
62
|
-
const mapping = isContainer(next.discriminator) ? next.discriminator.mapping : undefined;
|
|
63
|
-
if (isContainer(mapping)) {
|
|
64
|
-
mappings.push(mapping);
|
|
65
|
-
}
|
|
66
|
-
// One push per child: spreading an array of millions of children overflows the stack.
|
|
67
|
-
for (const child of Object.values(next)) {
|
|
68
|
-
pending.push(child);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return mappings;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
39
|
/** Remove the bundle's copies of the document's own schemas, in place. */
|
|
75
40
|
export function removeBundledMappingCopies(
|
|
76
41
|
bundled: unknown,
|
|
77
42
|
keysBefore: ReadonlySet<string>,
|
|
78
43
|
): void {
|
|
79
|
-
const schemas =
|
|
44
|
+
const schemas = componentSchemasOf(bundled);
|
|
80
45
|
const copies = schemas === undefined ? new Map<string, string>() : copiesIn(schemas, keysBefore);
|
|
81
46
|
if (copies.size === 0) {
|
|
82
47
|
return;
|
|
83
48
|
}
|
|
84
|
-
for (const mapping of
|
|
49
|
+
for (const mapping of findMappings(bundled)) {
|
|
85
50
|
for (const [name, value] of Object.entries(mapping)) {
|
|
86
51
|
const original = typeof value === "string" ? copies.get(value) : undefined;
|
|
87
52
|
if (original !== undefined) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { childPointer, ROOT_POINTER } from "../../domain/openapi/json-pointer.js";
|
|
2
|
+
|
|
3
|
+
/** `components.schemas` of a parsed document, which the loader repairs in place. */
|
|
4
|
+
|
|
5
|
+
export type ComponentSchemas = Record<string, unknown>;
|
|
6
|
+
|
|
7
|
+
/** `#/components/schemas`. */
|
|
8
|
+
export const SCHEMAS_POINTER = childPointer(childPointer(ROOT_POINTER, "components"), "schemas");
|
|
9
|
+
|
|
10
|
+
function isContainer(value: unknown): value is Record<string, unknown> {
|
|
11
|
+
return typeof value === "object" && value !== null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The `components.schemas` object of a document, when it has one. */
|
|
15
|
+
export function componentSchemasOf(document: unknown): ComponentSchemas | undefined {
|
|
16
|
+
const components = isContainer(document) ? document.components : undefined;
|
|
17
|
+
const schemas = isContainer(components) ? components.schemas : undefined;
|
|
18
|
+
return isContainer(schemas) ? schemas : undefined;
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { childPointer } from "../../domain/openapi/json-pointer.js";
|
|
2
|
+
import { componentSchemasOf, SCHEMAS_POINTER } from "./component-schemas.js";
|
|
3
|
+
import { findMappings } from "./ref-holders.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A discriminator `mapping` value may be a schema name (`cat: Cat`) or a URI reference. Redocly
|
|
7
|
+
* reads every value as a `$ref`, so a name failed with "Can't resolve $ref". OpenAPI 3.1.1
|
|
8
|
+
* (§4.8.25) leaves a value that is both to the implementation and recommends the schema name; a
|
|
9
|
+
* relative URI is then written `./Cat`. So a value that is a key of the document's
|
|
10
|
+
* `components.schemas` becomes the pointer to that schema, in place, before the `$ref`s are
|
|
11
|
+
* resolved. Any other value stays a URI reference.
|
|
12
|
+
*/
|
|
13
|
+
export function pointMappingNamesAtSchemas(document: unknown): void {
|
|
14
|
+
const schemas = componentSchemasOf(document);
|
|
15
|
+
if (schemas === undefined) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
for (const mapping of findMappings(document)) {
|
|
19
|
+
for (const [name, value] of Object.entries(mapping)) {
|
|
20
|
+
if (typeof value === "string" && Object.hasOwn(schemas, value)) {
|
|
21
|
+
mapping[name] = childPointer(SCHEMAS_POINTER, value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { LoadedDocument } from "./unsupported-keys.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Which loaded document with a query each node comes from, and the names Redocly and the loader
|
|
5
|
+
* give that document. Redocly names a component after the text behind the last `/` of the URL,
|
|
6
|
+
* query included, so `pet.json?ref=feature/new-api` and `owner.yaml?ref=feature/new-api` both give
|
|
7
|
+
* `new-api`: the name alone cannot tell the documents apart, the node can.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const REMOTE_URL_RE = /^https?:\/\//;
|
|
11
|
+
const PATH_SEPARATOR_RE = /[/\\]/;
|
|
12
|
+
const EXTENSION_RE = /\.[^.]+$/;
|
|
13
|
+
|
|
14
|
+
/** The base name Redocly gives a document and the one without the query. */
|
|
15
|
+
export interface DocumentNames {
|
|
16
|
+
readonly named: string;
|
|
17
|
+
readonly clean: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The base name Redocly 1.34 gives a document (`refBaseName`): the last segment, no extension. */
|
|
21
|
+
function redoclyBaseName(ref: string): string {
|
|
22
|
+
return (ref.split(PATH_SEPARATOR_RE).at(-1) ?? "").replace(EXTENSION_RE, "");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The base name of the URL without its query and fragment. A URL with no last segment
|
|
27
|
+
* (`https://host/?key=…`) is named after its host, so the name is never empty.
|
|
28
|
+
*/
|
|
29
|
+
function queryFreeBaseName(url: URL): string {
|
|
30
|
+
const withoutQuery = new URL(url.pathname, url.origin).href;
|
|
31
|
+
return redoclyBaseName(withoutQuery) || url.hostname;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The names of a remote document with a query whose Redocly name keeps it; else undefined. */
|
|
35
|
+
function documentNamesOf(ref: string): DocumentNames | undefined {
|
|
36
|
+
const url = REMOTE_URL_RE.test(ref) && URL.canParse(ref) ? new URL(ref) : undefined;
|
|
37
|
+
if (url === undefined || url.search === "") {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const names = { named: redoclyBaseName(ref), clean: queryFreeBaseName(url) };
|
|
41
|
+
return names.named === names.clean ? undefined : names;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isNode(value: unknown): value is object {
|
|
45
|
+
return typeof value === "object" && value !== null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Every object and array of a parsed document, each once (a YAML alias can repeat one). */
|
|
49
|
+
function nodesOf(parsed: unknown): object[] {
|
|
50
|
+
const visited = new Set<object>();
|
|
51
|
+
const pending = isNode(parsed) ? [parsed] : [];
|
|
52
|
+
for (let node = pending.pop(); node !== undefined; node = pending.pop()) {
|
|
53
|
+
if (!visited.has(node)) {
|
|
54
|
+
visited.add(node);
|
|
55
|
+
pending.push(...Object.values(node).filter(isNode));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return [...visited];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The names of the document each node of a loaded document with a query belongs to. The bundle
|
|
63
|
+
* keeps the nodes of the loaded documents as its components, so a component finds its document.
|
|
64
|
+
*/
|
|
65
|
+
export function queryDocumentNames(
|
|
66
|
+
documents: readonly LoadedDocument[],
|
|
67
|
+
): ReadonlyMap<object, DocumentNames> {
|
|
68
|
+
const byNode = new Map<object, DocumentNames>();
|
|
69
|
+
for (const { source, parsed } of documents) {
|
|
70
|
+
const names = documentNamesOf(source);
|
|
71
|
+
if (names === undefined) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
for (const node of nodesOf(parsed)) {
|
|
75
|
+
byNode.set(node, names);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return byNode;
|
|
79
|
+
}
|