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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const apiSettings = require('./api-settings.cjs');
|
|
4
4
|
const apiWrites = require('./api-writes.cjs');
|
|
5
|
+
const cliArguments = require('./cli-arguments.cjs');
|
|
5
6
|
const cliErrors = require('./cli-errors.cjs');
|
|
6
7
|
const cliOutput = require('./cli-output.cjs');
|
|
7
8
|
const docsLinks = require('./docs-links.cjs');
|
|
@@ -43,31 +44,50 @@ function apiTarget(api, configRoot) {
|
|
|
43
44
|
}
|
|
44
45
|
return { name, root, settings, configRoot };
|
|
45
46
|
}
|
|
46
|
-
function apiOptions(run,
|
|
47
|
+
function apiOptions(run, apiRun, target) {
|
|
47
48
|
const { name, settings, configRoot } = target;
|
|
49
|
+
const flags = { ...run.args.generatorFlags, ...apiSettings.apiFlags(name, settings) };
|
|
50
|
+
for (const notice of cliArguments.ineffectiveFlagNotices(flags)) {
|
|
51
|
+
run.deps.console.notice(`API ${name}: ${notice}`);
|
|
52
|
+
}
|
|
48
53
|
return {
|
|
49
|
-
...
|
|
50
|
-
...
|
|
51
|
-
...refLimits.refLimitOptions(run.args, run.deps.cwd),
|
|
54
|
+
...flags,
|
|
55
|
+
...apiRun.refLimits,
|
|
52
56
|
...apiSettings.apiRefLimitOptions(name, settings, configRoot),
|
|
53
57
|
...fixOption.fixOption(apiSettings.apiFixNames(name, settings) ?? run.args.fix),
|
|
54
|
-
redocly
|
|
58
|
+
redocly: run.deps.redoclyConfigs.forApi(apiRun.redocly, name)
|
|
55
59
|
};
|
|
56
60
|
}
|
|
57
61
|
function otherOutputs(files, apiName) {
|
|
58
62
|
return [...files.outputs].filter(([name]) => name !== apiName).map(([name, location]) => ({ name: `API ${name}`, location }));
|
|
59
63
|
}
|
|
60
|
-
async function generateApi(run,
|
|
64
|
+
async function generateApi(run, apiRun, target) {
|
|
65
|
+
const { files } = apiRun;
|
|
61
66
|
for (const warning of apiSettings.unknownSettingWarnings(target.name, target.settings)) {
|
|
62
67
|
run.deps.logger.warn(warning);
|
|
63
68
|
}
|
|
64
69
|
const output = apiSettings.apiOutputOf(target.name, target.settings);
|
|
65
|
-
const outputFile =
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
const outputFile = failingAsApi(target.name, () => {
|
|
71
|
+
const file = cliOutput.outputFileOf(run, { source: target.name, output }, target.configRoot);
|
|
72
|
+
cliOutput.ensureOutputIsNotSchema(run, file, files.schemas);
|
|
73
|
+
cliOutput.ensureOutputIsOwn(run, file, otherOutputs(files, target.name));
|
|
74
|
+
return file;
|
|
75
|
+
});
|
|
68
76
|
const source = cliOutput.resolveLocationUrl(target.root, target.configRoot);
|
|
69
|
-
const
|
|
70
|
-
|
|
77
|
+
const options = apiOptions(run, apiRun, target);
|
|
78
|
+
try {
|
|
79
|
+
const types = await run.deps.generate(source, options, target.name);
|
|
80
|
+
return { name: target.name, outputFile, types };
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw new cliErrors.ApiFailure(target.name, error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function failingAsApi(apiName, step) {
|
|
86
|
+
try {
|
|
87
|
+
return step();
|
|
88
|
+
} catch (error) {
|
|
89
|
+
throw new cliErrors.ApiFailure(apiName, error);
|
|
90
|
+
}
|
|
71
91
|
}
|
|
72
92
|
function configFilesOf(run, redocly, apis) {
|
|
73
93
|
const configRoot = configRootOf(redocly, run.deps.cwd);
|
|
@@ -100,9 +120,10 @@ async function settledInTurn(items, task) {
|
|
|
100
120
|
async function generateRedoclyApis(run, redocly) {
|
|
101
121
|
const apis = redoclyApisOf(redocly);
|
|
102
122
|
const { configRoot, files } = configFilesOf(run, redocly, apis);
|
|
123
|
+
const apiRun = { redocly, files, refLimits: refLimits.refLimitOptions(run.args, run.deps.cwd) };
|
|
103
124
|
const results = await settledInTurn(
|
|
104
125
|
apis,
|
|
105
|
-
(api) => generateApi(run,
|
|
126
|
+
(api) => generateApi(run, apiRun, apiTarget(api, configRoot))
|
|
106
127
|
);
|
|
107
128
|
const generated = results.flatMap(
|
|
108
129
|
(result) => result.status === "fulfilled" ? [result.value] : []
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redocly-apis.cjs","sources":["../../src/cli/redocly-apis.ts"],"sourcesContent":["import type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport type { GeneratorOptions } from \"../types.js\";\nimport {\n type ApiSettings,\n apiFixNames,\n apiFlags,\n apiOutputOf,\n apiRefLimitOptions,\n OUTPUT_SETTING,\n unknownSettingWarnings,\n} from \"./api-settings.js\";\nimport { type GeneratedApi, writeGeneratedApis } from \"./api-writes.js\";\nimport { cliError } from \"./cli-errors.js\";\nimport {\n type CliRun,\n ensureOutputIsNotSchema,\n ensureOutputIsOwn,\n filesReadBy,\n type NamedFile,\n outputFileOf,\n parseLocationUrl,\n redoclyConfigFiles,\n resolveLocationUrl,\n} from \"./cli-output.js\";\nimport { MULTIPLE_SCHEMAS_DOCS_URL } from \"./docs-links.js\";\nimport { fixOption } from \"./fix-option.js\";\nimport { refLimitOptions } from \"./ref-limits.js\";\n\n/** The `apis` of a Redocly config: each API is generated into its `x-openapi-ts.output`. */\n\n/** The key of an API's openapi-typesafe settings in `redocly.yaml`. */\nconst REDOCLY_CONFIG_KEY = \"x-openapi-ts\";\n\n/** An API of the config as written: `root` and the settings are not checked yet. */\ninterface RedoclyApi {\n readonly name: string;\n readonly root: unknown;\n readonly settings: unknown;\n}\n\nfunction redoclyApisOf(redocly: RedoclyConfig): RedoclyApi[] {\n return Object.entries(redocly.apis ?? {}).map(([name, api]) => {\n const fields = api as Readonly<Record<string, unknown>>;\n return { name, root: fields.root, settings: fields[REDOCLY_CONFIG_KEY] };\n });\n}\n\nexport function hasRedoclyApis(redocly: RedoclyConfig): boolean {\n return Object.keys(redocly.apis ?? {}).length > 0;\n}\n\n/** Paths in the config are relative to the config file; without a file, to the working dir. */\nfunction configRootOf(redocly: RedoclyConfig, cwd: URL): URL {\n return redocly.configFile ? resolveLocationUrl(redocly.configFile, cwd) : cwd;\n}\n\n/** An API whose root and settings are usable, and the directory its paths are relative to. */\ninterface ApiTarget {\n readonly name: string;\n readonly root: string;\n readonly settings: ApiSettings;\n readonly configRoot: URL;\n}\n\nfunction isSettingsMap(value: unknown): value is ApiSettings {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * The API with its settings. Fails with `CLI_CONFIG_OUTPUT_MISSING` when they name no output, and\n * with `CLI_CONFIG_INVALID` when they are no map or `root` is no path or URL; only this API then\n * fails, the others are still generated.\n */\nfunction apiTarget(api: RedoclyApi, configRoot: URL): ApiTarget {\n const { name, root, settings } = api;\n if (settings !== undefined && !isSettingsMap(settings)) {\n throw cliError(\"CLI_CONFIG_INVALID\", `API ${name}: \\`${REDOCLY_CONFIG_KEY}\\` must be a map`);\n }\n if (!settings?.[OUTPUT_SETTING]) {\n throw cliError(\n \"CLI_CONFIG_OUTPUT_MISSING\",\n `API ${name} is missing an \\`${REDOCLY_CONFIG_KEY}.output\\` key. ` +\n `See ${MULTIPLE_SCHEMAS_DOCS_URL}`,\n );\n }\n if (typeof root !== \"string\" || root === \"\") {\n throw cliError(\n \"CLI_CONFIG_INVALID\",\n `API ${name}: \\`root\\` in redocly.yaml must be the path or URL of its schema`,\n );\n }\n return { name, root, settings, configRoot };\n}\n\n/** The generator options of one API: its own settings win over the CLI's flags. */\nfunction apiOptions(run: CliRun, redocly: RedoclyConfig, target: ApiTarget): GeneratorOptions {\n const { name, settings, configRoot } = target;\n return {\n ...run.args.generatorFlags,\n ...apiFlags(name, settings),\n ...refLimitOptions(run.args, run.deps.cwd),\n ...apiRefLimitOptions(name, settings, configRoot),\n ...fixOption(apiFixNames(name, settings) ?? run.args.fix),\n redocly,\n };\n}\n\n/** The schemas and outputs of every API of the config, keyed by API name for the outputs. */\ninterface ConfigFiles {\n readonly schemas: readonly NamedFile[];\n readonly outputs: ReadonlyMap<string, URL>;\n}\n\n/** The outputs of the other APIs, as `ensureOutputIsOwn` names them. */\nfunction otherOutputs(files: ConfigFiles, apiName: string): NamedFile[] {\n return [...files.outputs]\n .filter(([name]) => name !== apiName)\n .map(([name, location]) => ({ name: `API ${name}`, location }));\n}\n\n/**\n * Generate the types of one API. Its output must not be a file the run reads before any API is\n * loaded (the root of any API, the Redocly config) nor another API's output.\n */\nasync function generateApi(\n run: CliRun,\n redocly: RedoclyConfig,\n target: ApiTarget,\n files: ConfigFiles,\n): Promise<GeneratedApi> {\n for (const warning of unknownSettingWarnings(target.name, target.settings)) {\n run.deps.logger.warn(warning);\n }\n const output = apiOutputOf(target.name, target.settings);\n const outputFile = outputFileOf(run, { source: target.name, output }, target.configRoot);\n ensureOutputIsNotSchema(run, outputFile, files.schemas);\n ensureOutputIsOwn(run, outputFile, otherOutputs(files, target.name));\n const source = resolveLocationUrl(target.root, target.configRoot);\n const types = await run.deps.generate(source, apiOptions(run, redocly, target));\n return { name: target.name, outputFile, types };\n}\n\n/**\n * The schema and the output of every API, and the config file itself. A location that is no\n * text or no valid URL is left out: it is no file that an output could be, and its own API fails\n * on it, not every API.\n */\nfunction configFilesOf(run: CliRun, redocly: RedoclyConfig, apis: readonly RedoclyApi[]) {\n const configRoot = configRootOf(redocly, run.deps.cwd);\n const roots = apis.flatMap(({ name, root }) => {\n const location = typeof root === \"string\" ? parseLocationUrl(root, configRoot) : undefined;\n return location ? [{ name: `schema ${root} of API ${name}`, location }] : [];\n });\n const outputs = new Map<string, URL>();\n for (const api of apis) {\n const output = isSettingsMap(api.settings) ? api.settings[OUTPUT_SETTING] : undefined;\n const location = typeof output === \"string\" ? parseLocationUrl(output, configRoot) : undefined;\n if (location) {\n outputs.set(api.name, location);\n }\n }\n const schemas = [...roots, ...redoclyConfigFiles(run, redocly)];\n return { configRoot, files: { schemas, outputs } satisfies ConfigFiles };\n}\n\n/** What `task` gives for each item, run one after another: the next starts when one settles. */\nasync function settledInTurn<T, R>(\n items: readonly T[],\n task: (item: T) => Promise<R>,\n): Promise<PromiseSettledResult<R>[]> {\n const results: PromiseSettledResult<R>[] = [];\n for (const item of items) {\n try {\n results.push({ status: \"fulfilled\", value: await task(item) });\n } catch (reason) {\n results.push({ status: \"rejected\", reason });\n }\n }\n return results;\n}\n\n/**\n * Generate every API of the config, one after another in the order of the config, then write\n * them. One at a time, so a run takes the memory of its largest API, not the sum of all of them,\n * and the work of one API cannot hold up the fetches of another until their timeout ends them.\n * Nothing is written until every API is read and every output is claimed, so no output can\n * replace a file that another API still reads; an output that is a file any API read (a `$ref`'d\n * schema) fails with `CLI_OUTPUT_IS_INPUT`. Every API is generated or checked even when another\n * fails, so `--check` reports a stale output wherever it is; the failures are returned in the\n * order of the config.\n */\nexport async function generateRedoclyApis(run: CliRun, redocly: RedoclyConfig): Promise<unknown[]> {\n const apis = redoclyApisOf(redocly);\n const { configRoot, files } = configFilesOf(run, redocly, apis);\n const results = await settledInTurn(apis, (api) =>\n generateApi(run, redocly, apiTarget(api, configRoot), files),\n );\n const generated = results.flatMap((result) =>\n result.status === \"fulfilled\" ? [result.value] : [],\n );\n const readFiles = generated.flatMap(({ name, types }) => filesReadBy(run, types, `API ${name}`));\n const writeFailures = writeGeneratedApis(run, generated, readFiles);\n return results.flatMap((result) =>\n result.status === \"rejected\" ? [result.reason] : (writeFailures.get(result.value.name) ?? []),\n );\n}\n"],"names":["resolveLocationUrl","cliError","OUTPUT_SETTING","MULTIPLE_SCHEMAS_DOCS_URL","apiFlags","refLimitOptions","apiRefLimitOptions","fixOption","apiFixNames","unknownSettingWarnings","apiOutputOf","outputFileOf","ensureOutputIsNotSchema","ensureOutputIsOwn","parseLocationUrl","redoclyConfigFiles","filesReadBy","writeGeneratedApis"],"mappings":";;;;;;;;;;AA+BA,MAAM,kBAAA,GAAqB,cAAA;AAS3B,SAAS,cAAc,OAAA,EAAsC;AAC3D,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,OAAA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,EAAA,MAAM,EAAE,UAAA,EAAY,KAAA,KAAU,aAAA,CAAc,GAAA,EAAK,SAAS,IAAI,CAAA;AAC9D,EAAA,MAAM,UAAU,MAAM,aAAA;AAAA,IAAc,IAAA;AAAA,IAAM,CAAC,QACzC,WAAA,CAAY,GAAA,EAAK,SAAS,SAAA,CAAU,GAAA,EAAK,UAAU,CAAA,EAAG,KAAK;AAAA,GAC7D;AACA,EAAA,MAAM,YAAY,OAAA,CAAQ,OAAA;AAAA,IAAQ,CAAC,WACjC,MAAA,CAAO,MAAA,KAAW,cAAc,CAAC,MAAA,CAAO,KAAK,CAAA,GAAI;AAAC,GACpD;AACA,EAAA,MAAM,SAAA,GAAY,SAAA,CAAU,OAAA,CAAQ,CAAC,EAAE,IAAA,EAAM,KAAA,EAAM,KAAMC,qBAAA,CAAY,GAAA,EAAK,KAAA,EAAO,CAAA,IAAA,EAAO,IAAI,EAAE,CAAC,CAAA;AAC/F,EAAA,MAAM,aAAA,GAAgBC,4BAAA,CAAmB,GAAA,EAAK,SAAA,EAAW,SAAS,CAAA;AAClE,EAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,IAAQ,CAAC,MAAA,KACtB,MAAA,CAAO,MAAA,KAAW,aAAa,CAAC,MAAA,CAAO,MAAM,CAAA,GAAK,cAAc,GAAA,CAAI,MAAA,CAAO,KAAA,CAAM,IAAI,KAAK;AAAC,GAC7F;AACF;;;"}
|
|
1
|
+
{"version":3,"file":"redocly-apis.cjs","sources":["../../src/cli/redocly-apis.ts"],"sourcesContent":["import type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport type { GeneratorOptions } from \"../types.js\";\nimport {\n type ApiSettings,\n apiFixNames,\n apiFlags,\n apiOutputOf,\n apiRefLimitOptions,\n OUTPUT_SETTING,\n unknownSettingWarnings,\n} from \"./api-settings.js\";\nimport { type GeneratedApi, writeGeneratedApis } from \"./api-writes.js\";\nimport { ineffectiveFlagNotices } from \"./cli-arguments.js\";\nimport { ApiFailure, cliError } from \"./cli-errors.js\";\nimport {\n type CliRun,\n ensureOutputIsNotSchema,\n ensureOutputIsOwn,\n filesReadBy,\n type NamedFile,\n outputFileOf,\n parseLocationUrl,\n redoclyConfigFiles,\n resolveLocationUrl,\n} from \"./cli-output.js\";\nimport { MULTIPLE_SCHEMAS_DOCS_URL } from \"./docs-links.js\";\nimport { fixOption } from \"./fix-option.js\";\nimport { type RefLimitOptions, refLimitOptions } from \"./ref-limits.js\";\n\n/** The `apis` of a Redocly config: each API is generated into its `x-openapi-ts.output`. */\n\n/** The key of an API's openapi-typesafe settings in `redocly.yaml`. */\nconst REDOCLY_CONFIG_KEY = \"x-openapi-ts\";\n\n/** An API of the config as written: `root` and the settings are not checked yet. */\ninterface RedoclyApi {\n readonly name: string;\n readonly root: unknown;\n readonly settings: unknown;\n}\n\nfunction redoclyApisOf(redocly: RedoclyConfig): RedoclyApi[] {\n return Object.entries(redocly.apis ?? {}).map(([name, api]) => {\n const fields = api as Readonly<Record<string, unknown>>;\n return { name, root: fields.root, settings: fields[REDOCLY_CONFIG_KEY] };\n });\n}\n\nexport function hasRedoclyApis(redocly: RedoclyConfig): boolean {\n return Object.keys(redocly.apis ?? {}).length > 0;\n}\n\n/** Paths in the config are relative to the config file; without a file, to the working dir. */\nfunction configRootOf(redocly: RedoclyConfig, cwd: URL): URL {\n return redocly.configFile ? resolveLocationUrl(redocly.configFile, cwd) : cwd;\n}\n\n/** An API whose root and settings are usable, and the directory its paths are relative to. */\ninterface ApiTarget {\n readonly name: string;\n readonly root: string;\n readonly settings: ApiSettings;\n readonly configRoot: URL;\n}\n\nfunction isSettingsMap(value: unknown): value is ApiSettings {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * The API with its settings. Fails with `CLI_CONFIG_OUTPUT_MISSING` when they name no output, and\n * with `CLI_CONFIG_INVALID` when they are no map or `root` is no path or URL; only this API then\n * fails, the others are still generated.\n */\nfunction apiTarget(api: RedoclyApi, configRoot: URL): ApiTarget {\n const { name, root, settings } = api;\n if (settings !== undefined && !isSettingsMap(settings)) {\n throw cliError(\"CLI_CONFIG_INVALID\", `API ${name}: \\`${REDOCLY_CONFIG_KEY}\\` must be a map`);\n }\n if (!settings?.[OUTPUT_SETTING]) {\n throw cliError(\n \"CLI_CONFIG_OUTPUT_MISSING\",\n `API ${name} is missing an \\`${REDOCLY_CONFIG_KEY}.output\\` key. ` +\n `See ${MULTIPLE_SCHEMAS_DOCS_URL}`,\n );\n }\n if (typeof root !== \"string\" || root === \"\") {\n throw cliError(\n \"CLI_CONFIG_INVALID\",\n `API ${name}: \\`root\\` in redocly.yaml must be the path or URL of its schema`,\n );\n }\n return { name, root, settings, configRoot };\n}\n\n/**\n * What every API of a run shares: the config, the files of all APIs, and the reference limits of\n * the command line, which are checked once before any API, so an invalid flag fails the run once.\n */\ninterface ApiRun {\n readonly redocly: RedoclyConfig;\n readonly files: ConfigFiles;\n readonly refLimits: RefLimitOptions;\n}\n\n/**\n * The generator options of one API: its own settings win over the CLI's flags, and its own lint\n * rules in `redocly.yaml` over the root's (upstream used the root's only). A flag that has\n * no effect with the merged flags is named for this API, since its settings may turn on the flag\n * that the command line lacks, or set one that has no effect themselves.\n */\nfunction apiOptions(run: CliRun, apiRun: ApiRun, target: ApiTarget): GeneratorOptions {\n const { name, settings, configRoot } = target;\n const flags = { ...run.args.generatorFlags, ...apiFlags(name, settings) };\n for (const notice of ineffectiveFlagNotices(flags)) {\n run.deps.console.notice(`API ${name}: ${notice}`);\n }\n return {\n ...flags,\n ...apiRun.refLimits,\n ...apiRefLimitOptions(name, settings, configRoot),\n ...fixOption(apiFixNames(name, settings) ?? run.args.fix),\n redocly: run.deps.redoclyConfigs.forApi(apiRun.redocly, name),\n };\n}\n\n/** The schemas and outputs of every API of the config, keyed by API name for the outputs. */\ninterface ConfigFiles {\n readonly schemas: readonly NamedFile[];\n readonly outputs: ReadonlyMap<string, URL>;\n}\n\n/** The outputs of the other APIs, as `ensureOutputIsOwn` names them. */\nfunction otherOutputs(files: ConfigFiles, apiName: string): NamedFile[] {\n return [...files.outputs]\n .filter(([name]) => name !== apiName)\n .map(([name, location]) => ({ name: `API ${name}`, location }));\n}\n\n/**\n * Generate the types of one API. Its output must not be a file the run reads before any API is\n * loaded (the root of any API, the Redocly config) nor another API's output.\n */\nasync function generateApi(run: CliRun, apiRun: ApiRun, target: ApiTarget): Promise<GeneratedApi> {\n const { files } = apiRun;\n for (const warning of unknownSettingWarnings(target.name, target.settings)) {\n run.deps.logger.warn(warning);\n }\n const output = apiOutputOf(target.name, target.settings);\n const outputFile = failingAsApi(target.name, () => {\n const file = outputFileOf(run, { source: target.name, output }, target.configRoot);\n ensureOutputIsNotSchema(run, file, files.schemas);\n ensureOutputIsOwn(run, file, otherOutputs(files, target.name));\n return file;\n });\n const source = resolveLocationUrl(target.root, target.configRoot);\n const options = apiOptions(run, apiRun, target);\n try {\n const types = await run.deps.generate(source, options, target.name);\n return { name: target.name, outputFile, types };\n } catch (error) {\n throw new ApiFailure(target.name, error);\n }\n}\n\n/**\n * The result of a step of one API, whose failure is reported with the API's name. Errors of an\n * API's settings name the API in their own message and are not wrapped.\n */\nfunction failingAsApi<T>(apiName: string, step: () => T): T {\n try {\n return step();\n } catch (error) {\n throw new ApiFailure(apiName, error);\n }\n}\n\n/**\n * The schema and the output of every API, and the config file itself. A location that is no\n * text or no valid URL is left out: it is no file that an output could be, and its own API fails\n * on it, not every API.\n */\nfunction configFilesOf(run: CliRun, redocly: RedoclyConfig, apis: readonly RedoclyApi[]) {\n const configRoot = configRootOf(redocly, run.deps.cwd);\n const roots = apis.flatMap(({ name, root }) => {\n const location = typeof root === \"string\" ? parseLocationUrl(root, configRoot) : undefined;\n return location ? [{ name: `schema ${root} of API ${name}`, location }] : [];\n });\n const outputs = new Map<string, URL>();\n for (const api of apis) {\n const output = isSettingsMap(api.settings) ? api.settings[OUTPUT_SETTING] : undefined;\n const location = typeof output === \"string\" ? parseLocationUrl(output, configRoot) : undefined;\n if (location) {\n outputs.set(api.name, location);\n }\n }\n const schemas = [...roots, ...redoclyConfigFiles(run, redocly)];\n return { configRoot, files: { schemas, outputs } satisfies ConfigFiles };\n}\n\n/** What `task` gives for each item, run one after another: the next starts when one settles. */\nasync function settledInTurn<T, R>(\n items: readonly T[],\n task: (item: T) => Promise<R>,\n): Promise<PromiseSettledResult<R>[]> {\n const results: PromiseSettledResult<R>[] = [];\n for (const item of items) {\n try {\n results.push({ status: \"fulfilled\", value: await task(item) });\n } catch (reason) {\n results.push({ status: \"rejected\", reason });\n }\n }\n return results;\n}\n\n/**\n * Generate every API of the config, one after another in the order of the config, then write\n * them. One at a time, so a run takes the memory of its largest API, not the sum of all of them,\n * and the work of one API cannot hold up the fetches of another until their timeout ends them.\n * Nothing is written until every API is read and every output is claimed, so no output can\n * replace a file that another API still reads; an output that is a file any API read (a `$ref`'d\n * schema) fails with `CLI_OUTPUT_IS_INPUT`. Every API is generated or checked even when another\n * fails, so `--check` reports a stale output wherever it is; the failures are returned in the\n * order of the config.\n */\nexport async function generateRedoclyApis(run: CliRun, redocly: RedoclyConfig): Promise<unknown[]> {\n const apis = redoclyApisOf(redocly);\n const { configRoot, files } = configFilesOf(run, redocly, apis);\n const apiRun = { redocly, files, refLimits: refLimitOptions(run.args, run.deps.cwd) };\n const results = await settledInTurn(apis, (api) =>\n generateApi(run, apiRun, apiTarget(api, configRoot)),\n );\n const generated = results.flatMap((result) =>\n result.status === \"fulfilled\" ? [result.value] : [],\n );\n const readFiles = generated.flatMap(({ name, types }) => filesReadBy(run, types, `API ${name}`));\n const writeFailures = writeGeneratedApis(run, generated, readFiles);\n return results.flatMap((result) =>\n result.status === \"rejected\" ? [result.reason] : (writeFailures.get(result.value.name) ?? []),\n );\n}\n"],"names":["resolveLocationUrl","cliError","OUTPUT_SETTING","MULTIPLE_SCHEMAS_DOCS_URL","apiFlags","ineffectiveFlagNotices","apiRefLimitOptions","fixOption","apiFixNames","unknownSettingWarnings","apiOutputOf","outputFileOf","ensureOutputIs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I,IAAA,CAAK,GAAG,CAAA,EAAE;AACpF,EAAA,MAAM,UAAU,MAAM,aAAA;AAAA,IAAc,IAAA;AAAA,IAAM,CAAC,QACzC,WAAA,CAAY,GAAA,EAAK,QAAQ,SAAA,CAAU,GAAA,EAAK,UAAU,CAAC;AAAA,GACrD;AACA,EAAA,MAAM,YAAY,OAAA,CAAQ,OAAA;AAAA,IAAQ,CAAC,WACjC,MAAA,CAAO,MAAA,KAAW,cAAc,CAAC,MAAA,CAAO,KAAK,CAAA,GAAI;AAAC,GACpD;AACA,EAAA,MAAM,SAAA,GAAY,SAAA,CAAU,OAAA,CAAQ,CAAC,EAAE,IAAA,EAAM,KAAA,EAAM,KAAMC,qBAAA,CAAY,GAAA,EAAK,KAAA,EAAO,CAAA,IAAA,EAAO,IAAI,EAAE,CAAC,CAAA;AAC/F,EAAA,MAAM,aAAA,GAAgBC,4BAAA,CAAmB,GAAA,EAAK,SAAA,EAAW,SAAS,CAAA;AAClE,EAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,IAAQ,CAAC,MAAA,KACtB,MAAA,CAAO,MAAA,KAAW,aAAa,CAAC,MAAA,CAAO,MAAM,CAAA,GAAK,cAAc,GAAA,CAAI,MAAA,CAAO,KAAA,CAAM,IAAI,KAAK;AAAC,GAC7F;AACF;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { OUTPUT_SETTING, unknownSettingWarnings, apiOutputOf, apiFixNames, apiRefLimitOptions
|
|
1
|
+
import { OUTPUT_SETTING, unknownSettingWarnings, apiOutputOf, apiFlags, apiFixNames, apiRefLimitOptions } from './api-settings.mjs';
|
|
2
2
|
import { writeGeneratedApis } from './api-writes.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { ineffectiveFlagNotices } from './cli-arguments.mjs';
|
|
4
|
+
import { ApiFailure, cliError } from './cli-errors.mjs';
|
|
4
5
|
import { filesReadBy, parseLocationUrl, redoclyConfigFiles, resolveLocationUrl, outputFileOf, ensureOutputIsNotSchema, ensureOutputIsOwn } from './cli-output.mjs';
|
|
5
6
|
import { MULTIPLE_SCHEMAS_DOCS_URL } from './docs-links.mjs';
|
|
6
7
|
import { fixOption } from './fix-option.mjs';
|
|
@@ -41,31 +42,50 @@ function apiTarget(api, configRoot) {
|
|
|
41
42
|
}
|
|
42
43
|
return { name, root, settings, configRoot };
|
|
43
44
|
}
|
|
44
|
-
function apiOptions(run,
|
|
45
|
+
function apiOptions(run, apiRun, target) {
|
|
45
46
|
const { name, settings, configRoot } = target;
|
|
47
|
+
const flags = { ...run.args.generatorFlags, ...apiFlags(name, settings) };
|
|
48
|
+
for (const notice of ineffectiveFlagNotices(flags)) {
|
|
49
|
+
run.deps.console.notice(`API ${name}: ${notice}`);
|
|
50
|
+
}
|
|
46
51
|
return {
|
|
47
|
-
...
|
|
48
|
-
...
|
|
49
|
-
...refLimitOptions(run.args, run.deps.cwd),
|
|
52
|
+
...flags,
|
|
53
|
+
...apiRun.refLimits,
|
|
50
54
|
...apiRefLimitOptions(name, settings, configRoot),
|
|
51
55
|
...fixOption(apiFixNames(name, settings) ?? run.args.fix),
|
|
52
|
-
redocly
|
|
56
|
+
redocly: run.deps.redoclyConfigs.forApi(apiRun.redocly, name)
|
|
53
57
|
};
|
|
54
58
|
}
|
|
55
59
|
function otherOutputs(files, apiName) {
|
|
56
60
|
return [...files.outputs].filter(([name]) => name !== apiName).map(([name, location]) => ({ name: `API ${name}`, location }));
|
|
57
61
|
}
|
|
58
|
-
async function generateApi(run,
|
|
62
|
+
async function generateApi(run, apiRun, target) {
|
|
63
|
+
const { files } = apiRun;
|
|
59
64
|
for (const warning of unknownSettingWarnings(target.name, target.settings)) {
|
|
60
65
|
run.deps.logger.warn(warning);
|
|
61
66
|
}
|
|
62
67
|
const output = apiOutputOf(target.name, target.settings);
|
|
63
|
-
const outputFile =
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
const outputFile = failingAsApi(target.name, () => {
|
|
69
|
+
const file = outputFileOf(run, { source: target.name, output }, target.configRoot);
|
|
70
|
+
ensureOutputIsNotSchema(run, file, files.schemas);
|
|
71
|
+
ensureOutputIsOwn(run, file, otherOutputs(files, target.name));
|
|
72
|
+
return file;
|
|
73
|
+
});
|
|
66
74
|
const source = resolveLocationUrl(target.root, target.configRoot);
|
|
67
|
-
const
|
|
68
|
-
|
|
75
|
+
const options = apiOptions(run, apiRun, target);
|
|
76
|
+
try {
|
|
77
|
+
const types = await run.deps.generate(source, options, target.name);
|
|
78
|
+
return { name: target.name, outputFile, types };
|
|
79
|
+
} catch (error) {
|
|
80
|
+
throw new ApiFailure(target.name, error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function failingAsApi(apiName, step) {
|
|
84
|
+
try {
|
|
85
|
+
return step();
|
|
86
|
+
} catch (error) {
|
|
87
|
+
throw new ApiFailure(apiName, error);
|
|
88
|
+
}
|
|
69
89
|
}
|
|
70
90
|
function configFilesOf(run, redocly, apis) {
|
|
71
91
|
const configRoot = configRootOf(redocly, run.deps.cwd);
|
|
@@ -98,9 +118,10 @@ async function settledInTurn(items, task) {
|
|
|
98
118
|
async function generateRedoclyApis(run, redocly) {
|
|
99
119
|
const apis = redoclyApisOf(redocly);
|
|
100
120
|
const { configRoot, files } = configFilesOf(run, redocly, apis);
|
|
121
|
+
const apiRun = { redocly, files, refLimits: refLimitOptions(run.args, run.deps.cwd) };
|
|
101
122
|
const results = await settledInTurn(
|
|
102
123
|
apis,
|
|
103
|
-
(api) => generateApi(run,
|
|
124
|
+
(api) => generateApi(run, apiRun, apiTarget(api, configRoot))
|
|
104
125
|
);
|
|
105
126
|
const generated = results.flatMap(
|
|
106
127
|
(result) => result.status === "fulfilled" ? [result.value] : []
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redocly-apis.mjs","sources":["../../src/cli/redocly-apis.ts"],"sourcesContent":["import type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport type { GeneratorOptions } from \"../types.js\";\nimport {\n type ApiSettings,\n apiFixNames,\n apiFlags,\n apiOutputOf,\n apiRefLimitOptions,\n OUTPUT_SETTING,\n unknownSettingWarnings,\n} from \"./api-settings.js\";\nimport { type GeneratedApi, writeGeneratedApis } from \"./api-writes.js\";\nimport { cliError } from \"./cli-errors.js\";\nimport {\n type CliRun,\n ensureOutputIsNotSchema,\n ensureOutputIsOwn,\n filesReadBy,\n type NamedFile,\n outputFileOf,\n parseLocationUrl,\n redoclyConfigFiles,\n resolveLocationUrl,\n} from \"./cli-output.js\";\nimport { MULTIPLE_SCHEMAS_DOCS_URL } from \"./docs-links.js\";\nimport { fixOption } from \"./fix-option.js\";\nimport { refLimitOptions } from \"./ref-limits.js\";\n\n/** The `apis` of a Redocly config: each API is generated into its `x-openapi-ts.output`. */\n\n/** The key of an API's openapi-typesafe settings in `redocly.yaml`. */\nconst REDOCLY_CONFIG_KEY = \"x-openapi-ts\";\n\n/** An API of the config as written: `root` and the settings are not checked yet. */\ninterface RedoclyApi {\n readonly name: string;\n readonly root: unknown;\n readonly settings: unknown;\n}\n\nfunction redoclyApisOf(redocly: RedoclyConfig): RedoclyApi[] {\n return Object.entries(redocly.apis ?? {}).map(([name, api]) => {\n const fields = api as Readonly<Record<string, unknown>>;\n return { name, root: fields.root, settings: fields[REDOCLY_CONFIG_KEY] };\n });\n}\n\nexport function hasRedoclyApis(redocly: RedoclyConfig): boolean {\n return Object.keys(redocly.apis ?? {}).length > 0;\n}\n\n/** Paths in the config are relative to the config file; without a file, to the working dir. */\nfunction configRootOf(redocly: RedoclyConfig, cwd: URL): URL {\n return redocly.configFile ? resolveLocationUrl(redocly.configFile, cwd) : cwd;\n}\n\n/** An API whose root and settings are usable, and the directory its paths are relative to. */\ninterface ApiTarget {\n readonly name: string;\n readonly root: string;\n readonly settings: ApiSettings;\n readonly configRoot: URL;\n}\n\nfunction isSettingsMap(value: unknown): value is ApiSettings {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * The API with its settings. Fails with `CLI_CONFIG_OUTPUT_MISSING` when they name no output, and\n * with `CLI_CONFIG_INVALID` when they are no map or `root` is no path or URL; only this API then\n * fails, the others are still generated.\n */\nfunction apiTarget(api: RedoclyApi, configRoot: URL): ApiTarget {\n const { name, root, settings } = api;\n if (settings !== undefined && !isSettingsMap(settings)) {\n throw cliError(\"CLI_CONFIG_INVALID\", `API ${name}: \\`${REDOCLY_CONFIG_KEY}\\` must be a map`);\n }\n if (!settings?.[OUTPUT_SETTING]) {\n throw cliError(\n \"CLI_CONFIG_OUTPUT_MISSING\",\n `API ${name} is missing an \\`${REDOCLY_CONFIG_KEY}.output\\` key. ` +\n `See ${MULTIPLE_SCHEMAS_DOCS_URL}`,\n );\n }\n if (typeof root !== \"string\" || root === \"\") {\n throw cliError(\n \"CLI_CONFIG_INVALID\",\n `API ${name}: \\`root\\` in redocly.yaml must be the path or URL of its schema`,\n );\n }\n return { name, root, settings, configRoot };\n}\n\n/** The generator options of one API: its own settings win over the CLI's flags. */\nfunction apiOptions(run: CliRun, redocly: RedoclyConfig, target: ApiTarget): GeneratorOptions {\n const { name, settings, configRoot } = target;\n return {\n ...run.args.generatorFlags,\n ...apiFlags(name, settings),\n ...refLimitOptions(run.args, run.deps.cwd),\n ...apiRefLimitOptions(name, settings, configRoot),\n ...fixOption(apiFixNames(name, settings) ?? run.args.fix),\n redocly,\n };\n}\n\n/** The schemas and outputs of every API of the config, keyed by API name for the outputs. */\ninterface ConfigFiles {\n readonly schemas: readonly NamedFile[];\n readonly outputs: ReadonlyMap<string, URL>;\n}\n\n/** The outputs of the other APIs, as `ensureOutputIsOwn` names them. */\nfunction otherOutputs(files: ConfigFiles, apiName: string): NamedFile[] {\n return [...files.outputs]\n .filter(([name]) => name !== apiName)\n .map(([name, location]) => ({ name: `API ${name}`, location }));\n}\n\n/**\n * Generate the types of one API. Its output must not be a file the run reads before any API is\n * loaded (the root of any API, the Redocly config) nor another API's output.\n */\nasync function generateApi(\n run: CliRun,\n redocly: RedoclyConfig,\n target: ApiTarget,\n files: ConfigFiles,\n): Promise<GeneratedApi> {\n for (const warning of unknownSettingWarnings(target.name, target.settings)) {\n run.deps.logger.warn(warning);\n }\n const output = apiOutputOf(target.name, target.settings);\n const outputFile = outputFileOf(run, { source: target.name, output }, target.configRoot);\n ensureOutputIsNotSchema(run, outputFile, files.schemas);\n ensureOutputIsOwn(run, outputFile, otherOutputs(files, target.name));\n const source = resolveLocationUrl(target.root, target.configRoot);\n const types = await run.deps.generate(source, apiOptions(run, redocly, target));\n return { name: target.name, outputFile, types };\n}\n\n/**\n * The schema and the output of every API, and the config file itself. A location that is no\n * text or no valid URL is left out: it is no file that an output could be, and its own API fails\n * on it, not every API.\n */\nfunction configFilesOf(run: CliRun, redocly: RedoclyConfig, apis: readonly RedoclyApi[]) {\n const configRoot = configRootOf(redocly, run.deps.cwd);\n const roots = apis.flatMap(({ name, root }) => {\n const location = typeof root === \"string\" ? parseLocationUrl(root, configRoot) : undefined;\n return location ? [{ name: `schema ${root} of API ${name}`, location }] : [];\n });\n const outputs = new Map<string, URL>();\n for (const api of apis) {\n const output = isSettingsMap(api.settings) ? api.settings[OUTPUT_SETTING] : undefined;\n const location = typeof output === \"string\" ? parseLocationUrl(output, configRoot) : undefined;\n if (location) {\n outputs.set(api.name, location);\n }\n }\n const schemas = [...roots, ...redoclyConfigFiles(run, redocly)];\n return { configRoot, files: { schemas, outputs } satisfies ConfigFiles };\n}\n\n/** What `task` gives for each item, run one after another: the next starts when one settles. */\nasync function settledInTurn<T, R>(\n items: readonly T[],\n task: (item: T) => Promise<R>,\n): Promise<PromiseSettledResult<R>[]> {\n const results: PromiseSettledResult<R>[] = [];\n for (const item of items) {\n try {\n results.push({ status: \"fulfilled\", value: await task(item) });\n } catch (reason) {\n results.push({ status: \"rejected\", reason });\n }\n }\n return results;\n}\n\n/**\n * Generate every API of the config, one after another in the order of the config, then write\n * them. One at a time, so a run takes the memory of its largest API, not the sum of all of them,\n * and the work of one API cannot hold up the fetches of another until their timeout ends them.\n * Nothing is written until every API is read and every output is claimed, so no output can\n * replace a file that another API still reads; an output that is a file any API read (a `$ref`'d\n * schema) fails with `CLI_OUTPUT_IS_INPUT`. Every API is generated or checked even when another\n * fails, so `--check` reports a stale output wherever it is; the failures are returned in the\n * order of the config.\n */\nexport async function generateRedoclyApis(run: CliRun, redocly: RedoclyConfig): Promise<unknown[]> {\n const apis = redoclyApisOf(redocly);\n const { configRoot, files } = configFilesOf(run, redocly, apis);\n const results = await settledInTurn(apis, (api) =>\n generateApi(run, redocly, apiTarget(api, configRoot), files),\n );\n const generated = results.flatMap((result) =>\n result.status === \"fulfilled\" ? [result.value] : [],\n );\n const readFiles = generated.flatMap(({ name, types }) => filesReadBy(run, types, `API ${name}`));\n const writeFailures = writeGeneratedApis(run, generated, readFiles);\n return results.flatMap((result) =>\n result.status === \"rejected\" ? [result.reason] : (writeFailures.get(result.value.name) ?? []),\n );\n}\n"],"names":[],"mappings":";;;;;;;;AA+BA,MAAM,kBAAA,GAAqB,cAAA;AAS3B,SAAS,cAAc,OAAA,EAAsC;AAC3D,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,OAAA,CAAQ,IAAA,IAAQ,EAAE,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,GAAG,CAAA,KAAM;AAC7D,IAAA,MAAM,MAAA,GAAS,GAAA;AACf,IAAA,OAAO,EAAE,MAAM,IAAA,EAAM,MAAA,CAAO,MAAM,QAAA,EAAU,MAAA,CAAO,kBAAkB,CAAA,EAAE;AAAA,EACzE,CAAC,CAAA;AACH;AAEO,SAAS,eAAe,OAAA,EAAiC;AAC9D,EAAA,OAAO,OAAO,IAAA,CAAK,OAAA,CAAQ,QAAQ,EAAE,EAAE,MAAA,GAAS,CAAA;AAClD;AAGA,SAAS,YAAA,CAAa,SAAwB,GAAA,EAAe;AAC3D,EAAA,OAAO,QAAQ,UAAA,GAAa,kBAAA,CAAmB,OAAA,CAAQ,UAAA,EAAY,GAAG,CAAA,GAAI,GAAA;A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AAA;AAC/F,EAAA,MAAM,aAAA,GAAgB,kBAAA,CAAmB,GAAA,EAAK,SAAA,EAAW,SAAS,CAAA;AAClE,EAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,IAAQ,CAAC,MAAA,KACtB,MAAA,CAAO,MAAA,KAAW,aAAa,CAAC,MAAA,CAAO,MAAM,CAAA,GAAK,cAAc,GAAA,CAAI,MAAA,CAAO,KAAA,CAAM,IAAI,KAAK;AAAC,GAC7F;AACF;;"}
|
|
1
|
+
{"version":3,"file":"redocly-apis.mjs","sources":["../../src/cli/redocly-apis.ts"],"sourcesContent":["import type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport type { GeneratorOptions } from \"../types.js\";\nimport {\n type ApiSettings,\n apiFixNames,\n apiFlags,\n apiOutputOf,\n apiRefLimitOptions,\n OUTPUT_SETTING,\n unknownSettingWarnings,\n} from \"./api-settings.js\";\nimport { type GeneratedApi, writeGeneratedApis } from \"./api-writes.js\";\nimport { ineffectiveFlagNotices } from \"./cli-arguments.js\";\nimport { ApiFailure, cliError } from \"./cli-errors.js\";\nimport {\n type CliRun,\n ensureOutputIsNotSchema,\n ensureOutputIsOwn,\n filesReadBy,\n type NamedFile,\n outputFileOf,\n parseLocationUrl,\n redoclyConfigFiles,\n resolveLocationUrl,\n} from \"./cli-output.js\";\nimport { MULTIPLE_SCHEMAS_DOCS_URL } from \"./docs-links.js\";\nimport { fixOption } from \"./fix-option.js\";\nimport { type RefLimitOptions, refLimitOptions } from \"./ref-limits.js\";\n\n/** The `apis` of a Redocly config: each API is generated into its `x-openapi-ts.output`. */\n\n/** The key of an API's openapi-typesafe settings in `redocly.yaml`. */\nconst REDOCLY_CONFIG_KEY = \"x-openapi-ts\";\n\n/** An API of the config as written: `root` and the settings are not checked yet. */\ninterface RedoclyApi {\n readonly name: string;\n readonly root: unknown;\n readonly settings: unknown;\n}\n\nfunction redoclyApisOf(redocly: RedoclyConfig): RedoclyApi[] {\n return Object.entries(redocly.apis ?? {}).map(([name, api]) => {\n const fields = api as Readonly<Record<string, unknown>>;\n return { name, root: fields.root, settings: fields[REDOCLY_CONFIG_KEY] };\n });\n}\n\nexport function hasRedoclyApis(redocly: RedoclyConfig): boolean {\n return Object.keys(redocly.apis ?? {}).length > 0;\n}\n\n/** Paths in the config are relative to the config file; without a file, to the working dir. */\nfunction configRootOf(redocly: RedoclyConfig, cwd: URL): URL {\n return redocly.configFile ? resolveLocationUrl(redocly.configFile, cwd) : cwd;\n}\n\n/** An API whose root and settings are usable, and the directory its paths are relative to. */\ninterface ApiTarget {\n readonly name: string;\n readonly root: string;\n readonly settings: ApiSettings;\n readonly configRoot: URL;\n}\n\nfunction isSettingsMap(value: unknown): value is ApiSettings {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * The API with its settings. Fails with `CLI_CONFIG_OUTPUT_MISSING` when they name no output, and\n * with `CLI_CONFIG_INVALID` when they are no map or `root` is no path or URL; only this API then\n * fails, the others are still generated.\n */\nfunction apiTarget(api: RedoclyApi, configRoot: URL): ApiTarget {\n const { name, root, settings } = api;\n if (settings !== undefined && !isSettingsMap(settings)) {\n throw cliError(\"CLI_CONFIG_INVALID\", `API ${name}: \\`${REDOCLY_CONFIG_KEY}\\` must be a map`);\n }\n if (!settings?.[OUTPUT_SETTING]) {\n throw cliError(\n \"CLI_CONFIG_OUTPUT_MISSING\",\n `API ${name} is missing an \\`${REDOCLY_CONFIG_KEY}.output\\` key. ` +\n `See ${MULTIPLE_SCHEMAS_DOCS_URL}`,\n );\n }\n if (typeof root !== \"string\" || root === \"\") {\n throw cliError(\n \"CLI_CONFIG_INVALID\",\n `API ${name}: \\`root\\` in redocly.yaml must be the path or URL of its schema`,\n );\n }\n return { name, root, settings, configRoot };\n}\n\n/**\n * What every API of a run shares: the config, the files of all APIs, and the reference limits of\n * the command line, which are checked once before any API, so an invalid flag fails the run once.\n */\ninterface ApiRun {\n readonly redocly: RedoclyConfig;\n readonly files: ConfigFiles;\n readonly refLimits: RefLimitOptions;\n}\n\n/**\n * The generator options of one API: its own settings win over the CLI's flags, and its own lint\n * rules in `redocly.yaml` over the root's (upstream used the root's only). A flag that has\n * no effect with the merged flags is named for this API, since its settings may turn on the flag\n * that the command line lacks, or set one that has no effect themselves.\n */\nfunction apiOptions(run: CliRun, apiRun: ApiRun, target: ApiTarget): GeneratorOptions {\n const { name, settings, configRoot } = target;\n const flags = { ...run.args.generatorFlags, ...apiFlags(name, settings) };\n for (const notice of ineffectiveFlagNotices(flags)) {\n run.deps.console.notice(`API ${name}: ${notice}`);\n }\n return {\n ...flags,\n ...apiRun.refLimits,\n ...apiRefLimitOptions(name, settings, configRoot),\n ...fixOption(apiFixNames(name, settings) ?? run.args.fix),\n redocly: run.deps.redoclyConfigs.forApi(apiRun.redocly, name),\n };\n}\n\n/** The schemas and outputs of every API of the config, keyed by API name for the outputs. */\ninterface ConfigFiles {\n readonly schemas: readonly NamedFile[];\n readonly outputs: ReadonlyMap<string, URL>;\n}\n\n/** The outputs of the other APIs, as `ensureOutputIsOwn` names them. */\nfunction otherOutputs(files: ConfigFiles, apiName: string): NamedFile[] {\n return [...files.outputs]\n .filter(([name]) => name !== apiName)\n .map(([name, location]) => ({ name: `API ${name}`, location }));\n}\n\n/**\n * Generate the types of one API. Its output must not be a file the run reads before any API is\n * loaded (the root of any API, the Redocly config) nor another API's output.\n */\nasync function generateApi(run: CliRun, apiRun: ApiRun, target: ApiTarget): Promise<GeneratedApi> {\n const { files } = apiRun;\n for (const warning of unknownSettingWarnings(target.name, target.settings)) {\n run.deps.logger.warn(warning);\n }\n const output = apiOutputOf(target.name, target.settings);\n const outputFile = failingAsApi(target.name, () => {\n const file = outputFileOf(run, { source: target.name, output }, target.configRoot);\n ensureOutputIsNotSchema(run, file, files.schemas);\n ensureOutputIsOwn(run, file, otherOutputs(files, target.name));\n return file;\n });\n const source = resolveLocationUrl(target.root, target.configRoot);\n const options = apiOptions(run, apiRun, target);\n try {\n const types = await run.deps.generate(source, options, target.name);\n return { name: target.name, outputFile, types };\n } catch (error) {\n throw new ApiFailure(target.name, error);\n }\n}\n\n/**\n * The result of a step of one API, whose failure is reported with the API's name. Errors of an\n * API's settings name the API in their own message and are not wrapped.\n */\nfunction failingAsApi<T>(apiName: string, step: () => T): T {\n try {\n return step();\n } catch (error) {\n throw new ApiFailure(apiName, error);\n }\n}\n\n/**\n * The schema and the output of every API, and the config file itself. A location that is no\n * text or no valid URL is left out: it is no file that an output could be, and its own API fails\n * on it, not every API.\n */\nfunction configFilesOf(run: CliRun, redocly: RedoclyConfig, apis: readonly RedoclyApi[]) {\n const configRoot = configRootOf(redocly, run.deps.cwd);\n const roots = apis.flatMap(({ name, root }) => {\n const location = typeof root === \"string\" ? parseLocationUrl(root, configRoot) : undefined;\n return location ? [{ name: `schema ${root} of API ${name}`, location }] : [];\n });\n const outputs = new Map<string, URL>();\n for (const api of apis) {\n const output = isSettingsMap(api.settings) ? api.settings[OUTPUT_SETTING] : undefined;\n const location = typeof output === \"string\" ? parseLocationUrl(output, configRoot) : undefined;\n if (location) {\n outputs.set(api.name, location);\n }\n }\n const schemas = [...roots, ...redoclyConfigFiles(run, redocly)];\n return { configRoot, files: { schemas, outputs } satisfies ConfigFiles };\n}\n\n/** What `task` gives for each item, run one after another: the next starts when one settles. */\nasync function settledInTurn<T, R>(\n items: readonly T[],\n task: (item: T) => Promise<R>,\n): Promise<PromiseSettledResult<R>[]> {\n const results: PromiseSettledResult<R>[] = [];\n for (const item of items) {\n try {\n results.push({ status: \"fulfilled\", value: await task(item) });\n } catch (reason) {\n results.push({ status: \"rejected\", reason });\n }\n }\n return results;\n}\n\n/**\n * Generate every API of the config, one after another in the order of the config, then write\n * them. One at a time, so a run takes the memory of its largest API, not the sum of all of them,\n * and the work of one API cannot hold up the fetches of another until their timeout ends them.\n * Nothing is written until every API is read and every output is claimed, so no output can\n * replace a file that another API still reads; an output that is a file any API read (a `$ref`'d\n * schema) fails with `CLI_OUTPUT_IS_INPUT`. Every API is generated or checked even when another\n * fails, so `--check` reports a stale output wherever it is; the failures are returned in the\n * order of the config.\n */\nexport async function generateRedoclyApis(run: CliRun, redocly: RedoclyConfig): Promise<unknown[]> {\n const apis = redoclyApisOf(redocly);\n const { configRoot, files } = configFilesOf(run, redocly, apis);\n const apiRun = { redocly, files, refLimits: refLimitOptions(run.args, run.deps.cwd) };\n const results = await settledInTurn(apis, (api) =>\n generateApi(run, apiRun, apiTarget(api, configRoot)),\n );\n const generated = results.flatMap((result) =>\n result.status === \"fulfilled\" ? [result.value] : [],\n );\n const readFiles = generated.flatMap(({ name, types }) => filesReadBy(run, types, `API ${name}`));\n const writeFailures = writeGeneratedApis(run, generated, readFiles);\n return results.flatMap((result) =>\n result.status === \"rejected\" ? [result.reason] : (writeFailures.get(result.value.name) ?? []),\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAgCA,MAAM,kBAAA,GAAqB,cAAA;AAS3B,SAAS,cAAc,OAAA,EAAsC;AAC3D,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,OAAA,CAAQ,IAAA,IAAQ,EAAE,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,GAAG,CAAA,KAAM;AAC7D,IAAA,MAAM,MAAA,GAAS,GAAA;AACf,IAAA,OAAO,EAAE,MAAM,IAAA,EAAM,MAAA,CAAO,MAAM,QAAA,EAAU,MAAA,CAAO,kBAAkB,CAAA,EAAE;AAAA,EACzE,CAAC,CAAA;AACH;AAEO,SAAS,eAAe,OAAA,EAAiC;AAC9D,EAAA,OAAO,OAAO,IAAA,CAAK,OAAA,CAAQ,QAAQ,EAAE,EAAE,MAAA,GAAS,CAAA;AAClD;AAGA,SAAS,YAAA,CAAa,SAAwB,GAAA,EAAe;AAC3D,EAAA,OAAO,QAAQ,UAAA,GAAa,kBAAA,CAAmB,OAAA,CAAQ,UAAA,EAAY,GAAG,CAAA,GAAI,GAAA;AAC5E;AAUA,SAAS,cAAc,KAAA,EAAsC;AAC3D,EAAA,OAAO,OA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@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const cliErrors = require('./cli-errors.cjs');
|
|
3
4
|
const cliOutput = require('./cli-output.cjs');
|
|
4
5
|
|
|
6
|
+
const FILE_PROTOCOL = "file:";
|
|
7
|
+
function localRootUrl(location, base) {
|
|
8
|
+
const url = cliOutput.resolveLocationUrl(location, base);
|
|
9
|
+
return url.protocol === FILE_PROTOCOL ? url : void 0;
|
|
10
|
+
}
|
|
5
11
|
function refLimitOptions(args, cwd) {
|
|
6
12
|
const { localRefRoot, remoteRefHosts } = args.refLimits;
|
|
13
|
+
const localRoot = localRefRoot === void 0 ? void 0 : localRootUrl(localRefRoot, cwd);
|
|
14
|
+
if (localRefRoot !== void 0 && localRoot === void 0) {
|
|
15
|
+
throw cliErrors.cliError(
|
|
16
|
+
"CLI_FLAG_INVALID",
|
|
17
|
+
`--local-ref-root ${localRefRoot}: a directory path or a file: URL.`
|
|
18
|
+
);
|
|
19
|
+
}
|
|
7
20
|
return {
|
|
8
|
-
...
|
|
21
|
+
...localRoot === void 0 ? {} : { localRefRoot: localRoot },
|
|
9
22
|
...remoteRefHosts === void 0 ? {} : { remoteRefHosts }
|
|
10
23
|
};
|
|
11
24
|
}
|
|
12
25
|
|
|
26
|
+
exports.localRootUrl = localRootUrl;
|
|
13
27
|
exports.refLimitOptions = refLimitOptions;
|
|
14
28
|
//# sourceMappingURL=ref-limits.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref-limits.cjs","sources":["../../src/cli/ref-limits.ts"],"sourcesContent":["import type { GeneratorOptions } from \"../types.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport { resolveLocationUrl } from \"./cli-output.js\";\n\n/** The `$ref` limits of the CLI flags as generator options (threat model R1, R2, ADR-017). */\n\nexport type RefLimitOptions = Pick<GeneratorOptions, \"localRefRoot\" | \"remoteRefHosts\">;\n\n/** `--local-ref-root` resolves against the working directory, like every other CLI path. */\nexport function refLimitOptions(args: CliArguments, cwd: URL): RefLimitOptions {\n const { localRefRoot, remoteRefHosts } = args.refLimits;\n return {\n ...(
|
|
1
|
+
{"version":3,"file":"ref-limits.cjs","sources":["../../src/cli/ref-limits.ts"],"sourcesContent":["import type { GeneratorOptions } from \"../types.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport { cliError } from \"./cli-errors.js\";\nimport { resolveLocationUrl } from \"./cli-output.js\";\n\n/** The `$ref` limits of the CLI flags as generator options (threat model R1, R2, ADR-017). */\n\nexport type RefLimitOptions = Pick<GeneratorOptions, \"localRefRoot\" | \"remoteRefHosts\">;\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** A local `$ref` root as a URL; undefined for a URL of another protocol, which names no folder. */\nexport function localRootUrl(location: string, base: URL): URL | undefined {\n const url = resolveLocationUrl(location, base);\n return url.protocol === FILE_PROTOCOL ? url : undefined;\n}\n\n/**\n * `--local-ref-root` resolves against the working directory, like every other CLI path. A URL of\n * another protocol (`https://…`) fails with `CLI_FLAG_INVALID`.\n */\nexport function refLimitOptions(args: CliArguments, cwd: URL): RefLimitOptions {\n const { localRefRoot, remoteRefHosts } = args.refLimits;\n const localRoot = localRefRoot === undefined ? undefined : localRootUrl(localRefRoot, cwd);\n if (localRefRoot !== undefined && localRoot === undefined) {\n throw cliError(\n \"CLI_FLAG_INVALID\",\n `--local-ref-root ${localRefRoot}: a directory path or a file: URL.`,\n );\n }\n return {\n ...(localRoot === undefined ? {} : { localRefRoot: localRoot }),\n ...(remoteRefHosts === undefined ? {} : { remoteRefHosts }),\n };\n}\n"],"names":["resolveLocationUrl","cliError"],"mappings":";;;;;AASA,MAAM,aAAA,GAAgB,OAAA;AAGf,SAAS,YAAA,CAAa,UAAkB,IAAA,EAA4B;AACzE,EAAA,MAAM,GAAA,GAAMA,4BAAA,CAAmB,QAAA,EAAU,IAAI,CAAA;AAC7C,EAAA,OAAO,GAAA,CAAI,QAAA,KAAa,aAAA,GAAgB,GAAA,GAAM,MAAA;AAChD;AAMO,SAAS,eAAA,CAAgB,MAAoB,GAAA,EAA2B;AAC7E,EAAA,MAAM,EAAE,YAAA,EAAc,cAAA,EAAe,GAAI,IAAA,CAAK,SAAA;AAC9C,EAAA,MAAM,YAAY,YAAA,KAAiB,MAAA,GAAY,MAAA,GAAY,YAAA,CAAa,cAAc,GAAG,CAAA;AACzF,EAAA,IAAI,YAAA,KAAiB,MAAA,IAAa,SAAA,KAAc,MAAA,EAAW;AACzD,IAAA,MAAMC,kBAAA;AAAA,MACJ,kBAAA;AAAA,MACA,oBAAoB,YAAY,CAAA,kCAAA;AAAA,KAClC;AAAA,EACF;AACA,EAAA,OAAO;AAAA,IACL,GAAI,SAAA,KAAc,MAAA,GAAY,EAAC,GAAI,EAAE,cAAc,SAAA,EAAU;AAAA,IAC7D,GAAI,cAAA,KAAmB,MAAA,GAAY,EAAC,GAAI,EAAE,cAAA;AAAe,GAC3D;AACF;;;"}
|
package/dist/cli/ref-limits.mjs
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
|
+
import { cliError } from './cli-errors.mjs';
|
|
1
2
|
import { resolveLocationUrl } from './cli-output.mjs';
|
|
2
3
|
|
|
4
|
+
const FILE_PROTOCOL = "file:";
|
|
5
|
+
function localRootUrl(location, base) {
|
|
6
|
+
const url = resolveLocationUrl(location, base);
|
|
7
|
+
return url.protocol === FILE_PROTOCOL ? url : void 0;
|
|
8
|
+
}
|
|
3
9
|
function refLimitOptions(args, cwd) {
|
|
4
10
|
const { localRefRoot, remoteRefHosts } = args.refLimits;
|
|
11
|
+
const localRoot = localRefRoot === void 0 ? void 0 : localRootUrl(localRefRoot, cwd);
|
|
12
|
+
if (localRefRoot !== void 0 && localRoot === void 0) {
|
|
13
|
+
throw cliError(
|
|
14
|
+
"CLI_FLAG_INVALID",
|
|
15
|
+
`--local-ref-root ${localRefRoot}: a directory path or a file: URL.`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
5
18
|
return {
|
|
6
|
-
...
|
|
19
|
+
...localRoot === void 0 ? {} : { localRefRoot: localRoot },
|
|
7
20
|
...remoteRefHosts === void 0 ? {} : { remoteRefHosts }
|
|
8
21
|
};
|
|
9
22
|
}
|
|
10
23
|
|
|
11
|
-
export { refLimitOptions };
|
|
24
|
+
export { localRootUrl, refLimitOptions };
|
|
12
25
|
//# sourceMappingURL=ref-limits.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref-limits.mjs","sources":["../../src/cli/ref-limits.ts"],"sourcesContent":["import type { GeneratorOptions } from \"../types.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport { resolveLocationUrl } from \"./cli-output.js\";\n\n/** The `$ref` limits of the CLI flags as generator options (threat model R1, R2, ADR-017). */\n\nexport type RefLimitOptions = Pick<GeneratorOptions, \"localRefRoot\" | \"remoteRefHosts\">;\n\n/** `--local-ref-root` resolves against the working directory, like every other CLI path. */\nexport function refLimitOptions(args: CliArguments, cwd: URL): RefLimitOptions {\n const { localRefRoot, remoteRefHosts } = args.refLimits;\n return {\n ...(
|
|
1
|
+
{"version":3,"file":"ref-limits.mjs","sources":["../../src/cli/ref-limits.ts"],"sourcesContent":["import type { GeneratorOptions } from \"../types.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport { cliError } from \"./cli-errors.js\";\nimport { resolveLocationUrl } from \"./cli-output.js\";\n\n/** The `$ref` limits of the CLI flags as generator options (threat model R1, R2, ADR-017). */\n\nexport type RefLimitOptions = Pick<GeneratorOptions, \"localRefRoot\" | \"remoteRefHosts\">;\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** A local `$ref` root as a URL; undefined for a URL of another protocol, which names no folder. */\nexport function localRootUrl(location: string, base: URL): URL | undefined {\n const url = resolveLocationUrl(location, base);\n return url.protocol === FILE_PROTOCOL ? url : undefined;\n}\n\n/**\n * `--local-ref-root` resolves against the working directory, like every other CLI path. A URL of\n * another protocol (`https://…`) fails with `CLI_FLAG_INVALID`.\n */\nexport function refLimitOptions(args: CliArguments, cwd: URL): RefLimitOptions {\n const { localRefRoot, remoteRefHosts } = args.refLimits;\n const localRoot = localRefRoot === undefined ? undefined : localRootUrl(localRefRoot, cwd);\n if (localRefRoot !== undefined && localRoot === undefined) {\n throw cliError(\n \"CLI_FLAG_INVALID\",\n `--local-ref-root ${localRefRoot}: a directory path or a file: URL.`,\n );\n }\n return {\n ...(localRoot === undefined ? {} : { localRefRoot: localRoot }),\n ...(remoteRefHosts === undefined ? {} : { remoteRefHosts }),\n };\n}\n"],"names":[],"mappings":";;;AASA,MAAM,aAAA,GAAgB,OAAA;AAGf,SAAS,YAAA,CAAa,UAAkB,IAAA,EAA4B;AACzE,EAAA,MAAM,GAAA,GAAM,kBAAA,CAAmB,QAAA,EAAU,IAAI,CAAA;AAC7C,EAAA,OAAO,GAAA,CAAI,QAAA,KAAa,aAAA,GAAgB,GAAA,GAAM,MAAA;AAChD;AAMO,SAAS,eAAA,CAAgB,MAAoB,GAAA,EAA2B;AAC7E,EAAA,MAAM,EAAE,YAAA,EAAc,cAAA,EAAe,GAAI,IAAA,CAAK,SAAA;AAC9C,EAAA,MAAM,YAAY,YAAA,KAAiB,MAAA,GAAY,MAAA,GAAY,YAAA,CAAa,cAAc,GAAG,CAAA;AACzF,EAAA,IAAI,YAAA,KAAiB,MAAA,IAAa,SAAA,KAAc,MAAA,EAAW;AACzD,IAAA,MAAM,QAAA;AAAA,MACJ,kBAAA;AAAA,MACA,oBAAoB,YAAY,CAAA,kCAAA;AAAA,KAClC;AAAA,EACF;AACA,EAAA,OAAO;AAAA,IACL,GAAI,SAAA,KAAc,MAAA,GAAY,EAAC,GAAI,EAAE,cAAc,SAAA,EAAU;AAAA,IAC7D,GAAI,cAAA,KAAmB,MAAA,GAAY,EAAC,GAAI,EAAE,cAAA;AAAe,GAC3D;AACF;;"}
|
package/dist/cli/run-cli.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const locationText = require('../domain/location-text.cjs');
|
|
3
4
|
const warnings = require('../domain/warnings.cjs');
|
|
4
5
|
const cliArguments = require('./cli-arguments.cjs');
|
|
5
6
|
const cliErrors = require('./cli-errors.cjs');
|
|
@@ -32,9 +33,13 @@ function schemaSource(run) {
|
|
|
32
33
|
}
|
|
33
34
|
return run.deps.stdin();
|
|
34
35
|
}
|
|
36
|
+
const GLOB_WILDCARD = "*";
|
|
37
|
+
function isGlobPattern(run, input) {
|
|
38
|
+
return input.includes(GLOB_WILDCARD) && !locationText.hasUrlScheme(input) && !run.deps.files.isFile(cliOutput.resolveLocationUrl(input, run.deps.cwd));
|
|
39
|
+
}
|
|
35
40
|
async function generateSingleSchema(run, redocly) {
|
|
36
41
|
const { input, output } = run.args;
|
|
37
|
-
if (input
|
|
42
|
+
if (input !== void 0 && isGlobPattern(run, input)) {
|
|
38
43
|
throw cliErrors.cliError(
|
|
39
44
|
"CLI_GLOB_UNSUPPORTED",
|
|
40
45
|
`Globbing has been deprecated in favor of redocly.yaml\u2019s \`apis\` keys. See ${docsLinks.MULTIPLE_SCHEMAS_DOCS_URL}`
|
|
@@ -46,6 +51,9 @@ async function generateSingleSchema(run, redocly) {
|
|
|
46
51
|
"--check needs the generated file to compare with: add --output <file>."
|
|
47
52
|
);
|
|
48
53
|
}
|
|
54
|
+
for (const notice of cliArguments.ineffectiveFlagNotices(run.args.generatorFlags)) {
|
|
55
|
+
run.deps.console.notice(notice);
|
|
56
|
+
}
|
|
49
57
|
const source = schemaSource(run);
|
|
50
58
|
const outputFile = output ? singleOutputFile(run, output, source, redocly) : void 0;
|
|
51
59
|
const options = {
|
|
@@ -74,21 +82,30 @@ async function generate(run) {
|
|
|
74
82
|
await generateSingleSchema(run, redocly);
|
|
75
83
|
return [];
|
|
76
84
|
}
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
warnAboutIgnoredArguments(run);
|
|
86
|
+
return redoclyApis.generateRedoclyApis(run, redocly);
|
|
87
|
+
}
|
|
88
|
+
function warnAboutIgnoredArguments(run) {
|
|
89
|
+
const { args, deps } = run;
|
|
90
|
+
if (args.input) {
|
|
91
|
+
deps.logger.warn(
|
|
79
92
|
warnings.warningText(
|
|
80
93
|
"APIs are specified both in Redocly Config and CLI argument. Only using Redocly config.",
|
|
81
94
|
warnings.WARNING_CODES.CLI_INPUT_IGNORED
|
|
82
95
|
)
|
|
83
96
|
);
|
|
84
97
|
}
|
|
85
|
-
|
|
98
|
+
if (args.output) {
|
|
99
|
+
deps.logger.warn(
|
|
100
|
+
warnings.warningText(
|
|
101
|
+
`APIs are specified in Redocly Config, so --output ${args.output} is ignored: each API is written to its x-openapi-ts.output.`,
|
|
102
|
+
warnings.WARNING_CODES.CLI_OUTPUT_IGNORED
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
86
106
|
}
|
|
87
107
|
async function runCommand(argv, deps) {
|
|
88
108
|
const startedAt = deps.now();
|
|
89
|
-
for (const notice of cliArguments.ineffectiveFlagNotices(argv)) {
|
|
90
|
-
deps.console.notice(notice);
|
|
91
|
-
}
|
|
92
109
|
const args = cliArguments.parseCliArguments(argv);
|
|
93
110
|
for (const flag of args.unknownFlags) {
|
|
94
111
|
deps.console.notice(`Unknown flag ${flag} is ignored (see --help)`);
|
package/dist/cli/run-cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-cli.cjs","sources":["../../src/cli/run-cli.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\nimport type { SchemaSource } from \"../types.js\";\nimport { ineffectiveFlagNotices, parseCliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies } from \"./cli-dependencies.js\";\nimport { cliError, describeCliFailure, EXIT_CODES, type ExitCode } from \"./cli-errors.js\";\nimport {\n type CliRun,\n ensureOutputIsNotSchema,\n filesReadBy,\n type OutputFile,\n outputFileOf,\n redoclyConfigFiles,\n resolveLocationUrl,\n writeOutput,\n} from \"./cli-output.js\";\nimport { MULTIPLE_SCHEMAS_DOCS_URL } from \"./docs-links.js\";\nimport { fixOption } from \"./fix-option.js\";\nimport { HELP_TEXT } from \"./help-text.js\";\nimport { generateRedoclyApis, hasRedoclyApis } from \"./redocly-apis.js\";\nimport { refLimitOptions } from \"./ref-limits.js\";\n\n/**\n * The CLI's use case: parse the arguments, then generate the APIs of the Redocly config, one\n * schema file or URL, or stdin. It has no process access of its own; `main.ts` wires it (ADR-012).\n */\n\nasync function loadRedoclyConfig(run: CliRun): Promise<RedoclyConfig> {\n const { redoclyConfigs } = run.deps;\n const explicitPath = run.args.redocly;\n const configPath = redoclyConfigs.find(explicitPath);\n if (explicitPath && !configPath) {\n throw cliError(\"CLI_CONFIG_NOT_FOUND\", `Redocly config not found at: ${explicitPath}`);\n }\n return configPath ? redoclyConfigs.load(configPath) : redoclyConfigs.createDefault();\n}\n\n/** The schema's URL, or stdin when no path or URL is given and something is piped in. */\nfunction schemaSource(run: CliRun): SchemaSource {\n const { input } = run.args;\n if (input) {\n return resolveLocationUrl(input, run.deps.cwd);\n }\n if (run.deps.isStdinTerminal()) {\n throw cliError(\n \"CLI_INPUT_MISSING\",\n \"No schema given: pass a schema path or URL, pipe a schema into stdin, or define `apis` \" +\n \"in redocly.yaml. See --help.\",\n );\n }\n return run.deps.stdin();\n}\n\n/**\n * One schema from a path, a URL or stdin; without `--output`, the types go to stdout. Warnings and\n * errors go to stderr either way, so they never mix with the types (upstream dropped warnings).\n */\nasync function generateSingleSchema(run: CliRun, redocly: RedoclyConfig): Promise<void> {\n const { input, output } = run.args;\n if (input?.includes(\"*\")) {\n throw cliError(\n \"CLI_GLOB_UNSUPPORTED\",\n \"Globbing has been deprecated in favor of redocly.yaml’s `apis` keys. \" +\n `See ${MULTIPLE_SCHEMAS_DOCS_URL}`,\n );\n }\n if (run.args.isCheck && !output) {\n // Without a file there is nothing to compare: the original printed the types and passed.\n throw cliError(\n \"CLI_CHECK_OUTPUT_MISSING\",\n \"--check needs the generated file to compare with: add --output <file>.\",\n );\n }\n const source = schemaSource(run);\n const outputFile = output ? singleOutputFile(run, output, source, redocly) : undefined;\n const options = {\n ...run.args.generatorFlags,\n ...refLimitOptions(run.args, run.deps.cwd),\n ...fixOption(run.args.fix),\n redocly,\n };\n const types = await run.deps.generate(source, options);\n if (!outputFile) {\n run.deps.writeStdout(types.contents);\n return;\n }\n writeOutput(run, outputFile, types, filesReadBy(run, types, outputFile.source));\n}\n\n/**\n * The `--output` file; it must not be the schema file nor the Redocly config, which writing it\n * would replace.\n */\nfunction singleOutputFile(\n run: CliRun,\n output: string,\n source: SchemaSource,\n redocly: RedoclyConfig,\n): OutputFile {\n const { input } = run.args;\n const outputFile = outputFileOf(run, { source: input ?? \"stdin\", output }, run.deps.cwd);\n const schemas =\n input && source instanceof URL ? [{ name: `schema ${input}`, location: source }] : [];\n ensureOutputIsNotSchema(run, outputFile, [...schemas, ...redoclyConfigFiles(run, redocly)]);\n return outputFile;\n}\n\nasync function generate(run: CliRun): Promise<unknown[]> {\n const redocly = await loadRedoclyConfig(run);\n if (!hasRedoclyApis(redocly)) {\n await generateSingleSchema(run, redocly);\n return [];\n }\n if (run.args.input) {\n run.deps.logger.warn(\n warningText(\n \"APIs are specified both in Redocly Config and CLI argument. Only using Redocly config.\",\n WARNING_CODES.CLI_INPUT_IGNORED,\n ),\n );\n }\n return generateRedoclyApis(run, redocly);\n}\n\n/** Run the command; the failures it returns did not stop the other outputs. */\nasync function runCommand(argv: readonly string[], deps: CliDependencies): Promise<unknown[]> {\n const startedAt = deps.now();\n for (const notice of ineffectiveFlagNotices(argv)) {\n deps.console.notice(notice);\n }\n const args = parseCliArguments(argv);\n for (const flag of args.unknownFlags) {\n deps.console.notice(`Unknown flag ${flag} is ignored (see --help)`);\n }\n if (args.isHelp || args.isVersion) {\n deps.console.info(args.isHelp ? HELP_TEXT : `v${deps.version}`);\n return [];\n }\n if (args.output) {\n deps.console.info(`✨ ${deps.style.bold(`openapi-typesafe ${deps.version}`)}`);\n }\n return generate({ deps, args, startedAt });\n}\n\n/** Print one line per failure; the exit code is the first failure's (ADR-011). */\nfunction reportFailures(failures: readonly unknown[], logger: Logger): ExitCode {\n const reports = failures.map(describeCliFailure);\n for (const report of reports) {\n logger.error(report.message);\n }\n return reports[0]?.exitCode ?? EXIT_CODES.SUCCESS;\n}\n\n/** Run the CLI with the arguments after `node cli.js`, and return the process exit code. */\nexport async function runCli(argv: readonly string[], deps: CliDependencies): Promise<ExitCode> {\n let failures: unknown[];\n try {\n failures = await runCommand(argv, deps);\n } catch (thrown) {\n failures = [thrown];\n }\n return reportFailures(failures, deps.logger);\n}\n"],"names":["cliError","resolveLocationUrl","MULTIPLE_SCHEMAS_DOCS_URL","refLimitOptions","fixOption","writeOutput","filesReadBy","outputFileOf","ensureOutputIsNotSchema","redoclyConfigFiles","hasRedoclyApis","warningText","WARNING_CODES","generateRedoclyApis","ineffectiveFlagNotices","parseCliArguments","HELP_TEXT","describeCliFailure","EXIT_CODES"],"mappings":";;;;;;;;;;;;AA4BA,eAAe,kBAAkB,GAAA,EAAqC;AACpE,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,GAAA,CAAI,IAAA;AAC/B,EAAA,MAAM,YAAA,GAAe,IAAI,IAAA,CAAK,OAAA;AAC9B,EAAA,MAAM,UAAA,GAAa,cAAA,CAAe,IAAA,CAAK,YAAY,CAAA;AACnD,EAAA,IAAI,YAAA,IAAgB,CAAC,UAAA,EAAY;AAC/B,IAAA,MAAMA,kBAAA,CAAS,sBAAA,EAAwB,CAAA,6BAAA,EAAgC,YAAY,CAAA,CAAE,CAAA;AAAA,EACvF;AACA,EAAA,OAAO,aAAa,cAAA,CAAe,IAAA,CAAK,UAAU,CAAA,GAAI,eAAe,aAAA,EAAc;AACrF;AAGA,SAAS,aAAa,GAAA,EAA2B;AAC/C,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,GAAA,CAAI,IAAA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AC/C,EAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC5B,IAAA,MAAA,CAAO,KAAA,CAAM,OAAO,OAAO,CAAA;AAAA,EAC7B;AACA,EAAA,OAAO,OAAA,CAAQ,CAAC,CAAA,EAAG,QAAA,IAAYC,oBAAA,CAAW,OAAA;AAC5C;AAGA,eAAsB,MAAA,CAAO,MAAyB,IAAA,EAA0C;AAC9F,EAAA,IAAI,QAAA;AACJ,EAAA,IAAI;AACF,IAAA,QAAA,GAAW,MAAM,UAAA,CAAW,IAAA,EAAM,IAAI,CAAA;AAAA,EACxC,SAAS,MAAA,EAAQ;AACf,IAAA,QAAA,GAAW,CAAC,MAAM,CAAA;AAAA,EACpB;AACA,EAAA,OAAO,cAAA,CAAe,QAAA,EAAU,IAAA,CAAK,MAAM,CAAA;AAC7C;;"}
|
|
1
|
+
{"version":3,"file":"run-cli.cjs","sources":["../../src/cli/run-cli.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport { hasUrlScheme } from \"../domain/location-text.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\nimport type { SchemaSource } from \"../types.js\";\nimport { ineffectiveFlagNotices, parseCliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies } from \"./cli-dependencies.js\";\nimport { cliError, describeCliFailure, EXIT_CODES, type ExitCode } from \"./cli-errors.js\";\nimport {\n type CliRun,\n ensureOutputIsNotSchema,\n filesReadBy,\n type OutputFile,\n outputFileOf,\n redoclyConfigFiles,\n resolveLocationUrl,\n writeOutput,\n} from \"./cli-output.js\";\nimport { MULTIPLE_SCHEMAS_DOCS_URL } from \"./docs-links.js\";\nimport { fixOption } from \"./fix-option.js\";\nimport { HELP_TEXT } from \"./help-text.js\";\nimport { generateRedoclyApis, hasRedoclyApis } from \"./redocly-apis.js\";\nimport { refLimitOptions } from \"./ref-limits.js\";\n\n/**\n * The CLI's use case: parse the arguments, then generate the APIs of the Redocly config, one\n * schema file or URL, or stdin. It has no process access of its own; `main.ts` wires it (ADR-012).\n */\n\nasync function loadRedoclyConfig(run: CliRun): Promise<RedoclyConfig> {\n const { redoclyConfigs } = run.deps;\n const explicitPath = run.args.redocly;\n const configPath = redoclyConfigs.find(explicitPath);\n if (explicitPath && !configPath) {\n throw cliError(\"CLI_CONFIG_NOT_FOUND\", `Redocly config not found at: ${explicitPath}`);\n }\n return configPath ? redoclyConfigs.load(configPath) : redoclyConfigs.createDefault();\n}\n\n/** The schema's URL, or stdin when no path or URL is given and something is piped in. */\nfunction schemaSource(run: CliRun): SchemaSource {\n const { input } = run.args;\n if (input) {\n return resolveLocationUrl(input, run.deps.cwd);\n }\n if (run.deps.isStdinTerminal()) {\n throw cliError(\n \"CLI_INPUT_MISSING\",\n \"No schema given: pass a schema path or URL, pipe a schema into stdin, or define `apis` \" +\n \"in redocly.yaml. See --help.\",\n );\n }\n return run.deps.stdin();\n}\n\n/** The character that made the original CLI read a schema argument as a glob pattern. */\nconst GLOB_WILDCARD = \"*\";\n\n/**\n * Whether the schema argument is a glob pattern, which the CLI no longer expands: a path with a\n * `*` that names no file. A URL is no pattern (`?fields=*` is its query), nor a file whose name\n * has a `*`, which the CLI reads as any other file.\n */\nfunction isGlobPattern(run: CliRun, input: string): boolean {\n return (\n input.includes(GLOB_WILDCARD) &&\n !hasUrlScheme(input) &&\n !run.deps.files.isFile(resolveLocationUrl(input, run.deps.cwd))\n );\n}\n\n/**\n * One schema from a path, a URL or stdin; without `--output`, the types go to stdout. Warnings and\n * errors go to stderr either way, so they never mix with the types (upstream dropped warnings).\n */\nasync function generateSingleSchema(run: CliRun, redocly: RedoclyConfig): Promise<void> {\n const { input, output } = run.args;\n if (input !== undefined && isGlobPattern(run, input)) {\n throw cliError(\n \"CLI_GLOB_UNSUPPORTED\",\n \"Globbing has been deprecated in favor of redocly.yaml’s `apis` keys. \" +\n `See ${MULTIPLE_SCHEMAS_DOCS_URL}`,\n );\n }\n if (run.args.isCheck && !output) {\n // Without a file there is nothing to compare: the original printed the types and passed.\n throw cliError(\n \"CLI_CHECK_OUTPUT_MISSING\",\n \"--check needs the generated file to compare with: add --output <file>.\",\n );\n }\n for (const notice of ineffectiveFlagNotices(run.args.generatorFlags)) {\n run.deps.console.notice(notice);\n }\n const source = schemaSource(run);\n const outputFile = output ? singleOutputFile(run, output, source, redocly) : undefined;\n const options = {\n ...run.args.generatorFlags,\n ...refLimitOptions(run.args, run.deps.cwd),\n ...fixOption(run.args.fix),\n redocly,\n };\n const types = await run.deps.generate(source, options);\n if (!outputFile) {\n run.deps.writeStdout(types.contents);\n return;\n }\n writeOutput(run, outputFile, types, filesReadBy(run, types, outputFile.source));\n}\n\n/**\n * The `--output` file; it must not be the schema file nor the Redocly config, which writing it\n * would replace.\n */\nfunction singleOutputFile(\n run: CliRun,\n output: string,\n source: SchemaSource,\n redocly: RedoclyConfig,\n): OutputFile {\n const { input } = run.args;\n const outputFile = outputFileOf(run, { source: input ?? \"stdin\", output }, run.deps.cwd);\n const schemas =\n input && source instanceof URL ? [{ name: `schema ${input}`, location: source }] : [];\n ensureOutputIsNotSchema(run, outputFile, [...schemas, ...redoclyConfigFiles(run, redocly)]);\n return outputFile;\n}\n\nasync function generate(run: CliRun): Promise<unknown[]> {\n const redocly = await loadRedoclyConfig(run);\n if (!hasRedoclyApis(redocly)) {\n await generateSingleSchema(run, redocly);\n return [];\n }\n warnAboutIgnoredArguments(run);\n return generateRedoclyApis(run, redocly);\n}\n\n/** With the APIs of a Redocly config, the input and the output of the command line are unused. */\nfunction warnAboutIgnoredArguments(run: CliRun): void {\n const { args, deps } = run;\n if (args.input) {\n deps.logger.warn(\n warningText(\n \"APIs are specified both in Redocly Config and CLI argument. Only using Redocly config.\",\n WARNING_CODES.CLI_INPUT_IGNORED,\n ),\n );\n }\n if (args.output) {\n deps.logger.warn(\n warningText(\n `APIs are specified in Redocly Config, so --output ${args.output} is ignored: ` +\n \"each API is written to its x-openapi-ts.output.\",\n WARNING_CODES.CLI_OUTPUT_IGNORED,\n ),\n );\n }\n}\n\n/** Run the command; the failures it returns did not stop the other outputs. */\nasync function runCommand(argv: readonly string[], deps: CliDependencies): Promise<unknown[]> {\n const startedAt = deps.now();\n const args = parseCliArguments(argv);\n for (const flag of args.unknownFlags) {\n deps.console.notice(`Unknown flag ${flag} is ignored (see --help)`);\n }\n if (args.isHelp || args.isVersion) {\n deps.console.info(args.isHelp ? HELP_TEXT : `v${deps.version}`);\n return [];\n }\n if (args.output) {\n deps.console.info(`✨ ${deps.style.bold(`openapi-typesafe ${deps.version}`)}`);\n }\n return generate({ deps, args, startedAt });\n}\n\n/** Print one line per failure; the exit code is the first failure's (ADR-011). */\nfunction reportFailures(failures: readonly unknown[], logger: Logger): ExitCode {\n const reports = failures.map(describeCliFailure);\n for (const report of reports) {\n logger.error(report.message);\n }\n return reports[0]?.exitCode ?? EXIT_CODES.SUCCESS;\n}\n\n/** Run the CLI with the arguments after `node cli.js`, and return the process exit code. */\nexport async function runCli(argv: readonly string[], deps: CliDependencies): Promise<ExitCode> {\n let failures: unknown[];\n try {\n failures = await runCommand(argv, deps);\n } catch (thrown) {\n failures = [thrown];\n }\n return reportFailures(failures, deps.logger);\n}\n"],"names":["cliError","resolveLocationUrl","hasUrlScheme","MULTIPLE_SCHEMAS_DOCS_URL","ineffectiveFlagNotices","refLimitOptions","fixOption","writeOutput","filesReadBy","outputFileOf","ensureOutputIsNotSchema","redoclyConfigFiles","hasRedoclyApis","generateRedoclyApis","warningText","WARNING_CODES","parseCliArguments","HELP_TEXT","describeCliFailure","EXIT_CODES"],"mappings":";;;;;;;;;;;;;AA6BA,eAAe,kBAAkB,GAAA,EAAqC;AACpE,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,GAAA,CAAI,IAAA;AAC/B,EAAA,MAAM,YAAA,GAAe,IAAI,IAAA,CAAK,OAAA;AAC9B,EAAA,MAAM,UAAA,GAAa,cAAA,CAAe,IAAA,CAAK,YAAY,CAAA;AAC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AO,MAAyB,IAAA,EAA0C;AAC9F,EAAA,IAAI,QAAA;AACJ,EAAA,IAAI;AACF,IAAA,QAAA,GAAW,MAAM,UAAA,CAAW,IAAA,EAAM,IAAI,CAAA;AAAA,EACxC,SAAS,MAAA,EAAQ;AACf,IAAA,QAAA,GAAW,CAAC,MAAM,CAAA;AAAA,EACpB;AACA,EAAA,OAAO,cAAA,CAAe,QAAA,EAAU,IAAA,CAAK,MAAM,CAAA;AAC7C;;"}
|
package/dist/cli/run-cli.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { hasUrlScheme } from '../domain/location-text.mjs';
|
|
1
2
|
import { warningText, WARNING_CODES } from '../domain/warnings.mjs';
|
|
2
|
-
import {
|
|
3
|
+
import { parseCliArguments, ineffectiveFlagNotices } from './cli-arguments.mjs';
|
|
3
4
|
import { describeCliFailure, EXIT_CODES, cliError } from './cli-errors.mjs';
|
|
4
5
|
import { writeOutput, filesReadBy, resolveLocationUrl, outputFileOf, ensureOutputIsNotSchema, redoclyConfigFiles } from './cli-output.mjs';
|
|
5
6
|
import { MULTIPLE_SCHEMAS_DOCS_URL } from './docs-links.mjs';
|
|
@@ -30,9 +31,13 @@ function schemaSource(run) {
|
|
|
30
31
|
}
|
|
31
32
|
return run.deps.stdin();
|
|
32
33
|
}
|
|
34
|
+
const GLOB_WILDCARD = "*";
|
|
35
|
+
function isGlobPattern(run, input) {
|
|
36
|
+
return input.includes(GLOB_WILDCARD) && !hasUrlScheme(input) && !run.deps.files.isFile(resolveLocationUrl(input, run.deps.cwd));
|
|
37
|
+
}
|
|
33
38
|
async function generateSingleSchema(run, redocly) {
|
|
34
39
|
const { input, output } = run.args;
|
|
35
|
-
if (input
|
|
40
|
+
if (input !== void 0 && isGlobPattern(run, input)) {
|
|
36
41
|
throw cliError(
|
|
37
42
|
"CLI_GLOB_UNSUPPORTED",
|
|
38
43
|
`Globbing has been deprecated in favor of redocly.yaml\u2019s \`apis\` keys. See ${MULTIPLE_SCHEMAS_DOCS_URL}`
|
|
@@ -44,6 +49,9 @@ async function generateSingleSchema(run, redocly) {
|
|
|
44
49
|
"--check needs the generated file to compare with: add --output <file>."
|
|
45
50
|
);
|
|
46
51
|
}
|
|
52
|
+
for (const notice of ineffectiveFlagNotices(run.args.generatorFlags)) {
|
|
53
|
+
run.deps.console.notice(notice);
|
|
54
|
+
}
|
|
47
55
|
const source = schemaSource(run);
|
|
48
56
|
const outputFile = output ? singleOutputFile(run, output, source, redocly) : void 0;
|
|
49
57
|
const options = {
|
|
@@ -72,21 +80,30 @@ async function generate(run) {
|
|
|
72
80
|
await generateSingleSchema(run, redocly);
|
|
73
81
|
return [];
|
|
74
82
|
}
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
warnAboutIgnoredArguments(run);
|
|
84
|
+
return generateRedoclyApis(run, redocly);
|
|
85
|
+
}
|
|
86
|
+
function warnAboutIgnoredArguments(run) {
|
|
87
|
+
const { args, deps } = run;
|
|
88
|
+
if (args.input) {
|
|
89
|
+
deps.logger.warn(
|
|
77
90
|
warningText(
|
|
78
91
|
"APIs are specified both in Redocly Config and CLI argument. Only using Redocly config.",
|
|
79
92
|
WARNING_CODES.CLI_INPUT_IGNORED
|
|
80
93
|
)
|
|
81
94
|
);
|
|
82
95
|
}
|
|
83
|
-
|
|
96
|
+
if (args.output) {
|
|
97
|
+
deps.logger.warn(
|
|
98
|
+
warningText(
|
|
99
|
+
`APIs are specified in Redocly Config, so --output ${args.output} is ignored: each API is written to its x-openapi-ts.output.`,
|
|
100
|
+
WARNING_CODES.CLI_OUTPUT_IGNORED
|
|
101
|
+
)
|
|
102
|
+
);
|
|
103
|
+
}
|
|
84
104
|
}
|
|
85
105
|
async function runCommand(argv, deps) {
|
|
86
106
|
const startedAt = deps.now();
|
|
87
|
-
for (const notice of ineffectiveFlagNotices(argv)) {
|
|
88
|
-
deps.console.notice(notice);
|
|
89
|
-
}
|
|
90
107
|
const args = parseCliArguments(argv);
|
|
91
108
|
for (const flag of args.unknownFlags) {
|
|
92
109
|
deps.console.notice(`Unknown flag ${flag} is ignored (see --help)`);
|