openapi-typesafe 1.0.0-rc.3 → 1.0.0-rc.5
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 +1972 -0
- package/dist/adapters/node-file-system/file-claims.cjs +105 -0
- package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.mjs +95 -0
- package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.cjs +82 -0
- package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.mjs +74 -0
- package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +97 -14
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +97 -14
- 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 +48 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +45 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -1
- package/dist/adapters/redocly-loader/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/loaded-documents.cjs +28 -0
- package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs.map +1 -0
- package/dist/adapters/redocly-loader/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-named-components.cjs +137 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs +134 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +40 -29
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +38 -27
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +45 -4
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +45 -4
- 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 +53 -12
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
- package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +40 -9
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -9
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +61 -0
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +58 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +18 -9
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +20 -11
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +10 -4
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +10 -4
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/default-ports.cjs +14 -2
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +14 -2
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/discriminator-enum-parent.cjs +2 -2
- package/dist/api/discriminator-enum-parent.cjs.map +1 -1
- package/dist/api/discriminator-enum-parent.mjs +3 -3
- package/dist/api/discriminator-enum-parent.mjs.map +1 -1
- package/dist/api/discriminator-other-owners.cjs +5 -3
- package/dist/api/discriminator-other-owners.cjs.map +1 -1
- package/dist/api/discriminator-other-owners.mjs +5 -3
- package/dist/api/discriminator-other-owners.mjs.map +1 -1
- package/dist/api/discriminator-patch.cjs +5 -1
- package/dist/api/discriminator-patch.cjs.map +1 -1
- package/dist/api/discriminator-patch.mjs +5 -1
- package/dist/api/discriminator-patch.mjs.map +1 -1
- package/dist/api/discriminator-scan.cjs +15 -8
- package/dist/api/discriminator-scan.cjs.map +1 -1
- package/dist/api/discriminator-scan.mjs +15 -8
- package/dist/api/discriminator-scan.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 -12
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +6 -12
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-utils.cjs.map +1 -1
- package/dist/api/legacy-utils.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +9 -6
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +10 -8
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/ref-limit-options.cjs +63 -0
- package/dist/api/ref-limit-options.cjs.map +1 -0
- package/dist/api/ref-limit-options.mjs +57 -0
- package/dist/api/ref-limit-options.mjs.map +1 -0
- package/dist/api/schema-callbacks.cjs +36 -12
- package/dist/api/schema-callbacks.cjs.map +1 -1
- package/dist/api/schema-callbacks.mjs +36 -12
- package/dist/api/schema-callbacks.mjs.map +1 -1
- package/dist/api/transform-context.cjs +7 -3
- package/dist/api/transform-context.cjs.map +1 -1
- package/dist/api/transform-context.mjs +7 -3
- package/dist/api/transform-context.mjs.map +1 -1
- package/dist/api/transform-schema.cjs +47 -10
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +48 -11
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/print/text-writer.cjs +10 -3
- package/dist/application/print/text-writer.cjs.map +1 -1
- package/dist/application/print/text-writer.mjs +10 -3
- package/dist/application/print/text-writer.mjs.map +1 -1
- package/dist/application/stack-overflow.cjs +2 -1
- package/dist/application/stack-overflow.cjs.map +1 -1
- package/dist/application/stack-overflow.mjs +2 -1
- package/dist/application/stack-overflow.mjs.map +1 -1
- package/dist/application/transform/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/components.cjs +1 -1
- package/dist/application/transform/document/components.cjs.map +1 -1
- package/dist/application/transform/document/components.mjs +2 -2
- package/dist/application/transform/document/components.mjs.map +1 -1
- package/dist/application/transform/document/declared-type-names.cjs +23 -0
- package/dist/application/transform/document/declared-type-names.cjs.map +1 -0
- package/dist/application/transform/document/declared-type-names.mjs +20 -0
- package/dist/application/transform/document/declared-type-names.mjs.map +1 -0
- package/dist/application/transform/document/defs-root.cjs +1 -1
- package/dist/application/transform/document/defs-root.cjs.map +1 -1
- package/dist/application/transform/document/defs-root.mjs +2 -2
- package/dist/application/transform/document/defs-root.mjs.map +1 -1
- package/dist/application/transform/document/document.cjs +7 -2
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +6 -3
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
- package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
- package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
- package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
- package/dist/application/transform/document/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/global-type-references.cjs +1 -0
- package/dist/application/transform/document/global-type-references.cjs.map +1 -1
- package/dist/application/transform/document/global-type-references.mjs +1 -1
- package/dist/application/transform/document/global-type-references.mjs.map +1 -1
- package/dist/application/transform/document/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/media-type.cjs +2 -2
- package/dist/application/transform/document/media-type.cjs.map +1 -1
- package/dist/application/transform/document/media-type.mjs +3 -3
- package/dist/application/transform/document/media-type.mjs.map +1 -1
- package/dist/application/transform/document/operation-keys-written.cjs +26 -0
- package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
- package/dist/application/transform/document/operation-keys-written.mjs +24 -0
- package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
- package/dist/application/transform/document/operation.cjs +1 -1
- package/dist/application/transform/document/operation.cjs.map +1 -1
- package/dist/application/transform/document/operation.mjs +2 -2
- package/dist/application/transform/document/operation.mjs.map +1 -1
- package/dist/application/transform/document/parameter-entries.cjs +34 -0
- package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
- package/dist/application/transform/document/parameter-entries.mjs +30 -0
- package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
- package/dist/application/transform/document/parameter.cjs +12 -4
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +13 -5
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +29 -34
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +29 -34
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +15 -17
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +15 -19
- 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 +70 -0
- package/dist/application/transform/document/path-template-refs.cjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.mjs +67 -0
- package/dist/application/transform/document/path-template-refs.mjs.map +1 -0
- package/dist/application/transform/document/paths-enum.cjs +8 -6
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +8 -7
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +43 -67
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +42 -68
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/referenced-parameter.cjs +80 -0
- package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
- package/dist/application/transform/document/referenced-parameter.mjs +78 -0
- package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
- package/dist/application/transform/document/request-body.cjs +1 -1
- package/dist/application/transform/document/request-body.cjs.map +1 -1
- package/dist/application/transform/document/request-body.mjs +2 -2
- package/dist/application/transform/document/request-body.mjs.map +1 -1
- package/dist/application/transform/document/response.cjs +2 -2
- package/dist/application/transform/document/response.cjs.map +1 -1
- package/dist/application/transform/document/response.mjs +3 -3
- package/dist/application/transform/document/response.mjs.map +1 -1
- package/dist/application/transform/document/responses.cjs +1 -1
- package/dist/application/transform/document/responses.cjs.map +1 -1
- package/dist/application/transform/document/responses.mjs +2 -2
- package/dist/application/transform/document/responses.mjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.cjs +8 -23
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.mjs +8 -24
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
- package/dist/application/transform/document/type-resolution.cjs +3 -1
- package/dist/application/transform/document/type-resolution.cjs.map +1 -1
- package/dist/application/transform/document/type-resolution.mjs +3 -1
- package/dist/application/transform/document/type-resolution.mjs.map +1 -1
- package/dist/application/transform/document/webhooks.cjs +10 -3
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +10 -3
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +16 -5
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +16 -5
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
- package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
- package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
- package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.cjs +23 -0
- package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.mjs +21 -0
- package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.cjs +4 -4
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
- package/dist/application/transform/footer/type-evaluation.mjs +4 -4
- package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
- package/dist/application/transform/helper-types.cjs +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/numbered-names.cjs +9 -0
- package/dist/application/transform/numbered-names.cjs.map +1 -1
- package/dist/application/transform/numbered-names.mjs +9 -1
- package/dist/application/transform/numbered-names.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +5 -5
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +3 -3
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.cjs +47 -66
- package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.mjs +36 -50
- 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 +68 -13
- package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/original-index.mjs +70 -15
- 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 +52 -0
- package/dist/application/transform/ref-pointer/property-shape.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs +45 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/typed-walk.cjs +79 -21
- package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/typed-walk.mjs +76 -18
- package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -1
- package/dist/application/transform/ref-type.cjs +2 -1
- package/dist/application/transform/ref-type.cjs.map +1 -1
- package/dist/application/transform/ref-type.mjs +2 -1
- package/dist/application/transform/ref-type.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/composition-type.cjs +1 -1
- package/dist/application/transform/schema/composition-type.cjs.map +1 -1
- package/dist/application/transform/schema/composition-type.mjs +2 -2
- package/dist/application/transform/schema/composition-type.mjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.cjs +1 -1
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.mjs +2 -2
- package/dist/application/transform/schema/enum-rule.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 +18 -8
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +19 -9
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/ref-siblings.cjs +47 -0
- package/dist/application/transform/schema/ref-siblings.cjs.map +1 -0
- package/dist/application/transform/schema/ref-siblings.mjs +45 -0
- package/dist/application/transform/schema/ref-siblings.mjs.map +1 -0
- package/dist/application/transform/schema/schema-transform.cjs +6 -3
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +6 -3
- 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/application/transform/schema-comment.cjs +5 -1
- package/dist/application/transform/schema-comment.cjs.map +1 -1
- package/dist/application/transform/schema-comment.mjs +5 -1
- package/dist/application/transform/schema-comment.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 +57 -9
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +56 -11
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +72 -0
- package/dist/cli/api-writes.cjs.map +1 -0
- package/dist/cli/api-writes.mjs +69 -0
- package/dist/cli/api-writes.mjs.map +1 -0
- package/dist/cli/cli-arguments.cjs +51 -11
- package/dist/cli/cli-arguments.cjs.map +1 -1
- package/dist/cli/cli-arguments.mjs +51 -11
- package/dist/cli/cli-arguments.mjs.map +1 -1
- package/dist/cli/cli-errors.cjs +29 -1
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +29 -2
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +111 -4
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +104 -5
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +13 -3
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +14 -4
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +94 -37
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +99 -42
- 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 +37 -14
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +39 -16
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/append-all.cjs +10 -0
- package/dist/domain/append-all.cjs.map +1 -0
- package/dist/domain/append-all.mjs +8 -0
- package/dist/domain/append-all.mjs.map +1 -0
- package/dist/domain/cause-secrets.cjs +52 -0
- package/dist/domain/cause-secrets.cjs.map +1 -0
- package/dist/domain/cause-secrets.mjs +50 -0
- package/dist/domain/cause-secrets.mjs.map +1 -0
- package/dist/domain/errors.cjs +11 -3
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +11 -3
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/identifier-text.cjs.map +1 -1
- package/dist/domain/ir/identifier-text.mjs +1 -1
- package/dist/domain/ir/identifier-text.mjs.map +1 -1
- package/dist/domain/ir/ir-shape.cjs +187 -0
- package/dist/domain/ir/ir-shape.cjs.map +1 -0
- package/dist/domain/ir/ir-shape.mjs +184 -0
- package/dist/domain/ir/ir-shape.mjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
- package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
- package/dist/domain/location-text.cjs +9 -0
- package/dist/domain/location-text.cjs.map +1 -0
- package/dist/domain/location-text.mjs +7 -0
- package/dist/domain/location-text.mjs.map +1 -0
- package/dist/domain/openapi/alias-expansion.cjs +3 -1
- package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.mjs +3 -1
- package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.cjs +3 -3
- package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.mjs +4 -4
- package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
- package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
- package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
- package/dist/domain/openapi/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/openapi/json-pointer.cjs +43 -1
- package/dist/domain/openapi/json-pointer.cjs.map +1 -1
- package/dist/domain/openapi/json-pointer.mjs +40 -2
- package/dist/domain/openapi/json-pointer.mjs.map +1 -1
- package/dist/domain/openapi/schema-dialect.cjs +15 -0
- package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
- package/dist/domain/openapi/schema-dialect.mjs +12 -0
- package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.cjs +1 -1
- package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
- package/dist/domain/openapi/unsupported-features.mjs +2 -2
- package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
- package/dist/domain/output-fixes.cjs +20 -0
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +20 -0
- 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/url-secrets.cjs +48 -0
- package/dist/domain/url-secrets.cjs.map +1 -0
- package/dist/domain/url-secrets.mjs +45 -0
- package/dist/domain/url-secrets.mjs.map +1 -0
- package/dist/domain/warnings.cjs +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 +46 -20
- package/dist/index.d.mts +46 -20
- package/dist/index.d.ts +46 -20
- package/package.json +4 -5
- package/src/adapters/node-file-system/file-claims.ts +138 -0
- package/src/adapters/node-file-system/file-identity.ts +137 -0
- package/src/adapters/node-file-system/node-file-system.ts +158 -18
- package/src/adapters/pipe-safe-writer/pipe-safe-writer.ts +29 -0
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +60 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
- package/src/adapters/redocly-loader/component-schemas.ts +19 -0
- package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
- package/src/adapters/redocly-loader/mapping-schema-names.ts +25 -0
- package/src/adapters/redocly-loader/query-named-components.ts +201 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +64 -38
- package/src/adapters/redocly-loader/ref-access.ts +51 -4
- package/src/adapters/redocly-loader/ref-holders.ts +76 -15
- package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +85 -13
- package/src/adapters/redocly-loader/remote-node-limit.ts +102 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
- package/src/adapters/redocly-loader/schema-source.ts +35 -11
- package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
- package/src/adapters/terminal-logger/terminal-logger.ts +17 -6
- package/src/api/default-ports.ts +33 -4
- package/src/api/discriminator-enum-parent.ts +3 -3
- package/src/api/discriminator-other-owners.ts +5 -3
- package/src/api/discriminator-patch.ts +5 -1
- package/src/api/discriminator-scan.ts +16 -8
- package/src/api/document-refs.ts +29 -1
- package/src/api/document-run.ts +10 -19
- package/src/api/legacy-utils.ts +5 -1
- package/src/api/openapi-ts.ts +26 -8
- package/src/api/ref-limit-options.ts +76 -0
- package/src/api/run-context.ts +3 -0
- package/src/api/schema-callbacks.ts +60 -17
- package/src/api/transform-context.ts +7 -3
- package/src/api/transform-schema.ts +79 -12
- package/src/application/ports/file-system.ts +47 -0
- package/src/application/ports/schema-loader.ts +11 -1
- package/src/application/print/text-writer.ts +10 -3
- package/src/application/stack-overflow.ts +9 -5
- package/src/application/transform/declared-value-types.ts +42 -0
- package/src/application/transform/document/components.ts +2 -2
- package/src/application/transform/document/declared-type-names.ts +36 -0
- package/src/application/transform/document/defs-root.ts +2 -2
- package/src/application/transform/document/document.ts +8 -5
- package/src/application/transform/document/enum-names-given-back.ts +91 -0
- package/src/application/transform/document/exploded-query-values.ts +88 -0
- package/src/application/transform/document/global-type-references.ts +1 -1
- package/src/application/transform/document/header.ts +25 -5
- package/src/application/transform/document/media-type.ts +4 -3
- package/src/application/transform/document/operation-keys-written.ts +27 -0
- package/src/application/transform/document/operation.ts +2 -2
- package/src/application/transform/document/parameter-entries.ts +70 -0
- package/src/application/transform/document/parameter.ts +21 -9
- package/src/application/transform/document/parameters.ts +56 -66
- package/src/application/transform/document/path-item.ts +16 -34
- package/src/application/transform/document/path-template-key.ts +152 -0
- package/src/application/transform/document/path-template-refs.ts +106 -0
- package/src/application/transform/document/paths-enum.ts +24 -10
- package/src/application/transform/document/paths.ts +59 -125
- package/src/application/transform/document/referenced-parameter.ts +146 -0
- package/src/application/transform/document/request-body.ts +2 -2
- package/src/application/transform/document/response.ts +3 -3
- package/src/application/transform/document/responses.ts +2 -2
- package/src/application/transform/document/root-type-aliases.ts +17 -38
- package/src/application/transform/document/type-resolution.ts +2 -1
- package/src/application/transform/document/webhooks.ts +19 -6
- package/src/application/transform/footer/document-footer.ts +36 -9
- package/src/application/transform/footer/enum-name-claims.ts +62 -0
- package/src/application/transform/footer/operation-keys.ts +28 -0
- package/src/application/transform/footer/type-evaluation.ts +4 -4
- package/src/application/transform/helper-types.ts +8 -7
- package/src/application/transform/numbered-names.ts +15 -0
- package/src/application/transform/ref-pointer/generated-location.ts +3 -3
- package/src/application/transform/ref-pointer/generated-shape.ts +67 -78
- 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 +100 -17
- 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 +97 -0
- package/src/application/transform/ref-pointer/typed-walk.ts +117 -25
- package/src/application/transform/ref-type.ts +2 -1
- package/src/application/transform/schema/access-flags.ts +5 -2
- package/src/application/transform/schema/composition-type.ts +2 -2
- package/src/application/transform/schema/enum-rule.ts +6 -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 +22 -12
- package/src/application/transform/schema/ref-siblings.ts +76 -0
- package/src/application/transform/schema/schema-context.ts +3 -0
- package/src/application/transform/schema/schema-transform.ts +6 -3
- package/src/application/transform/schema/unevaluated-properties.ts +4 -44
- package/src/application/transform/schema-comment.ts +5 -1
- package/src/application/transform/transform-context.ts +5 -0
- package/src/cli/api-logger.ts +17 -0
- package/src/cli/api-settings.ts +80 -13
- package/src/cli/api-writes.ts +117 -0
- package/src/cli/cli-arguments.ts +90 -14
- package/src/cli/cli-dependencies.ts +26 -4
- package/src/cli/cli-errors.ts +42 -1
- package/src/cli/cli-output.ts +195 -15
- package/src/cli/main.ts +14 -5
- package/src/cli/redocly-apis.ts +177 -52
- package/src/cli/ref-limits.ts +21 -2
- package/src/cli/run-cli.ts +76 -15
- package/src/domain/append-all.ts +10 -0
- package/src/domain/cause-secrets.ts +86 -0
- package/src/domain/errors.ts +16 -5
- package/src/domain/ir/identifier-text.ts +6 -5
- package/src/domain/ir/ir-shape.ts +299 -0
- package/src/domain/ir/newer-identifier-ranges.ts +183 -30
- package/src/domain/location-text.ts +12 -0
- package/src/domain/openapi/alias-expansion.ts +4 -1
- package/src/domain/openapi/discriminated-union.ts +6 -4
- package/src/domain/openapi/discriminator-conflicts.ts +21 -7
- package/src/domain/openapi/document-object.ts +2 -0
- package/src/domain/openapi/document-places.ts +78 -0
- package/src/domain/openapi/json-pointer.ts +96 -7
- package/src/domain/openapi/schema-dialect.ts +22 -0
- package/src/domain/openapi/unsupported-features.ts +2 -2
- package/src/domain/output-fixes.ts +28 -2
- package/src/domain/terminal-text.ts +44 -0
- package/src/domain/url-secrets.ts +72 -0
- package/src/domain/warnings.ts +1 -0
- package/src/types/generator-options.ts +1 -1
- package/dist/cli/main.d.cts +0 -2
- package/dist/cli/main.d.mts +0 -2
- package/dist/cli/main.d.ts +0 -2
- package/dist/domain/url-credentials.cjs +0 -10
- package/dist/domain/url-credentials.cjs.map +0 -1
- package/dist/domain/url-credentials.mjs +0 -8
- package/dist/domain/url-credentials.mjs.map +0 -1
- package/src/domain/url-credentials.ts +0 -18
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { ClaimedFile } from "../application/ports/file-system.js";
|
|
2
|
+
import type { GeneratedTypes } from "./cli-dependencies.js";
|
|
3
|
+
import {
|
|
4
|
+
type CliRun,
|
|
5
|
+
duplicateOutputError,
|
|
6
|
+
emitOutput,
|
|
7
|
+
ensureOutputIsNotSchema,
|
|
8
|
+
type NamedFile,
|
|
9
|
+
type OutputFile,
|
|
10
|
+
} from "./cli-output.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Writing the generated APIs of a Redocly config. Before the first byte is written, every output
|
|
14
|
+
* is claimed: a missing one is created empty, so the file system gives it its own identity. Two
|
|
15
|
+
* APIs whose files then have one identity fail with `CLI_OUTPUT_DUPLICATE` and write nothing,
|
|
16
|
+
* also when their names looked different (ADR-043, decision 1).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** An API whose types are generated and not written yet. */
|
|
20
|
+
export interface GeneratedApi {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly outputFile: OutputFile;
|
|
23
|
+
readonly types: GeneratedTypes;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** An API whose output is claimed; `claim` is undefined with `--check`, which writes nothing. */
|
|
27
|
+
interface ClaimedApi {
|
|
28
|
+
readonly api: GeneratedApi;
|
|
29
|
+
readonly claim: ClaimedFile | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The failures of the API an API name maps to; an API without failures was written. */
|
|
33
|
+
type ApiFailures = Map<string, unknown[]>;
|
|
34
|
+
|
|
35
|
+
/** The failure of a step, as a list: empty when it succeeded. */
|
|
36
|
+
export function failuresOf(step: () => void): unknown[] {
|
|
37
|
+
try {
|
|
38
|
+
step();
|
|
39
|
+
return [];
|
|
40
|
+
} catch (failure) {
|
|
41
|
+
return [failure];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Claim the output of each API; an API whose claim fails gets that failure instead. */
|
|
46
|
+
function claimOutputs(run: CliRun, apis: readonly GeneratedApi[], failures: ApiFailures) {
|
|
47
|
+
const claimed: ClaimedApi[] = [];
|
|
48
|
+
for (const api of apis) {
|
|
49
|
+
try {
|
|
50
|
+
const claim = run.args.isCheck ? undefined : run.deps.files.claimFile(api.outputFile.file);
|
|
51
|
+
claimed.push({ api, claim });
|
|
52
|
+
} catch (failure) {
|
|
53
|
+
failures.set(api.name, [failure]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return claimed;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The APIs that share their claimed file with another, by API name, with the other names. */
|
|
60
|
+
function sharedOutputs(claimed: readonly ClaimedApi[]): Map<string, string[]> {
|
|
61
|
+
const byIdentity = new Map<string, string[]>();
|
|
62
|
+
for (const { api, claim } of claimed) {
|
|
63
|
+
if (claim) {
|
|
64
|
+
byIdentity.set(claim.identity, [...(byIdentity.get(claim.identity) ?? []), api.name]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const shared = new Map<string, string[]>();
|
|
68
|
+
for (const names of byIdentity.values()) {
|
|
69
|
+
for (const name of names.length > 1 ? names : []) {
|
|
70
|
+
shared.set(
|
|
71
|
+
name,
|
|
72
|
+
names.filter((other) => other !== name).map((other) => `API ${other}`),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return shared;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Write one claimed API; a failed write releases the claim, so no empty file is left. */
|
|
80
|
+
function writeClaimed(run: CliRun, { api, claim }: ClaimedApi): unknown[] {
|
|
81
|
+
const failures = failuresOf(() => emitOutput(run, api.outputFile, api.types.contents));
|
|
82
|
+
return failures.length > 0 && claim
|
|
83
|
+
? [...failures, ...failuresOf(() => claim.release())]
|
|
84
|
+
: failures;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Write (or `--check`) every API unless its output is a file the run read or the file of another
|
|
89
|
+
* API. Returns the failures by API name. Claims are released in reverse order, so a directory
|
|
90
|
+
* one claim created is empty by the time it is removed.
|
|
91
|
+
*/
|
|
92
|
+
export function writeGeneratedApis(
|
|
93
|
+
run: CliRun,
|
|
94
|
+
apis: readonly GeneratedApi[],
|
|
95
|
+
readFiles: readonly NamedFile[],
|
|
96
|
+
): ApiFailures {
|
|
97
|
+
const failures: ApiFailures = new Map();
|
|
98
|
+
const ownOutputs = apis.filter((api) => {
|
|
99
|
+
const failure = failuresOf(() => ensureOutputIsNotSchema(run, api.outputFile, readFiles));
|
|
100
|
+
failures.set(api.name, failure);
|
|
101
|
+
return failure.length === 0;
|
|
102
|
+
});
|
|
103
|
+
const claimed = claimOutputs(run, ownOutputs, failures);
|
|
104
|
+
const shared = sharedOutputs(claimed);
|
|
105
|
+
for (const entry of [...claimed].reverse()) {
|
|
106
|
+
const { api, claim } = entry;
|
|
107
|
+
const others = shared.get(api.name);
|
|
108
|
+
if (others) {
|
|
109
|
+
const release = claim ? failuresOf(() => claim.release()) : [];
|
|
110
|
+
failures.set(api.name, [duplicateOutputError(api.outputFile, others), ...release]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const entry of claimed.filter(({ api }) => !shared.has(api.name))) {
|
|
114
|
+
failures.set(entry.api.name, writeClaimed(run, entry));
|
|
115
|
+
}
|
|
116
|
+
return failures;
|
|
117
|
+
}
|
package/src/cli/cli-arguments.ts
CHANGED
|
@@ -83,23 +83,95 @@ const REMOVED_FLAGS: readonly (readonly [string, string])[] = [
|
|
|
83
83
|
];
|
|
84
84
|
|
|
85
85
|
/** Flags that only work together with `--root-types`. */
|
|
86
|
-
const ROOT_TYPES_FLAGS = ["
|
|
86
|
+
const ROOT_TYPES_FLAGS = ["rootTypesNoSchemaPrefix", "rootTypesKeepCasing"] as const;
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
const OPTIONS_END = "--";
|
|
89
|
+
const LONG_PREFIX = "--";
|
|
90
|
+
const NEGATION_PREFIX = "--no-";
|
|
91
|
+
const VALUE_SEPARATOR = "=";
|
|
92
|
+
const BOOLEAN_VALUES: ReadonlySet<string> = new Set(["true", "false"]);
|
|
93
|
+
|
|
94
|
+
/** A flag as written before `--`: its name (`--redoc`, `-o`) and the text after `=`, if any. */
|
|
95
|
+
interface WrittenFlag {
|
|
96
|
+
readonly name: string;
|
|
97
|
+
readonly value: string | undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function writtenFlags(argv: readonly string[]): WrittenFlag[] {
|
|
101
|
+
const end = argv.indexOf(OPTIONS_END);
|
|
102
|
+
return (end === -1 ? argv : argv.slice(0, end))
|
|
103
|
+
.filter((arg) => arg.startsWith("-") && arg !== "-")
|
|
104
|
+
.map((arg) => {
|
|
105
|
+
const at = arg.indexOf(VALUE_SEPARATOR);
|
|
106
|
+
return at === -1
|
|
107
|
+
? { name: arg, value: undefined }
|
|
108
|
+
: { name: arg.slice(0, at), value: arg.slice(at + 1) };
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* A long flag as yargs-parser reads it: in kebab-case and without `--no-`, so `--immutableTypes`
|
|
114
|
+
* and `--no-immutable-types` are `--immutable-types`. A short flag stays as written.
|
|
115
|
+
*/
|
|
116
|
+
function canonicalFlagName(name: string): string {
|
|
117
|
+
if (!name.startsWith(LONG_PREFIX)) {
|
|
118
|
+
return name;
|
|
119
|
+
}
|
|
120
|
+
const bare = name.startsWith(NEGATION_PREFIX)
|
|
121
|
+
? name.slice(NEGATION_PREFIX.length)
|
|
122
|
+
: name.slice(LONG_PREFIX.length);
|
|
123
|
+
return `${LONG_PREFIX}${kebabCase(bare)}`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** An old flag fails by its name in any spelling, also with a value (`--redoc=redocly.yaml`). */
|
|
127
|
+
function rejectRemovedFlags(flags: readonly WrittenFlag[]): void {
|
|
128
|
+
const names = new Set(flags.map(({ name }) => canonicalFlagName(name)));
|
|
89
129
|
for (const [flag, message] of REMOVED_FLAGS) {
|
|
90
|
-
if (
|
|
130
|
+
if (names.has(flag)) {
|
|
91
131
|
throw cliError("CLI_FLAG_REMOVED", message);
|
|
92
132
|
}
|
|
93
133
|
}
|
|
94
134
|
}
|
|
95
135
|
|
|
136
|
+
const ALIASES = { redocly: ["c"], exportType: ["t"], output: ["o"] };
|
|
137
|
+
|
|
138
|
+
/** The short aliases of boolean flags (`-t`), which take a value the same way (`-t=true`). */
|
|
139
|
+
const BOOLEAN_ALIASES = Object.entries(ALIASES)
|
|
140
|
+
.filter(([flag]) => CAMEL_CASE_BOOLEAN_FLAGS.includes(flag))
|
|
141
|
+
.flatMap(([, aliases]) => aliases.map((alias) => `-${alias}`));
|
|
142
|
+
|
|
143
|
+
const BOOLEAN_FLAG_NAMES: ReadonlySet<string> = new Set([
|
|
144
|
+
...BOOLEAN_FLAGS.map((flag) => `${LONG_PREFIX}${flag}`),
|
|
145
|
+
...BOOLEAN_ALIASES,
|
|
146
|
+
]);
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A boolean flag takes `=true` or `=false`, and its `--no-` form takes no value. yargs-parser read
|
|
150
|
+
* any other value as false (`--enum=1`, `--alphabetize=yes`), which turned the option off.
|
|
151
|
+
*/
|
|
152
|
+
function rejectInvalidBooleans(flags: readonly WrittenFlag[]): void {
|
|
153
|
+
for (const { name, value } of flags) {
|
|
154
|
+
const negated = name.startsWith(NEGATION_PREFIX)
|
|
155
|
+
? `${LONG_PREFIX}${name.slice(NEGATION_PREFIX.length)}`
|
|
156
|
+
: undefined;
|
|
157
|
+
const isNegatedWithValue = negated !== undefined && BOOLEAN_FLAG_NAMES.has(negated);
|
|
158
|
+
const isInvalid = BOOLEAN_FLAG_NAMES.has(name) && !BOOLEAN_VALUES.has(value ?? "true");
|
|
159
|
+
if (value !== undefined && (isNegatedWithValue || isInvalid)) {
|
|
160
|
+
throw cliError(
|
|
161
|
+
"CLI_FLAG_INVALID",
|
|
162
|
+
`${name}=${value}: a boolean flag takes no value, or =true or =false.`,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
96
168
|
/** Notices for flags that have no effect in this combination, printed before the run. */
|
|
97
|
-
export function ineffectiveFlagNotices(
|
|
98
|
-
if (
|
|
169
|
+
export function ineffectiveFlagNotices(flags: GeneratorFlags): string[] {
|
|
170
|
+
if (flags.rootTypes === true) {
|
|
99
171
|
return [];
|
|
100
172
|
}
|
|
101
|
-
return ROOT_TYPES_FLAGS.filter((flag) =>
|
|
102
|
-
(flag) =>
|
|
173
|
+
return ROOT_TYPES_FLAGS.filter((flag) => flags[flag] === true).map(
|
|
174
|
+
(flag) => `--${kebabCase(flag)} has no effect without --root-types flag`,
|
|
103
175
|
);
|
|
104
176
|
}
|
|
105
177
|
|
|
@@ -117,7 +189,10 @@ function optionalString(value: unknown): string | undefined {
|
|
|
117
189
|
return value === undefined ? undefined : String(value);
|
|
118
190
|
}
|
|
119
191
|
|
|
120
|
-
/**
|
|
192
|
+
/**
|
|
193
|
+
* The last value of a flag that takes one value: given twice, the last one wins, as for the
|
|
194
|
+
* boolean flags (yargs-parser gives a list of every value).
|
|
195
|
+
*/
|
|
121
196
|
function lastString(value: unknown): string | undefined {
|
|
122
197
|
return optionalString(Array.isArray(value) ? value.at(-1) : value);
|
|
123
198
|
}
|
|
@@ -154,8 +229,6 @@ const STRING_FLAGS = [
|
|
|
154
229
|
...["localRefRoot", "remoteRefHosts"].flatMap((flag) => [flag, kebabCase(flag)]),
|
|
155
230
|
];
|
|
156
231
|
|
|
157
|
-
const ALIASES = { redocly: ["c"], exportType: ["t"], output: ["o"] };
|
|
158
|
-
|
|
159
232
|
/** Every name yargs-parser can return for a flag this CLI reads. */
|
|
160
233
|
const KNOWN_FLAGS = new Set<string>([
|
|
161
234
|
...BOOLEAN_FLAGS,
|
|
@@ -186,11 +259,14 @@ function writtenFlagName(key: string, argv: readonly string[]): string {
|
|
|
186
259
|
}
|
|
187
260
|
|
|
188
261
|
/**
|
|
189
|
-
* Parse the arguments after `node cli.js`. Fails with `CLI_FLAG_REMOVED` for an old flag
|
|
262
|
+
* Parse the arguments after `node cli.js`. Fails with `CLI_FLAG_REMOVED` for an old flag, with
|
|
263
|
+
* `CLI_FLAG_INVALID` for a boolean flag with another value than true or false, and with
|
|
190
264
|
* `OPTION_FIX_UNKNOWN` for an unknown `--fix` name.
|
|
191
265
|
*/
|
|
192
266
|
export function parseCliArguments(argv: readonly string[]): CliArguments {
|
|
193
|
-
|
|
267
|
+
const flags = writtenFlags(argv);
|
|
268
|
+
rejectRemovedFlags(flags);
|
|
269
|
+
rejectInvalidBooleans(flags);
|
|
194
270
|
const parsed = parser([...argv], {
|
|
195
271
|
boolean: BOOLEAN_FLAGS,
|
|
196
272
|
string: STRING_FLAGS,
|
|
@@ -198,8 +274,8 @@ export function parseCliArguments(argv: readonly string[]): CliArguments {
|
|
|
198
274
|
});
|
|
199
275
|
return {
|
|
200
276
|
input: optionalString(parsed._[0]),
|
|
201
|
-
output:
|
|
202
|
-
redocly:
|
|
277
|
+
output: lastString(parsed.output),
|
|
278
|
+
redocly: lastString(parsed.redocly),
|
|
203
279
|
isCheck: parsed.check === true,
|
|
204
280
|
isHelp: "help" in parsed,
|
|
205
281
|
isVersion: "version" in parsed,
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { Readable } from "node:stream";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
DirectoryCheck,
|
|
4
|
+
FileCheck,
|
|
5
|
+
FileClaims,
|
|
6
|
+
FileIdentity,
|
|
7
|
+
FileReader,
|
|
8
|
+
FileWriter,
|
|
9
|
+
} from "../application/ports/file-system.js";
|
|
3
10
|
import type { Logger } from "../application/ports/logger.js";
|
|
4
11
|
import type { RedoclyConfigSource } from "../application/ports/redocly-config-source.js";
|
|
5
12
|
import type { GeneratorOptions, SchemaSource } from "../types.js";
|
|
@@ -19,8 +26,23 @@ export interface TextStyle {
|
|
|
19
26
|
dim(text: string): string;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
/**
|
|
23
|
-
export
|
|
29
|
+
/** The printed declarations of one schema, and the local files they were generated from. */
|
|
30
|
+
export interface GeneratedTypes {
|
|
31
|
+
/** The declarations, with the comment header. */
|
|
32
|
+
readonly contents: string;
|
|
33
|
+
/** The schema, when it is a local file, and every local file its `$ref`s loaded. */
|
|
34
|
+
readonly localFiles: readonly URL[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Generate the types of one schema. With `apiName`, an API of `redocly.yaml`, every line the
|
|
39
|
+
* generation logs names that API.
|
|
40
|
+
*/
|
|
41
|
+
export type GenerateTypes = (
|
|
42
|
+
source: SchemaSource,
|
|
43
|
+
options: GeneratorOptions,
|
|
44
|
+
apiName?: string,
|
|
45
|
+
) => Promise<GeneratedTypes>;
|
|
24
46
|
|
|
25
47
|
export interface CliDependencies {
|
|
26
48
|
/** The working directory, as a directory URL (with a trailing slash). */
|
|
@@ -38,7 +60,7 @@ export interface CliDependencies {
|
|
|
38
60
|
* input with no prompt, which looks like a hang (upstream #1905).
|
|
39
61
|
*/
|
|
40
62
|
readonly isStdinTerminal: () => boolean;
|
|
41
|
-
readonly files: FileReader & FileWriter;
|
|
63
|
+
readonly files: FileReader & FileWriter & FileIdentity & DirectoryCheck & FileCheck & FileClaims;
|
|
42
64
|
readonly redoclyConfigs: RedoclyConfigSource;
|
|
43
65
|
readonly generate: GenerateTypes;
|
|
44
66
|
/** A monotonic time in milliseconds, for the time printed after each output. */
|
package/src/cli/cli-errors.ts
CHANGED
|
@@ -68,9 +68,24 @@ function parseFailedMessage(error: OpenAPITypesafeError): string {
|
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Text piped into stdin that is only a YAML string (`echo api.yaml | openapi-typesafe`) gets the
|
|
73
|
+
* CLI's advice, not the Node API's (`openapiTS(pathToFileURL(path))`).
|
|
74
|
+
*/
|
|
75
|
+
function sourceInvalidMessage(error: OpenAPITypesafeError): string {
|
|
76
|
+
const { received, text } = error.details;
|
|
77
|
+
if (received !== "stream" || typeof text !== "string") {
|
|
78
|
+
return error.message;
|
|
79
|
+
}
|
|
80
|
+
return (
|
|
81
|
+
`stdin held only the YAML string "${text}", not an OpenAPI document. To read a file, pass ` +
|
|
82
|
+
"its path or URL as the first argument: openapi-typesafe ./openapi.yaml -o ./schema.ts"
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
71
86
|
const CLI_ERROR_REPORTS: Readonly<Record<ErrorCode, CliErrorReport>> = {
|
|
72
87
|
SCHEMA_SOURCE_EMPTY: { exitCode: EXIT_CODES.SCHEMA },
|
|
73
|
-
SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA },
|
|
88
|
+
SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: sourceInvalidMessage },
|
|
74
89
|
SCHEMA_LOAD_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: loadFailedMessage },
|
|
75
90
|
SCHEMA_PARSE_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: parseFailedMessage },
|
|
76
91
|
SCHEMA_VERSION_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },
|
|
@@ -84,14 +99,20 @@ const CLI_ERROR_REPORTS: Readonly<Record<ErrorCode, CliErrorReport>> = {
|
|
|
84
99
|
ENUM_NAME_EMPTY: { exitCode: EXIT_CODES.SCHEMA },
|
|
85
100
|
CALLBACK_RESULT_UNREADABLE: { exitCode: EXIT_CODES.USAGE },
|
|
86
101
|
OPTION_FIX_UNKNOWN: { exitCode: EXIT_CODES.USAGE },
|
|
102
|
+
OPTION_INVALID: { exitCode: EXIT_CODES.USAGE },
|
|
87
103
|
TYPESCRIPT_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },
|
|
88
104
|
CLI_FLAG_REMOVED: { exitCode: EXIT_CODES.USAGE },
|
|
105
|
+
CLI_FLAG_INVALID: { exitCode: EXIT_CODES.USAGE },
|
|
89
106
|
CLI_GLOB_UNSUPPORTED: { exitCode: EXIT_CODES.USAGE },
|
|
90
107
|
CLI_CONFIG_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },
|
|
91
108
|
CLI_CONFIG_INVALID: { exitCode: EXIT_CODES.USAGE },
|
|
92
109
|
CLI_CONFIG_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
|
|
93
110
|
CLI_CHECK_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
|
|
94
111
|
CLI_INPUT_MISSING: { exitCode: EXIT_CODES.USAGE },
|
|
112
|
+
CLI_OUTPUT_IS_INPUT: { exitCode: EXIT_CODES.USAGE },
|
|
113
|
+
CLI_OUTPUT_DUPLICATE: { exitCode: EXIT_CODES.USAGE },
|
|
114
|
+
CLI_OUTPUT_INVALID: { exitCode: EXIT_CODES.USAGE },
|
|
115
|
+
CLI_LOCATION_INVALID: { exitCode: EXIT_CODES.USAGE },
|
|
95
116
|
OUTPUT_STALE: { exitCode: EXIT_CODES.OUTPUT_STALE },
|
|
96
117
|
OUTPUT_READ_FAILED: { exitCode: EXIT_CODES.OUTPUT },
|
|
97
118
|
OUTPUT_WRITE_FAILED: { exitCode: EXIT_CODES.OUTPUT },
|
|
@@ -108,6 +129,10 @@ export interface CliFailure {
|
|
|
108
129
|
* else is a bug and prints its stack, so it can be reported.
|
|
109
130
|
*/
|
|
110
131
|
export function describeCliFailure(error: unknown): CliFailure {
|
|
132
|
+
if (error instanceof ApiFailure) {
|
|
133
|
+
const failure = describeCliFailure(error.cause);
|
|
134
|
+
return { ...failure, message: `API ${error.apiName}: ${failure.message}` };
|
|
135
|
+
}
|
|
111
136
|
if (!isOpenAPITypesafeError(error)) {
|
|
112
137
|
const text = error instanceof Error ? (error.stack ?? error.message) : String(error);
|
|
113
138
|
return { exitCode: EXIT_CODES.INTERNAL, message: `Unexpected error: ${text}` };
|
|
@@ -117,6 +142,22 @@ export function describeCliFailure(error: unknown): CliFailure {
|
|
|
117
142
|
return { exitCode: report.exitCode, message: `${message} (${error.code})` };
|
|
118
143
|
}
|
|
119
144
|
|
|
145
|
+
/**
|
|
146
|
+
* A failure of one API of a Redocly config. The CLI reports its cause with the API named first,
|
|
147
|
+
* as the config errors of an API are; the cause keeps its code and so its exit code.
|
|
148
|
+
*/
|
|
149
|
+
export class ApiFailure extends Error {
|
|
150
|
+
override readonly name = "ApiFailure";
|
|
151
|
+
override readonly cause: unknown;
|
|
152
|
+
readonly apiName: string;
|
|
153
|
+
|
|
154
|
+
constructor(apiName: string, cause: unknown) {
|
|
155
|
+
super(`API ${apiName} failed`, { cause });
|
|
156
|
+
this.apiName = apiName;
|
|
157
|
+
this.cause = cause;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
120
161
|
/** Errors of the CLI itself; its messages are the original CLI's messages. */
|
|
121
162
|
export function cliError(
|
|
122
163
|
code: Extract<ErrorCode, `CLI_${string}` | `OUTPUT_${string}`>,
|
package/src/cli/cli-output.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
3
|
import { formatDuration } from "../adapters/terminal-logger/terminal-logger.js";
|
|
4
|
+
import type { RedoclyConfig } from "../application/ports/redocly-config-source.js";
|
|
5
|
+
import { hasUrlScheme } from "../domain/location-text.js";
|
|
6
|
+
import { terminalSafeText } from "../domain/terminal-text.js";
|
|
7
|
+
import { redactUnparsedUrl, redactUrlSecrets } from "../domain/url-secrets.js";
|
|
4
8
|
import type { CliArguments } from "./cli-arguments.js";
|
|
5
|
-
import type { CliDependencies } from "./cli-dependencies.js";
|
|
9
|
+
import type { CliDependencies, GeneratedTypes } from "./cli-dependencies.js";
|
|
6
10
|
import { cliError } from "./cli-errors.js";
|
|
7
11
|
|
|
8
12
|
/** Writing one generated file, or checking it with `--check`, and the line printed for it. */
|
|
@@ -14,35 +18,200 @@ export interface CliRun {
|
|
|
14
18
|
readonly startedAt: number;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
/**
|
|
18
|
-
export interface
|
|
21
|
+
/** An output as the user wrote it: `source` names the schema, `output` is the path or URL. */
|
|
22
|
+
export interface NamedOutput {
|
|
19
23
|
readonly source: string;
|
|
20
24
|
readonly output: string;
|
|
21
|
-
readonly file: URL;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const URL_SCHEME = /^[a-z][a-z\d+.-]+:/i;
|
|
27
|
+
/** A generated file: an output with the location of its local file. */
|
|
28
|
+
export interface OutputFile extends NamedOutput {
|
|
29
|
+
readonly file: URL;
|
|
30
|
+
}
|
|
29
31
|
|
|
30
32
|
/**
|
|
31
|
-
* The URL of a location the user wrote: a URL
|
|
32
|
-
*
|
|
33
|
-
*
|
|
33
|
+
* The URL of a location the user wrote: a URL, else a file path, absolute or relative to the
|
|
34
|
+
* directory of `base` (a directory or file URL). A relative `file:` URL (`file:api.yaml`) resolves
|
|
35
|
+
* against `base` too, as in openapi-typescript. A path is not parsed as a URL, so `#`, `?` and `%`
|
|
36
|
+
* are part of the file name. A location with a scheme that does not parse as a URL
|
|
37
|
+
* (`http://[::1/x`) fails with `CLI_LOCATION_INVALID`.
|
|
34
38
|
*/
|
|
35
39
|
export function resolveLocationUrl(location: string, base: URL): URL {
|
|
36
|
-
if (
|
|
37
|
-
|
|
40
|
+
if (hasUrlScheme(location)) {
|
|
41
|
+
const url = URL.parse(location, base.href);
|
|
42
|
+
if (url === null) {
|
|
43
|
+
const shown = redactUnparsedUrl(location);
|
|
44
|
+
throw cliError("CLI_LOCATION_INVALID", `The location ${shown} is not a valid URL`);
|
|
45
|
+
}
|
|
46
|
+
return url;
|
|
38
47
|
}
|
|
39
48
|
const baseDirectory = fileURLToPath(new URL(".", base));
|
|
40
49
|
return pathToFileURL(path.resolve(baseDirectory, location));
|
|
41
50
|
}
|
|
42
51
|
|
|
52
|
+
const FILE_PROTOCOL = "file:";
|
|
53
|
+
|
|
54
|
+
/** Segments that name a directory: the directory itself and its parent. */
|
|
55
|
+
const DIRECTORY_SEGMENTS: ReadonlySet<string> = new Set([".", ".."]);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Whether the location names a directory as written, before resolving drops the sign: a trailing
|
|
59
|
+
* `/` (or `\\` on Windows), or a last segment `.` or `..` (`-o gen/.`, `-o a/b/..`). For a URL
|
|
60
|
+
* the parsed path tells it too, since the URL parser drops `.`, `..` and their `%2E` forms.
|
|
61
|
+
*/
|
|
62
|
+
function namesDirectory(location: string, file: URL): boolean {
|
|
63
|
+
const lastSegment = location
|
|
64
|
+
.split(path.sep)
|
|
65
|
+
.flatMap((part) => part.split("/"))
|
|
66
|
+
.at(-1);
|
|
67
|
+
return (
|
|
68
|
+
lastSegment === "" || DIRECTORY_SEGMENTS.has(lastSegment ?? "") || file.pathname.endsWith("/")
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function invalidOutput(output: string, reason: string): Error {
|
|
73
|
+
return cliError("CLI_OUTPUT_INVALID", `The output ${output} ${reason}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The URL of the output, if it is a local file that can be written; it may not exist yet. */
|
|
77
|
+
function outputUrlOf(run: CliRun, output: string, base: URL): URL {
|
|
78
|
+
const file = parseLocationUrl(output, base);
|
|
79
|
+
if (file?.protocol !== FILE_PROTOCOL) {
|
|
80
|
+
throw invalidOutput(
|
|
81
|
+
output,
|
|
82
|
+
"is not a local file. Write the types to a file path or a file: URL.",
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (!isLocalFile(file)) {
|
|
86
|
+
throw invalidOutput(output, "names no file on this computer. Use a file path instead.");
|
|
87
|
+
}
|
|
88
|
+
if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {
|
|
89
|
+
throw invalidOutput(output, "is a directory. Name the file to write the types to in it.");
|
|
90
|
+
}
|
|
91
|
+
return file;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** A `file:` URL with a host, or with an encoded slash, names no path on this platform. */
|
|
95
|
+
function isLocalFile(file: URL): boolean {
|
|
96
|
+
try {
|
|
97
|
+
fileURLToPath(file);
|
|
98
|
+
return true;
|
|
99
|
+
} catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The output file of `source`, as the user wrote it in `output`, relative to `base`. Fails with
|
|
106
|
+
* `CLI_OUTPUT_INVALID` before anything is generated when it is not a local file (a URL of
|
|
107
|
+
* another scheme) or is a directory (a trailing separator, a last segment `.` or `..`, or a
|
|
108
|
+
* directory on disk). Without this check, `-o dir/` and `-o dir/.` wrote a file named `dir`.
|
|
109
|
+
*/
|
|
110
|
+
export function outputFileOf(run: CliRun, named: NamedOutput, base: URL): OutputFile {
|
|
111
|
+
return { ...named, file: outputUrlOf(run, named.output, base) };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** A file the CLI reads or writes: `name` is how an error names it, `location` where it is. */
|
|
115
|
+
export interface NamedFile {
|
|
116
|
+
readonly name: string;
|
|
117
|
+
readonly location: URL;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The `files` that are the local file `output`, also through a link or in another letter case. */
|
|
121
|
+
function filesAtOutput(run: CliRun, output: OutputFile, files: readonly NamedFile[]): NamedFile[] {
|
|
122
|
+
return files.filter(
|
|
123
|
+
({ location }) =>
|
|
124
|
+
location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** A location as a path relative to the working directory, as error messages name files. */
|
|
129
|
+
function displayPathOf(run: CliRun, location: URL): string {
|
|
130
|
+
return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || ".";
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** The Redocly config file the run read, if any: no output may replace it. */
|
|
134
|
+
export function redoclyConfigFiles(run: CliRun, redocly: RedoclyConfig): NamedFile[] {
|
|
135
|
+
if (!redocly.configFile) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);
|
|
139
|
+
return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The local files that `owner` (a schema or an API) was generated from, `$ref`'d ones too. */
|
|
143
|
+
export function filesReadBy(run: CliRun, types: GeneratedTypes, owner: string): NamedFile[] {
|
|
144
|
+
return types.localFiles.map((location) => ({
|
|
145
|
+
name: `schema ${displayPathOf(run, location)} that ${owner} reads`,
|
|
146
|
+
location,
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Fail with `CLI_OUTPUT_IS_INPUT` when `output` is one of the `schemas` (or the Redocly config).
|
|
152
|
+
* Writing it would replace that file with the types, which upstream did without a word. The CLI
|
|
153
|
+
* checks the files it knows before generating, so nothing is loaded or written, and the files
|
|
154
|
+
* that `$ref`s loaded after generating, before anything is written.
|
|
155
|
+
*/
|
|
156
|
+
export function ensureOutputIsNotSchema(
|
|
157
|
+
run: CliRun,
|
|
158
|
+
output: OutputFile,
|
|
159
|
+
schemas: readonly NamedFile[],
|
|
160
|
+
): void {
|
|
161
|
+
const [schema] = filesAtOutput(run, output, schemas);
|
|
162
|
+
if (schema) {
|
|
163
|
+
throw cliError(
|
|
164
|
+
"CLI_OUTPUT_IS_INPUT",
|
|
165
|
+
`The output ${output.output} is the ${schema.name}: writing the types would ` +
|
|
166
|
+
"overwrite it. Choose another output file.",
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Fail with `CLI_OUTPUT_DUPLICATE` when the output of an API is also one of `otherOutputs`.
|
|
173
|
+
* Whichever write came last would win, so every API with that output fails, before anything is
|
|
174
|
+
* generated.
|
|
175
|
+
*/
|
|
176
|
+
export function ensureOutputIsOwn(
|
|
177
|
+
run: CliRun,
|
|
178
|
+
output: OutputFile,
|
|
179
|
+
otherOutputs: readonly NamedFile[],
|
|
180
|
+
): void {
|
|
181
|
+
const clashes = filesAtOutput(run, output, otherOutputs);
|
|
182
|
+
if (clashes.length > 0) {
|
|
183
|
+
throw duplicateOutputError(
|
|
184
|
+
output,
|
|
185
|
+
clashes.map(({ name }) => name),
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** `CLI_OUTPUT_DUPLICATE` for `output`, which is also the output of the `others` (named). */
|
|
191
|
+
export function duplicateOutputError(output: NamedOutput, others: readonly string[]): Error {
|
|
192
|
+
return cliError(
|
|
193
|
+
"CLI_OUTPUT_DUPLICATE",
|
|
194
|
+
`The output ${output.output} of API ${output.source} is also the output of ` +
|
|
195
|
+
`${others.join(", ")}: they would overwrite each other. Give each API its own output file.`,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** As `resolveLocationUrl`, but undefined for a URL that does not parse instead of a throw. */
|
|
200
|
+
export function parseLocationUrl(location: string, base: URL): URL | undefined {
|
|
201
|
+
if (hasUrlScheme(location)) {
|
|
202
|
+
return URL.parse(location, base.href) ?? undefined;
|
|
203
|
+
}
|
|
204
|
+
return resolveLocationUrl(location, base);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* The line for a written file. It goes to the job log, so a source URL shows no secrets, and a
|
|
209
|
+
* line break or escape sequence in a name cannot start a forged line.
|
|
210
|
+
*/
|
|
43
211
|
function printDone(run: CliRun, output: OutputFile): void {
|
|
44
212
|
const { style, now } = run.deps;
|
|
45
|
-
const
|
|
213
|
+
const source = terminalSafeText(redactUrlSecrets(output.source));
|
|
214
|
+
const target = style.green(`${source} → ${style.bold(terminalSafeText(output.output))}`);
|
|
46
215
|
const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);
|
|
47
216
|
run.deps.console.info(`🚀 ${target} ${duration}`);
|
|
48
217
|
}
|
|
@@ -65,3 +234,14 @@ export function emitOutput(run: CliRun, output: OutputFile, contents: string): v
|
|
|
65
234
|
run.deps.files.writeText(output.file, contents);
|
|
66
235
|
printDone(run, output);
|
|
67
236
|
}
|
|
237
|
+
|
|
238
|
+
/** Write (or `--check`) the types, unless the output is one of the files the run read. */
|
|
239
|
+
export function writeOutput(
|
|
240
|
+
run: CliRun,
|
|
241
|
+
output: OutputFile,
|
|
242
|
+
types: GeneratedTypes,
|
|
243
|
+
readFiles: readonly NamedFile[],
|
|
244
|
+
): void {
|
|
245
|
+
ensureOutputIsNotSchema(run, output, readFiles);
|
|
246
|
+
emitOutput(run, output, types.contents);
|
|
247
|
+
}
|