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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-flags.cjs","sources":["../../../../src/application/transform/schema/access-flags.ts"],"sourcesContent":["import type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext } from \"./schema-context.js\";\n\n/** Whether a property is `readOnly` or `writeOnly` (JSON Schema 2020-12 Validation §9.4). */\nexport interface AccessFlags {\n readonly isReadOnly: boolean;\n readonly isWriteOnly: boolean;\n}\n\nconst NO_FLAGS: AccessFlags = { isReadOnly: false, isWriteOnly: false };\n\nfunction ownFlags(schema: SchemaObject): AccessFlags {\n return { isReadOnly: Boolean(schema.readOnly), isWriteOnly: Boolean(schema.writeOnly) };\n}\n\nfunction merged(left: AccessFlags, right: AccessFlags): AccessFlags {\n return {\n isReadOnly: left.isReadOnly || right.isReadOnly,\n isWriteOnly: left.isWriteOnly || right.isWriteOnly,\n };\n}\n\n/**\n * The flags of a schema and of the schemas that always apply to the same value: the one its\n * `$ref` names and its `allOf` members, followed until a schema repeats. `readOnly` is an\n * annotation, and the annotations of those schemas are the value's (2020-12 Core §7.7.1); in\n * OpenAPI 3.0 a referenced schema is the property's definition. `anyOf` and `oneOf` members apply\n * only when they match, which the type cannot tell, so they are not read.\n */\nfunction appliedFlags(\n schema: Schema | undefined,\n context: SchemaContext
|
|
1
|
+
{"version":3,"file":"access-flags.cjs","sources":["../../../../src/application/transform/schema/access-flags.ts"],"sourcesContent":["import type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext } from \"./schema-context.js\";\n\n/** Whether a property is `readOnly` or `writeOnly` (JSON Schema 2020-12 Validation §9.4). */\nexport interface AccessFlags {\n readonly isReadOnly: boolean;\n readonly isWriteOnly: boolean;\n}\n\nconst NO_FLAGS: AccessFlags = { isReadOnly: false, isWriteOnly: false };\n\nfunction ownFlags(schema: SchemaObject): AccessFlags {\n return { isReadOnly: Boolean(schema.readOnly), isWriteOnly: Boolean(schema.writeOnly) };\n}\n\nfunction merged(left: AccessFlags, right: AccessFlags): AccessFlags {\n return {\n isReadOnly: left.isReadOnly || right.isReadOnly,\n isWriteOnly: left.isWriteOnly || right.isWriteOnly,\n };\n}\n\n/**\n * The flags of a schema and of the schemas that always apply to the same value: the one its\n * `$ref` names and its `allOf` members, followed until a schema repeats. `readOnly` is an\n * annotation, and the annotations of those schemas are the value's (2020-12 Core §7.7.1); in\n * OpenAPI 3.0 a referenced schema is the property's definition. `anyOf` and `oneOf` members apply\n * only when they match, which the type cannot tell, so they are not read.\n */\nfunction appliedFlags(\n schema: Schema | undefined,\n context: Pick<SchemaContext, \"refs\">,\n seen: ReadonlySet<Schema>,\n): AccessFlags {\n if (typeof schema !== \"object\" || schema === null || seen.has(schema)) {\n return NO_FLAGS;\n }\n const inner = new Set([...seen, schema]);\n // `readOnly` next to a `$ref` is read too, as the generator always has.\n const object = schema as SchemaObject & { readonly $ref?: unknown };\n const target =\n typeof object.$ref === \"string\" ? (context.refs.resolve(object.$ref) as Schema) : undefined;\n return (object.allOf ?? []).reduce<AccessFlags>(\n (flags, member) => merged(flags, appliedFlags(member, context, inner)),\n merged(ownFlags(object), appliedFlags(target, context, inner)),\n );\n}\n\n/**\n * The flags of a property schema. Without the `read-write-refs` fix only the keywords written on\n * it count, as in openapi-typescript; with it, also those of the schemas its `$ref` and `allOf`\n * apply (upstream #1938).\n */\nexport function propertyAccessFlags(\n value: Schema,\n context: Pick<SchemaContext, \"options\" | \"refs\">,\n): AccessFlags {\n if (typeof value !== \"object\") {\n return NO_FLAGS;\n }\n if (!context.options.fixes.has(FIX.READ_WRITE_REFS)) {\n return ownFlags(value as SchemaObject);\n }\n return appliedFlags(value, context, new Set());\n}\n"],"names":["FIX"],"mappings":";;;;AAUA,MAAM,Q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AAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,OAAA,CAAQ,OAAA,CAAQ,MAAM,GAAA,CAAIA,eAAA,CAAI,eAAe,CAAA,EAAG;AACnD,IAAA,OAAO,SAAS,KAAqB,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,YAAA,CAAa,KAAA,EAAO,OAAA,kBAAS,IAAI,KAAK,CAAA;AAC/C;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-flags.mjs","sources":["../../../../src/application/transform/schema/access-flags.ts"],"sourcesContent":["import type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext } from \"./schema-context.js\";\n\n/** Whether a property is `readOnly` or `writeOnly` (JSON Schema 2020-12 Validation §9.4). */\nexport interface AccessFlags {\n readonly isReadOnly: boolean;\n readonly isWriteOnly: boolean;\n}\n\nconst NO_FLAGS: AccessFlags = { isReadOnly: false, isWriteOnly: false };\n\nfunction ownFlags(schema: SchemaObject): AccessFlags {\n return { isReadOnly: Boolean(schema.readOnly), isWriteOnly: Boolean(schema.writeOnly) };\n}\n\nfunction merged(left: AccessFlags, right: AccessFlags): AccessFlags {\n return {\n isReadOnly: left.isReadOnly || right.isReadOnly,\n isWriteOnly: left.isWriteOnly || right.isWriteOnly,\n };\n}\n\n/**\n * The flags of a schema and of the schemas that always apply to the same value: the one its\n * `$ref` names and its `allOf` members, followed until a schema repeats. `readOnly` is an\n * annotation, and the annotations of those schemas are the value's (2020-12 Core §7.7.1); in\n * OpenAPI 3.0 a referenced schema is the property's definition. `anyOf` and `oneOf` members apply\n * only when they match, which the type cannot tell, so they are not read.\n */\nfunction appliedFlags(\n schema: Schema | undefined,\n context: SchemaContext
|
|
1
|
+
{"version":3,"file":"access-flags.mjs","sources":["../../../../src/application/transform/schema/access-flags.ts"],"sourcesContent":["import type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext } from \"./schema-context.js\";\n\n/** Whether a property is `readOnly` or `writeOnly` (JSON Schema 2020-12 Validation §9.4). */\nexport interface AccessFlags {\n readonly isReadOnly: boolean;\n readonly isWriteOnly: boolean;\n}\n\nconst NO_FLAGS: AccessFlags = { isReadOnly: false, isWriteOnly: false };\n\nfunction ownFlags(schema: SchemaObject): AccessFlags {\n return { isReadOnly: Boolean(schema.readOnly), isWriteOnly: Boolean(schema.writeOnly) };\n}\n\nfunction merged(left: AccessFlags, right: AccessFlags): AccessFlags {\n return {\n isReadOnly: left.isReadOnly || right.isReadOnly,\n isWriteOnly: left.isWriteOnly || right.isWriteOnly,\n };\n}\n\n/**\n * The flags of a schema and of the schemas that always apply to the same value: the one its\n * `$ref` names and its `allOf` members, followed until a schema repeats. `readOnly` is an\n * annotation, and the annotations of those schemas are the value's (2020-12 Core §7.7.1); in\n * OpenAPI 3.0 a referenced schema is the property's definition. `anyOf` and `oneOf` members apply\n * only when they match, which the type cannot tell, so they are not read.\n */\nfunction appliedFlags(\n schema: Schema | undefined,\n context: Pick<SchemaContext, \"refs\">,\n seen: ReadonlySet<Schema>,\n): AccessFlags {\n if (typeof schema !== \"object\" || schema === null || seen.has(schema)) {\n return NO_FLAGS;\n }\n const inner = new Set([...seen, schema]);\n // `readOnly` next to a `$ref` is read too, as the generator always has.\n const object = schema as SchemaObject & { readonly $ref?: unknown };\n const target =\n typeof object.$ref === \"string\" ? (context.refs.resolve(object.$ref) as Schema) : undefined;\n return (object.allOf ?? []).reduce<AccessFlags>(\n (flags, member) => merged(flags, appliedFlags(member, context, inner)),\n merged(ownFlags(object), appliedFlags(target, context, inner)),\n );\n}\n\n/**\n * The flags of a property schema. Without the `read-write-refs` fix only the keywords written on\n * it count, as in openapi-typescript; with it, also those of the schemas its `$ref` and `allOf`\n * apply (upstream #1938).\n */\nexport function propertyAccessFlags(\n value: Schema,\n context: Pick<SchemaContext, \"options\" | \"refs\">,\n): AccessFlags {\n if (typeof value !== \"object\") {\n return NO_FLAGS;\n }\n if (!context.options.fixes.has(FIX.READ_WRITE_REFS)) {\n return ownFlags(value as SchemaObject);\n }\n return appliedFlags(value, context, new Set());\n}\n"],"names":[],"mappings":";;AAUA,MAAM,QAAA,GAAwB,EAAE,UAAA,EAAY,KAAA,EAAO,aAAa,KAAA,EAAM;AAEtE,SAAS,SAAS,MAAA,EAAmC;AACnD,EAAA,OAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,MAAA,CAAO,QAAQ,GAAG,WAAA,EAAa,OAAA,CAAQ,MAAA,CAAO,SAAS,CAAA,EAAE;AACxF;AAEA,SAAS,MAAA,CAAO,MAAmB,KAAA,EAAiC;AAClE,EAAA,OAAO;AAAA,IACL,UAAA,EAAY,IAAA,CAAK,UAAA,IAAc,KAAA,CAAM,UAAA;AAAA,IACrC,WAAA,EAAa,IAAA,CAAK,WAAA,IAAe,KAAA,CAAM;AAAA,GACzC;AACF;AASA,SAAS,YAAA,CACP,MAAA,EACA,OAAA,EACA,IAAA,EACa;AACb,EAAA,IAAI,OAAO,WAAW,QAAA,IAAY,MAAA,KAAW,QAAQ,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,EAAG;AACrE,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,MAAM,wBAAQ,IAAI,GAAA,CAAI,CAAC,GAAG,IAAA,EAAM,MAAM,CAAC,CAAA;AAEvC,EAAA,MAAM,MAAA,GAAS,MAAA;AACf,EAAA,MAAM,MAAA,GACJ,OAAO,MAAA,CAAO,IAAA,KAAS,QAAA,GAAY,QAAQ,IAAA,CAAK,OAAA,CAAQ,MAAA,CAAO,IAAI,CAAA,GAAe,MAAA;AACpF,EAAA,OAAA,CAAQ,MAAA,CAAO,KAAA,IAAS,EAAC,EAAG,MAAA;AAAA,IAC1B,CAAC,OAAO,MAAA,KAAW,MAAA,CAAO,OAAO,YAAA,CAAa,MAAA,EAAQ,OAAA,EAAS,KAAK,CAAC,CAAA;AAAA,IACrE,MAAA,CAAO,SAAS,MAAM,CAAA,EAAG,aAAa,MAAA,EAAQ,OAAA,EAAS,KAAK,CAAC;AAAA,GAC/D;AACF;AAOO,SAAS,mBAAA,CACd,OACA,OAAA,EACa;AACb,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,OAAA,CAAQ,OAAA,CAAQ,MAAM,GAAA,CAAI,GAAA,CAAI,eAAe,CAAA,EAAG;AACnD,IAAA,OAAO,SAAS,KAAqB,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,YAAA,CAAa,KAAA,EAAO,OAAA,kBAAS,IAAI,KAAK,CAAA;AAC/C;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const declaredTypes = require('../document/declared-types.cjs');
|
|
4
|
+
const typeAssignability = require('../document/type-assignability.cjs');
|
|
5
|
+
const typeCombinators = require('../type-combinators.cjs');
|
|
6
|
+
|
|
7
|
+
function withPropertyTypes(indexType, propertyTypes) {
|
|
8
|
+
const relate = typeAssignability.assignabilityProof(declaredTypes.NO_DECLARED_TYPES);
|
|
9
|
+
const members = unionMembers(indexType);
|
|
10
|
+
const added = [];
|
|
11
|
+
for (const member of propertyTypes.flatMap(unionMembers)) {
|
|
12
|
+
if (relate(member, typeCombinators.unionOf([...members, ...added])) !== "assignable") {
|
|
13
|
+
added.push(member);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return added.length === 0 ? indexType : typeCombinators.unionOf([...members, ...added]);
|
|
17
|
+
}
|
|
18
|
+
const unionMembers = (type) => type.kind === "union" ? type.types : [type];
|
|
19
|
+
|
|
20
|
+
exports.withPropertyTypes = withPropertyTypes;
|
|
21
|
+
//# sourceMappingURL=index-signature-type.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-signature-type.cjs","sources":["../../../../src/application/transform/schema/index-signature-type.ts"],"sourcesContent":["import type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { NO_DECLARED_TYPES } from \"../document/declared-types.js\";\nimport { assignabilityProof } from \"../document/type-assignability.js\";\nimport { unionOf } from \"../type-combinators.js\";\n\n/**\n * The index signature type with the property types it does not admit. TypeScript checks an index\n * signature against every key of a value, declared ones too, so `{ total: number } & { [key:\n * string]: string }` admits no value with `total` (with a required `total`, none at all). The\n * signature takes those property types too, as `unevaluated-properties` does. A property type\n * proven assignable adds nothing, so output that admitted its values stays; one the proof cannot\n * decide (a `$ref`) is added, member by member, so the union stays flat. `$defs` is a keyword, not\n * data, so it is not read.\n */\nexport function withPropertyTypes(indexType: IrType, propertyTypes: readonly IrType[]): IrType {\n const relate = assignabilityProof(NO_DECLARED_TYPES);\n const members = unionMembers(indexType);\n const added: IrType[] = [];\n // Each member of a property type joins the union on its own, unless the union admits it\n // already: `(string | null) | (string | null)` is written `string | null`.\n for (const member of propertyTypes.flatMap(unionMembers)) {\n if (relate(member, unionOf([...members, ...added])) !== \"assignable\") {\n added.push(member);\n }\n }\n // Without an added member the index type stays as printed before, repeats and all.\n return added.length === 0 ? indexType : unionOf([...members, ...added]);\n}\n\nconst unionMembers = (type: IrType): readonly IrType[] =>\n type.kind === \"union\" ? type.types : [type];\n"],"names":["assignabilityProof","NO_DECLARED_TYPES","unionOf"],"mappings":";;;;;;AAcO,SAAS,iBAAA,CAAkB,WAAmB,aAAA,EAA0C;AAC7F,EAAA,MAAM,MAAA,GAASA,qCAAmBC,+BAAiB,CAAA;AACnD,EAAA,MAAM,OAAA,GAAU,aAAa,SAAS,CAAA;AACtC,EAAA,MAAM,QAAkB,EAAC;AAGzB,EAAA,KAAA,MAAW,MAAA,IAAU,aAAA,CAAc,OAAA,CAAQ,YAAY,CAAA,EAAG;AACxD,IAAA,IAAI,MAAA,CAAO,MAAA,EAAQC,uBAAA,CAAQ,CAAC,GAAG,OAAA,EAAS,GAAG,KAAK,CAAC,CAAC,CAAA,KAAM,YAAA,EAAc;AACpE,MAAA,KAAA,CAAM,KAAK,MAAM,CAAA;AAAA,IACnB;AAAA,EACF;AAEA,EAAA,OAAO,KAAA,CAAM,MAAA,KAAW,CAAA,GAAI,SAAA,GAAYA,uBAAA,CAAQ,CAAC,GAAG,OAAA,EAAS,GAAG,KAAK,CAAC,CAAA;AACxE;AAEA,MAAM,YAAA,GAAe,CAAC,IAAA,KACpB,IAAA,CAAK,SAAS,OAAA,GAAU,IAAA,CAAK,KAAA,GAAQ,CAAC,IAAI,CAAA;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NO_DECLARED_TYPES } from '../document/declared-types.mjs';
|
|
2
|
+
import { assignabilityProof } from '../document/type-assignability.mjs';
|
|
3
|
+
import { unionOf } from '../type-combinators.mjs';
|
|
4
|
+
|
|
5
|
+
function withPropertyTypes(indexType, propertyTypes) {
|
|
6
|
+
const relate = assignabilityProof(NO_DECLARED_TYPES);
|
|
7
|
+
const members = unionMembers(indexType);
|
|
8
|
+
const added = [];
|
|
9
|
+
for (const member of propertyTypes.flatMap(unionMembers)) {
|
|
10
|
+
if (relate(member, unionOf([...members, ...added])) !== "assignable") {
|
|
11
|
+
added.push(member);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return added.length === 0 ? indexType : unionOf([...members, ...added]);
|
|
15
|
+
}
|
|
16
|
+
const unionMembers = (type) => type.kind === "union" ? type.types : [type];
|
|
17
|
+
|
|
18
|
+
export { withPropertyTypes };
|
|
19
|
+
//# sourceMappingURL=index-signature-type.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-signature-type.mjs","sources":["../../../../src/application/transform/schema/index-signature-type.ts"],"sourcesContent":["import type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { NO_DECLARED_TYPES } from \"../document/declared-types.js\";\nimport { assignabilityProof } from \"../document/type-assignability.js\";\nimport { unionOf } from \"../type-combinators.js\";\n\n/**\n * The index signature type with the property types it does not admit. TypeScript checks an index\n * signature against every key of a value, declared ones too, so `{ total: number } & { [key:\n * string]: string }` admits no value with `total` (with a required `total`, none at all). The\n * signature takes those property types too, as `unevaluated-properties` does. A property type\n * proven assignable adds nothing, so output that admitted its values stays; one the proof cannot\n * decide (a `$ref`) is added, member by member, so the union stays flat. `$defs` is a keyword, not\n * data, so it is not read.\n */\nexport function withPropertyTypes(indexType: IrType, propertyTypes: readonly IrType[]): IrType {\n const relate = assignabilityProof(NO_DECLARED_TYPES);\n const members = unionMembers(indexType);\n const added: IrType[] = [];\n // Each member of a property type joins the union on its own, unless the union admits it\n // already: `(string | null) | (string | null)` is written `string | null`.\n for (const member of propertyTypes.flatMap(unionMembers)) {\n if (relate(member, unionOf([...members, ...added])) !== \"assignable\") {\n added.push(member);\n }\n }\n // Without an added member the index type stays as printed before, repeats and all.\n return added.length === 0 ? indexType : unionOf([...members, ...added]);\n}\n\nconst unionMembers = (type: IrType): readonly IrType[] =>\n type.kind === \"union\" ? type.types : [type];\n"],"names":[],"mappings":";;;;AAcO,SAAS,iBAAA,CAAkB,WAAmB,aAAA,EAA0C;AAC7F,EAAA,MAAM,MAAA,GAAS,mBAAmB,iBAAiB,CAAA;AACnD,EAAA,MAAM,OAAA,GAAU,aAAa,SAAS,CAAA;AACtC,EAAA,MAAM,QAAkB,EAAC;AAGzB,EAAA,KAAA,MAAW,MAAA,IAAU,aAAA,CAAc,OAAA,CAAQ,YAAY,CAAA,EAAG;AACxD,IAAA,IAAI,MAAA,CAAO,MAAA,EAAQ,OAAA,CAAQ,CAAC,GAAG,OAAA,EAAS,GAAG,KAAK,CAAC,CAAC,CAAA,KAAM,YAAA,EAAc;AACpE,MAAA,KAAA,CAAM,KAAK,MAAM,CAAA;AAAA,IACnB;AAAA,EACF;AAEA,EAAA,OAAO,KAAA,CAAM,MAAA,KAAW,CAAA,GAAI,SAAA,GAAY,OAAA,CAAQ,CAAC,GAAG,OAAA,EAAS,GAAG,KAAK,CAAC,CAAA;AACxE;AAEA,MAAM,YAAA,GAAe,CAAC,IAAA,KACpB,IAAA,CAAK,SAAS,OAAA,GAAU,IAAA,CAAK,KAAA,GAAQ,CAAC,IAAI,CAAA;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const documentPlaces = require('../../../domain/openapi/document-places.cjs');
|
|
4
|
+
const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
|
|
5
|
+
const outputFixes = require('../../../domain/output-fixes.cjs');
|
|
6
|
+
|
|
7
|
+
const ORIGINAL_INPUT_WORDS = ["parameters", "requestBody", "requestBodies"];
|
|
8
|
+
function isInputLocation(path, fixes) {
|
|
9
|
+
if (path === void 0) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return fixes.has(outputFixes.FIX.DEFAULT_INPUT_LOCATIONS) ? isStructuralInput(path) : namesInput(path);
|
|
13
|
+
}
|
|
14
|
+
function namesInput(path) {
|
|
15
|
+
return ORIGINAL_INPUT_WORDS.some((word) => path.includes(word));
|
|
16
|
+
}
|
|
17
|
+
function isStructuralInput(path) {
|
|
18
|
+
const place = documentPlaces.placeOf(jsonPointer.parseRefPointer(path));
|
|
19
|
+
return place === "outside" ? namesInput(path) : place === "input";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.isInputLocation = isInputLocation;
|
|
23
|
+
//# sourceMappingURL=input-location.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-location.cjs","sources":["../../../../src/application/transform/schema/input-location.ts"],"sourcesContent":["import { placeOf } from \"../../../domain/openapi/document-places.js\";\nimport { parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport { FIX, type OutputFix } from \"../../../domain/output-fixes.js\";\n\n/** The words that mark an input anywhere in a location, as the original reads them. */\nconst ORIGINAL_INPUT_WORDS = [\"parameters\", \"requestBody\", \"requestBodies\"] as const;\n\n/**\n * Whether a schema location describes an input: a parameter or a request body. A client may\n * leave out an input property that has a `default`, so the default makes no such property\n * required. The original tests the location text for a word, so a schema or path that is only\n * named so (`#/components/schemas/Job/properties/parameters`, `/system-parameters`) counts as an\n * input too. The `default-input-locations` fix reads a pointer into the document by the\n * document's structure instead (ADR-021).\n */\nexport function isInputLocation(path: string | undefined, fixes: ReadonlySet<OutputFix>): boolean {\n if (path === undefined) {\n return false;\n }\n return fixes.has(FIX.DEFAULT_INPUT_LOCATIONS) ? isStructuralInput(path) : namesInput(path);\n}\n\nfunction namesInput(path: string): boolean {\n return ORIGINAL_INPUT_WORDS.some((word) => path.includes(word));\n}\n\n/**\n * Whether the document's structure makes the pointer an input. A path an exported transformer was\n * given that is no pointer into the document (`/items/{id}`) has no known structure, so the\n * original's words still mark an input there.\n */\nfunction isStructuralInput(path: string): boolean {\n const place = placeOf(parseRefPointer(path));\n return place === \"outside\" ? namesInput(path) : place === \"input\";\n}\n"],"names":["FIX","placeOf","parseRefPointer"],"mappings":";;;;;;AAKA,MAAM,oBAAA,GAAuB,CAAC,YAAA,EAAc,aAAA,EAAe,eAAe,CAAA;AAUnE,SAAS,eAAA,CAAgB,MAA0B,KAAA,EAAwC;AAChG,EAAA,IAAI,SAAS,MAAA,EAAW;AACtB,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA,CAAM,IAAIA,eAAA,CAAI,uBAAuB,IAAI,iBAAA,CAAkB,IAAI,CAAA,GAAI,UAAA,CAAW,IAAI,CAAA;AAC3F;AAEA,SAAS,WAAW,IAAA,EAAuB;AACzC,EAAA,OAAO,qBAAqB,IAAA,CAAK,CAAC,SAAS,IAAA,CAAK,QAAA,CAAS,IAAI,CAAC,CAAA;AAChE;AAOA,SAAS,kBAAkB,IAAA,EAAuB;AAChD,EAAA,MAAM,KAAA,GAAQC,sBAAA,CAAQC,2BAAA,CAAgB,IAAI,CAAC,CAAA;AAC3C,EAAA,OAAO,KAAA,KAAU,SAAA,GAAY,UAAA,CAAW,IAAI,IAAI,KAAA,KAAU,OAAA;AAC5D;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { placeOf } from '../../../domain/openapi/document-places.mjs';
|
|
2
|
+
import { parseRefPointer } from '../../../domain/openapi/json-pointer.mjs';
|
|
3
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
4
|
+
|
|
5
|
+
const ORIGINAL_INPUT_WORDS = ["parameters", "requestBody", "requestBodies"];
|
|
6
|
+
function isInputLocation(path, fixes) {
|
|
7
|
+
if (path === void 0) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return fixes.has(FIX.DEFAULT_INPUT_LOCATIONS) ? isStructuralInput(path) : namesInput(path);
|
|
11
|
+
}
|
|
12
|
+
function namesInput(path) {
|
|
13
|
+
return ORIGINAL_INPUT_WORDS.some((word) => path.includes(word));
|
|
14
|
+
}
|
|
15
|
+
function isStructuralInput(path) {
|
|
16
|
+
const place = placeOf(parseRefPointer(path));
|
|
17
|
+
return place === "outside" ? namesInput(path) : place === "input";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { isInputLocation };
|
|
21
|
+
//# sourceMappingURL=input-location.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-location.mjs","sources":["../../../../src/application/transform/schema/input-location.ts"],"sourcesContent":["import { placeOf } from \"../../../domain/openapi/document-places.js\";\nimport { parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport { FIX, type OutputFix } from \"../../../domain/output-fixes.js\";\n\n/** The words that mark an input anywhere in a location, as the original reads them. */\nconst ORIGINAL_INPUT_WORDS = [\"parameters\", \"requestBody\", \"requestBodies\"] as const;\n\n/**\n * Whether a schema location describes an input: a parameter or a request body. A client may\n * leave out an input property that has a `default`, so the default makes no such property\n * required. The original tests the location text for a word, so a schema or path that is only\n * named so (`#/components/schemas/Job/properties/parameters`, `/system-parameters`) counts as an\n * input too. The `default-input-locations` fix reads a pointer into the document by the\n * document's structure instead (ADR-021).\n */\nexport function isInputLocation(path: string | undefined, fixes: ReadonlySet<OutputFix>): boolean {\n if (path === undefined) {\n return false;\n }\n return fixes.has(FIX.DEFAULT_INPUT_LOCATIONS) ? isStructuralInput(path) : namesInput(path);\n}\n\nfunction namesInput(path: string): boolean {\n return ORIGINAL_INPUT_WORDS.some((word) => path.includes(word));\n}\n\n/**\n * Whether the document's structure makes the pointer an input. A path an exported transformer was\n * given that is no pointer into the document (`/items/{id}`) has no known structure, so the\n * original's words still mark an input there.\n */\nfunction isStructuralInput(path: string): boolean {\n const place = placeOf(parseRefPointer(path));\n return place === \"outside\" ? namesInput(path) : place === \"input\";\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,oBAAA,GAAuB,CAAC,YAAA,EAAc,aAAA,EAAe,eAAe,CAAA;AAUnE,SAAS,eAAA,CAAgB,MAA0B,KAAA,EAAwC;AAChG,EAAA,IAAI,SAAS,MAAA,EAAW;AACtB,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA,CAAM,IAAI,GAAA,CAAI,uBAAuB,IAAI,iBAAA,CAAkB,IAAI,CAAA,GAAI,UAAA,CAAW,IAAI,CAAA;AAC3F;AAEA,SAAS,WAAW,IAAA,EAAuB;AACzC,EAAA,OAAO,qBAAqB,IAAA,CAAK,CAAC,SAAS,IAAA,CAAK,QAAA,CAAS,IAAI,CAAC,CAAA;AAChE;AAOA,SAAS,kBAAkB,IAAA,EAAuB;AAChD,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,eAAA,CAAgB,IAAI,CAAC,CAAA;AAC3C,EAAA,OAAO,KAAA,KAAU,SAAA,GAAY,UAAA,CAAW,IAAI,IAAI,KAAA,KAAU,OAAA;AAC5D;;"}
|
|
@@ -10,9 +10,11 @@ const schemaComment = require('../schema-comment.cjs');
|
|
|
10
10
|
const sharedTypes = require('../shared-types.cjs');
|
|
11
11
|
const typeCombinators = require('../type-combinators.cjs');
|
|
12
12
|
const accessFlags = require('./access-flags.cjs');
|
|
13
|
+
const indexSignatureType = require('./index-signature-type.cjs');
|
|
13
14
|
const inheritedDiscriminator = require('./inherited-discriminator.cjs');
|
|
15
|
+
const inputLocation = require('./input-location.cjs');
|
|
16
|
+
const refSiblings = require('./ref-siblings.cjs');
|
|
14
17
|
|
|
15
|
-
const INPUT_PATH_PARTS = ["parameters", "requestBody", "requestBodies"];
|
|
16
18
|
class InvalidPropertyError extends errors.OpenAPITypesafeError {
|
|
17
19
|
constructor(path, key, value) {
|
|
18
20
|
const received = Array.isArray(value) ? "Array" : typeof value;
|
|
@@ -49,8 +51,7 @@ function propertyFacts(value, request) {
|
|
|
49
51
|
}
|
|
50
52
|
function isOptionalProperty(key, facts, schema, request) {
|
|
51
53
|
const { options } = request.context;
|
|
52
|
-
const
|
|
53
|
-
const isDefaultRequired = facts.hasDefault && options.defaultNonNullable && !INPUT_PATH_PARTS.some((part) => path?.includes(part));
|
|
54
|
+
const isDefaultRequired = facts.hasDefault && options.defaultNonNullable && !inputLocation.isInputLocation(request.location.path, options.fixes);
|
|
54
55
|
const isRequired = schema.required?.includes(key) || schema.required === void 0 && options.propertiesRequiredByDefault || isDefaultRequired;
|
|
55
56
|
return !isRequired;
|
|
56
57
|
}
|
|
@@ -61,9 +62,14 @@ function isExcluded(value, facts, request) {
|
|
|
61
62
|
const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;
|
|
62
63
|
return Boolean(resolved?.deprecated);
|
|
63
64
|
}
|
|
65
|
+
function plainRef({ ref }, value, request) {
|
|
66
|
+
const isAllOf = ref && refSiblings.refWithSiblingsAsAllOf(value, request.context.options);
|
|
67
|
+
return isAllOf ? void 0 : ref;
|
|
68
|
+
}
|
|
64
69
|
function propertyType(key, value, facts, request) {
|
|
65
70
|
const path = jsonPointer.appendPointer(request.location.path, [key]);
|
|
66
|
-
const
|
|
71
|
+
const ref = plainRef(facts, value, request);
|
|
72
|
+
const type = ref ? pointerType.schemaRefType(ref, request) : request.transformNested(value, { ...request.location, path });
|
|
67
73
|
const custom = request.context.callbacks.transform(value, request.location);
|
|
68
74
|
return custom === null ? { type, isOptional: null } : { type: custom.type, isOptional: custom.isOptional || null };
|
|
69
75
|
}
|
|
@@ -167,6 +173,9 @@ function objectType(schema, request) {
|
|
|
167
173
|
return inherited ? constructors.irObject([inheritedDiscriminator.discriminatorMember(inherited, request)]) : null;
|
|
168
174
|
}
|
|
169
175
|
const members = discriminatorAndPropertyMembers(schema, request);
|
|
176
|
+
const propertyTypes = members.flatMap(
|
|
177
|
+
(member) => member.kind === "property" ? [member.type] : []
|
|
178
|
+
);
|
|
170
179
|
if ("$defs" in schema && typeof schema.$defs === "object" && Object.keys(schema.$defs).length > 0) {
|
|
171
180
|
members.push(defsMember(schema.$defs, request));
|
|
172
181
|
}
|
|
@@ -174,8 +183,9 @@ function objectType(schema, request) {
|
|
|
174
183
|
if (valueTypes.length === 0) {
|
|
175
184
|
return members.length > 0 ? constructors.irObject(members) : null;
|
|
176
185
|
}
|
|
186
|
+
const indexType = indexSignatureType.withPropertyTypes(typeCombinators.unionOf(valueTypes), propertyTypes);
|
|
177
187
|
const index = constructors.irObject([
|
|
178
|
-
constructors.irStringIndexSignature("key",
|
|
188
|
+
constructors.irStringIndexSignature("key", indexType, request.context.options.immutable)
|
|
179
189
|
]);
|
|
180
190
|
return typeCombinators.intersectionOf([...members.length > 0 ? [constructors.irObject(members)] : [], index]);
|
|
181
191
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-type.cjs","sources":["../../../../src/application/transform/schema/object-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport {\n irObject,\n irProperty,\n irReference,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport { type AccessFlags, propertyAccessFlags } from \"./access-flags.js\";\nimport { discriminatorMember, inheritedDiscriminator } from \"./inherited-discriminator.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/** Path parts where a default value cannot make a property required (inputs may omit it). */\nconst INPUT_PATH_PARTS = [\"parameters\", \"requestBody\", \"requestBodies\"] as const;\n\nexport class InvalidPropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined, key: string, value: unknown) {\n const received = Array.isArray(value) ? \"Array\" : typeof value;\n super({\n code: ERROR_CODES.SCHEMA_PROPERTY_INVALID,\n message:\n `${path}: invalid property ${key}. ` + `Expected Schema Object or boolean, got ${received}`,\n details: { path, property: key, received },\n });\n this.name = \"InvalidPropertyError\";\n }\n}\n\n/** `--read-write-markers`: `$Read<T>` / `$Write<T>`, unless the property is both or neither. */\nfunction withReadWriteMarker(type: IrType, flags: AccessFlags, options: SchemaOptions): IrType {\n if (!options.readWriteMarkers || flags.isReadOnly === flags.isWriteOnly) {\n return type;\n }\n return irReference(flags.isReadOnly ? \"$Read\" : \"$Write\", [type]);\n}\n\n/** Apply `transformProperty`, then the schema's JSDoc. */\nfunction finishProperty(\n property: IrPropertySignature,\n schema: Schema,\n path: string,\n request: SchemaRequest,\n): IrPropertySignature {\n const location = { ...request.location, path };\n const transformed =\n request.context.callbacks.transformProperty(property, schema, location) ?? property;\n // The original adds the schema's comment after any comment the callback set.\n return withSchemaComment(\n transformed,\n schema,\n schemaCommentOptionsOf(request.context.options.fixes),\n );\n}\n\n/** What the property loop reads from a property schema, in the original order. */\ninterface PropertyFacts {\n readonly ref: string | undefined;\n readonly flags: AccessFlags;\n readonly hasDefault: boolean;\n}\n\nfunction propertyFacts(value: Schema, request: SchemaRequest): PropertyFacts {\n if (typeof value !== \"object\") {\n return { ref: undefined, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };\n }\n // `in` throws for a null value, as in the original (which also reads `$ref` first).\n const ref = \"$ref\" in value && value.$ref ? value.$ref : undefined;\n const flags = propertyAccessFlags(value, request.context);\n return { ref, flags, hasDefault: \"default\" in value && value.default !== undefined };\n}\n\nfunction isOptionalProperty(\n key: string,\n facts: PropertyFacts,\n schema: SchemaObject,\n request: SchemaRequest,\n): boolean {\n const { options } = request.context;\n const path = request.location.path;\n const isDefaultRequired =\n facts.hasDefault &&\n options.defaultNonNullable &&\n !INPUT_PATH_PARTS.some((part) => path?.includes(part));\n const isRequired =\n schema.required?.includes(key) ||\n (schema.required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\nfunction isExcluded(value: Schema, facts: PropertyFacts, request: SchemaRequest): boolean {\n if (!request.context.options.excludeDeprecated) {\n return false;\n }\n const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;\n return Boolean((resolved as SchemaObject | undefined)?.deprecated);\n}\n\n/** A type, and whether a callback forced the property optional (null: no override). */\ninterface CustomResult {\n readonly type: IrType;\n readonly isOptional: true | null;\n}\n\nfunction propertyType(\n key: string,\n value: Schema,\n facts: PropertyFacts,\n request: SchemaRequest,\n): CustomResult {\n const path = appendPointer(request.location.path, [key]);\n const type = facts.ref\n ? schemaRefType(facts.ref, request)\n : request.transformNested(value, { ...request.location, path });\n const custom = request.context.callbacks.transform(value, request.location);\n return custom === null\n ? { type, isOptional: null }\n : { type: custom.type, isOptional: custom.isOptional || null };\n}\n\nfunction propertyMember(\n key: string,\n value: Schema,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrMember | null {\n if ((typeof value !== \"object\" && typeof value !== \"boolean\") || Array.isArray(value)) {\n throw new InvalidPropertyError(request.location.path, key, value);\n }\n const facts = propertyFacts(value, request);\n if (isExcluded(value, facts, request)) {\n return null;\n }\n const { options } = request.context;\n const isOptional = isOptionalProperty(key, facts, schema, request);\n const result = propertyType(key, value, facts, request);\n const property = irProperty(\n toPropertyName(key),\n withReadWriteMarker(result.type, facts.flags, options),\n {\n isOptional: result.isOptional ?? isOptional,\n isReadonly: options.immutable || (!options.readWriteMarkers && facts.flags.isReadOnly),\n },\n );\n return finishProperty(property, value, appendPointer(request.location.path, [key]), request);\n}\n\nfunction propertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const members: IrMember[] = [];\n for (const [key, value] of documentEntries(schema.properties ?? {}, request.context.options)) {\n const member = propertyMember(key, value, schema, request);\n if (member !== null) {\n members.push(member);\n }\n }\n return members;\n}\n\n/**\n * `$defs` as a nested `$defs?: { … }` member, in document order (never alphabetized). It is\n * optional because `$defs` is a schema keyword, not data: the original made it required, so a\n * value of the type needed a `$defs` key (research/legacy-bugs.md, item 17, upstream #2664).\n */\nfunction defsMember(\n defs: Readonly<Record<string, SchemaObject>>,\n request: SchemaRequest,\n): IrMember {\n const { options } = request.context;\n const members = Object.entries(defs).map(([key, value]) => {\n const path = appendPointer(request.location.path, [\"$defs\", key]);\n const flags = propertyAccessFlags(value, request.context);\n const type = withReadWriteMarker(\n request.transformNested(value, { ...request.location, path }),\n flags,\n options,\n );\n const property = irProperty(toPropertyName(key), type, {\n isReadonly: options.immutable || (!options.readWriteMarkers && flags.isReadOnly),\n });\n return finishProperty(property, value, path, request);\n });\n return irProperty(toPropertyName(\"$defs\"), irObject(members), { isOptional: true });\n}\n\nfunction hasObjectKeywords(schema: SchemaObject): boolean {\n const hasProperties = Boolean(schema.properties && Object.keys(schema.properties).length);\n return (\n hasProperties ||\n Boolean(schema.additionalProperties || schema.patternProperties || schema.$defs)\n );\n}\n\n/** Value types of the `[key: string]` index signature, in the original order. */\nfunction indexValueTypes(schema: SchemaObject, request: SchemaRequest): IrType[] {\n const { additionalProperties } = schema;\n const isObject = typeof additionalProperties === \"object\";\n const hasExplicit = isObject && Object.keys(additionalProperties).length > 0;\n const hasImplicit =\n additionalProperties === true || (isObject && Object.keys(additionalProperties).length === 0);\n const types: IrType[] = [];\n if (hasExplicit) {\n types.push(request.transformNested(additionalProperties as Schema, request.location, true));\n }\n if (hasImplicit || (!additionalProperties && request.context.options.additionalProperties)) {\n types.push(UNKNOWN_TYPE);\n }\n const patterns = schema.patternProperties;\n if (typeof patterns === \"object\" && patterns !== null && Object.keys(patterns).length > 0) {\n for (const [, value] of documentEntries(patterns, request.context.options)) {\n types.push(request.transformNested(value, request.location));\n }\n }\n return types;\n}\n\n/**\n * Whether the schema declares property `key` and the type keeps it: `--exclude-deprecated` drops\n * a deprecated one.\n */\nexport function isKeptProperty(schema: SchemaObject, key: string, request: SchemaRequest): boolean {\n const properties = schema.properties ?? {};\n if (!Object.hasOwn(properties, key)) {\n return false;\n }\n const value = properties[key] as Schema;\n const isExcludable = request.context.options.excludeDeprecated && typeof value === \"object\";\n return !isExcludable || !isExcluded(value, propertyFacts(value, request), request);\n}\n\n/**\n * The members for the discriminator and `properties`. A schema that declares the discriminator\n * property itself keeps its own declaration, required as the discriminator needs: both in one\n * object type do not compile (TS2300, the Apple SiriKit Cloud Media API). A declaration that\n * `--exclude-deprecated` drops does not count, so the discriminator property stays.\n */\nfunction discriminatorAndPropertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const inherited = inheritedDiscriminator(schema, request);\n if (inherited === undefined) {\n return propertyMembers(schema, request);\n }\n const name = inherited.discriminator.propertyName;\n if (!isKeptProperty(schema, name, request)) {\n return [discriminatorMember(inherited, request), ...propertyMembers(schema, request)];\n }\n // Without `required`, `--properties-required-by-default` requires every property already; a\n // list of one would make the others optional.\n const isAllRequired =\n schema.required === undefined && request.context.options.propertiesRequiredByDefault;\n const required = isAllRequired ? undefined : [...(schema.required ?? []), name];\n return propertyMembers({ ...schema, required } as SchemaObject, request);\n}\n\n/**\n * Object keywords: discriminator, `properties`, `$defs`, and an index signature for\n * `additionalProperties` / `patternProperties` (or `--additional-properties`). Null when the schema\n * has none of them.\n */\nexport function objectType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (!hasObjectKeywords(schema)) {\n const inherited = inheritedDiscriminator(schema, request);\n return inherited ? irObject([discriminatorMember(inherited, request)]) : null;\n }\n const members = discriminatorAndPropertyMembers(schema, request);\n // As in the original, a null `$defs` throws here (Object.keys) instead of being skipped.\n if (\n \"$defs\" in schema &&\n typeof schema.$defs === \"object\" &&\n Object.keys(schema.$defs).length > 0\n ) {\n members.push(defsMember(schema.$defs, request));\n }\n const valueTypes = indexValueTypes(schema, request);\n if (valueTypes.length === 0) {\n return members.length > 0 ? irObject(members) : null;\n }\n const index = irObject([\n irStringIndexSignature(\"key\", unionOf(valueTypes), request.context.options.immutable),\n ]);\n return intersectionOf([...(members.length > 0 ? [irObject(members)] : []), index]);\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","irReference","withSchemaComment","schemaCommentOptionsOf","propertyAccessFlags","appendPointer","schemaRefType","irProperty","toPropertyName","documentEntries","irObject","UNKNOWN_TYPE","inheritedDiscriminator","discriminatorMember","irStringIndexSignature","unionOf","intersectionOf"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAM,gBAAA,GAAmB,CAAC,YAAA,EAAc,aAAA,EAAe,eAAe,CAAA;AAE/D,MAAM,6BAA6BA,2BAAA,CAAqB;AAAA,EAC7D,WAAA,CAAY,IAAA,EAA0B,GAAA,EAAa,KAAA,EAAgB;AACjE,IAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,UAAU,OAAO,KAAA;AACzD,IAAA,KAAA,CAAM;AAAA,MACJ,MAAMC,kBAAA,CAAY,uBAAA;AAAA,MAClB,SACE,CAAA,EAAG,IAAI,CAAA,mBAAA,EAAsB,GAAG,4CAAiD,QAAQ,CAAA,CAAA;AAAA,MAC3F,OAAA,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AAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA,CAAE,MAAA,GAAS,CAAA,EACnC;AACA,IAAA,OAAA,CAAQ,IAAA,CAAK,UAAA,CAAW,MAAA,CAAO,KAAA,EAAO,OAAO,CAAC,CAAA;AAAA,EAChD;AACA,EAAA,MAAM,UAAA,GAAa,eAAA,CAAgB,MAAA,EAAQ,OAAO,CAAA;AAClD,EAAA,IAAI,UAAA,CAAW,WAAW,CAAA,EAAG;AAC3B,IAAA,OAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,GAAIH,qBAAA,CAAS,OAAO,CAAA,GAAI,IAAA;AAAA,EAClD;AACA,EAAA,MAAM,QAAQA,qBAAA,CAAS;AAAA,IACrBI,mCAAA,CAAuB,OAAOC,uBAAA,CAAQ,UAAU,GAAG,OAAA,CAAQ,OAAA,CAAQ,QAAQ,SAAS;AAAA,GACrF,CAAA;AACD,EAAA,OAAOC,8BAAA,CAAe,CAAC,GAAI,OAAA,CAAQ,SAAS,CAAA,GAAI,CAACN,qBAAA,CAAS,OAAO,CAAC,CAAA,GAAI,EAAC,EAAI,KAAK,CAAC,CAAA;AACnF;;;;"}
|
|
1
|
+
{"version":3,"file":"object-type.cjs","sources":["../../../../src/application/transform/schema/object-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport {\n irObject,\n irProperty,\n irReference,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport { type AccessFlags, propertyAccessFlags } from \"./access-flags.js\";\nimport { withPropertyTypes } from \"./index-signature-type.js\";\nimport { discriminatorMember, inheritedDiscriminator } from \"./inherited-discriminator.js\";\nimport { isInputLocation } from \"./input-location.js\";\nimport { refWithSiblingsAsAllOf } from \"./ref-siblings.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\nexport class InvalidPropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined, key: string, value: unknown) {\n const received = Array.isArray(value) ? \"Array\" : typeof value;\n super({\n code: ERROR_CODES.SCHEMA_PROPERTY_INVALID,\n message:\n `${path}: invalid property ${key}. ` + `Expected Schema Object or boolean, got ${received}`,\n details: { path, property: key, received },\n });\n this.name = \"InvalidPropertyError\";\n }\n}\n\n/** `--read-write-markers`: `$Read<T>` / `$Write<T>`, unless the property is both or neither. */\nfunction withReadWriteMarker(type: IrType, flags: AccessFlags, options: SchemaOptions): IrType {\n if (!options.readWriteMarkers || flags.isReadOnly === flags.isWriteOnly) {\n return type;\n }\n return irReference(flags.isReadOnly ? \"$Read\" : \"$Write\", [type]);\n}\n\n/** Apply `transformProperty`, then the schema's JSDoc. */\nfunction finishProperty(\n property: IrPropertySignature,\n schema: Schema,\n path: string,\n request: SchemaRequest,\n): IrPropertySignature {\n const location = { ...request.location, path };\n const transformed =\n request.context.callbacks.transformProperty(property, schema, location) ?? property;\n // The original adds the schema's comment after any comment the callback set.\n return withSchemaComment(\n transformed,\n schema,\n schemaCommentOptionsOf(request.context.options.fixes),\n );\n}\n\n/** What the property loop reads from a property schema, in the original order. */\ninterface PropertyFacts {\n readonly ref: string | undefined;\n readonly flags: AccessFlags;\n readonly hasDefault: boolean;\n}\n\nfunction propertyFacts(value: Schema, request: SchemaRequest): PropertyFacts {\n if (typeof value !== \"object\") {\n return { ref: undefined, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };\n }\n // `in` throws for a null value, as in the original (which also reads `$ref` first).\n const ref = \"$ref\" in value && value.$ref ? value.$ref : undefined;\n const flags = propertyAccessFlags(value, request.context);\n return { ref, flags, hasDefault: \"default\" in value && value.default !== undefined };\n}\n\nfunction isOptionalProperty(\n key: string,\n facts: PropertyFacts,\n schema: SchemaObject,\n request: SchemaRequest,\n): boolean {\n const { options } = request.context;\n const isDefaultRequired =\n facts.hasDefault &&\n options.defaultNonNullable &&\n !isInputLocation(request.location.path, options.fixes);\n const isRequired =\n schema.required?.includes(key) ||\n (schema.required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\nfunction isExcluded(value: Schema, facts: PropertyFacts, request: SchemaRequest): boolean {\n if (!request.context.options.excludeDeprecated) {\n return false;\n }\n const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;\n return Boolean((resolved as SchemaObject | undefined)?.deprecated);\n}\n\n/** A type, and whether a callback forced the property optional (null: no override). */\ninterface CustomResult {\n readonly type: IrType;\n readonly isOptional: true | null;\n}\n\n/** A `$ref` with siblings that `ref-siblings` types as an `allOf` is typed as a schema. */\nfunction plainRef({ ref }: PropertyFacts, value: Schema, request: SchemaRequest) {\n const isAllOf = ref && refWithSiblingsAsAllOf(value as SchemaObject, request.context.options);\n return isAllOf ? undefined : ref;\n}\n\nfunction propertyType(\n key: string,\n value: Schema,\n facts: PropertyFacts,\n request: SchemaRequest,\n): CustomResult {\n const path = appendPointer(request.location.path, [key]);\n const ref = plainRef(facts, value, request);\n const type = ref\n ? schemaRefType(ref, request)\n : request.transformNested(value, { ...request.location, path });\n const custom = request.context.callbacks.transform(value, request.location);\n return custom === null\n ? { type, isOptional: null }\n : { type: custom.type, isOptional: custom.isOptional || null };\n}\n\nfunction propertyMember(\n key: string,\n value: Schema,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrMember | null {\n if ((typeof value !== \"object\" && typeof value !== \"boolean\") || Array.isArray(value)) {\n throw new InvalidPropertyError(request.location.path, key, value);\n }\n const facts = propertyFacts(value, request);\n if (isExcluded(value, facts, request)) {\n return null;\n }\n const { options } = request.context;\n const isOptional = isOptionalProperty(key, facts, schema, request);\n const result = propertyType(key, value, facts, request);\n const property = irProperty(\n toPropertyName(key),\n withReadWriteMarker(result.type, facts.flags, options),\n {\n isOptional: result.isOptional ?? isOptional,\n isReadonly: options.immutable || (!options.readWriteMarkers && facts.flags.isReadOnly),\n },\n );\n return finishProperty(property, value, appendPointer(request.location.path, [key]), request);\n}\n\nfunction propertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const members: IrMember[] = [];\n for (const [key, value] of documentEntries(schema.properties ?? {}, request.context.options)) {\n const member = propertyMember(key, value, schema, request);\n if (member !== null) {\n members.push(member);\n }\n }\n return members;\n}\n\n/**\n * `$defs` as a nested `$defs?: { … }` member, in document order (never alphabetized). It is\n * optional because `$defs` is a schema keyword, not data: the original made it required, so a\n * value of the type needed a `$defs` key (research/legacy-bugs.md, item 17, upstream #2664).\n */\nfunction defsMember(\n defs: Readonly<Record<string, SchemaObject>>,\n request: SchemaRequest,\n): IrMember {\n const { options } = request.context;\n const members = Object.entries(defs).map(([key, value]) => {\n const path = appendPointer(request.location.path, [\"$defs\", key]);\n const flags = propertyAccessFlags(value, request.context);\n const type = withReadWriteMarker(\n request.transformNested(value, { ...request.location, path }),\n flags,\n options,\n );\n const property = irProperty(toPropertyName(key), type, {\n isReadonly: options.immutable || (!options.readWriteMarkers && flags.isReadOnly),\n });\n return finishProperty(property, value, path, request);\n });\n return irProperty(toPropertyName(\"$defs\"), irObject(members), { isOptional: true });\n}\n\nfunction hasObjectKeywords(schema: SchemaObject): boolean {\n const hasProperties = Boolean(schema.properties && Object.keys(schema.properties).length);\n return (\n hasProperties ||\n Boolean(schema.additionalProperties || schema.patternProperties || schema.$defs)\n );\n}\n\n/** Value types of the `[key: string]` index signature, in the original order. */\nfunction indexValueTypes(schema: SchemaObject, request: SchemaRequest): IrType[] {\n const { additionalProperties } = schema;\n const isObject = typeof additionalProperties === \"object\";\n const hasExplicit = isObject && Object.keys(additionalProperties).length > 0;\n const hasImplicit =\n additionalProperties === true || (isObject && Object.keys(additionalProperties).length === 0);\n const types: IrType[] = [];\n if (hasExplicit) {\n types.push(request.transformNested(additionalProperties as Schema, request.location, true));\n }\n if (hasImplicit || (!additionalProperties && request.context.options.additionalProperties)) {\n types.push(UNKNOWN_TYPE);\n }\n const patterns = schema.patternProperties;\n if (typeof patterns === \"object\" && patterns !== null && Object.keys(patterns).length > 0) {\n for (const [, value] of documentEntries(patterns, request.context.options)) {\n types.push(request.transformNested(value, request.location));\n }\n }\n return types;\n}\n\n/**\n * Whether the schema declares property `key` and the type keeps it: `--exclude-deprecated` drops\n * a deprecated one.\n */\nexport function isKeptProperty(schema: SchemaObject, key: string, request: SchemaRequest): boolean {\n const properties = schema.properties ?? {};\n if (!Object.hasOwn(properties, key)) {\n return false;\n }\n const value = properties[key] as Schema;\n const isExcludable = request.context.options.excludeDeprecated && typeof value === \"object\";\n return !isExcludable || !isExcluded(value, propertyFacts(value, request), request);\n}\n\n/**\n * The members for the discriminator and `properties`. A schema that declares the discriminator\n * property itself keeps its own declaration, required as the discriminator needs: both in one\n * object type do not compile (TS2300, the Apple SiriKit Cloud Media API). A declaration that\n * `--exclude-deprecated` drops does not count, so the discriminator property stays.\n */\nfunction discriminatorAndPropertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const inherited = inheritedDiscriminator(schema, request);\n if (inherited === undefined) {\n return propertyMembers(schema, request);\n }\n const name = inherited.discriminator.propertyName;\n if (!isKeptProperty(schema, name, request)) {\n return [discriminatorMember(inherited, request), ...propertyMembers(schema, request)];\n }\n // Without `required`, `--properties-required-by-default` requires every property already; a\n // list of one would make the others optional.\n const isAllRequired =\n schema.required === undefined && request.context.options.propertiesRequiredByDefault;\n const required = isAllRequired ? undefined : [...(schema.required ?? []), name];\n return propertyMembers({ ...schema, required } as SchemaObject, request);\n}\n\n/**\n * Object keywords: discriminator, `properties`, `$defs`, and an index signature for\n * `additionalProperties` / `patternProperties` (or `--additional-properties`). Null when the schema\n * has none of them.\n */\nexport function objectType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (!hasObjectKeywords(schema)) {\n const inherited = inheritedDiscriminator(schema, request);\n return inherited ? irObject([discriminatorMember(inherited, request)]) : null;\n }\n const members = discriminatorAndPropertyMembers(schema, request);\n const propertyTypes = members.flatMap((member) =>\n member.kind === \"property\" ? [member.type] : [],\n );\n // As in the original, a null `$defs` throws here (Object.keys) instead of being skipped.\n if (\n \"$defs\" in schema &&\n typeof schema.$defs === \"object\" &&\n Object.keys(schema.$defs).length > 0\n ) {\n members.push(defsMember(schema.$defs, request));\n }\n const valueTypes = indexValueTypes(schema, request);\n if (valueTypes.length === 0) {\n return members.length > 0 ? irObject(members) : null;\n }\n const indexType = withPropertyTypes(unionOf(valueTypes), propertyTypes);\n const index = irObject([\n irStringIndexSignature(\"key\", indexType, request.context.options.immutable),\n ]);\n return intersectionOf([...(members.length > 0 ? [irObject(members)] : []), index]);\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","irReference","withSchemaComment","schemaCommentOptionsOf","propertyAccessFlags","isInputLocation","refWithSiblingsAsAllOf","appendPointer","schemaRefType","irProperty","toPropertyName","documentEntries","irObject","UNKNOWN_TYPE","inheritedDiscriminator","discriminatorMember","withPropertyTypes","unionOf","irStringIndexSignature","intersectionOf"],"mappings":";;;;;;;;;;;;;;;;;AAwBO,MAAM,6BAA6BA,2BAAA,CAAqB;AAAA,EAC7D,WAAA,CAAY,IAAA,EAA0B,GAAA,EAAa,KAAA,EAAgB;AACjE,IAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,UAAU,OAAO,KAAA;AACzD,IAAA,KAAA,CAAM;AAAA,MACJ,MAAMC,kBAAA,CAAY,uBAAA;AAAA,MAClB,SACE,CAAA,EAAG,IAAI,CAAA,mBAAA,EAAsB,GAAG,4CAAiD,QAAQ,C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OptionsOf } from '../schema-comment.mjs
|
|
|
8
8
|
import { UNKNOWN_TYPE } from '../shared-types.mjs';
|
|
9
9
|
import { unionOf, intersectionOf } from '../type-combinators.mjs';
|
|
10
10
|
import { propertyAccessFlags } from './access-flags.mjs';
|
|
11
|
+
import { withPropertyTypes } from './index-signature-type.mjs';
|
|
11
12
|
import { inheritedDiscriminator, discriminatorMember } from './inherited-discriminator.mjs';
|
|
13
|
+
import { isInputLocation } from './input-location.mjs';
|
|
14
|
+
import { refWithSiblingsAsAllOf } from './ref-siblings.mjs';
|
|
12
15
|
|
|
13
|
-
const INPUT_PATH_PARTS = ["parameters", "requestBody", "requestBodies"];
|
|
14
16
|
class InvalidPropertyError extends OpenAPITypesafeError {
|
|
15
17
|
constructor(path, key, value) {
|
|
16
18
|
const received = Array.isArray(value) ? "Array" : typeof value;
|
|
@@ -47,8 +49,7 @@ function propertyFacts(value, request) {
|
|
|
47
49
|
}
|
|
48
50
|
function isOptionalProperty(key, facts, schema, request) {
|
|
49
51
|
const { options } = request.context;
|
|
50
|
-
const
|
|
51
|
-
const isDefaultRequired = facts.hasDefault && options.defaultNonNullable && !INPUT_PATH_PARTS.some((part) => path?.includes(part));
|
|
52
|
+
const isDefaultRequired = facts.hasDefault && options.defaultNonNullable && !isInputLocation(request.location.path, options.fixes);
|
|
52
53
|
const isRequired = schema.required?.includes(key) || schema.required === void 0 && options.propertiesRequiredByDefault || isDefaultRequired;
|
|
53
54
|
return !isRequired;
|
|
54
55
|
}
|
|
@@ -59,9 +60,14 @@ function isExcluded(value, facts, request) {
|
|
|
59
60
|
const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;
|
|
60
61
|
return Boolean(resolved?.deprecated);
|
|
61
62
|
}
|
|
63
|
+
function plainRef({ ref }, value, request) {
|
|
64
|
+
const isAllOf = ref && refWithSiblingsAsAllOf(value, request.context.options);
|
|
65
|
+
return isAllOf ? void 0 : ref;
|
|
66
|
+
}
|
|
62
67
|
function propertyType(key, value, facts, request) {
|
|
63
68
|
const path = appendPointer(request.location.path, [key]);
|
|
64
|
-
const
|
|
69
|
+
const ref = plainRef(facts, value, request);
|
|
70
|
+
const type = ref ? schemaRefType(ref, request) : request.transformNested(value, { ...request.location, path });
|
|
65
71
|
const custom = request.context.callbacks.transform(value, request.location);
|
|
66
72
|
return custom === null ? { type, isOptional: null } : { type: custom.type, isOptional: custom.isOptional || null };
|
|
67
73
|
}
|
|
@@ -165,6 +171,9 @@ function objectType(schema, request) {
|
|
|
165
171
|
return inherited ? irObject([discriminatorMember(inherited, request)]) : null;
|
|
166
172
|
}
|
|
167
173
|
const members = discriminatorAndPropertyMembers(schema, request);
|
|
174
|
+
const propertyTypes = members.flatMap(
|
|
175
|
+
(member) => member.kind === "property" ? [member.type] : []
|
|
176
|
+
);
|
|
168
177
|
if ("$defs" in schema && typeof schema.$defs === "object" && Object.keys(schema.$defs).length > 0) {
|
|
169
178
|
members.push(defsMember(schema.$defs, request));
|
|
170
179
|
}
|
|
@@ -172,8 +181,9 @@ function objectType(schema, request) {
|
|
|
172
181
|
if (valueTypes.length === 0) {
|
|
173
182
|
return members.length > 0 ? irObject(members) : null;
|
|
174
183
|
}
|
|
184
|
+
const indexType = withPropertyTypes(unionOf(valueTypes), propertyTypes);
|
|
175
185
|
const index = irObject([
|
|
176
|
-
irStringIndexSignature("key",
|
|
186
|
+
irStringIndexSignature("key", indexType, request.context.options.immutable)
|
|
177
187
|
]);
|
|
178
188
|
return intersectionOf([...members.length > 0 ? [irObject(members)] : [], index]);
|
|
179
189
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-type.mjs","sources":["../../../../src/application/transform/schema/object-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport {\n irObject,\n irProperty,\n irReference,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport { type AccessFlags, propertyAccessFlags } from \"./access-flags.js\";\nimport { discriminatorMember, inheritedDiscriminator } from \"./inherited-discriminator.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/** Path parts where a default value cannot make a property required (inputs may omit it). */\nconst INPUT_PATH_PARTS = [\"parameters\", \"requestBody\", \"requestBodies\"] as const;\n\nexport class InvalidPropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined, key: string, value: unknown) {\n const received = Array.isArray(value) ? \"Array\" : typeof value;\n super({\n code: ERROR_CODES.SCHEMA_PROPERTY_INVALID,\n message:\n `${path}: invalid property ${key}. ` + `Expected Schema Object or boolean, got ${received}`,\n details: { path, property: key, received },\n });\n this.name = \"InvalidPropertyError\";\n }\n}\n\n/** `--read-write-markers`: `$Read<T>` / `$Write<T>`, unless the property is both or neither. */\nfunction withReadWriteMarker(type: IrType, flags: AccessFlags, options: SchemaOptions): IrType {\n if (!options.readWriteMarkers || flags.isReadOnly === flags.isWriteOnly) {\n return type;\n }\n return irReference(flags.isReadOnly ? \"$Read\" : \"$Write\", [type]);\n}\n\n/** Apply `transformProperty`, then the schema's JSDoc. */\nfunction finishProperty(\n property: IrPropertySignature,\n schema: Schema,\n path: string,\n request: SchemaRequest,\n): IrPropertySignature {\n const location = { ...request.location, path };\n const transformed =\n request.context.callbacks.transformProperty(property, schema, location) ?? property;\n // The original adds the schema's comment after any comment the callback set.\n return withSchemaComment(\n transformed,\n schema,\n schemaCommentOptionsOf(request.context.options.fixes),\n );\n}\n\n/** What the property loop reads from a property schema, in the original order. */\ninterface PropertyFacts {\n readonly ref: string | undefined;\n readonly flags: AccessFlags;\n readonly hasDefault: boolean;\n}\n\nfunction propertyFacts(value: Schema, request: SchemaRequest): PropertyFacts {\n if (typeof value !== \"object\") {\n return { ref: undefined, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };\n }\n // `in` throws for a null value, as in the original (which also reads `$ref` first).\n const ref = \"$ref\" in value && value.$ref ? value.$ref : undefined;\n const flags = propertyAccessFlags(value, request.context);\n return { ref, flags, hasDefault: \"default\" in value && value.default !== undefined };\n}\n\nfunction isOptionalProperty(\n key: string,\n facts: PropertyFacts,\n schema: SchemaObject,\n request: SchemaRequest,\n): boolean {\n const { options } = request.context;\n const path = request.location.path;\n const isDefaultRequired =\n facts.hasDefault &&\n options.defaultNonNullable &&\n !INPUT_PATH_PARTS.some((part) => path?.includes(part));\n const isRequired =\n schema.required?.includes(key) ||\n (schema.required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\nfunction isExcluded(value: Schema, facts: PropertyFacts, request: SchemaRequest): boolean {\n if (!request.context.options.excludeDeprecated) {\n return false;\n }\n const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;\n return Boolean((resolved as SchemaObject | undefined)?.deprecated);\n}\n\n/** A type, and whether a callback forced the property optional (null: no override). */\ninterface CustomResult {\n readonly type: IrType;\n readonly isOptional: true | null;\n}\n\nfunction propertyType(\n key: string,\n value: Schema,\n facts: PropertyFacts,\n request: SchemaRequest,\n): CustomResult {\n const path = appendPointer(request.location.path, [key]);\n const type = facts.ref\n ? schemaRefType(facts.ref, request)\n : request.transformNested(value, { ...request.location, path });\n const custom = request.context.callbacks.transform(value, request.location);\n return custom === null\n ? { type, isOptional: null }\n : { type: custom.type, isOptional: custom.isOptional || null };\n}\n\nfunction propertyMember(\n key: string,\n value: Schema,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrMember | null {\n if ((typeof value !== \"object\" && typeof value !== \"boolean\") || Array.isArray(value)) {\n throw new InvalidPropertyError(request.location.path, key, value);\n }\n const facts = propertyFacts(value, request);\n if (isExcluded(value, facts, request)) {\n return null;\n }\n const { options } = request.context;\n const isOptional = isOptionalProperty(key, facts, schema, request);\n const result = propertyType(key, value, facts, request);\n const property = irProperty(\n toPropertyName(key),\n withReadWriteMarker(result.type, facts.flags, options),\n {\n isOptional: result.isOptional ?? isOptional,\n isReadonly: options.immutable || (!options.readWriteMarkers && facts.flags.isReadOnly),\n },\n );\n return finishProperty(property, value, appendPointer(request.location.path, [key]), request);\n}\n\nfunction propertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const members: IrMember[] = [];\n for (const [key, value] of documentEntries(schema.properties ?? {}, request.context.options)) {\n const member = propertyMember(key, value, schema, request);\n if (member !== null) {\n members.push(member);\n }\n }\n return members;\n}\n\n/**\n * `$defs` as a nested `$defs?: { … }` member, in document order (never alphabetized). It is\n * optional because `$defs` is a schema keyword, not data: the original made it required, so a\n * value of the type needed a `$defs` key (research/legacy-bugs.md, item 17, upstream #2664).\n */\nfunction defsMember(\n defs: Readonly<Record<string, SchemaObject>>,\n request: SchemaRequest,\n): IrMember {\n const { options } = request.context;\n const members = Object.entries(defs).map(([key, value]) => {\n const path = appendPointer(request.location.path, [\"$defs\", key]);\n const flags = propertyAccessFlags(value, request.context);\n const type = withReadWriteMarker(\n request.transformNested(value, { ...request.location, path }),\n flags,\n options,\n );\n const property = irProperty(toPropertyName(key), type, {\n isReadonly: options.immutable || (!options.readWriteMarkers && flags.isReadOnly),\n });\n return finishProperty(property, value, path, request);\n });\n return irProperty(toPropertyName(\"$defs\"), irObject(members), { isOptional: true });\n}\n\nfunction hasObjectKeywords(schema: SchemaObject): boolean {\n const hasProperties = Boolean(schema.properties && Object.keys(schema.properties).length);\n return (\n hasProperties ||\n Boolean(schema.additionalProperties || schema.patternProperties || schema.$defs)\n );\n}\n\n/** Value types of the `[key: string]` index signature, in the original order. */\nfunction indexValueTypes(schema: SchemaObject, request: SchemaRequest): IrType[] {\n const { additionalProperties } = schema;\n const isObject = typeof additionalProperties === \"object\";\n const hasExplicit = isObject && Object.keys(additionalProperties).length > 0;\n const hasImplicit =\n additionalProperties === true || (isObject && Object.keys(additionalProperties).length === 0);\n const types: IrType[] = [];\n if (hasExplicit) {\n types.push(request.transformNested(additionalProperties as Schema, request.location, true));\n }\n if (hasImplicit || (!additionalProperties && request.context.options.additionalProperties)) {\n types.push(UNKNOWN_TYPE);\n }\n const patterns = schema.patternProperties;\n if (typeof patterns === \"object\" && patterns !== null && Object.keys(patterns).length > 0) {\n for (const [, value] of documentEntries(patterns, request.context.options)) {\n types.push(request.transformNested(value, request.location));\n }\n }\n return types;\n}\n\n/**\n * Whether the schema declares property `key` and the type keeps it: `--exclude-deprecated` drops\n * a deprecated one.\n */\nexport function isKeptProperty(schema: SchemaObject, key: string, request: SchemaRequest): boolean {\n const properties = schema.properties ?? {};\n if (!Object.hasOwn(properties, key)) {\n return false;\n }\n const value = properties[key] as Schema;\n const isExcludable = request.context.options.excludeDeprecated && typeof value === \"object\";\n return !isExcludable || !isExcluded(value, propertyFacts(value, request), request);\n}\n\n/**\n * The members for the discriminator and `properties`. A schema that declares the discriminator\n * property itself keeps its own declaration, required as the discriminator needs: both in one\n * object type do not compile (TS2300, the Apple SiriKit Cloud Media API). A declaration that\n * `--exclude-deprecated` drops does not count, so the discriminator property stays.\n */\nfunction discriminatorAndPropertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const inherited = inheritedDiscriminator(schema, request);\n if (inherited === undefined) {\n return propertyMembers(schema, request);\n }\n const name = inherited.discriminator.propertyName;\n if (!isKeptProperty(schema, name, request)) {\n return [discriminatorMember(inherited, request), ...propertyMembers(schema, request)];\n }\n // Without `required`, `--properties-required-by-default` requires every property already; a\n // list of one would make the others optional.\n const isAllRequired =\n schema.required === undefined && request.context.options.propertiesRequiredByDefault;\n const required = isAllRequired ? undefined : [...(schema.required ?? []), name];\n return propertyMembers({ ...schema, required } as SchemaObject, request);\n}\n\n/**\n * Object keywords: discriminator, `properties`, `$defs`, and an index signature for\n * `additionalProperties` / `patternProperties` (or `--additional-properties`). Null when the schema\n * has none of them.\n */\nexport function objectType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (!hasObjectKeywords(schema)) {\n const inherited = inheritedDiscriminator(schema, request);\n return inherited ? irObject([discriminatorMember(inherited, request)]) : null;\n }\n const members = discriminatorAndPropertyMembers(schema, request);\n // As in the original, a null `$defs` throws here (Object.keys) instead of being skipped.\n if (\n \"$defs\" in schema &&\n typeof schema.$defs === \"object\" &&\n Object.keys(schema.$defs).length > 0\n ) {\n members.push(defsMember(schema.$defs, request));\n }\n const valueTypes = indexValueTypes(schema, request);\n if (valueTypes.length === 0) {\n return members.length > 0 ? irObject(members) : null;\n }\n const index = irObject([\n irStringIndexSignature(\"key\", unionOf(valueTypes), request.context.options.immutable),\n ]);\n return intersectionOf([...(members.length > 0 ? [irObject(members)] : []), index]);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAsBA,MAAM,gBAAA,GAAmB,CAAC,YAAA,EAAc,aAAA,EAAe,eAAe,CAAA;AAE/D,MAAM,6BAA6B,oBAAA,CAAqB;AAAA,EAC7D,WAAA,CAAY,IAAA,EAA0B,GAAA,EAAa,KAAA,EAAgB;AACjE,IAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,UAAU,OAAO,KAAA;AACzD,IAAA,KAAA,CAAM;AAAA,MACJ,MAAM,WAAA,CAAY,uBAAA;AAAA,MAClB,SACE,CAAA,EAAG,IAAI,CAAA,mBAAA,EAAsB,GAAG,4CAAiD,QAAQ,CAAA,CAAA;AAAA,MAC3F,OAAA,EAAS,EAAE,IAAA,EAAM,QAAA,EAAU,KAAK,QAAA;AAAS,KAC1C,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,sBAAA;AAAA,EACd;A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A,EAChD;AACA,EAAA,MAAM,UAAA,GAAa,eAAA,CAAgB,MAAA,EAAQ,OAAO,CAAA;AAClD,EAAA,IAAI,UAAA,CAAW,WAAW,CAAA,EAAG;AAC3B,IAAA,OAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,GAAI,QAAA,CAAS,OAAO,CAAA,GAAI,IAAA;AAAA,EAClD;AACA,EAAA,MAAM,QAAQ,QAAA,CAAS;AAAA,IACrB,sBAAA,CAAuB,OAAO,OAAA,CAAQ,UAAU,GAAG,OAAA,CAAQ,OAAA,CAAQ,QAAQ,SAAS;AAAA,GACrF,CAAA;AACD,EAAA,OAAO,cAAA,CAAe,CAAC,GAAI,OAAA,CAAQ,SAAS,CAAA,GAAI,CAAC,QAAA,CAAS,OAAO,CAAC,CAAA,GAAI,EAAC,EAAI,KAAK,CAAC,CAAA;AACnF;;"}
|
|
1
|
+
{"version":3,"file":"object-type.mjs","sources":["../../../../src/application/transform/schema/object-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport {\n irObject,\n irProperty,\n irReference,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport { type AccessFlags, propertyAccessFlags } from \"./access-flags.js\";\nimport { withPropertyTypes } from \"./index-signature-type.js\";\nimport { discriminatorMember, inheritedDiscriminator } from \"./inherited-discriminator.js\";\nimport { isInputLocation } from \"./input-location.js\";\nimport { refWithSiblingsAsAllOf } from \"./ref-siblings.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\nexport class InvalidPropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined, key: string, value: unknown) {\n const received = Array.isArray(value) ? \"Array\" : typeof value;\n super({\n code: ERROR_CODES.SCHEMA_PROPERTY_INVALID,\n message:\n `${path}: invalid property ${key}. ` + `Expected Schema Object or boolean, got ${received}`,\n details: { path, property: key, received },\n });\n this.name = \"InvalidPropertyError\";\n }\n}\n\n/** `--read-write-markers`: `$Read<T>` / `$Write<T>`, unless the property is both or neither. */\nfunction withReadWriteMarker(type: IrType, flags: AccessFlags, options: SchemaOptions): IrType {\n if (!options.readWriteMarkers || flags.isReadOnly === flags.isWriteOnly) {\n return type;\n }\n return irReference(flags.isReadOnly ? \"$Read\" : \"$Write\", [type]);\n}\n\n/** Apply `transformProperty`, then the schema's JSDoc. */\nfunction finishProperty(\n property: IrPropertySignature,\n schema: Schema,\n path: string,\n request: SchemaRequest,\n): IrPropertySignature {\n const location = { ...request.location, path };\n const transformed =\n request.context.callbacks.transformProperty(property, schema, location) ?? property;\n // The original adds the schema's comment after any comment the callback set.\n return withSchemaComment(\n transformed,\n schema,\n schemaCommentOptionsOf(request.context.options.fixes),\n );\n}\n\n/** What the property loop reads from a property schema, in the original order. */\ninterface PropertyFacts {\n readonly ref: string | undefined;\n readonly flags: AccessFlags;\n readonly hasDefault: boolean;\n}\n\nfunction propertyFacts(value: Schema, request: SchemaRequest): PropertyFacts {\n if (typeof value !== \"object\") {\n return { ref: undefined, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };\n }\n // `in` throws for a null value, as in the original (which also reads `$ref` first).\n const ref = \"$ref\" in value && value.$ref ? value.$ref : undefined;\n const flags = propertyAccessFlags(value, request.context);\n return { ref, flags, hasDefault: \"default\" in value && value.default !== undefined };\n}\n\nfunction isOptionalProperty(\n key: string,\n facts: PropertyFacts,\n schema: SchemaObject,\n request: SchemaRequest,\n): boolean {\n const { options } = request.context;\n const isDefaultRequired =\n facts.hasDefault &&\n options.defaultNonNullable &&\n !isInputLocation(request.location.path, options.fixes);\n const isRequired =\n schema.required?.includes(key) ||\n (schema.required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\nfunction isExcluded(value: Schema, facts: PropertyFacts, request: SchemaRequest): boolean {\n if (!request.context.options.excludeDeprecated) {\n return false;\n }\n const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;\n return Boolean((resolved as SchemaObject | undefined)?.deprecated);\n}\n\n/** A type, and whether a callback forced the property optional (null: no override). */\ninterface CustomResult {\n readonly type: IrType;\n readonly isOptional: true | null;\n}\n\n/** A `$ref` with siblings that `ref-siblings` types as an `allOf` is typed as a schema. */\nfunction plainRef({ ref }: PropertyFacts, value: Schema, request: SchemaRequest) {\n const isAllOf = ref && refWithSiblingsAsAllOf(value as SchemaObject, request.context.options);\n return isAllOf ? undefined : ref;\n}\n\nfunction propertyType(\n key: string,\n value: Schema,\n facts: PropertyFacts,\n request: SchemaRequest,\n): CustomResult {\n const path = appendPointer(request.location.path, [key]);\n const ref = plainRef(facts, value, request);\n const type = ref\n ? schemaRefType(ref, request)\n : request.transformNested(value, { ...request.location, path });\n const custom = request.context.callbacks.transform(value, request.location);\n return custom === null\n ? { type, isOptional: null }\n : { type: custom.type, isOptional: custom.isOptional || null };\n}\n\nfunction propertyMember(\n key: string,\n value: Schema,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrMember | null {\n if ((typeof value !== \"object\" && typeof value !== \"boolean\") || Array.isArray(value)) {\n throw new InvalidPropertyError(request.location.path, key, value);\n }\n const facts = propertyFacts(value, request);\n if (isExcluded(value, facts, request)) {\n return null;\n }\n const { options } = request.context;\n const isOptional = isOptionalProperty(key, facts, schema, request);\n const result = propertyType(key, value, facts, request);\n const property = irProperty(\n toPropertyName(key),\n withReadWriteMarker(result.type, facts.flags, options),\n {\n isOptional: result.isOptional ?? isOptional,\n isReadonly: options.immutable || (!options.readWriteMarkers && facts.flags.isReadOnly),\n },\n );\n return finishProperty(property, value, appendPointer(request.location.path, [key]), request);\n}\n\nfunction propertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const members: IrMember[] = [];\n for (const [key, value] of documentEntries(schema.properties ?? {}, request.context.options)) {\n const member = propertyMember(key, value, schema, request);\n if (member !== null) {\n members.push(member);\n }\n }\n return members;\n}\n\n/**\n * `$defs` as a nested `$defs?: { … }` member, in document order (never alphabetized). It is\n * optional because `$defs` is a schema keyword, not data: the original made it required, so a\n * value of the type needed a `$defs` key (research/legacy-bugs.md, item 17, upstream #2664).\n */\nfunction defsMember(\n defs: Readonly<Record<string, SchemaObject>>,\n request: SchemaRequest,\n): IrMember {\n const { options } = request.context;\n const members = Object.entries(defs).map(([key, value]) => {\n const path = appendPointer(request.location.path, [\"$defs\", key]);\n const flags = propertyAccessFlags(value, request.context);\n const type = withReadWriteMarker(\n request.transformNested(value, { ...request.location, path }),\n flags,\n options,\n );\n const property = irProperty(toPropertyName(key), type, {\n isReadonly: options.immutable || (!options.readWriteMarkers && flags.isReadOnly),\n });\n return finishProperty(property, value, path, request);\n });\n return irProperty(toPropertyName(\"$defs\"), irObject(members), { isOptional: true });\n}\n\nfunction hasObjectKeywords(schema: SchemaObject): boolean {\n const hasProperties = Boolean(schema.properties && Object.keys(schema.properties).length);\n return (\n hasProperties ||\n Boolean(schema.additionalProperties || schema.patternProperties || schema.$defs)\n );\n}\n\n/** Value types of the `[key: string]` index signature, in the original order. */\nfunction indexValueTypes(schema: SchemaObject, request: SchemaRequest): IrType[] {\n const { additionalProperties } = schema;\n const isObject = typeof additionalProperties === \"object\";\n const hasExplicit = isObject && Object.keys(additionalProperties).length > 0;\n const hasImplicit =\n additionalProperties === true || (isObject && Object.keys(additionalProperties).length === 0);\n const types: IrType[] = [];\n if (hasExplicit) {\n types.push(request.transformNested(additionalProperties as Schema, request.location, true));\n }\n if (hasImplicit || (!additionalProperties && request.context.options.additionalProperties)) {\n types.push(UNKNOWN_TYPE);\n }\n const patterns = schema.patternProperties;\n if (typeof patterns === \"object\" && patterns !== null && Object.keys(patterns).length > 0) {\n for (const [, value] of documentEntries(patterns, request.context.options)) {\n types.push(request.transformNested(value, request.location));\n }\n }\n return types;\n}\n\n/**\n * Whether the schema declares property `key` and the type keeps it: `--exclude-deprecated` drops\n * a deprecated one.\n */\nexport function isKeptProperty(schema: SchemaObject, key: string, request: SchemaRequest): boolean {\n const properties = schema.properties ?? {};\n if (!Object.hasOwn(properties, key)) {\n return false;\n }\n const value = properties[key] as Schema;\n const isExcludable = request.context.options.excludeDeprecated && typeof value === \"object\";\n return !isExcludable || !isExcluded(value, propertyFacts(value, request), request);\n}\n\n/**\n * The members for the discriminator and `properties`. A schema that declares the discriminator\n * property itself keeps its own declaration, required as the discriminator needs: both in one\n * object type do not compile (TS2300, the Apple SiriKit Cloud Media API). A declaration that\n * `--exclude-deprecated` drops does not count, so the discriminator property stays.\n */\nfunction discriminatorAndPropertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const inherited = inheritedDiscriminator(schema, request);\n if (inherited === undefined) {\n return propertyMembers(schema, request);\n }\n const name = inherited.discriminator.propertyName;\n if (!isKeptProperty(schema, name, request)) {\n return [discriminatorMember(inherited, request), ...propertyMembers(schema, request)];\n }\n // Without `required`, `--properties-required-by-default` requires every property already; a\n // list of one would make the others optional.\n const isAllRequired =\n schema.required === undefined && request.context.options.propertiesRequiredByDefault;\n const required = isAllRequired ? undefined : [...(schema.required ?? []), name];\n return propertyMembers({ ...schema, required } as SchemaObject, request);\n}\n\n/**\n * Object keywords: discriminator, `properties`, `$defs`, and an index signature for\n * `additionalProperties` / `patternProperties` (or `--additional-properties`). Null when the schema\n * has none of them.\n */\nexport function objectType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (!hasObjectKeywords(schema)) {\n const inherited = inheritedDiscriminator(schema, request);\n return inherited ? irObject([discriminatorMember(inherited, request)]) : null;\n }\n const members = discriminatorAndPropertyMembers(schema, request);\n const propertyTypes = members.flatMap((member) =>\n member.kind === \"property\" ? [member.type] : [],\n );\n // As in the original, a null `$defs` throws here (Object.keys) instead of being skipped.\n if (\n \"$defs\" in schema &&\n typeof schema.$defs === \"object\" &&\n Object.keys(schema.$defs).length > 0\n ) {\n members.push(defsMember(schema.$defs, request));\n }\n const valueTypes = indexValueTypes(schema, request);\n if (valueTypes.length === 0) {\n return members.length > 0 ? irObject(members) : null;\n }\n const indexType = withPropertyTypes(unionOf(valueTypes), propertyTypes);\n const index = irObject([\n irStringIndexSignature(\"key\", indexType, request.context.options.immutable),\n ]);\n return intersectionOf([...(members.length > 0 ? [irObject(members)] : []), index]);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAwBO,MAAM,6BAA6B,oBAAA,CAAqB;AAAA,EAC7D,WAAA,CAAY,IAAA,EAA0B,GAAA,EAAa,KAAA,EAAgB;AACjE,IAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,UAAU,OAAO,KAAA;AACzD,IAAA,KAAA,CAAM;AAAA,MACJ,MAAM,WAAA,CAAY,uBAAA;AAAA,MAClB,SACE,CAAA,EAAG,IAAI,CAAA,mBAAA,EAAsB,GAAG,4CAAiD,QAAQ,CAAA,CAAA;AAAA,MAC3F,OAAA,EAAS,EAAE,IAAA,EAAM,QAAA,EAAU,KAAK,QAAA;AAAS,KAC1C,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,sBAAA;AAAA,EACd;AACF;AAGA,SAAS,mBAAA,CAAoB,IAAA,EAAc,KAAA,EAAoB,OAAA,EAAgC;AAC7F,EAAA,IAAI,CAAC,OAAA,CAAQ,gBAAA,IAAoB,KAAA,CAAM,UAAA,KAAe,MAAM,WAAA,EAAa;AACvE,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,YAAY,KAAA,CAAM,UAAA,GAAa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AA,CAAE,MAAA,GAAS,CAAA,EACnC;AACA,IAAA,OAAA,CAAQ,IAAA,CAAK,UAAA,CAAW,MAAA,CAAO,KAAA,EAAO,OAAO,CAAC,CAAA;AAAA,EAChD;AACA,EAAA,MAAM,UAAA,GAAa,eAAA,CAAgB,MAAA,EAAQ,OAAO,CAAA;AAClD,EAAA,IAAI,UAAA,CAAW,WAAW,CAAA,EAAG;AAC3B,IAAA,OAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,GAAI,QAAA,CAAS,OAAO,CAAA,GAAI,IAAA;AAAA,EAClD;AACA,EAAA,MAAM,SAAA,GAAY,iBAAA,CAAkB,OAAA,CAAQ,UAAU,GAAG,aAAa,CAAA;AACtE,EAAA,MAAM,QAAQ,QAAA,CAAS;AAAA,IACrB,uBAAuB,KAAA,EAAO,SAAA,EAAW,OAAA,CAAQ,OAAA,CAAQ,QAAQ,SAAS;AAAA,GAC3E,CAAA;AACD,EAAA,OAAO,cAAA,CAAe,CAAC,GAAI,OAAA,CAAQ,SAAS,CAAA,GAAI,CAAC,QAAA,CAAS,OAAO,CAAC,CAAA,GAAI,EAAC,EAAI,KAAK,CAAC,CAAA;AACnF;;"}
|
|
@@ -28,7 +28,8 @@ const SHAPE_RULES = [
|
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
name: "const",
|
|
31
|
-
|
|
31
|
+
// `const: null` is the value null (JSON Schema §6.1.3); the original read it as no `const`.
|
|
32
|
+
matches: (schema) => schema.const !== void 0,
|
|
32
33
|
transform: (schema) => literalType.literalType(schema.const)
|
|
33
34
|
},
|
|
34
35
|
enumRule.enumRule
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-transform.cjs","sources":["../../../../src/application/transform/schema/schema-transform.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { compositionType } from \"./composition-type.js\";\nimport { enumRule } from \"./enum-rule.js\";\nimport { refWithSiblingsAsAllOf } from \"./ref-siblings.js\";\nimport type { SchemaContext, SchemaLocation } from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nexport class InvalidSchemaError extends OpenAPITypesafeError {\n constructor(schema: unknown, path: string | undefined) {\n const received = Array.isArray(schema) ? \"Array\" : typeof schema;\n super({\n code: ERROR_CODES.SCHEMA_OBJECT_INVALID,\n message: `Expected SchemaObject, received ${received} at ${path}`,\n details: { path, received },\n });\n this.name = \"InvalidSchemaError\";\n }\n}\n\n/** Shape rules in the original precedence; composition handles everything they do not match. */\nconst SHAPE_RULES: readonly SchemaRule[] = [\n {\n name: \"$ref\",\n matches: (schema) => \"$ref\" in schema,\n transform: (schema, request) => schemaRefType((schema as { $ref: string }).$ref, request),\n },\n {\n name: \"const\",\n
|
|
1
|
+
{"version":3,"file":"schema-transform.cjs","sources":["../../../../src/application/transform/schema/schema-transform.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { compositionType } from \"./composition-type.js\";\nimport { enumRule } from \"./enum-rule.js\";\nimport { refWithSiblingsAsAllOf } from \"./ref-siblings.js\";\nimport type { SchemaContext, SchemaLocation } from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nexport class InvalidSchemaError extends OpenAPITypesafeError {\n constructor(schema: unknown, path: string | undefined) {\n const received = Array.isArray(schema) ? \"Array\" : typeof schema;\n super({\n code: ERROR_CODES.SCHEMA_OBJECT_INVALID,\n message: `Expected SchemaObject, received ${received} at ${path}`,\n details: { path, received },\n });\n this.name = \"InvalidSchemaError\";\n }\n}\n\n/** Shape rules in the original precedence; composition handles everything they do not match. */\nconst SHAPE_RULES: readonly SchemaRule[] = [\n {\n name: \"$ref\",\n matches: (schema) => \"$ref\" in schema,\n transform: (schema, request) => schemaRefType((schema as { $ref: string }).$ref, request),\n },\n {\n name: \"const\",\n // `const: null` is the value null (JSON Schema §6.1.3); the original read it as no `const`.\n matches: (schema) => schema.const !== undefined,\n transform: (schema) => literalType(schema.const),\n },\n enumRule,\n];\n\n/** A schema checked for its input shape, or the type of a non-object schema. */\ntype CheckedSchema = { readonly type: IrType } | { readonly schema: SchemaObject };\n\n/** A missing schema is `never`; `true` allows anything; other non-objects are invalid. */\nfunction checkSchema(schema: unknown, path: string | undefined): CheckedSchema {\n if (!schema) {\n return { type: irKeyword(\"never\") };\n }\n if (schema === true) {\n return { type: UNKNOWN_TYPE };\n }\n if (Array.isArray(schema) || typeof schema !== \"object\") {\n throw new InvalidSchemaError(schema, path);\n }\n return { schema: schema as SchemaObject };\n}\n\nfunction request(\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties: boolean,\n): SchemaRequest {\n return {\n location,\n context,\n isFromAdditionalProperties,\n transformNested: (schema, nestedLocation, isNestedFromAdditionalProperties = false) =>\n transformSchema(schema, nestedLocation, context, isNestedFromAdditionalProperties),\n };\n}\n\n/**\n * Transform a schema without the `postTransform` callback (the original\n * `transformSchemaObjectWithComposition`). Nested schemas still get `postTransform`.\n */\nexport function transformSchemaShape(\n schema: Schema | null | undefined,\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties = false,\n): IrType {\n const checked = checkSchema(schema, location.path);\n if (\"type\" in checked) {\n return checked.type;\n }\n const current = request(location, context, isFromAdditionalProperties);\n const shaped = refWithSiblingsAsAllOf(checked.schema, context.options) ?? checked.schema;\n const rule = SHAPE_RULES.find((candidate) => candidate.matches(shaped));\n return rule ? rule.transform(shaped, current) : compositionType(shaped, current);\n}\n\n/** Transform a schema to IR, then apply `postTransform` (the original `transformSchemaObject`). */\nexport function transformSchema(\n schema: Schema | null | undefined,\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties = false,\n): IrType {\n const type = transformSchemaShape(schema, location, context, isFromAdditionalProperties);\n return context.callbacks.postTransform(type, location) ?? type;\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","request","schemaRefType","literalType","enumRule","irKeyword","UNKNOWN_TYPE","refWithSiblingsAsAllOf","compositionType"],"mappings":";;;;;;;;;;;AAaO,MAAM,2BAA2BA,2BAAA,CAAqB;AAAA,EAC3D,WAAA,CAAY,QAAiB,IAAA,EAA0B;AACrD,IAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAI,UAAU,OAAO,MAAA;AAC1D,IAAA,KAAA,CAAM;AAAA,MACJ,MAAMC,kBAAA,CAAY,qBAAA;AAAA,MAClB,OAAA,EAAS,CAAA,gCAAA,EAAmC,QAAQ,CAAA,IAAA,EAAO,IAAI,CAAA,CAAA;AAAA,MAC/D,OAAA,EAAS,EAAE,IAAA,EAAM,QAAA;AAAS,KAC3B,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AAAA,EACd;AACF;AAGA,MAAM,WAAA,GAAqC;AAAA,EACzC;AAAA,IACE,IAAA,EAAM,MAAA;AAAA,IACN,OAAA,EAAS,CAAC,MAAA,KAAW,MAAA,IAAU,MAAA;AAAA,IAC/B,WAAW,CAAC,MAAA,EAAQC,aAAYC,yBAAA,CAAe,MAAA,CAA4B,MAAMD,QAAO;AAAA,GAC1F;AAAA,EACA;AAAA,IACE,IAAA,EAAM,OAAA;AAAA;AAAA,IAEN,OAAA,EAAS,CAAC,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CAAuB,OAAA,CAAQ,QAAQ,OAAA,CAAQ,OAAO,KAAK,OAAA,CAAQ,MAAA;AAClF,EAAA,MAAM,IAAA,GAAO,YAAY,IAAA,CAAK,CAAC,cAAc,SAAA,CAAU,OAAA,CAAQ,MAAM,CAAC,CAAA;AACtE,EAAA,OAAO,IAAA,GAAO,KAAK,SAAA,CAAU,MAAA,EAAQ,OAAO,CAAA,GAAIC,+BAAA,CAAgB,QAAQ,OAAO,CAAA;AACjF;AAGO,SAAS,eAAA,CACd,MAAA,EACA,QAAA,EACA,OAAA,EACA,6BAA6B,KAAA,EACrB;AACR,EAAA,MAAM,IAAA,GAAO,oBAAA,CAAqB,MAAA,EAAQ,QAAA,EAAU,SAAS,0BAA0B,CAAA;AACvF,EAAA,OAAO,OAAA,CAAQ,SAAA,CAAU,aAAA,CAAc,IAAA,EAAM,QAAQ,CAAA,IAAK,IAAA;AAC5D;;;;"}
|
|
@@ -26,7 +26,8 @@ const SHAPE_RULES = [
|
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
name: "const",
|
|
29
|
-
|
|
29
|
+
// `const: null` is the value null (JSON Schema §6.1.3); the original read it as no `const`.
|
|
30
|
+
matches: (schema) => schema.const !== void 0,
|
|
30
31
|
transform: (schema) => literalType(schema.const)
|
|
31
32
|
},
|
|
32
33
|
enumRule
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-transform.mjs","sources":["../../../../src/application/transform/schema/schema-transform.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { compositionType } from \"./composition-type.js\";\nimport { enumRule } from \"./enum-rule.js\";\nimport { refWithSiblingsAsAllOf } from \"./ref-siblings.js\";\nimport type { SchemaContext, SchemaLocation } from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nexport class InvalidSchemaError extends OpenAPITypesafeError {\n constructor(schema: unknown, path: string | undefined) {\n const received = Array.isArray(schema) ? \"Array\" : typeof schema;\n super({\n code: ERROR_CODES.SCHEMA_OBJECT_INVALID,\n message: `Expected SchemaObject, received ${received} at ${path}`,\n details: { path, received },\n });\n this.name = \"InvalidSchemaError\";\n }\n}\n\n/** Shape rules in the original precedence; composition handles everything they do not match. */\nconst SHAPE_RULES: readonly SchemaRule[] = [\n {\n name: \"$ref\",\n matches: (schema) => \"$ref\" in schema,\n transform: (schema, request) => schemaRefType((schema as { $ref: string }).$ref, request),\n },\n {\n name: \"const\",\n
|
|
1
|
+
{"version":3,"file":"schema-transform.mjs","sources":["../../../../src/application/transform/schema/schema-transform.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { compositionType } from \"./composition-type.js\";\nimport { enumRule } from \"./enum-rule.js\";\nimport { refWithSiblingsAsAllOf } from \"./ref-siblings.js\";\nimport type { SchemaContext, SchemaLocation } from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nexport class InvalidSchemaError extends OpenAPITypesafeError {\n constructor(schema: unknown, path: string | undefined) {\n const received = Array.isArray(schema) ? \"Array\" : typeof schema;\n super({\n code: ERROR_CODES.SCHEMA_OBJECT_INVALID,\n message: `Expected SchemaObject, received ${received} at ${path}`,\n details: { path, received },\n });\n this.name = \"InvalidSchemaError\";\n }\n}\n\n/** Shape rules in the original precedence; composition handles everything they do not match. */\nconst SHAPE_RULES: readonly SchemaRule[] = [\n {\n name: \"$ref\",\n matches: (schema) => \"$ref\" in schema,\n transform: (schema, request) => schemaRefType((schema as { $ref: string }).$ref, request),\n },\n {\n name: \"const\",\n // `const: null` is the value null (JSON Schema §6.1.3); the original read it as no `const`.\n matches: (schema) => schema.const !== undefined,\n transform: (schema) => literalType(schema.const),\n },\n enumRule,\n];\n\n/** A schema checked for its input shape, or the type of a non-object schema. */\ntype CheckedSchema = { readonly type: IrType } | { readonly schema: SchemaObject };\n\n/** A missing schema is `never`; `true` allows anything; other non-objects are invalid. */\nfunction checkSchema(schema: unknown, path: string | undefined): CheckedSchema {\n if (!schema) {\n return { type: irKeyword(\"never\") };\n }\n if (schema === true) {\n return { type: UNKNOWN_TYPE };\n }\n if (Array.isArray(schema) || typeof schema !== \"object\") {\n throw new InvalidSchemaError(schema, path);\n }\n return { schema: schema as SchemaObject };\n}\n\nfunction request(\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties: boolean,\n): SchemaRequest {\n return {\n location,\n context,\n isFromAdditionalProperties,\n transformNested: (schema, nestedLocation, isNestedFromAdditionalProperties = false) =>\n transformSchema(schema, nestedLocation, context, isNestedFromAdditionalProperties),\n };\n}\n\n/**\n * Transform a schema without the `postTransform` callback (the original\n * `transformSchemaObjectWithComposition`). Nested schemas still get `postTransform`.\n */\nexport function transformSchemaShape(\n schema: Schema | null | undefined,\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties = false,\n): IrType {\n const checked = checkSchema(schema, location.path);\n if (\"type\" in checked) {\n return checked.type;\n }\n const current = request(location, context, isFromAdditionalProperties);\n const shaped = refWithSiblingsAsAllOf(checked.schema, context.options) ?? checked.schema;\n const rule = SHAPE_RULES.find((candidate) => candidate.matches(shaped));\n return rule ? rule.transform(shaped, current) : compositionType(shaped, current);\n}\n\n/** Transform a schema to IR, then apply `postTransform` (the original `transformSchemaObject`). */\nexport function transformSchema(\n schema: Schema | null | undefined,\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties = false,\n): IrType {\n const type = transformSchemaShape(schema, location, context, isFromAdditionalProperties);\n return context.callbacks.postTransform(type, location) ?? type;\n}\n"],"names":["request"],"mappings":";;;;;;;;;AAaO,MAAM,2BAA2B,oBAAA,CAAqB;AAAA,EAC3D,WAAA,CAAY,QAAiB,IAAA,EAA0B;AACrD,IAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAI,UAAU,OAAO,MAAA;AAC1D,IAAA,KAAA,CAAM;AAAA,MACJ,MAAM,WAAA,CAAY,qBAAA;AAAA,MAClB,OAAA,EAAS,CAAA,gCAAA,EAAmC,QAAQ,CAAA,IAAA,EAAO,IAAI,CAAA,CAAA;AAAA,MAC/D,OAAA,EAAS,EAAE,IAAA,EAAM,QAAA;AAAS,KAC3B,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AAAA,EACd;AACF;AAGA,MAAM,WAAA,GAAqC;AAAA,EACzC;AAAA,IACE,IAAA,EAAM,MAAA;AAAA,IACN,OAAA,EAAS,CAAC,MAAA,KAAW,MAAA,IAAU,MAAA;AAAA,IAC/B,WAAW,CAAC,MAAA,EAAQA,aAAY,aAAA,CAAe,MAAA,CAA4B,MAAMA,QAAO;AAAA,GAC1F;AAAA,EACA;AAAA,IACE,IAAA,EAAM,OAAA;AAAA;AAAA,IAEN,OAAA,EAAS,CAAC,MAAA,KAAW,MAAA,CAAO,KAAA,KAAU,MAAA;AAAA,IACtC,SAAA,EAAW,CAAC,MAAA,KAAW,WAAA,CAAY,OAAO,KAAK;AAAA,GACjD;AAAA,EACA;AACF,CAAA;AAMA,SAAS,WAAA,CAAY,QAAiB,IAAA,EAAyC;AAC7E,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,EAAE,IAAA,EAAM,SAAA,CAAU,OAA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