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
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { irRaw } from "../../../domain/ir/constructors.js";
|
|
2
|
+
import type { IrDeclaration } from "../../../domain/ir/nodes.js";
|
|
3
|
+
import type { PathsObject } from "../../../domain/openapi/path-item-object.js";
|
|
4
|
+
import { documentEntries } from "../document-entries.js";
|
|
5
|
+
import { HELPER_TYPES } from "../helper-types.js";
|
|
6
|
+
import type { TransformContext } from "../transform-context.js";
|
|
7
|
+
import type { PathKeyPart } from "./path-key-overlaps.js";
|
|
8
|
+
import { booleanExpandedKeys, pathTemplateParts, templateText } from "./path-template-key.js";
|
|
9
|
+
import { isUntakenKey, pathKeyOf } from "./paths.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* `--path-params-as-types` and `$ref`s into a templated path. Such a path is an index signature
|
|
13
|
+
* of `paths` (`` [path: `/pets/${number}`] ``), so `paths["/pets/{id}"]`, the type of a `$ref`
|
|
14
|
+
* to it, names no key: `{id}` is no number (TS2339). The reference indexes `paths` by the
|
|
15
|
+
* template instead, which reaches the signature; so does the type of an `--enum-values` array,
|
|
16
|
+
* which indexes `FlattenedDeepRequired<paths>`. With only `${string}` placeholders the URL
|
|
17
|
+
* itself matches the template and the output compiles, so it stays as it is.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const PATHS_TYPE_NAME = "paths";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The index of a templated path: the union of the keys it is written with. A `${boolean}` key the
|
|
24
|
+
* document's own path took (`/flags/true` next to `/flags/{enabled}`) is left out, so the index
|
|
25
|
+
* names only this path's members. Undefined when every key was taken: the path has no member.
|
|
26
|
+
*/
|
|
27
|
+
function templateIndexText(url: string, parts: readonly PathKeyPart[], takenUrls: Set<string>) {
|
|
28
|
+
const keys = booleanExpandedKeys(parts)
|
|
29
|
+
.map(pathKeyOf)
|
|
30
|
+
.filter((key) => isUntakenKey(url, key, takenUrls));
|
|
31
|
+
const texts = keys.map((key) =>
|
|
32
|
+
key.kind === "literal" ? JSON.stringify(key.url) : templateText(key.parts),
|
|
33
|
+
);
|
|
34
|
+
return texts.length === 0 ? undefined : texts.join(" | ");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The index of each templated path whose URL does not match its keys, by URL. */
|
|
38
|
+
export function unmatchedTemplateKeys(
|
|
39
|
+
paths: PathsObject | null | undefined,
|
|
40
|
+
context: TransformContext,
|
|
41
|
+
): ReadonlyMap<string, string> {
|
|
42
|
+
const keys = new Map<string, string>();
|
|
43
|
+
// A document may hold any value as `paths`; one that is no object has no paths.
|
|
44
|
+
if (!context.options.pathParamsAsTypes || typeof paths !== "object" || paths === null) {
|
|
45
|
+
return keys;
|
|
46
|
+
}
|
|
47
|
+
// The same walk as `pathMembers`, so a URL is taken by the same path as there.
|
|
48
|
+
const takenUrls = new Set(Object.keys(paths));
|
|
49
|
+
for (const [url, pathItem] of documentEntries(paths, context.options)) {
|
|
50
|
+
if (!pathItem || typeof pathItem !== "object" || "$ref" in pathItem || !url.includes("{")) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const parts = pathTemplateParts(url, pathItem, context);
|
|
54
|
+
const index = parts === null ? undefined : templateIndexText(url, parts, takenUrls);
|
|
55
|
+
const isUnmatched = parts?.some(
|
|
56
|
+
(part) => part.kind === "placeholder" && part.type !== "string",
|
|
57
|
+
);
|
|
58
|
+
if (isUnmatched && index !== undefined) {
|
|
59
|
+
keys.set(url, index);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return keys;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isNode(value: unknown): value is Readonly<Record<string, unknown>> {
|
|
66
|
+
return typeof value === "object" && value !== null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isBarePathsReference(node: unknown): boolean {
|
|
70
|
+
const reference = node as Readonly<Record<string, unknown>> | undefined;
|
|
71
|
+
return (
|
|
72
|
+
reference?.kind === "reference" &&
|
|
73
|
+
reference.name === PATHS_TYPE_NAME &&
|
|
74
|
+
(reference.typeArguments as readonly unknown[] | undefined)?.length === 0
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The `paths` root as a `$ref` or an `--enum-values` array indexes it: `paths`, or
|
|
80
|
+
* `FlattenedDeepRequired<paths>` (`rootType`), whose mapped keys are those of `paths`.
|
|
81
|
+
*/
|
|
82
|
+
function isPathsRoot(node: unknown): boolean {
|
|
83
|
+
const reference = node as Readonly<Record<string, unknown>> | undefined;
|
|
84
|
+
const typeArguments = reference?.typeArguments as readonly unknown[] | undefined;
|
|
85
|
+
const isDeepRoot =
|
|
86
|
+
reference?.kind === "reference" &&
|
|
87
|
+
reference.name === HELPER_TYPES.flattenedDeepRequired.name &&
|
|
88
|
+
typeArguments?.length === 1 &&
|
|
89
|
+
isBarePathsReference(typeArguments[0]);
|
|
90
|
+
return isDeepRoot || isBarePathsReference(node);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** `paths["<url>"]`: an index of the `paths` root by a string literal. */
|
|
94
|
+
function pathsIndexUrl(node: Readonly<Record<string, unknown>>): string | undefined {
|
|
95
|
+
const index = node.index as Readonly<Record<string, unknown>> | undefined;
|
|
96
|
+
const isPathsIndex =
|
|
97
|
+
node.kind === "indexedAccess" && isPathsRoot(node.object) && index?.kind === "stringLiteral";
|
|
98
|
+
return isPathsIndex ? (index.value as string) : undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function rewrittenNode(value: unknown, keys: ReadonlyMap<string, string>): unknown {
|
|
102
|
+
if (Array.isArray(value)) {
|
|
103
|
+
return value.map((item) => rewrittenNode(item, keys));
|
|
104
|
+
}
|
|
105
|
+
if (!isNode(value)) {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
const template = keys.get(pathsIndexUrl(value) ?? "");
|
|
109
|
+
if (template !== undefined) {
|
|
110
|
+
return { ...value, index: irRaw(template) };
|
|
111
|
+
}
|
|
112
|
+
// `origin` holds the compiler node a raw type was printed from; it is not IR.
|
|
113
|
+
return Object.fromEntries(
|
|
114
|
+
Object.entries(value).map(([key, child]) => [
|
|
115
|
+
key,
|
|
116
|
+
key === "origin" ? child : rewrittenNode(child, keys),
|
|
117
|
+
]),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The declarations with each `paths["<url>"]` of an unmatched template indexed by it. */
|
|
122
|
+
export function withTemplatePathRefs<T extends IrDeclaration>(
|
|
123
|
+
declarations: readonly T[],
|
|
124
|
+
keys: ReadonlyMap<string, string>,
|
|
125
|
+
): T[] {
|
|
126
|
+
return keys.size === 0 ? [...declarations] : (rewrittenNode(declarations, keys) as T[]);
|
|
127
|
+
}
|
|
@@ -3,6 +3,7 @@ import type { OperationObject } from "../../../domain/openapi/operation-object.j
|
|
|
3
3
|
import {
|
|
4
4
|
ADDITIONAL_OPERATIONS_KEY,
|
|
5
5
|
HTTP_METHODS,
|
|
6
|
+
type OperationEntry,
|
|
6
7
|
type PathItemMethod,
|
|
7
8
|
type PathsObject,
|
|
8
9
|
QUERY_METHOD,
|
|
@@ -72,12 +73,19 @@ function pathItemEntries(pathItem: object): [string, unknown][] {
|
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
/** Which operations get a member; the generator leaves out those `--exclude-deprecated` drops. */
|
|
77
|
+
export type OperationFilter = (operation: OperationEntry) => boolean;
|
|
78
|
+
|
|
79
|
+
const INCLUDES_EVERY_OPERATION: OperationFilter = () => true;
|
|
80
|
+
|
|
81
|
+
function pathOperations(paths: PathsObject, isIncluded: OperationFilter): PathOperation[] {
|
|
76
82
|
return Object.entries(paths).flatMap(([url, pathItem]) =>
|
|
77
|
-
pathItemEntries(pathItem)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
pathItemEntries(pathItem)
|
|
84
|
+
.filter(([, operation]) => isIncluded(operation as OperationEntry))
|
|
85
|
+
.map(([method, operation]) => {
|
|
86
|
+
const operationId = (operation as OperationObject).operationId || undefined;
|
|
87
|
+
return { url, method, operationId };
|
|
88
|
+
}),
|
|
81
89
|
);
|
|
82
90
|
}
|
|
83
91
|
|
|
@@ -108,8 +116,11 @@ function uniqueNames(operations: readonly PathOperation[]): string[] {
|
|
|
108
116
|
* One enum member per operation: the URL as the value, the operation ID (or a key built from the
|
|
109
117
|
* method and URL) as the name. Paths are in document order; `--alphabetize` does not apply.
|
|
110
118
|
*/
|
|
111
|
-
export function apiPathsEnum(
|
|
112
|
-
|
|
119
|
+
export function apiPathsEnum(
|
|
120
|
+
paths: PathsObject,
|
|
121
|
+
isIncluded: OperationFilter = INCLUDES_EVERY_OPERATION,
|
|
122
|
+
): ApiPathsEnum {
|
|
123
|
+
const operations = pathOperations(paths, isIncluded);
|
|
113
124
|
const names = uniqueNames(operations);
|
|
114
125
|
return {
|
|
115
126
|
values: operations.map((operation) => operation.url),
|
|
@@ -121,7 +132,10 @@ export function apiPathsEnum(paths: PathsObject): ApiPathsEnum {
|
|
|
121
132
|
* The `ApiPaths` enum declaration. Its own naming state is equivalent to the run's: the name is a
|
|
122
133
|
* valid identifier, and member names only reset the state, never read it.
|
|
123
134
|
*/
|
|
124
|
-
export function apiPathsEnumDeclaration(
|
|
135
|
+
export function apiPathsEnumDeclaration(
|
|
136
|
+
paths: PathsObject,
|
|
137
|
+
isIncluded: OperationFilter = INCLUDES_EVERY_OPERATION,
|
|
138
|
+
): IrEnumDeclaration {
|
|
125
139
|
const naming = new EnumNaming();
|
|
126
|
-
return enumDeclaration(naming.enumName(API_PATHS_NAME), apiPathsEnum(paths), naming);
|
|
140
|
+
return enumDeclaration(naming.enumName(API_PATHS_NAME), apiPathsEnum(paths, isIncluded), naming);
|
|
127
141
|
}
|
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
import { irIntersection, irObject, irProperty, irRaw } from "../../../domain/ir/constructors.js";
|
|
2
2
|
import type { IrMember, IrType } from "../../../domain/ir/nodes.js";
|
|
3
3
|
import { toPropertyName } from "../../../domain/ir/property-name.js";
|
|
4
|
-
import { escapeTemplateText } from "../../../domain/ir/raw-text-escapes.js";
|
|
5
4
|
import { appendPointer, ROOT_POINTER } from "../../../domain/openapi/json-pointer.js";
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
ParameterObject,
|
|
9
|
-
ParameterOrReference,
|
|
10
|
-
} from "../../../domain/openapi/parameter-object.js";
|
|
11
|
-
import {
|
|
12
|
-
type PathItemObject,
|
|
13
|
-
type PathsObject,
|
|
14
|
-
pathItemOperations,
|
|
15
|
-
} from "../../../domain/openapi/path-item-object.js";
|
|
16
|
-
import type { ReferenceSchema, SchemaObject } from "../../../domain/openapi/schema-object.js";
|
|
17
|
-
import { FIX } from "../../../domain/output-fixes.js";
|
|
5
|
+
import type { PathItemObject, PathsObject } from "../../../domain/openapi/path-item-object.js";
|
|
18
6
|
import { documentEntries } from "../document-entries.js";
|
|
19
7
|
import { refType } from "../ref-type.js";
|
|
20
8
|
import type { TransformContext } from "../transform-context.js";
|
|
@@ -26,124 +14,73 @@ import {
|
|
|
26
14
|
coveringTemplateKeys,
|
|
27
15
|
type PathKey,
|
|
28
16
|
type PathKeyPart,
|
|
29
|
-
type PathPlaceholder,
|
|
30
17
|
} from "./path-key-overlaps.js";
|
|
31
18
|
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
booleanExpandedKeys,
|
|
20
|
+
pathTemplateParts,
|
|
21
|
+
plainUrlOf,
|
|
22
|
+
templateText,
|
|
23
|
+
} from "./path-template-key.js";
|
|
36
24
|
import { assignabilityProof } from "./type-assignability.js";
|
|
37
25
|
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
["integer", "number"],
|
|
45
|
-
["boolean", "boolean"],
|
|
46
|
-
]);
|
|
47
|
-
const STRING_PLACEHOLDER: PathPlaceholder = "string";
|
|
48
|
-
|
|
49
|
-
function resolvedParameter(
|
|
50
|
-
parameter: ParameterOrReference,
|
|
51
|
-
context: TransformContext,
|
|
52
|
-
): ParameterObject | undefined {
|
|
53
|
-
return "$ref" in parameter && parameter.$ref
|
|
54
|
-
? (context.refs.resolve(parameter.$ref) as ParameterObject | undefined)
|
|
55
|
-
: (parameter as ParameterObject);
|
|
26
|
+
/** A path's member, its key and its path item type for the overlap check. */
|
|
27
|
+
export interface PathMember {
|
|
28
|
+
readonly url: string;
|
|
29
|
+
readonly member: IrMember;
|
|
30
|
+
readonly key: PathKey;
|
|
31
|
+
readonly type: IrType;
|
|
56
32
|
}
|
|
57
33
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
): void {
|
|
63
|
-
for (const parameter of parameters) {
|
|
64
|
-
const resolved = resolvedParameter(parameter, context);
|
|
65
|
-
if (resolved && resolved.in === "path") {
|
|
66
|
-
byName.set(resolved.name, resolved);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
34
|
+
/** The key of the parts: a plain URL, or a template with placeholders left. */
|
|
35
|
+
export function pathKeyOf(parts: readonly PathKeyPart[]): PathKey {
|
|
36
|
+
const plainUrl = plainUrlOf(parts);
|
|
37
|
+
return plainUrl === null ? { kind: "template", parts } : literalKey(plainUrl);
|
|
69
38
|
}
|
|
70
39
|
|
|
71
|
-
/**
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
addPathParameters(pathItem.parameters ?? [], byName, context);
|
|
78
|
-
for (const { operation: entry } of pathItemOperations(pathItem)) {
|
|
79
|
-
const operation = (entry as ReferenceSchema).$ref
|
|
80
|
-
? (context.refs.resolve((entry as ReferenceSchema).$ref) as OperationObject | undefined)
|
|
81
|
-
: (entry as OperationObject);
|
|
82
|
-
addPathParameters(operation?.parameters ?? [], byName, context);
|
|
40
|
+
/** The member of one key of a path: a property for a plain URL, else an index signature. */
|
|
41
|
+
function keyMember(url: string, parts: readonly PathKeyPart[], type: IrType, isReadonly: boolean) {
|
|
42
|
+
const key = pathKeyOf(parts);
|
|
43
|
+
if (key.kind === "literal") {
|
|
44
|
+
const member = irProperty(toPropertyName(key.url), type, { isReadonly });
|
|
45
|
+
return { url, member, key, type };
|
|
83
46
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
});
|
|
47
|
+
const member: IrMember = {
|
|
48
|
+
kind: "indexSignature",
|
|
49
|
+
parameterName: "path",
|
|
50
|
+
parameterType: irRaw(templateText(parts)),
|
|
51
|
+
type,
|
|
52
|
+
isReadonly,
|
|
53
|
+
comments: [],
|
|
54
|
+
};
|
|
55
|
+
return { url, member, key, type };
|
|
94
56
|
}
|
|
95
57
|
|
|
96
58
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
59
|
+
* Whether a key of the path at `url` is written. A URL that `${boolean}` keys give is not when it
|
|
60
|
+
* is taken already: by a path of the document, which OpenAPI matches before a template (Paths
|
|
61
|
+
* Object), or by the keys of an earlier path. A property written twice does not compile (TS2300).
|
|
62
|
+
* `takenUrls` starts with the document's URLs and gets each expanded URL, in document order.
|
|
100
63
|
*/
|
|
101
|
-
function
|
|
102
|
-
url
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
): PathKeyPart[] | null {
|
|
106
|
-
const found = url.match(PATH_PARAMETER_RE);
|
|
107
|
-
if (!found) {
|
|
108
|
-
return null;
|
|
64
|
+
export function isUntakenKey(url: string, key: PathKey, takenUrls: Set<string>): boolean {
|
|
65
|
+
const isExpandedUrl = key.kind === "literal" && key.url !== url;
|
|
66
|
+
if (!isExpandedUrl) {
|
|
67
|
+
return true;
|
|
109
68
|
}
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return { match, type: PLACEHOLDERS.get(schema?.type) ?? STRING_PLACEHOLDER };
|
|
114
|
-
});
|
|
115
|
-
return context.options.fixes.has(FIX.PATH_PARAM_TYPE_NAMES)
|
|
116
|
-
? splitTemplateParts(url, matches)
|
|
117
|
-
: replacedTemplateParts(url, matches);
|
|
69
|
+
const isTaken = takenUrls.has(key.url);
|
|
70
|
+
takenUrls.add(key.url);
|
|
71
|
+
return !isTaken;
|
|
118
72
|
}
|
|
119
73
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
* `${` in the URL could end the literal or open a placeholder, and add code to the generated file
|
|
123
|
-
* (intentional fix). So the text parts are escaped.
|
|
124
|
-
*/
|
|
125
|
-
function templateText(parts: readonly PathKeyPart[]): string {
|
|
126
|
-
const text = parts
|
|
127
|
-
.map((part) =>
|
|
128
|
-
part.kind === "text" ? escapeTemplateText(part.text) : placeholderText(part.type),
|
|
129
|
-
)
|
|
130
|
-
.join("");
|
|
131
|
-
return `\`${text}\``;
|
|
74
|
+
function withoutTakenUrls(url: string, members: readonly PathMember[], takenUrls: Set<string>) {
|
|
75
|
+
return members.filter(({ key }) => isUntakenKey(url, key, takenUrls));
|
|
132
76
|
}
|
|
133
77
|
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
readonly url: string;
|
|
137
|
-
readonly member: IrMember;
|
|
138
|
-
readonly key: PathKey;
|
|
139
|
-
readonly type: IrType;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function pathItemMember(
|
|
78
|
+
/** The members of a path: one, or one per key of its `${boolean}` placeholders. */
|
|
79
|
+
function pathItemMembers(
|
|
143
80
|
url: string,
|
|
144
81
|
pathItem: PathItemObject,
|
|
145
82
|
context: TransformContext,
|
|
146
|
-
): PathMember {
|
|
83
|
+
): PathMember[] {
|
|
147
84
|
const isReadonly = context.options.immutable;
|
|
148
85
|
const type = pathItemType(
|
|
149
86
|
pathItem,
|
|
@@ -156,17 +93,9 @@ function pathItemMember(
|
|
|
156
93
|
: null;
|
|
157
94
|
if (parts === null) {
|
|
158
95
|
const member = irProperty(toPropertyName(url), type, { isReadonly });
|
|
159
|
-
return { url, member, key: literalKey(url), type };
|
|
96
|
+
return [{ url, member, key: literalKey(url), type }];
|
|
160
97
|
}
|
|
161
|
-
|
|
162
|
-
kind: "indexSignature",
|
|
163
|
-
parameterName: "path",
|
|
164
|
-
parameterType: irRaw(templateText(parts)),
|
|
165
|
-
type,
|
|
166
|
-
isReadonly,
|
|
167
|
-
comments: [],
|
|
168
|
-
};
|
|
169
|
-
return { url, member, key: { kind: "template", parts }, type };
|
|
98
|
+
return booleanExpandedKeys(parts).map((key) => keyMember(url, key, type, isReadonly));
|
|
170
99
|
}
|
|
171
100
|
|
|
172
101
|
function literalKey(url: string): PathKey {
|
|
@@ -248,6 +177,7 @@ export function pathsObjectType(
|
|
|
248
177
|
/** The members of the `paths` interface (OpenAPI 3.1 §4.8.8): one per path, by URL. */
|
|
249
178
|
export function pathMembers(paths: PathsObject, context: TransformContext): PathMember[] {
|
|
250
179
|
const members: PathMember[] = [];
|
|
180
|
+
const takenUrls = new Set(Object.keys(paths));
|
|
251
181
|
for (const [url, pathItem] of documentEntries(paths, context.options)) {
|
|
252
182
|
if (!pathItem || typeof pathItem !== "object") {
|
|
253
183
|
continue;
|
|
@@ -259,10 +189,10 @@ export function pathMembers(paths: PathsObject, context: TransformContext): Path
|
|
|
259
189
|
continue;
|
|
260
190
|
}
|
|
261
191
|
const startedAt = context.diagnostics.now();
|
|
262
|
-
const
|
|
263
|
-
members.push(
|
|
192
|
+
const pathMembersOfUrl = pathItemMembers(url, pathItem, context);
|
|
193
|
+
members.push(...withoutTakenUrls(url, pathMembersOfUrl, takenUrls));
|
|
264
194
|
// The original reports only paths written as properties.
|
|
265
|
-
if (
|
|
195
|
+
if (pathMembersOfUrl[0]?.key.kind === "literal" && pathMembersOfUrl[0].key.url === url) {
|
|
266
196
|
context.diagnostics.debug(`Transformed path "${url}"`, context.diagnostics.now() - startedAt);
|
|
267
197
|
}
|
|
268
198
|
}
|
|
@@ -4,19 +4,32 @@ import { toPropertyName } from "../../../domain/ir/property-name.js";
|
|
|
4
4
|
import { appendPointer, ROOT_POINTER } from "../../../domain/openapi/json-pointer.js";
|
|
5
5
|
import type { PathItemObject, PathsObject } from "../../../domain/openapi/path-item-object.js";
|
|
6
6
|
import { documentEntries } from "../document-entries.js";
|
|
7
|
+
import { refType } from "../ref-type.js";
|
|
7
8
|
import type { TransformContext } from "../transform-context.js";
|
|
8
9
|
import { pathItemType } from "./path-item.js";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
* The `webhooks` interface body (OpenAPI 3.1 §4.8.1): one path item per webhook name.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* The `webhooks` interface body (OpenAPI 3.1 §4.8.1): one path item per webhook name. A `$ref`
|
|
13
|
+
* entry (often to `components/pathItems`) is the type it points at, as in `paths`; the original
|
|
14
|
+
* read it as a path item, so every method was `never`. Members carry no JSDoc.
|
|
14
15
|
*/
|
|
15
16
|
export function webhooksType(webhooks: PathsObject, context: TransformContext): IrType {
|
|
16
17
|
const members = documentEntries(webhooks, context.options).map(([name, pathItem]) => {
|
|
17
|
-
const
|
|
18
|
-
const type = pathItemType(pathItem as PathItemObject, location, context);
|
|
18
|
+
const type = webhookType(name, pathItem, context);
|
|
19
19
|
return irProperty(toPropertyName(name), type, { isReadonly: context.options.immutable });
|
|
20
20
|
});
|
|
21
21
|
return irObject(members);
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
function webhookType(
|
|
25
|
+
name: string,
|
|
26
|
+
pathItem: PathsObject[string],
|
|
27
|
+
context: TransformContext,
|
|
28
|
+
): IrType {
|
|
29
|
+
// A document may hold any value here; one that is no object is read as a path item, as before.
|
|
30
|
+
if (typeof pathItem === "object" && pathItem !== null && "$ref" in pathItem) {
|
|
31
|
+
return refType(pathItem.$ref);
|
|
32
|
+
}
|
|
33
|
+
const location = { path: appendPointer(ROOT_POINTER, ["webhooks", name]) };
|
|
34
|
+
return pathItemType(pathItem as PathItemObject, location, context);
|
|
35
|
+
}
|
|
@@ -32,14 +32,23 @@ export interface FooterSink {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* The `--dedupe-enums` key
|
|
36
|
-
* the
|
|
35
|
+
* The `--dedupe-enums` key. Two enums share a declaration only when the original shares it and
|
|
36
|
+
* each value has the same name and description in both. The original key pairs the values in
|
|
37
|
+
* default sort order with the metadata at the sorted position, not with the value's own metadata,
|
|
38
|
+
* so `[desc, asc]` and `[asc, desc]`, both named `[Desc, Asc]`, shared one declaration, and one of
|
|
39
|
+
* them typed `asc` as `Desc = "desc"`. The original also joined `name:description` texts with
|
|
40
|
+
* `,`, and a member name stood in for its value, so enums with other values (`"1"` and `1`, `A`
|
|
41
|
+
* and `1` both named `Active`, `["a", "b"]` and `["a:,b"]`) shared one key. As JSON, an equal key
|
|
42
|
+
* means the same values and metadata; enums the original kept apart still are.
|
|
37
43
|
*/
|
|
38
44
|
function dedupeKey(request: EnumDeclarationRequest): string {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.
|
|
45
|
+
const sorted = [...request.values].sort(compareAsStrings);
|
|
46
|
+
const originalPairs = sorted.map((value, index) => memberKey(value, request.metadata[index]));
|
|
47
|
+
const ownPairs = request.values
|
|
48
|
+
.map((value, index) => ({ value, member: memberKey(value, request.metadata[index]) }))
|
|
49
|
+
.sort((left, right) => compareAsStrings(left.value, right.value))
|
|
50
|
+
.map(({ member }) => member);
|
|
51
|
+
return JSON.stringify([originalPairs, ownPairs]);
|
|
43
52
|
}
|
|
44
53
|
|
|
45
54
|
/** `Array.prototype.sort` without a comparator: compares the values as strings. */
|
|
@@ -52,8 +61,9 @@ function compareAsStrings(left: string | number, right: string | number): number
|
|
|
52
61
|
return leftText < rightText ? -1 : 1;
|
|
53
62
|
}
|
|
54
63
|
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
/** One member: the value (JSON keeps `"1"` and `1` apart), its name and its description. */
|
|
65
|
+
function memberKey(value: string | number, metadata: EnumMemberMetadata | undefined) {
|
|
66
|
+
return [value, metadata?.name ?? null, metadata?.description || null];
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
/** Separates a repeated `--enum-values` array name from its number, as root type aliases do. */
|
|
@@ -65,10 +65,10 @@ export const READ_WRITE_MARKER_TYPES = lines(
|
|
|
65
65
|
"};",
|
|
66
66
|
"type ReadWritePrimitive = string | number | boolean | bigint | symbol | null | undefined;",
|
|
67
67
|
"type ReadWriteLeaf = ReadWritePrimitive | ((...args: never) => unknown);",
|
|
68
|
-
"type ReadWriteMarkedKeys<T, Marker> = {",
|
|
69
|
-
" [K in keyof T
|
|
70
|
-
"NonNullable<T[K]> extends Marker ? K : never;",
|
|
71
|
-
"}
|
|
68
|
+
"type ReadWriteMarkedKeys<T, Marker> = keyof {",
|
|
69
|
+
" [K in keyof T as 0 extends 1 & T[K] ? never : NonNullable<T[K]> extends never ? never : " +
|
|
70
|
+
"NonNullable<T[K]> extends Marker ? K : never]: never;",
|
|
71
|
+
"};",
|
|
72
72
|
'type ReadWriteResolveArray<T extends readonly unknown[], Resolved extends "read" | ' +
|
|
73
73
|
'"write"> = T[number][] extends T ? T extends unknown[] ? ReadWriteResolve<T[number], ' +
|
|
74
74
|
"Resolved>[] : readonly ReadWriteResolve<T[number], Resolved>[] : {",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { appendPointer, ROOT_POINTER } from "../../../domain/openapi/json-pointer.js";
|
|
2
2
|
import type { RefResolver } from "../schema/schema-context.js";
|
|
3
|
-
import { isJsonObject } from "./
|
|
3
|
+
import { isJsonObject } from "./located-node.js";
|
|
4
4
|
import {
|
|
5
5
|
leadingSegmentsOf,
|
|
6
6
|
type RefPointer,
|