openapi-typesafe 1.0.0-rc.2 → 1.0.0-rc.4
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 +1831 -0
- package/dist/adapters/node-deprecations/node-deprecations.cjs +14 -0
- package/dist/adapters/node-deprecations/node-deprecations.cjs.map +1 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs +12 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.cjs +105 -0
- package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.mjs +95 -0
- package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.cjs +82 -0
- package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.mjs +74 -0
- package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +90 -14
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +90 -14
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +75 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +72 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -1
- package/dist/adapters/redocly-loader/loaded-documents.cjs +28 -0
- package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +14 -15
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +12 -13
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.cjs +2 -2
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.mjs +3 -3
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
- package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +47 -0
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +44 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +11 -7
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +12 -8
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/default-ports.cjs +19 -2
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +19 -3
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.mjs +2 -2
- package/dist/api/discriminator-conflict-warnings.mjs.map +1 -1
- package/dist/api/discriminator-enum-parent.cjs +2 -2
- package/dist/api/discriminator-enum-parent.cjs.map +1 -1
- package/dist/api/discriminator-enum-parent.mjs +3 -3
- package/dist/api/discriminator-enum-parent.mjs.map +1 -1
- package/dist/api/discriminator-other-owners.cjs +5 -3
- package/dist/api/discriminator-other-owners.cjs.map +1 -1
- package/dist/api/discriminator-other-owners.mjs +5 -3
- package/dist/api/discriminator-other-owners.mjs.map +1 -1
- package/dist/api/discriminator-patch.cjs +8 -4
- package/dist/api/discriminator-patch.cjs.map +1 -1
- package/dist/api/discriminator-patch.mjs +9 -5
- package/dist/api/discriminator-patch.mjs.map +1 -1
- package/dist/api/discriminator-scan.cjs +17 -10
- package/dist/api/discriminator-scan.cjs.map +1 -1
- package/dist/api/discriminator-scan.mjs +18 -11
- package/dist/api/discriminator-scan.mjs.map +1 -1
- package/dist/api/document-run.cjs +4 -3
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +4 -3
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-callback-warning.cjs +7 -4
- package/dist/api/legacy-callback-warning.cjs.map +1 -1
- package/dist/api/legacy-callback-warning.mjs +8 -5
- package/dist/api/legacy-callback-warning.mjs.map +1 -1
- package/dist/api/legacy-utils.cjs.map +1 -1
- package/dist/api/legacy-utils.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +9 -5
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +10 -7
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/schema-callbacks.cjs +36 -12
- package/dist/api/schema-callbacks.cjs.map +1 -1
- package/dist/api/schema-callbacks.mjs +36 -12
- package/dist/api/schema-callbacks.mjs.map +1 -1
- package/dist/api/string-to-ast.cjs +7 -9
- package/dist/api/string-to-ast.cjs.map +1 -1
- package/dist/api/string-to-ast.mjs +8 -9
- package/dist/api/string-to-ast.mjs.map +1 -1
- package/dist/api/transform-context.cjs +7 -3
- package/dist/api/transform-context.cjs.map +1 -1
- package/dist/api/transform-context.mjs +7 -3
- package/dist/api/transform-context.mjs.map +1 -1
- package/dist/api/transform-schema.cjs +42 -12
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +44 -14
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/print/text-writer.cjs +10 -3
- package/dist/application/print/text-writer.cjs.map +1 -1
- package/dist/application/print/text-writer.mjs +10 -3
- package/dist/application/print/text-writer.mjs.map +1 -1
- package/dist/application/stack-overflow.cjs +2 -1
- package/dist/application/stack-overflow.cjs.map +1 -1
- package/dist/application/stack-overflow.mjs +2 -1
- package/dist/application/stack-overflow.mjs.map +1 -1
- package/dist/application/transform/document/components.cjs +2 -2
- package/dist/application/transform/document/components.cjs.map +1 -1
- package/dist/application/transform/document/components.mjs +4 -4
- package/dist/application/transform/document/components.mjs.map +1 -1
- package/dist/application/transform/document/declared-type-names.cjs +23 -0
- package/dist/application/transform/document/declared-type-names.cjs.map +1 -0
- package/dist/application/transform/document/declared-type-names.mjs +20 -0
- package/dist/application/transform/document/declared-type-names.mjs.map +1 -0
- package/dist/application/transform/document/defs-root.cjs +1 -1
- package/dist/application/transform/document/defs-root.cjs.map +1 -1
- package/dist/application/transform/document/defs-root.mjs +2 -2
- package/dist/application/transform/document/defs-root.mjs.map +1 -1
- package/dist/application/transform/document/document.cjs +4 -1
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +3 -2
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
- package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
- package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
- package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
- package/dist/application/transform/document/global-type-references.cjs +1 -0
- package/dist/application/transform/document/global-type-references.cjs.map +1 -1
- package/dist/application/transform/document/global-type-references.mjs +1 -1
- package/dist/application/transform/document/global-type-references.mjs.map +1 -1
- package/dist/application/transform/document/media-type.cjs +2 -2
- package/dist/application/transform/document/media-type.cjs.map +1 -1
- package/dist/application/transform/document/media-type.mjs +3 -3
- package/dist/application/transform/document/media-type.mjs.map +1 -1
- package/dist/application/transform/document/operation-keys-written.cjs +26 -0
- package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
- package/dist/application/transform/document/operation-keys-written.mjs +24 -0
- package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
- package/dist/application/transform/document/operation.cjs +1 -1
- package/dist/application/transform/document/operation.cjs.map +1 -1
- package/dist/application/transform/document/operation.mjs +2 -2
- package/dist/application/transform/document/operation.mjs.map +1 -1
- package/dist/application/transform/document/parameter-entries.cjs +34 -0
- package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
- package/dist/application/transform/document/parameter-entries.mjs +30 -0
- package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
- package/dist/application/transform/document/parameter.cjs +12 -4
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +13 -5
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +7 -30
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +8 -31
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +11 -14
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +12 -16
- package/dist/application/transform/document/path-item.mjs.map +1 -1
- package/dist/application/transform/document/paths-enum.cjs +1 -0
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +1 -1
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +6 -2
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +8 -4
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/referenced-parameter.cjs +80 -0
- package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
- package/dist/application/transform/document/referenced-parameter.mjs +78 -0
- package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
- package/dist/application/transform/document/request-body.cjs +1 -1
- package/dist/application/transform/document/request-body.cjs.map +1 -1
- package/dist/application/transform/document/request-body.mjs +2 -2
- package/dist/application/transform/document/request-body.mjs.map +1 -1
- package/dist/application/transform/document/response.cjs +2 -2
- package/dist/application/transform/document/response.cjs.map +1 -1
- package/dist/application/transform/document/response.mjs +3 -3
- package/dist/application/transform/document/response.mjs.map +1 -1
- package/dist/application/transform/document/responses.cjs +1 -1
- package/dist/application/transform/document/responses.cjs.map +1 -1
- package/dist/application/transform/document/responses.mjs +2 -2
- package/dist/application/transform/document/responses.mjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.cjs +8 -23
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.mjs +8 -24
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
- package/dist/application/transform/document/type-resolution.cjs +3 -1
- package/dist/application/transform/document/type-resolution.cjs.map +1 -1
- package/dist/application/transform/document/type-resolution.mjs +3 -1
- package/dist/application/transform/document/type-resolution.mjs.map +1 -1
- package/dist/application/transform/document/webhooks.cjs +1 -1
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +2 -2
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +10 -2
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +10 -2
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
- package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
- package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
- package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.cjs +23 -0
- package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.mjs +21 -0
- package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.cjs +4 -4
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
- package/dist/application/transform/footer/type-evaluation.mjs +4 -4
- package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
- package/dist/application/transform/helper-types.cjs +1 -1
- package/dist/application/transform/helper-types.cjs.map +1 -1
- package/dist/application/transform/helper-types.mjs +1 -1
- package/dist/application/transform/helper-types.mjs.map +1 -1
- package/dist/application/transform/numbered-names.cjs +9 -0
- package/dist/application/transform/numbered-names.cjs.map +1 -1
- package/dist/application/transform/numbered-names.mjs +9 -1
- package/dist/application/transform/numbered-names.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +2 -2
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs +2 -2
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
- package/dist/application/transform/ref-type.cjs +2 -1
- package/dist/application/transform/ref-type.cjs.map +1 -1
- package/dist/application/transform/ref-type.mjs +2 -1
- package/dist/application/transform/ref-type.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs +2 -2
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/array-type.cjs +2 -2
- package/dist/application/transform/schema/array-type.cjs.map +1 -1
- package/dist/application/transform/schema/array-type.mjs +3 -3
- package/dist/application/transform/schema/array-type.mjs.map +1 -1
- package/dist/application/transform/schema/composition-type.cjs +4 -4
- package/dist/application/transform/schema/composition-type.cjs.map +1 -1
- package/dist/application/transform/schema/composition-type.mjs +6 -6
- package/dist/application/transform/schema/composition-type.mjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.cjs +4 -6
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.mjs +6 -8
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
- package/dist/application/transform/schema/object-type.cjs +3 -3
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +4 -4
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/presence-members.cjs +1 -1
- package/dist/application/transform/schema/presence-members.cjs.map +1 -1
- package/dist/application/transform/schema/presence-members.mjs +2 -2
- package/dist/application/transform/schema/presence-members.mjs.map +1 -1
- package/dist/application/transform/schema/ref-siblings.cjs +47 -0
- package/dist/application/transform/schema/ref-siblings.cjs.map +1 -0
- package/dist/application/transform/schema/ref-siblings.mjs +45 -0
- package/dist/application/transform/schema/ref-siblings.mjs.map +1 -0
- package/dist/application/transform/schema/required-variants.cjs +2 -2
- package/dist/application/transform/schema/required-variants.cjs.map +1 -1
- package/dist/application/transform/schema/required-variants.mjs +3 -3
- package/dist/application/transform/schema/required-variants.mjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.cjs +4 -2
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +4 -2
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.mjs +2 -2
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
- package/dist/application/transform/schema-comment.cjs +6 -2
- package/dist/application/transform/schema-comment.cjs.map +1 -1
- package/dist/application/transform/schema-comment.mjs +7 -3
- package/dist/application/transform/schema-comment.mjs.map +1 -1
- package/dist/cli/api-settings.cjs +62 -6
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +60 -7
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +72 -0
- package/dist/cli/api-writes.cjs.map +1 -0
- package/dist/cli/api-writes.mjs +69 -0
- package/dist/cli/api-writes.mjs.map +1 -0
- package/dist/cli/cli-errors.cjs +12 -1
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +12 -1
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +106 -1
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +99 -2
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +5 -1
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +6 -2
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +82 -36
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +85 -39
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +13 -7
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +14 -8
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/append-all.cjs +10 -0
- package/dist/domain/append-all.cjs.map +1 -0
- package/dist/domain/append-all.mjs +8 -0
- package/dist/domain/append-all.mjs.map +1 -0
- package/dist/domain/cause-secrets.cjs +37 -0
- package/dist/domain/cause-secrets.cjs.map +1 -0
- package/dist/domain/cause-secrets.mjs +35 -0
- package/dist/domain/cause-secrets.mjs.map +1 -0
- package/dist/domain/deprecations.cjs +11 -0
- package/dist/domain/deprecations.cjs.map +1 -0
- package/dist/domain/deprecations.mjs +9 -0
- package/dist/domain/deprecations.mjs.map +1 -0
- package/dist/domain/errors.cjs +9 -3
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +9 -3
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/identifier-text.cjs.map +1 -1
- package/dist/domain/ir/identifier-text.mjs +1 -1
- package/dist/domain/ir/identifier-text.mjs.map +1 -1
- package/dist/domain/ir/ir-shape.cjs +187 -0
- package/dist/domain/ir/ir-shape.cjs.map +1 -0
- package/dist/domain/ir/ir-shape.mjs +184 -0
- package/dist/domain/ir/ir-shape.mjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
- package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.cjs +3 -1
- package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.mjs +3 -1
- package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.cjs +3 -3
- package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.mjs +4 -4
- package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
- package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
- package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
- package/dist/domain/openapi/json-pointer.cjs +43 -1
- package/dist/domain/openapi/json-pointer.cjs.map +1 -1
- package/dist/domain/openapi/json-pointer.mjs +40 -2
- package/dist/domain/openapi/json-pointer.mjs.map +1 -1
- package/dist/domain/openapi/schema-dialect.cjs +15 -0
- package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
- package/dist/domain/openapi/schema-dialect.mjs +12 -0
- package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.cjs +1 -1
- package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
- package/dist/domain/openapi/unsupported-features.mjs +2 -2
- package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
- package/dist/domain/output-fixes.cjs +25 -14
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +25 -13
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/url-secrets.cjs +48 -0
- package/dist/domain/url-secrets.cjs.map +1 -0
- package/dist/domain/url-secrets.mjs +45 -0
- package/dist/domain/url-secrets.mjs.map +1 -0
- package/dist/domain/warnings.cjs +0 -1
- package/dist/domain/warnings.cjs.map +1 -1
- package/dist/domain/warnings.mjs +0 -1
- package/dist/domain/warnings.mjs.map +1 -1
- package/dist/index.cjs +2 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -20
- package/dist/index.d.mts +57 -20
- package/dist/index.d.ts +57 -20
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -6
- package/src/adapters/node-deprecations/node-deprecations.ts +14 -0
- package/src/adapters/node-file-system/file-claims.ts +138 -0
- package/src/adapters/node-file-system/file-identity.ts +137 -0
- package/src/adapters/node-file-system/node-file-system.ts +145 -18
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +95 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
- package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +18 -24
- package/src/adapters/redocly-loader/ref-access.ts +37 -3
- package/src/adapters/redocly-loader/ref-holders.ts +3 -3
- package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +74 -11
- package/src/adapters/redocly-loader/remote-node-limit.ts +62 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
- package/src/adapters/redocly-loader/schema-source.ts +20 -8
- package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
- package/src/adapters/terminal-logger/terminal-logger.ts +10 -5
- package/src/api/default-ports.ts +40 -4
- package/src/api/discriminator-conflict-warnings.ts +2 -2
- package/src/api/discriminator-enum-parent.ts +3 -3
- package/src/api/discriminator-other-owners.ts +5 -3
- package/src/api/discriminator-patch.ts +9 -6
- package/src/api/discriminator-scan.ts +19 -11
- package/src/api/document-run.ts +9 -3
- package/src/api/legacy-callback-warning.ts +13 -6
- package/src/api/legacy-utils.ts +5 -1
- package/src/api/openapi-ts.ts +26 -7
- package/src/api/run-context.ts +6 -0
- package/src/api/schema-callbacks.ts +60 -17
- package/src/api/string-to-ast.ts +11 -15
- package/src/api/transform-context.ts +7 -3
- package/src/api/transform-schema.ts +67 -15
- package/src/application/ports/deprecation-reporter.ts +9 -0
- package/src/application/ports/file-system.ts +39 -0
- package/src/application/ports/schema-loader.ts +11 -1
- package/src/application/print/text-writer.ts +10 -3
- package/src/application/stack-overflow.ts +9 -5
- package/src/application/transform/document/components.ts +4 -4
- package/src/application/transform/document/declared-type-names.ts +36 -0
- package/src/application/transform/document/defs-root.ts +2 -2
- package/src/application/transform/document/document.ts +4 -3
- package/src/application/transform/document/enum-names-given-back.ts +91 -0
- package/src/application/transform/document/global-type-references.ts +1 -1
- package/src/application/transform/document/media-type.ts +4 -3
- package/src/application/transform/document/operation-keys-written.ts +27 -0
- package/src/application/transform/document/operation.ts +2 -2
- package/src/application/transform/document/parameter-entries.ts +70 -0
- package/src/application/transform/document/parameter.ts +21 -9
- package/src/application/transform/document/parameters.ts +13 -58
- package/src/application/transform/document/path-item.ts +13 -31
- package/src/application/transform/document/paths-enum.ts +1 -1
- package/src/application/transform/document/paths.ts +8 -4
- package/src/application/transform/document/referenced-parameter.ts +146 -0
- package/src/application/transform/document/request-body.ts +2 -2
- package/src/application/transform/document/response.ts +3 -3
- package/src/application/transform/document/responses.ts +2 -2
- package/src/application/transform/document/root-type-aliases.ts +17 -38
- package/src/application/transform/document/type-resolution.ts +2 -1
- package/src/application/transform/document/webhooks.ts +2 -2
- package/src/application/transform/footer/document-footer.ts +18 -1
- package/src/application/transform/footer/enum-name-claims.ts +62 -0
- package/src/application/transform/footer/operation-keys.ts +28 -0
- package/src/application/transform/footer/type-evaluation.ts +4 -4
- package/src/application/transform/helper-types.ts +6 -5
- package/src/application/transform/numbered-names.ts +15 -0
- package/src/application/transform/ref-pointer/generated-location.ts +2 -2
- package/src/application/transform/ref-pointer/pointer-type.ts +2 -4
- package/src/application/transform/ref-type.ts +2 -1
- package/src/application/transform/schema/access-flags.ts +2 -2
- package/src/application/transform/schema/array-type.ts +3 -5
- package/src/application/transform/schema/composition-type.ts +6 -6
- package/src/application/transform/schema/enum-rule.ts +10 -8
- package/src/application/transform/schema/object-type.ts +4 -4
- package/src/application/transform/schema/presence-members.ts +2 -2
- package/src/application/transform/schema/ref-siblings.ts +76 -0
- package/src/application/transform/schema/required-variants.ts +3 -3
- package/src/application/transform/schema/schema-context.ts +3 -0
- package/src/application/transform/schema/schema-transform.ts +4 -2
- package/src/application/transform/schema/unevaluated-properties.ts +2 -2
- package/src/application/transform/schema-comment.ts +7 -3
- package/src/application/transform/transform-context.ts +5 -0
- package/src/cli/api-settings.ts +82 -7
- package/src/cli/api-writes.ts +117 -0
- package/src/cli/cli-dependencies.ts +21 -4
- package/src/cli/cli-errors.ts +20 -1
- package/src/cli/cli-output.ts +186 -7
- package/src/cli/main.ts +6 -3
- package/src/cli/redocly-apis.ts +153 -48
- package/src/cli/run-cli.ts +37 -8
- package/src/domain/append-all.ts +10 -0
- package/src/domain/cause-secrets.ts +52 -0
- package/src/domain/deprecations.ts +15 -0
- package/src/domain/errors.ts +22 -7
- package/src/domain/ir/identifier-text.ts +6 -5
- package/src/domain/ir/ir-shape.ts +299 -0
- package/src/domain/ir/newer-identifier-ranges.ts +183 -30
- package/src/domain/openapi/alias-expansion.ts +4 -1
- package/src/domain/openapi/discriminated-union.ts +6 -4
- package/src/domain/openapi/discriminator-conflicts.ts +21 -7
- package/src/domain/openapi/document-object.ts +2 -0
- package/src/domain/openapi/json-pointer.ts +96 -7
- package/src/domain/openapi/schema-dialect.ts +22 -0
- package/src/domain/openapi/unsupported-features.ts +2 -2
- package/src/domain/output-fixes.ts +37 -18
- package/src/domain/url-secrets.ts +72 -0
- package/src/domain/warnings.ts +0 -1
- package/src/index.ts +2 -6
- package/src/types/generator-options.ts +1 -1
- package/dist/cli/main.d.cts +0 -2
- package/dist/cli/main.d.mts +0 -2
- package/dist/cli/main.d.ts +0 -2
- package/dist/domain/url-credentials.cjs +0 -10
- package/dist/domain/url-credentials.cjs.map +0 -1
- package/dist/domain/url-credentials.mjs +0 -8
- package/dist/domain/url-credentials.mjs.map +0 -1
- package/src/domain/url-credentials.ts +0 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pointer-type.mjs","sources":["../../../../src/application/transform/ref-pointer/pointer-type.ts"],"sourcesContent":["import { irReference } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"pointer-type.mjs","sources":["../../../../src/application/transform/ref-pointer/pointer-type.ts"],"sourcesContent":["import { irReference } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { InvalidRefError, refType } from \"../ref-type.js\";\nimport type { SchemaRequest } from \"../schema/schema-rule.js\";\nimport { generatedLocationOf } from \"./generated-location.js\";\nimport { isJsonObject } from \"./generated-shape.js\";\nimport { hasInlineCycle } from \"./inline-cycles.js\";\nimport { originalIndexFails } from \"./original-index.js\";\nimport { leadingSegmentsOf, pointerNode, type RefPointer, refPointerOf } from \"./pointer-walk.js\";\nimport { typedWalk } from \"./typed-walk.js\";\n\n/**\n * The type of a schema `$ref` (ADR-026). The original indexed every segment of the pointer by\n * name (`refType`), also schema keywords the generated types do not have (`[\"schema\"]`,\n * `[\"items\"]`, `[\"allOf\"][\"0\"]`), and did not look through optional or nullable values. Where that\n * type does not compile, the `$ref` now gets the type of what it points at; where it compiles\n * (through an index signature), it stays, and the `ref-pointers` fix gives the right type there.\n */\n\nfunction pointerOf(ref: string): RefPointer {\n const pointer = refPointerOf(ref);\n if (pointer === null) {\n throw new InvalidRefError(ref);\n }\n return pointer;\n}\n\n/** The target of a pointer that crosses a segment with no type: its `$ref`, or its own type. */\nfunction targetType(\n ref: string,\n pointer: RefPointer,\n request: SchemaRequest,\n seen: readonly string[],\n) {\n const target = pointerNode(pointer, request.context.refs);\n if (isJsonObject(target) && typeof target.$ref === \"string\") {\n return seen.includes(target.$ref) ? null : schemaRefType(target.$ref, request, [...seen, ref]);\n }\n if (target === undefined || hasInlineCycle(ref, request.context.options, request.context.refs)) {\n return null;\n }\n // Typed where the generator types the node, so it shares the node's enum (`--enum`).\n const location = generatedLocationOf(ref, request.context.refs);\n return request.transformNested(\n target as never,\n { path: location.path, schema: target },\n location.isFromAdditionalProperties,\n );\n}\n\nfunction correctedType(\n ref: string,\n pointer: RefPointer,\n request: SchemaRequest,\n seen: readonly string[],\n) {\n const { options, refs } = request.context;\n const result = typedWalk({ pointer, options, refs });\n return result.kind === \"typed\" ? result.walk.type : targetType(ref, pointer, request, seen);\n}\n\nfunction isCorrected(pointer: RefPointer, request: SchemaRequest): boolean {\n const { options, refs } = request.context;\n return options.fixes.has(FIX.REF_POINTERS) || originalIndexFails({ pointer, options, refs });\n}\n\n/** The type of a schema `$ref`. Throws InvalidRefError when the `$ref` has no pointer. */\nexport function schemaRefType(\n ref: string,\n request: SchemaRequest,\n seen: readonly string[] = [],\n): IrType {\n const pointer = pointerOf(ref);\n if (pointer.segments.length <= leadingSegmentsOf(pointer) || !isCorrected(pointer, request)) {\n return refType(ref);\n }\n return correctedType(ref, pointer, request, seen) ?? refType(ref);\n}\n\n/**\n * The type of a `$ref` that `WithRequired` takes. A `$ref` to an optional or nullable value has\n * no keys (`keyof (T | undefined)` is `never`), so it is wrapped in `NonNullable` (TS2344).\n */\nexport function requirableRefType(ref: string, type: IrType, request: SchemaRequest): IrType {\n const { options, refs } = request.context;\n const result = typedWalk({ pointer: pointerOf(ref), options, refs });\n const isAbsent = result.kind === \"typed\" && result.walk.presence === \"absent\";\n return isAbsent ? irReference(\"NonNullable\", [type]) : type;\n}\n"],"names":[],"mappings":";;;;;;;;;;AAoBA,SAAS,UAAU,GAAA,EAAyB;AAC1C,EAAA,MAAM,OAAA,GAAU,aAAa,GAAG,CAAA;AAChC,EAAA,IAAI,YAAY,IAAA,EAAM;AACpB,IAAA,MAAM,IAAI,gBAAgB,GAAG,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,OAAA;AACT;AAGA,SAAS,UAAA,CACP,GAAA,EACA,OAAA,EACA,OAAA,EACA,IAAA,EACA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AAA,EAAK,GAAI,OAAA,CAAQ,OAAA;AAClC,EAAA,OAAO,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAI,GAAA,CAAI,YAAY,CAAA,IAAK,kBAAA,CAAmB,EAAE,OAAA,EAAS,OAAA,EAAS,IAAA,EAAM,CAAA;AAC7F;AAGO,SAAS,aAAA,CACd,GAAA,EACA,OAAA,EACA,IAAA,GAA0B,EAAC,EACnB;AACR,EAAA,MAAM,OAAA,GAAU,UAAU,GAAG,CAAA;AAC7B,EAAA,IAAI,OAAA,CAAQ,QAAA,CAAS,MAAA,IAAU,iBAAA,CAAkB,OAAO,KAAK,CAAC,WAAA,CAAY,OAAA,EAAS,OAAO,CAAA,EAAG;AAC3F,IAAA,OAAO,QAAQ,GAAG,CAAA;AAAA,EACpB;AACA,EAAA,OAAO,cAAc,GAAA,EAAK,OAAA,EAAS,SAAS,IAAI,CAAA,IAAK,QAAQ,GAAG,CAAA;AAClE;AAMO,SAAS,iBAAA,CAAkB,GAAA,EAAa,IAAA,EAAc,OAAA,EAAgC;AAC3F,EAAA,MAAM,EAAE,OAAA,EAAS,IAAA,EAAK,GAAI,OAAA,CAAQ,OAAA;AAClC,EAAA,MAAM,MAAA,GAAS,UAAU,EAAE,OAAA,EAAS,UAAU,GAAG,CAAA,EAAG,OAAA,EAAS,IAAA,EAAM,CAAA;AACnE,EAAA,MAAM,WAAW,MAAA,CAAO,IAAA,KAAS,OAAA,IAAW,MAAA,CAAO,KAAK,QAAA,KAAa,QAAA;AACrE,EAAA,OAAO,WAAW,WAAA,CAAY,aAAA,EAAe,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzD;;"}
|
|
@@ -31,7 +31,8 @@ function indexKeyword(type, segment, isLast) {
|
|
|
31
31
|
return segment === DEFS_KEYWORD && !isLast ? constructors.irReference("NonNullable", [indexed]) : indexed;
|
|
32
32
|
}
|
|
33
33
|
function rootType(rootSegment, isDeep) {
|
|
34
|
-
|
|
34
|
+
const root = constructors.irReference(rootSegment);
|
|
35
|
+
return isDeep ? constructors.irReference("FlattenedDeepRequired", [root]) : root;
|
|
35
36
|
}
|
|
36
37
|
function refType(ref, options = {}) {
|
|
37
38
|
const [rootSegment, ...pointer] = jsonPointer.parseRefPointer(ref);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref-type.cjs","sources":["../../../src/application/transform/ref-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport {\n irIndexedAccess,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n irString,\n} from \"../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../domain/openapi/json-pointer.js\";\n\n/** Where a referenced parameter lives in the generated `parameters` type. */\nexport interface RefParameterTarget {\n readonly in: string;\n readonly name: string;\n}\n\nexport interface RefTypeOptions {\n /** Wrap the root in `FlattenedDeepRequired<…>`. */\n readonly isDeep?: boolean;\n /** Segments to narrow with `Extract<T, { segment: unknown }>` before indexing. */\n readonly extractProperties?: readonly string[];\n /** Set when the `$ref` resolves to a parameter object: its last segment indexes `in`, `name`. */\n readonly parameter?: RefParameterTarget | null;\n}\n\nexport class InvalidRefError extends OpenAPITypesafeError {\n constructor(ref: string) {\n super({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: `Error parsing $ref: ${ref}. Is this a valid $ref?`,\n details: { ref },\n });\n this.name = \"InvalidRefError\";\n }\n}\n\n/** Segments that index into the root type, always as escaped string literal types. */\nexport function indexBy(type: IrType, ...segments: readonly string[]): IrType {\n return segments.reduce<IrType>(\n (object, segment) => irIndexedAccess(object, irString(segment, \"escaped\")),\n type,\n );\n}\n\n/**\n * `Extract<T, { name: unknown }>`. The original wrote the name as an identifier even when it is\n * not one (`{ content-type: unknown }`), which is a syntax error; it is now quoted like any other\n * property name, and an identifier stays as it was.\n */\nexport function extractVariantsWith(type: IrType, propertyName: string): IrType {\n const probe = irProperty(toPropertyName(propertyName), irKeyword(\"unknown\"));\n return irReference(\"Extract\", [type, irObject([probe])]);\n}\n\nconst DEFS_KEYWORD = \"$defs\";\n\n/**\n * Index by `segment`. A `$defs` member is optional (it is a keyword, not data), so when more\n * segments follow it is wrapped in `NonNullable<…>` first; otherwise the next index fails on\n * `undefined` (upstream #2664).\n */\nexport function indexKeyword(type: IrType, segment: string, isLast: boolean): IrType {\n const indexed = indexBy(type, segment);\n return segment === DEFS_KEYWORD && !isLast ? irReference(\"NonNullable\", [indexed]) : indexed;\n}\n\nexport function rootType(rootSegment: string, isDeep: boolean): IrType {\n
|
|
1
|
+
{"version":3,"file":"ref-type.cjs","sources":["../../../src/application/transform/ref-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport {\n irIndexedAccess,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n irString,\n} from \"../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../domain/openapi/json-pointer.js\";\n\n/** Where a referenced parameter lives in the generated `parameters` type. */\nexport interface RefParameterTarget {\n readonly in: string;\n readonly name: string;\n}\n\nexport interface RefTypeOptions {\n /** Wrap the root in `FlattenedDeepRequired<…>`. */\n readonly isDeep?: boolean;\n /** Segments to narrow with `Extract<T, { segment: unknown }>` before indexing. */\n readonly extractProperties?: readonly string[];\n /** Set when the `$ref` resolves to a parameter object: its last segment indexes `in`, `name`. */\n readonly parameter?: RefParameterTarget | null;\n}\n\nexport class InvalidRefError extends OpenAPITypesafeError {\n constructor(ref: string) {\n super({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: `Error parsing $ref: ${ref}. Is this a valid $ref?`,\n details: { ref },\n });\n this.name = \"InvalidRefError\";\n }\n}\n\n/** Segments that index into the root type, always as escaped string literal types. */\nexport function indexBy(type: IrType, ...segments: readonly string[]): IrType {\n return segments.reduce<IrType>(\n (object, segment) => irIndexedAccess(object, irString(segment, \"escaped\")),\n type,\n );\n}\n\n/**\n * `Extract<T, { name: unknown }>`. The original wrote the name as an identifier even when it is\n * not one (`{ content-type: unknown }`), which is a syntax error; it is now quoted like any other\n * property name, and an identifier stays as it was.\n */\nexport function extractVariantsWith(type: IrType, propertyName: string): IrType {\n const probe = irProperty(toPropertyName(propertyName), irKeyword(\"unknown\"));\n return irReference(\"Extract\", [type, irObject([probe])]);\n}\n\nconst DEFS_KEYWORD = \"$defs\";\n\n/**\n * Index by `segment`. A `$defs` member is optional (it is a keyword, not data), so when more\n * segments follow it is wrapped in `NonNullable<…>` first; otherwise the next index fails on\n * `undefined` (upstream #2664).\n */\nexport function indexKeyword(type: IrType, segment: string, isLast: boolean): IrType {\n const indexed = indexBy(type, segment);\n return segment === DEFS_KEYWORD && !isLast ? irReference(\"NonNullable\", [indexed]) : indexed;\n}\n\nexport function rootType(rootSegment: string, isDeep: boolean): IrType {\n const root = irReference(rootSegment);\n return isDeep ? irReference(\"FlattenedDeepRequired\", [root]) : root;\n}\n\n/**\n * The indexed-access type of a `$ref` into the generated types (the original `oapiRef`), for\n * example `components[\"schemas\"][\"Foo\"]`. The first three segments index directly. After them,\n * `properties` segments are skipped (objects are flattened, upstream issue 1742), a parameter's\n * last segment becomes `[in][name]`, and listed segments are narrowed with `Extract` first.\n *\n * Throws InvalidRefError when the `$ref` has no pointer.\n */\nexport function refType(ref: string, options: RefTypeOptions = {}): IrType {\n const [rootSegment, ...pointer] = parseRefPointer(ref);\n if (rootSegment === undefined) {\n throw new InvalidRefError(ref);\n }\n const extracted = new Set(options.extractProperties ?? []);\n const lastIndex = pointer.length - 1;\n const leading = indexBy(rootType(rootSegment, options.isDeep ?? false), ...pointer.slice(0, 2));\n return pointer.slice(2).reduce<IrType>((type, segment, offset) => {\n if (segment === \"properties\") {\n return type;\n }\n if (options.parameter && offset + 2 === lastIndex) {\n return indexBy(type, options.parameter.in, options.parameter.name);\n }\n const isLast = offset + 2 === lastIndex;\n return extracted.has(segment)\n ? indexBy(extractVariantsWith(type, segment), segment)\n : indexKeyword(type, segment, isLast);\n }, leading);\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","irIndexedAccess","irString","propertyName","irProperty","toPropertyName","irKeyword","irReference","irObject","parseRefPointer"],"mappings":";;;;;;;AA4BO,MAAM,wBAAwBA,2BAAA,CAAqB;AAAA,EACxD,YAAY,GAAA,EAAa;AACvB,IAAA,KAAA,CAAM;AAAA,MACJ,MAAMC,kBAAA,CAAY,kBAAA;AAAA,MAClB,OAAA,EAAS,uBAAuB,GAAG,CAAA,uBAAA,CAAA;AAAA,MACnC,OAAA,EAAS,EAAE,GAAA;AAAI,KAChB,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AAAA,EACd;AACF;AAGO,SAAS,OAAA,CAAQ,SAAiB,QAAA,EAAqC;AAC5E,EAAA,OAAO,QAAA,CAAS,MAAA;AAAA,IACd,CAAC,QAAQ,OAAA,KAAYC,4BAAA,CAAgB,QAAQC,qBAAA,CAAS,OAAA,EAAS,SAAS,CAAC,CAAA;AAAA,IACzE;AAAA,GACF;AACF;AAOO,SAAS,mBAAA,CAAoB,MAAcC,cAAA,EAA8B;AAC9E,EAAA,MAAM,QAAQC,uBAAA,CAAWC,2BAAA,CAAeF,cAAY,CAAA,EAAGG,sBAAA,CAAU,SAAS,CAAC,CAAA;AAC3E,EAAA,OAAOC,wBAAA,CAAY,WAAW,CAAC,IAAA,EAAMC,sBAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACzD;AAEA,MAAM,YAAA,GAAe,OAAA;AAOd,SAAS,YAAA,CAAa,IAAA,EAAc,OAAA,EAAiB,MAAA,EAAyB;AACnF,EAAA,MAAM,OAAA,GAAU,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAA;AACrC,EAAA,OAAO,OAAA,KAAY,gBAAgB,CAAC,MAAA,GAASD,yBAAY,aA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AU,GAAA,CAAI,OAAO,CAAA,GACxB,QAAQ,mBAAA,CAAoB,IAAA,EAAM,OAAO,CAAA,EAAG,OAAO,CAAA,GACnD,YAAA,CAAa,IAAA,EAAM,SAAS,MAAM,CAAA;AAAA,EACxC,GAAG,OAAO,CAAA;AACZ;;;;;;;"}
|
|
@@ -29,7 +29,8 @@ function indexKeyword(type, segment, isLast) {
|
|
|
29
29
|
return segment === DEFS_KEYWORD && !isLast ? irReference("NonNullable", [indexed]) : indexed;
|
|
30
30
|
}
|
|
31
31
|
function rootType(rootSegment, isDeep) {
|
|
32
|
-
|
|
32
|
+
const root = irReference(rootSegment);
|
|
33
|
+
return isDeep ? irReference("FlattenedDeepRequired", [root]) : root;
|
|
33
34
|
}
|
|
34
35
|
function refType(ref, options = {}) {
|
|
35
36
|
const [rootSegment, ...pointer] = parseRefPointer(ref);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref-type.mjs","sources":["../../../src/application/transform/ref-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport {\n irIndexedAccess,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n irString,\n} from \"../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../domain/openapi/json-pointer.js\";\n\n/** Where a referenced parameter lives in the generated `parameters` type. */\nexport interface RefParameterTarget {\n readonly in: string;\n readonly name: string;\n}\n\nexport interface RefTypeOptions {\n /** Wrap the root in `FlattenedDeepRequired<…>`. */\n readonly isDeep?: boolean;\n /** Segments to narrow with `Extract<T, { segment: unknown }>` before indexing. */\n readonly extractProperties?: readonly string[];\n /** Set when the `$ref` resolves to a parameter object: its last segment indexes `in`, `name`. */\n readonly parameter?: RefParameterTarget | null;\n}\n\nexport class InvalidRefError extends OpenAPITypesafeError {\n constructor(ref: string) {\n super({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: `Error parsing $ref: ${ref}. Is this a valid $ref?`,\n details: { ref },\n });\n this.name = \"InvalidRefError\";\n }\n}\n\n/** Segments that index into the root type, always as escaped string literal types. */\nexport function indexBy(type: IrType, ...segments: readonly string[]): IrType {\n return segments.reduce<IrType>(\n (object, segment) => irIndexedAccess(object, irString(segment, \"escaped\")),\n type,\n );\n}\n\n/**\n * `Extract<T, { name: unknown }>`. The original wrote the name as an identifier even when it is\n * not one (`{ content-type: unknown }`), which is a syntax error; it is now quoted like any other\n * property name, and an identifier stays as it was.\n */\nexport function extractVariantsWith(type: IrType, propertyName: string): IrType {\n const probe = irProperty(toPropertyName(propertyName), irKeyword(\"unknown\"));\n return irReference(\"Extract\", [type, irObject([probe])]);\n}\n\nconst DEFS_KEYWORD = \"$defs\";\n\n/**\n * Index by `segment`. A `$defs` member is optional (it is a keyword, not data), so when more\n * segments follow it is wrapped in `NonNullable<…>` first; otherwise the next index fails on\n * `undefined` (upstream #2664).\n */\nexport function indexKeyword(type: IrType, segment: string, isLast: boolean): IrType {\n const indexed = indexBy(type, segment);\n return segment === DEFS_KEYWORD && !isLast ? irReference(\"NonNullable\", [indexed]) : indexed;\n}\n\nexport function rootType(rootSegment: string, isDeep: boolean): IrType {\n
|
|
1
|
+
{"version":3,"file":"ref-type.mjs","sources":["../../../src/application/transform/ref-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport {\n irIndexedAccess,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n irString,\n} from \"../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../domain/openapi/json-pointer.js\";\n\n/** Where a referenced parameter lives in the generated `parameters` type. */\nexport interface RefParameterTarget {\n readonly in: string;\n readonly name: string;\n}\n\nexport interface RefTypeOptions {\n /** Wrap the root in `FlattenedDeepRequired<…>`. */\n readonly isDeep?: boolean;\n /** Segments to narrow with `Extract<T, { segment: unknown }>` before indexing. */\n readonly extractProperties?: readonly string[];\n /** Set when the `$ref` resolves to a parameter object: its last segment indexes `in`, `name`. */\n readonly parameter?: RefParameterTarget | null;\n}\n\nexport class InvalidRefError extends OpenAPITypesafeError {\n constructor(ref: string) {\n super({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: `Error parsing $ref: ${ref}. Is this a valid $ref?`,\n details: { ref },\n });\n this.name = \"InvalidRefError\";\n }\n}\n\n/** Segments that index into the root type, always as escaped string literal types. */\nexport function indexBy(type: IrType, ...segments: readonly string[]): IrType {\n return segments.reduce<IrType>(\n (object, segment) => irIndexedAccess(object, irString(segment, \"escaped\")),\n type,\n );\n}\n\n/**\n * `Extract<T, { name: unknown }>`. The original wrote the name as an identifier even when it is\n * not one (`{ content-type: unknown }`), which is a syntax error; it is now quoted like any other\n * property name, and an identifier stays as it was.\n */\nexport function extractVariantsWith(type: IrType, propertyName: string): IrType {\n const probe = irProperty(toPropertyName(propertyName), irKeyword(\"unknown\"));\n return irReference(\"Extract\", [type, irObject([probe])]);\n}\n\nconst DEFS_KEYWORD = \"$defs\";\n\n/**\n * Index by `segment`. A `$defs` member is optional (it is a keyword, not data), so when more\n * segments follow it is wrapped in `NonNullable<…>` first; otherwise the next index fails on\n * `undefined` (upstream #2664).\n */\nexport function indexKeyword(type: IrType, segment: string, isLast: boolean): IrType {\n const indexed = indexBy(type, segment);\n return segment === DEFS_KEYWORD && !isLast ? irReference(\"NonNullable\", [indexed]) : indexed;\n}\n\nexport function rootType(rootSegment: string, isDeep: boolean): IrType {\n const root = irReference(rootSegment);\n return isDeep ? irReference(\"FlattenedDeepRequired\", [root]) : root;\n}\n\n/**\n * The indexed-access type of a `$ref` into the generated types (the original `oapiRef`), for\n * example `components[\"schemas\"][\"Foo\"]`. The first three segments index directly. After them,\n * `properties` segments are skipped (objects are flattened, upstream issue 1742), a parameter's\n * last segment becomes `[in][name]`, and listed segments are narrowed with `Extract` first.\n *\n * Throws InvalidRefError when the `$ref` has no pointer.\n */\nexport function refType(ref: string, options: RefTypeOptions = {}): IrType {\n const [rootSegment, ...pointer] = parseRefPointer(ref);\n if (rootSegment === undefined) {\n throw new InvalidRefError(ref);\n }\n const extracted = new Set(options.extractProperties ?? []);\n const lastIndex = pointer.length - 1;\n const leading = indexBy(rootType(rootSegment, options.isDeep ?? false), ...pointer.slice(0, 2));\n return pointer.slice(2).reduce<IrType>((type, segment, offset) => {\n if (segment === \"properties\") {\n return type;\n }\n if (options.parameter && offset + 2 === lastIndex) {\n return indexBy(type, options.parameter.in, options.parameter.name);\n }\n const isLast = offset + 2 === lastIndex;\n return extracted.has(segment)\n ? indexBy(extractVariantsWith(type, segment), segment)\n : indexKeyword(type, segment, isLast);\n }, leading);\n}\n"],"names":[],"mappings":";;;;;AA4BO,MAAM,wBAAwB,oBAAA,CAAqB;AAAA,EACxD,YAAY,GAAA,EAAa;AACvB,IAAA,KAAA,CAAM;AAAA,MACJ,MAAM,WAAA,CAAY,kBAAA;AAAA,MAClB,OAAA,EAAS,uBAAuB,GAAG,CAAA,uBAAA,CAAA;AAAA,MACnC,OAAA,EAAS,EAAE,GAAA;AAAI,KAChB,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AAAA,EACd;AACF;AAGO,SAAS,OAAA,CAAQ,SAAiB,QAAA,EAAqC;AAC5E,EAAA,OAAO,QAAA,CAAS,MAAA;AAAA,IACd,CAAC,QAAQ,OAAA,KAAY,eAAA,CAAgB,QAAQ,QAAA,CAAS,OAAA,EAAS,SAAS,CAAC,CAAA;AAAA,IACzE;AAAA,GACF;AACF;AAOO,SAAS,mBAAA,CAAoB,MAAc,YAAA,EAA8B;AAC9E,EAAA,MAAM,QAAQ,UAAA,CAAW,cAAA,CAAe,YAAY,CAAA,EAAG,SAAA,CAAU,SAAS,CAAC,CAAA;AAC3E,EAAA,OAAO,WAAA,CAAY,WAAW,CAAC,IAAA,EAAM,SAAS,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A,IAAI,OAAA,CAAQ,SAAA,IAAa,MAAA,GAAS,CAAA,KAAM,SAAA,EAAW;AACjD,MAAA,OAAO,QAAQ,IAAA,EAAM,OAAA,CAAQ,UAAU,EAAA,EAAI,OAAA,CAAQ,UAAU,IAAI,CAAA;AAAA,IACnE;AACA,IAAA,MAAM,MAAA,GAAS,SAAS,CAAA,KAAM,SAAA;AAC9B,IAAA,OAAO,SAAA,CAAU,GAAA,CAAI,OAAO,CAAA,GACxB,QAAQ,mBAAA,CAAoB,IAAA,EAAM,OAAO,CAAA,EAAG,OAAO,CAAA,GACnD,YAAA,CAAa,IAAA,EAAM,SAAS,MAAM,CAAA;AAAA,EACxC,GAAG,OAAO,CAAA;AACZ;;"}
|
|
@@ -28,7 +28,7 @@ function propertyAccessFlags(value, context) {
|
|
|
28
28
|
if (typeof value !== "object") {
|
|
29
29
|
return NO_FLAGS;
|
|
30
30
|
}
|
|
31
|
-
if (!context.options.fixes.has(outputFixes.
|
|
31
|
+
if (!context.options.fixes.has(outputFixes.FIX.READ_WRITE_REFS)) {
|
|
32
32
|
return ownFlags(value);
|
|
33
33
|
}
|
|
34
34
|
return appliedFlags(value, context, /* @__PURE__ */ new Set());
|
|
@@ -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 {
|
|
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,\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(value: Schema, context: SchemaContext): 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,QAAA,GAAwB,EAAE,UAAA,EAAY,KAAA,EAAO,aAAa,KAAA,EAAM;AAEtE,SAAS,SAAS,M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I,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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
2
2
|
|
|
3
3
|
const NO_FLAGS = { isReadOnly: false, isWriteOnly: false };
|
|
4
4
|
function ownFlags(schema) {
|
|
@@ -26,7 +26,7 @@ function propertyAccessFlags(value, context) {
|
|
|
26
26
|
if (typeof value !== "object") {
|
|
27
27
|
return NO_FLAGS;
|
|
28
28
|
}
|
|
29
|
-
if (!context.options.fixes.has(
|
|
29
|
+
if (!context.options.fixes.has(FIX.READ_WRITE_REFS)) {
|
|
30
30
|
return ownFlags(value);
|
|
31
31
|
}
|
|
32
32
|
return appliedFlags(value, context, /* @__PURE__ */ new Set());
|
|
@@ -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 {
|
|
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,\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(value: Schema, context: SchemaContext): 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,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G;AACnD,IAAA,OAAO,SAAS,KAAqB,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,YAAA,CAAa,KAAA,EAAO,OAAA,kBAAS,IAAI,KAAK,CAAA;AAC/C;;"}
|
|
@@ -45,7 +45,7 @@ function prefixItemsTupleType(prefixItems, schema, request) {
|
|
|
45
45
|
return constructors.irTuple(rest === null ? elements : [...elements, constructors.irTupleElement(constructors.irArray(rest), true)]);
|
|
46
46
|
}
|
|
47
47
|
function isPrefixItemsFixed(schema, request) {
|
|
48
|
-
return schema.prefixItems !== void 0 && request.context.options.fixes.has(outputFixes.
|
|
48
|
+
return schema.prefixItems !== void 0 && request.context.options.fixes.has(outputFixes.FIX.PREFIX_ITEMS);
|
|
49
49
|
}
|
|
50
50
|
function singleItemType(schema, request) {
|
|
51
51
|
const { items } = schema;
|
|
@@ -117,7 +117,7 @@ function fixedArrayType(schema, request) {
|
|
|
117
117
|
}
|
|
118
118
|
function isArrayLengthFixed(request) {
|
|
119
119
|
const { arrayLength, fixes } = request.context.options;
|
|
120
|
-
return arrayLength && fixes.has(outputFixes.
|
|
120
|
+
return arrayLength && fixes.has(outputFixes.FIX.ARRAY_LENGTH_TUPLES);
|
|
121
121
|
}
|
|
122
122
|
function arrayType(schema, request) {
|
|
123
123
|
if (isArrayLengthFixed(request)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-type.cjs","sources":["../../../../src/application/transform/schema/array-type.ts"],"sourcesContent":["import {\n irArray,\n irOptionalTupleElement,\n irReadonly,\n irTuple,\n irTupleElement,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrTupleElement, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `--array-length` writes tuples only while the estimated number of tuple elements stays below\n * this; the original chose it as roughly where TypeScript starts to struggle with tuple inference.\n */\nconst MAX_LENGTH_TUPLE_ELEMENTS = 30;\n\n/**\n * The tuple of `prefixItems` (or of an `items` list); null without either. The original closes a\n * `prefixItems` tuple and requires every element; the `prefix-items` fix does not.\n */\nfunction prefixTupleType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items } = schema;\n if (schema.prefixItems && isPrefixItemsFixed(schema, request)) {\n return prefixItemsTupleType(schema.prefixItems, schema, request);\n }\n if (!schema.prefixItems && !Array.isArray(items)) {\n return null;\n }\n const prefixItems = schema.prefixItems ?? (items as SchemaObject[]);\n return irTuple(\n prefixItems.map((item) => irTupleElement(request.transformNested(item, request.location))),\n );\n}\n\n/** The type of the items after the prefix, or null when there may be none (`false`). */\nfunction restItemType(schema: Schema, request: SchemaRequest): IrType | null {\n return schema === false ? null : request.transformNested(schema, request.location);\n}\n\n/**\n * The type of the items after a `prefixItems` tuple (JSON Schema 2020-12 §10.3.1): `items`, else\n * `unevaluatedItems`, which does not apply to the items `contains` matches, else any item. Null\n * when no item may follow. An `items` list is not a schema in 2020-12, so it allows any item.\n */\nfunction prefixRestType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items, unevaluatedItems, contains } = schema;\n if (items !== undefined && !Array.isArray(items)) {\n return restItemType(items as Schema, request);\n }\n if (unevaluatedItems === undefined || items !== undefined) {\n return UNKNOWN_TYPE;\n }\n const unevaluated = restItemType(unevaluatedItems, request);\n const matched = contains === undefined ? null : restItemType(contains, request);\n const types = [unevaluated, matched].filter((type): type is IrType => type !== null);\n return types.length === 0 ? null : unionOf(types);\n}\n\n/**\n * The `prefix-items` tuple of `prefixItems`: an array may end before the prefix does, so the\n * elements from `minItems` on are optional (`T?`), and a rest element types the items after it.\n */\nfunction prefixItemsTupleType(\n prefixItems: readonly Schema[],\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType {\n const { min } = lengthBounds(schema);\n const elements = prefixItems.map((item, index): IrTupleElement => {\n const type = request.transformNested(item, request.location);\n return index < min ? irTupleElement(type) : irOptionalTupleElement(type);\n });\n const rest = prefixRestType(schema, request);\n return irTuple(rest === null ? elements : [...elements, irTupleElement(irArray(rest), true)]);\n}\n\nfunction isPrefixItemsFixed(schema: SchemaObject, request: SchemaRequest): boolean {\n return (\n schema.prefixItems !== undefined && request.context.options.fixes.has(OutputFix.PREFIX_ITEMS)\n );\n}\n\n/** The type of one item; `unknown` without `items`. */\nfunction singleItemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { items } = schema;\n return items ? request.transformNested(items as SchemaObject, request.location) : UNKNOWN_TYPE;\n}\n\n/**\n * The item type as the original returns it: a tuple stands for the whole array, and a nested\n * `type: array` item is wrapped in an array here already.\n */\nfunction itemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return tuple;\n }\n const { items } = schema;\n // Checked first: the `in` test below throws for `items: null`.\n if (!items) {\n return UNKNOWN_TYPE;\n }\n const nested = singleItemType(schema, request);\n const isNestedArray = typeof items === \"object\" && \"type\" in items && items.type === \"array\";\n return isNestedArray ? irArray(nested) : nested;\n}\n\nfunction repeat(type: IrType, count: number): IrType[] {\n return Array.from({ length: count }, () => type);\n}\n\ninterface LengthBounds {\n readonly min: number;\n readonly max: number | undefined;\n}\n\nfunction lengthBounds(schema: SchemaObject): LengthBounds {\n const { minItems, maxItems } = schema;\n const min = typeof minItems === \"number\" && minItems >= 0 ? minItems : 0;\n const isMaxValid = typeof maxItems === \"number\" && maxItems >= 0 && min <= maxItems;\n return { min, max: isMaxValid ? maxItems : undefined };\n}\n\n/**\n * Tuples for `--array-length`, as the original builds them. With both bounds it emits tuples of\n * length 0 to `max - min` (not `min` to `max`); the `array-length-tuples` fix corrects it.\n */\nfunction lengthTupleType(schema: SchemaObject, item: IrType, bounds: LengthBounds): IrType {\n const { min, max } = bounds;\n if (min === max) {\n return unionOf([irTuple(repeat(item, min).map((type) => irTupleElement(type)))]);\n }\n if ((schema.maxItems as number) > 0) {\n const lengths = Array.from({ length: Math.max(0, (max ?? 0) - min + 1) }, (_, index) => index);\n return unionOf(\n lengths.map((length) => irTuple(repeat(item, length).map((type) => irTupleElement(type)))),\n );\n }\n const elements = repeat(item, min).map((type) => irTupleElement(type));\n return irTuple([...elements, irTupleElement(irArray(item), true)]);\n}\n\nfunction isLengthTupleWanted(bounds: LengthBounds, request: SchemaRequest): boolean {\n const { min, max } = bounds;\n const estimatedSize = max === undefined ? min : (max * (max + 1) - min * (min - 1)) / 2;\n const hasBounds = min !== 0 || max !== undefined;\n return (\n request.context.options.arrayLength && hasBounds && estimatedSize < MAX_LENGTH_TUPLE_ELEMENTS\n );\n}\n\n/** Applies `--immutable` to one array or tuple type. */\ntype ArrayWrapper = (type: IrType) => IrType;\n\nfunction tupleOf(item: IrType, length: number, isOpen: boolean): IrType {\n const elements = repeat(item, length).map((type) => irTupleElement(type));\n return irTuple(isOpen ? [...elements, irTupleElement(irArray(item), true)] : elements);\n}\n\n/** Tuples of every length from `min` to `max`; without `max`, `min` items and a rest element. */\nfunction fixedLengthTupleType(item: IrType, bounds: LengthBounds, wrap: ArrayWrapper): IrType {\n const { min, max } = bounds;\n if (max === undefined) {\n return wrap(tupleOf(item, min, true));\n }\n const lengths = Array.from({ length: max - min + 1 }, (_, index) => min + index);\n return unionOf(lengths.map((length) => wrap(tupleOf(item, length, false))));\n}\n\n/**\n * `type: array` with `--array-length` and the `array-length-tuples` fix (#2048, #2330, #2546):\n * the tuples have `min` to `max` items, the item type is used as it is (a nested array stays one\n * level deep), a `prefixItems` tuple gets no length tuples around it, and `--immutable` makes\n * every tuple `readonly`.\n */\nfunction fixedArrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n const wrap: ArrayWrapper = (type) =>\n request.context.options.immutable ? irReadonly(type) : type;\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return wrap(tuple);\n }\n const item = singleItemType(schema, request);\n const bounds = lengthBounds(schema);\n return isLengthTupleWanted(bounds, request)\n ? fixedLengthTupleType(item, bounds, wrap)\n : wrap(irArray(item));\n}\n\nfunction isArrayLengthFixed(request: SchemaRequest): boolean {\n const { arrayLength, fixes } = request.context.options;\n return arrayLength && fixes.has(OutputFix.ARRAY_LENGTH_TUPLES);\n}\n\n/** `type: array`, including tuples (`prefixItems`, array `items`) and `--array-length`. */\nexport function arrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n if (isArrayLengthFixed(request)) {\n return fixedArrayType(schema, request);\n }\n const item = itemType(schema, request);\n const bounds = lengthBounds(schema);\n // A `prefix-items` tuple has its own lengths, so `--array-length` adds no tuples around it.\n if (!isPrefixItemsFixed(schema, request) && isLengthTupleWanted(bounds, request)) {\n return lengthTupleType(schema, item, bounds);\n }\n // A tuple or an array item is used as the array type itself.\n const type = item.kind === \"tuple\" || item.kind === \"array\" ? item : irArray(item);\n return request.context.options.immutable ? irReadonly(type) : type;\n}\n"],"names":["irTuple","irTupleElement","UNKNOWN_TYPE","unionOf","irOptionalTupleElement","irArray","OutputFix","irReadonly"],"mappings":";;;;;;;AAkBA,MAAM,yBAAA,GAA4B,EAAA;AAMlC,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAuC;AACpF,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,IAAI,MAAA,CAAO,WAAA,IAAe,kBAAA,CAAmB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAC7D,IAAA,OAAO,oBAAA,CAAqB,MAAA,CAAO,WAAA,EAAa,MAAA,EAAQ,OAAO,CAAA;AAAA,EACjE;AACA,EAAA,IAAI,CAAC,MAAA,CAAO,WAAA,IAAe,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAA,GAAc,OAAO,WAAA,IAAgB,KAAA;AAC3C,EAAA,OAAOA,oBAAA;AAAA,IACL,WAAA,CAAY,GAAA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AS,mBAAmB,OAAA,EAAiC;AAC3D,EAAA,MAAM,EAAE,WAAA,EAAa,KAAA,EAAM,GAAI,QAAQ,OAAA,CAAQ,OAAA;AAC/C,EAAA,OAAO,WAAA,IAAe,KAAA,CAAM,GAAA,CAAIC,qBAAA,CAAU,mBAAmB,CAAA;AAC/D;AAGO,SAAS,SAAA,CAAU,QAAsB,OAAA,EAAgC;AAC9E,EAAA,IAAI,kBAAA,CAAmB,OAAO,CAAA,EAAG;AAC/B,IAAA,OAAO,cAAA,CAAe,QAAQ,OAAO,CAAA;AAAA,EACvC;AACA,EAAA,MAAM,IAAA,GAAO,QAAA,CAAS,MAAA,EAAQ,OAAO,CAAA;AACrC,EAAA,MAAM,MAAA,GAAS,aAAa,MAAM,CAAA;AAElC,EAAA,IAAI,CAAC,mBAAmB,MAAA,EAAQ,OAAO,KAAK,mBAAA,CAAoB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAChF,IAAA,OAAO,eAAA,CAAgB,MAAA,EAAQ,IAAA,EAAM,MAAM,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAA,GAAO,KAAK,IAAA,KAAS,OAAA,IAAW,KAAK,IAAA,KAAS,OAAA,GAAU,IAAA,GAAOD,oBAAA,CAAQ,IAAI,CAAA;AACjF,EAAA,OAAO,QAAQ,OAAA,CAAQ,OAAA,CAAQ,SAAA,GAAYE,uBAAA,CAAW,IAAI,CAAA,GAAI,IAAA;AAChE;;"}
|
|
1
|
+
{"version":3,"file":"array-type.cjs","sources":["../../../../src/application/transform/schema/array-type.ts"],"sourcesContent":["import {\n irArray,\n irOptionalTupleElement,\n irReadonly,\n irTuple,\n irTupleElement,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrTupleElement, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `--array-length` writes tuples only while the estimated number of tuple elements stays below\n * this; the original chose it as roughly where TypeScript starts to struggle with tuple inference.\n */\nconst MAX_LENGTH_TUPLE_ELEMENTS = 30;\n\n/**\n * The tuple of `prefixItems` (or of an `items` list); null without either. The original closes a\n * `prefixItems` tuple and requires every element; the `prefix-items` fix does not.\n */\nfunction prefixTupleType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items } = schema;\n if (schema.prefixItems && isPrefixItemsFixed(schema, request)) {\n return prefixItemsTupleType(schema.prefixItems, schema, request);\n }\n if (!schema.prefixItems && !Array.isArray(items)) {\n return null;\n }\n const prefixItems = schema.prefixItems ?? (items as SchemaObject[]);\n return irTuple(\n prefixItems.map((item) => irTupleElement(request.transformNested(item, request.location))),\n );\n}\n\n/** The type of the items after the prefix, or null when there may be none (`false`). */\nfunction restItemType(schema: Schema, request: SchemaRequest): IrType | null {\n return schema === false ? null : request.transformNested(schema, request.location);\n}\n\n/**\n * The type of the items after a `prefixItems` tuple (JSON Schema 2020-12 §10.3.1): `items`, else\n * `unevaluatedItems`, which does not apply to the items `contains` matches, else any item. Null\n * when no item may follow. An `items` list is not a schema in 2020-12, so it allows any item.\n */\nfunction prefixRestType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items, unevaluatedItems, contains } = schema;\n if (items !== undefined && !Array.isArray(items)) {\n return restItemType(items as Schema, request);\n }\n if (unevaluatedItems === undefined || items !== undefined) {\n return UNKNOWN_TYPE;\n }\n const unevaluated = restItemType(unevaluatedItems, request);\n const matched = contains === undefined ? null : restItemType(contains, request);\n const types = [unevaluated, matched].filter((type): type is IrType => type !== null);\n return types.length === 0 ? null : unionOf(types);\n}\n\n/**\n * The `prefix-items` tuple of `prefixItems`: an array may end before the prefix does, so the\n * elements from `minItems` on are optional (`T?`), and a rest element types the items after it.\n */\nfunction prefixItemsTupleType(\n prefixItems: readonly Schema[],\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType {\n const { min } = lengthBounds(schema);\n const elements = prefixItems.map((item, index): IrTupleElement => {\n const type = request.transformNested(item, request.location);\n return index < min ? irTupleElement(type) : irOptionalTupleElement(type);\n });\n const rest = prefixRestType(schema, request);\n return irTuple(rest === null ? elements : [...elements, irTupleElement(irArray(rest), true)]);\n}\n\nfunction isPrefixItemsFixed(schema: SchemaObject, request: SchemaRequest): boolean {\n return schema.prefixItems !== undefined && request.context.options.fixes.has(FIX.PREFIX_ITEMS);\n}\n\n/** The type of one item; `unknown` without `items`. */\nfunction singleItemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { items } = schema;\n return items ? request.transformNested(items as SchemaObject, request.location) : UNKNOWN_TYPE;\n}\n\n/**\n * The item type as the original returns it: a tuple stands for the whole array, and a nested\n * `type: array` item is wrapped in an array here already.\n */\nfunction itemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return tuple;\n }\n const { items } = schema;\n // Checked first: the `in` test below throws for `items: null`.\n if (!items) {\n return UNKNOWN_TYPE;\n }\n const nested = singleItemType(schema, request);\n const isNestedArray = typeof items === \"object\" && \"type\" in items && items.type === \"array\";\n return isNestedArray ? irArray(nested) : nested;\n}\n\nfunction repeat(type: IrType, count: number): IrType[] {\n return Array.from({ length: count }, () => type);\n}\n\ninterface LengthBounds {\n readonly min: number;\n readonly max: number | undefined;\n}\n\nfunction lengthBounds(schema: SchemaObject): LengthBounds {\n const { minItems, maxItems } = schema;\n const min = typeof minItems === \"number\" && minItems >= 0 ? minItems : 0;\n const isMaxValid = typeof maxItems === \"number\" && maxItems >= 0 && min <= maxItems;\n return { min, max: isMaxValid ? maxItems : undefined };\n}\n\n/**\n * Tuples for `--array-length`, as the original builds them. With both bounds it emits tuples of\n * length 0 to `max - min` (not `min` to `max`); the `array-length-tuples` fix corrects it.\n */\nfunction lengthTupleType(schema: SchemaObject, item: IrType, bounds: LengthBounds): IrType {\n const { min, max } = bounds;\n if (min === max) {\n return unionOf([irTuple(repeat(item, min).map((type) => irTupleElement(type)))]);\n }\n if ((schema.maxItems as number) > 0) {\n const lengths = Array.from({ length: Math.max(0, (max ?? 0) - min + 1) }, (_, index) => index);\n return unionOf(\n lengths.map((length) => irTuple(repeat(item, length).map((type) => irTupleElement(type)))),\n );\n }\n const elements = repeat(item, min).map((type) => irTupleElement(type));\n return irTuple([...elements, irTupleElement(irArray(item), true)]);\n}\n\nfunction isLengthTupleWanted(bounds: LengthBounds, request: SchemaRequest): boolean {\n const { min, max } = bounds;\n const estimatedSize = max === undefined ? min : (max * (max + 1) - min * (min - 1)) / 2;\n const hasBounds = min !== 0 || max !== undefined;\n return (\n request.context.options.arrayLength && hasBounds && estimatedSize < MAX_LENGTH_TUPLE_ELEMENTS\n );\n}\n\n/** Applies `--immutable` to one array or tuple type. */\ntype ArrayWrapper = (type: IrType) => IrType;\n\nfunction tupleOf(item: IrType, length: number, isOpen: boolean): IrType {\n const elements = repeat(item, length).map((type) => irTupleElement(type));\n return irTuple(isOpen ? [...elements, irTupleElement(irArray(item), true)] : elements);\n}\n\n/** Tuples of every length from `min` to `max`; without `max`, `min` items and a rest element. */\nfunction fixedLengthTupleType(item: IrType, bounds: LengthBounds, wrap: ArrayWrapper): IrType {\n const { min, max } = bounds;\n if (max === undefined) {\n return wrap(tupleOf(item, min, true));\n }\n const lengths = Array.from({ length: max - min + 1 }, (_, index) => min + index);\n return unionOf(lengths.map((length) => wrap(tupleOf(item, length, false))));\n}\n\n/**\n * `type: array` with `--array-length` and the `array-length-tuples` fix (#2048, #2330, #2546):\n * the tuples have `min` to `max` items, the item type is used as it is (a nested array stays one\n * level deep), a `prefixItems` tuple gets no length tuples around it, and `--immutable` makes\n * every tuple `readonly`.\n */\nfunction fixedArrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n const wrap: ArrayWrapper = (type) =>\n request.context.options.immutable ? irReadonly(type) : type;\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return wrap(tuple);\n }\n const item = singleItemType(schema, request);\n const bounds = lengthBounds(schema);\n return isLengthTupleWanted(bounds, request)\n ? fixedLengthTupleType(item, bounds, wrap)\n : wrap(irArray(item));\n}\n\nfunction isArrayLengthFixed(request: SchemaRequest): boolean {\n const { arrayLength, fixes } = request.context.options;\n return arrayLength && fixes.has(FIX.ARRAY_LENGTH_TUPLES);\n}\n\n/** `type: array`, including tuples (`prefixItems`, array `items`) and `--array-length`. */\nexport function arrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n if (isArrayLengthFixed(request)) {\n return fixedArrayType(schema, request);\n }\n const item = itemType(schema, request);\n const bounds = lengthBounds(schema);\n // A `prefix-items` tuple has its own lengths, so `--array-length` adds no tuples around it.\n if (!isPrefixItemsFixed(schema, request) && isLengthTupleWanted(bounds, request)) {\n return lengthTupleType(schema, item, bounds);\n }\n // A tuple or an array item is used as the array type itself.\n const type = item.kind === \"tuple\" || item.kind === \"array\" ? item : irArray(item);\n return request.context.options.immutable ? irReadonly(type) : type;\n}\n"],"names":["irTuple","irTupleElement","UNKNOWN_TYPE","unionOf","irOptionalTupleElement","irArray","FIX","irReadonly"],"mappings":";;;;;;;AAkBA,MAAM,yBAAA,GAA4B,EAAA;AAMlC,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAuC;AACpF,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,IAAI,MAAA,CAAO,WAAA,IAAe,kBAAA,CAAmB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAC7D,IAAA,OAAO,oBAAA,CAAqB,MAAA,CAAO,WAAA,EAAa,MAAA,EAAQ,OAAO,CAAA;AAAA,EACjE;AACA,EAAA,IAAI,CAAC,MAAA,CAAO,WAAA,IAAe,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAA,GAAc,OAAO,WAAA,IAAgB,KAAA;AAC3C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F,oBAAA,CAAQ,IAAI,CAAC,CAAA;AACxB;AAEA,SAAS,mBAAmB,OAAA,EAAiC;AAC3D,EAAA,MAAM,EAAE,WAAA,EAAa,KAAA,EAAM,GAAI,QAAQ,OAAA,CAAQ,OAAA;AAC/C,EAAA,OAAO,WAAA,IAAe,KAAA,CAAM,GAAA,CAAIC,eAAA,CAAI,mBAAmB,CAAA;AACzD;AAGO,SAAS,SAAA,CAAU,QAAsB,OAAA,EAAgC;AAC9E,EAAA,IAAI,kBAAA,CAAmB,OAAO,CAAA,EAAG;AAC/B,IAAA,OAAO,cAAA,CAAe,QAAQ,OAAO,CAAA;AAAA,EACvC;AACA,EAAA,MAAM,IAAA,GAAO,QAAA,CAAS,MAAA,EAAQ,OAAO,CAAA;AACrC,EAAA,MAAM,MAAA,GAAS,aAAa,MAAM,CAAA;AAElC,EAAA,IAAI,CAAC,mBAAmB,MAAA,EAAQ,OAAO,KAAK,mBAAA,CAAoB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAChF,IAAA,OAAO,eAAA,CAAgB,MAAA,EAAQ,IAAA,EAAM,MAAM,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAA,GAAO,KAAK,IAAA,KAAS,OAAA,IAAW,KAAK,IAAA,KAAS,OAAA,GAAU,IAAA,GAAOD,oBAAA,CAAQ,IAAI,CAAA;AACjF,EAAA,OAAO,QAAQ,OAAA,CAAQ,OAAA,CAAQ,SAAA,GAAYE,uBAAA,CAAW,IAAI,CAAA,GAAI,IAAA;AAChE;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { irArray, irReadonly, irTuple, irTupleElement, irOptionalTupleElement } from '../../../domain/ir/constructors.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
3
3
|
import { UNKNOWN_TYPE } from '../shared-types.mjs';
|
|
4
4
|
import { unionOf } from '../type-combinators.mjs';
|
|
5
5
|
|
|
@@ -43,7 +43,7 @@ function prefixItemsTupleType(prefixItems, schema, request) {
|
|
|
43
43
|
return irTuple(rest === null ? elements : [...elements, irTupleElement(irArray(rest), true)]);
|
|
44
44
|
}
|
|
45
45
|
function isPrefixItemsFixed(schema, request) {
|
|
46
|
-
return schema.prefixItems !== void 0 && request.context.options.fixes.has(
|
|
46
|
+
return schema.prefixItems !== void 0 && request.context.options.fixes.has(FIX.PREFIX_ITEMS);
|
|
47
47
|
}
|
|
48
48
|
function singleItemType(schema, request) {
|
|
49
49
|
const { items } = schema;
|
|
@@ -115,7 +115,7 @@ function fixedArrayType(schema, request) {
|
|
|
115
115
|
}
|
|
116
116
|
function isArrayLengthFixed(request) {
|
|
117
117
|
const { arrayLength, fixes } = request.context.options;
|
|
118
|
-
return arrayLength && fixes.has(
|
|
118
|
+
return arrayLength && fixes.has(FIX.ARRAY_LENGTH_TUPLES);
|
|
119
119
|
}
|
|
120
120
|
function arrayType(schema, request) {
|
|
121
121
|
if (isArrayLengthFixed(request)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-type.mjs","sources":["../../../../src/application/transform/schema/array-type.ts"],"sourcesContent":["import {\n irArray,\n irOptionalTupleElement,\n irReadonly,\n irTuple,\n irTupleElement,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrTupleElement, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `--array-length` writes tuples only while the estimated number of tuple elements stays below\n * this; the original chose it as roughly where TypeScript starts to struggle with tuple inference.\n */\nconst MAX_LENGTH_TUPLE_ELEMENTS = 30;\n\n/**\n * The tuple of `prefixItems` (or of an `items` list); null without either. The original closes a\n * `prefixItems` tuple and requires every element; the `prefix-items` fix does not.\n */\nfunction prefixTupleType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items } = schema;\n if (schema.prefixItems && isPrefixItemsFixed(schema, request)) {\n return prefixItemsTupleType(schema.prefixItems, schema, request);\n }\n if (!schema.prefixItems && !Array.isArray(items)) {\n return null;\n }\n const prefixItems = schema.prefixItems ?? (items as SchemaObject[]);\n return irTuple(\n prefixItems.map((item) => irTupleElement(request.transformNested(item, request.location))),\n );\n}\n\n/** The type of the items after the prefix, or null when there may be none (`false`). */\nfunction restItemType(schema: Schema, request: SchemaRequest): IrType | null {\n return schema === false ? null : request.transformNested(schema, request.location);\n}\n\n/**\n * The type of the items after a `prefixItems` tuple (JSON Schema 2020-12 §10.3.1): `items`, else\n * `unevaluatedItems`, which does not apply to the items `contains` matches, else any item. Null\n * when no item may follow. An `items` list is not a schema in 2020-12, so it allows any item.\n */\nfunction prefixRestType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items, unevaluatedItems, contains } = schema;\n if (items !== undefined && !Array.isArray(items)) {\n return restItemType(items as Schema, request);\n }\n if (unevaluatedItems === undefined || items !== undefined) {\n return UNKNOWN_TYPE;\n }\n const unevaluated = restItemType(unevaluatedItems, request);\n const matched = contains === undefined ? null : restItemType(contains, request);\n const types = [unevaluated, matched].filter((type): type is IrType => type !== null);\n return types.length === 0 ? null : unionOf(types);\n}\n\n/**\n * The `prefix-items` tuple of `prefixItems`: an array may end before the prefix does, so the\n * elements from `minItems` on are optional (`T?`), and a rest element types the items after it.\n */\nfunction prefixItemsTupleType(\n prefixItems: readonly Schema[],\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType {\n const { min } = lengthBounds(schema);\n const elements = prefixItems.map((item, index): IrTupleElement => {\n const type = request.transformNested(item, request.location);\n return index < min ? irTupleElement(type) : irOptionalTupleElement(type);\n });\n const rest = prefixRestType(schema, request);\n return irTuple(rest === null ? elements : [...elements, irTupleElement(irArray(rest), true)]);\n}\n\nfunction isPrefixItemsFixed(schema: SchemaObject, request: SchemaRequest): boolean {\n return (\n schema.prefixItems !== undefined && request.context.options.fixes.has(OutputFix.PREFIX_ITEMS)\n );\n}\n\n/** The type of one item; `unknown` without `items`. */\nfunction singleItemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { items } = schema;\n return items ? request.transformNested(items as SchemaObject, request.location) : UNKNOWN_TYPE;\n}\n\n/**\n * The item type as the original returns it: a tuple stands for the whole array, and a nested\n * `type: array` item is wrapped in an array here already.\n */\nfunction itemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return tuple;\n }\n const { items } = schema;\n // Checked first: the `in` test below throws for `items: null`.\n if (!items) {\n return UNKNOWN_TYPE;\n }\n const nested = singleItemType(schema, request);\n const isNestedArray = typeof items === \"object\" && \"type\" in items && items.type === \"array\";\n return isNestedArray ? irArray(nested) : nested;\n}\n\nfunction repeat(type: IrType, count: number): IrType[] {\n return Array.from({ length: count }, () => type);\n}\n\ninterface LengthBounds {\n readonly min: number;\n readonly max: number | undefined;\n}\n\nfunction lengthBounds(schema: SchemaObject): LengthBounds {\n const { minItems, maxItems } = schema;\n const min = typeof minItems === \"number\" && minItems >= 0 ? minItems : 0;\n const isMaxValid = typeof maxItems === \"number\" && maxItems >= 0 && min <= maxItems;\n return { min, max: isMaxValid ? maxItems : undefined };\n}\n\n/**\n * Tuples for `--array-length`, as the original builds them. With both bounds it emits tuples of\n * length 0 to `max - min` (not `min` to `max`); the `array-length-tuples` fix corrects it.\n */\nfunction lengthTupleType(schema: SchemaObject, item: IrType, bounds: LengthBounds): IrType {\n const { min, max } = bounds;\n if (min === max) {\n return unionOf([irTuple(repeat(item, min).map((type) => irTupleElement(type)))]);\n }\n if ((schema.maxItems as number) > 0) {\n const lengths = Array.from({ length: Math.max(0, (max ?? 0) - min + 1) }, (_, index) => index);\n return unionOf(\n lengths.map((length) => irTuple(repeat(item, length).map((type) => irTupleElement(type)))),\n );\n }\n const elements = repeat(item, min).map((type) => irTupleElement(type));\n return irTuple([...elements, irTupleElement(irArray(item), true)]);\n}\n\nfunction isLengthTupleWanted(bounds: LengthBounds, request: SchemaRequest): boolean {\n const { min, max } = bounds;\n const estimatedSize = max === undefined ? min : (max * (max + 1) - min * (min - 1)) / 2;\n const hasBounds = min !== 0 || max !== undefined;\n return (\n request.context.options.arrayLength && hasBounds && estimatedSize < MAX_LENGTH_TUPLE_ELEMENTS\n );\n}\n\n/** Applies `--immutable` to one array or tuple type. */\ntype ArrayWrapper = (type: IrType) => IrType;\n\nfunction tupleOf(item: IrType, length: number, isOpen: boolean): IrType {\n const elements = repeat(item, length).map((type) => irTupleElement(type));\n return irTuple(isOpen ? [...elements, irTupleElement(irArray(item), true)] : elements);\n}\n\n/** Tuples of every length from `min` to `max`; without `max`, `min` items and a rest element. */\nfunction fixedLengthTupleType(item: IrType, bounds: LengthBounds, wrap: ArrayWrapper): IrType {\n const { min, max } = bounds;\n if (max === undefined) {\n return wrap(tupleOf(item, min, true));\n }\n const lengths = Array.from({ length: max - min + 1 }, (_, index) => min + index);\n return unionOf(lengths.map((length) => wrap(tupleOf(item, length, false))));\n}\n\n/**\n * `type: array` with `--array-length` and the `array-length-tuples` fix (#2048, #2330, #2546):\n * the tuples have `min` to `max` items, the item type is used as it is (a nested array stays one\n * level deep), a `prefixItems` tuple gets no length tuples around it, and `--immutable` makes\n * every tuple `readonly`.\n */\nfunction fixedArrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n const wrap: ArrayWrapper = (type) =>\n request.context.options.immutable ? irReadonly(type) : type;\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return wrap(tuple);\n }\n const item = singleItemType(schema, request);\n const bounds = lengthBounds(schema);\n return isLengthTupleWanted(bounds, request)\n ? fixedLengthTupleType(item, bounds, wrap)\n : wrap(irArray(item));\n}\n\nfunction isArrayLengthFixed(request: SchemaRequest): boolean {\n const { arrayLength, fixes } = request.context.options;\n return arrayLength && fixes.has(OutputFix.ARRAY_LENGTH_TUPLES);\n}\n\n/** `type: array`, including tuples (`prefixItems`, array `items`) and `--array-length`. */\nexport function arrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n if (isArrayLengthFixed(request)) {\n return fixedArrayType(schema, request);\n }\n const item = itemType(schema, request);\n const bounds = lengthBounds(schema);\n // A `prefix-items` tuple has its own lengths, so `--array-length` adds no tuples around it.\n if (!isPrefixItemsFixed(schema, request) && isLengthTupleWanted(bounds, request)) {\n return lengthTupleType(schema, item, bounds);\n }\n // A tuple or an array item is used as the array type itself.\n const type = item.kind === \"tuple\" || item.kind === \"array\" ? item : irArray(item);\n return request.context.options.immutable ? irReadonly(type) : type;\n}\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,yBAAA,GAA4B,EAAA;AAMlC,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAuC;AACpF,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,IAAI,MAAA,CAAO,WAAA,IAAe,kBAAA,CAAmB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAC7D,IAAA,OAAO,oBAAA,CAAqB,MAAA,CAAO,WAAA,EAAa,MAAA,EAAQ,OAAO,CAAA;AAAA,EACjE;AACA,EAAA,IAAI,CAAC,MAAA,CAAO,WAAA,IAAe,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAA,GAAc,OAAO,WAAA,IAAgB,KAAA;AAC3C,EAAA,OAAO,OAAA;AAAA,IACL,WAAA,CAAY,GAAA,CAAI,CAAC,IAAA,KAAS,cAAA,CAAe,OAAA,CAAQ,eAAA,CAAgB,IAAA,EAAM,OAAA,CAAQ,QAAQ,CAAC,CAAC;AAAA,GAC3F;AACF;AAGA,SAAS,YAAA,CAAa,QAAgB,OAAA,EAAuC;AAC3E,EAAA,OAAO,WAAW,KAAA,GAAQ,IAAA,GAAO,QAAQ,eAAA,CAAgB,MAAA,EAAQ,QAAQ,QAAQ,CAAA;AACnF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AA,EACvC;AACA,EAAA,MAAM,IAAA,GAAO,QAAA,CAAS,MAAA,EAAQ,OAAO,CAAA;AACrC,EAAA,MAAM,MAAA,GAAS,aAAa,MAAM,CAAA;AAElC,EAAA,IAAI,CAAC,mBAAmB,MAAA,EAAQ,OAAO,KAAK,mBAAA,CAAoB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAChF,IAAA,OAAO,eAAA,CAAgB,MAAA,EAAQ,IAAA,EAAM,MAAM,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAA,GAAO,KAAK,IAAA,KAAS,OAAA,IAAW,KAAK,IAAA,KAAS,OAAA,GAAU,IAAA,GAAO,OAAA,CAAQ,IAAI,CAAA;AACjF,EAAA,OAAO,QAAQ,OAAA,CAAQ,OAAA,CAAQ,SAAA,GAAY,UAAA,CAAW,IAAI,CAAA,GAAI,IAAA;AAChE;;"}
|
|
1
|
+
{"version":3,"file":"array-type.mjs","sources":["../../../../src/application/transform/schema/array-type.ts"],"sourcesContent":["import {\n irArray,\n irOptionalTupleElement,\n irReadonly,\n irTuple,\n irTupleElement,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrTupleElement, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `--array-length` writes tuples only while the estimated number of tuple elements stays below\n * this; the original chose it as roughly where TypeScript starts to struggle with tuple inference.\n */\nconst MAX_LENGTH_TUPLE_ELEMENTS = 30;\n\n/**\n * The tuple of `prefixItems` (or of an `items` list); null without either. The original closes a\n * `prefixItems` tuple and requires every element; the `prefix-items` fix does not.\n */\nfunction prefixTupleType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items } = schema;\n if (schema.prefixItems && isPrefixItemsFixed(schema, request)) {\n return prefixItemsTupleType(schema.prefixItems, schema, request);\n }\n if (!schema.prefixItems && !Array.isArray(items)) {\n return null;\n }\n const prefixItems = schema.prefixItems ?? (items as SchemaObject[]);\n return irTuple(\n prefixItems.map((item) => irTupleElement(request.transformNested(item, request.location))),\n );\n}\n\n/** The type of the items after the prefix, or null when there may be none (`false`). */\nfunction restItemType(schema: Schema, request: SchemaRequest): IrType | null {\n return schema === false ? null : request.transformNested(schema, request.location);\n}\n\n/**\n * The type of the items after a `prefixItems` tuple (JSON Schema 2020-12 §10.3.1): `items`, else\n * `unevaluatedItems`, which does not apply to the items `contains` matches, else any item. Null\n * when no item may follow. An `items` list is not a schema in 2020-12, so it allows any item.\n */\nfunction prefixRestType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items, unevaluatedItems, contains } = schema;\n if (items !== undefined && !Array.isArray(items)) {\n return restItemType(items as Schema, request);\n }\n if (unevaluatedItems === undefined || items !== undefined) {\n return UNKNOWN_TYPE;\n }\n const unevaluated = restItemType(unevaluatedItems, request);\n const matched = contains === undefined ? null : restItemType(contains, request);\n const types = [unevaluated, matched].filter((type): type is IrType => type !== null);\n return types.length === 0 ? null : unionOf(types);\n}\n\n/**\n * The `prefix-items` tuple of `prefixItems`: an array may end before the prefix does, so the\n * elements from `minItems` on are optional (`T?`), and a rest element types the items after it.\n */\nfunction prefixItemsTupleType(\n prefixItems: readonly Schema[],\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType {\n const { min } = lengthBounds(schema);\n const elements = prefixItems.map((item, index): IrTupleElement => {\n const type = request.transformNested(item, request.location);\n return index < min ? irTupleElement(type) : irOptionalTupleElement(type);\n });\n const rest = prefixRestType(schema, request);\n return irTuple(rest === null ? elements : [...elements, irTupleElement(irArray(rest), true)]);\n}\n\nfunction isPrefixItemsFixed(schema: SchemaObject, request: SchemaRequest): boolean {\n return schema.prefixItems !== undefined && request.context.options.fixes.has(FIX.PREFIX_ITEMS);\n}\n\n/** The type of one item; `unknown` without `items`. */\nfunction singleItemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { items } = schema;\n return items ? request.transformNested(items as SchemaObject, request.location) : UNKNOWN_TYPE;\n}\n\n/**\n * The item type as the original returns it: a tuple stands for the whole array, and a nested\n * `type: array` item is wrapped in an array here already.\n */\nfunction itemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return tuple;\n }\n const { items } = schema;\n // Checked first: the `in` test below throws for `items: null`.\n if (!items) {\n return UNKNOWN_TYPE;\n }\n const nested = singleItemType(schema, request);\n const isNestedArray = typeof items === \"object\" && \"type\" in items && items.type === \"array\";\n return isNestedArray ? irArray(nested) : nested;\n}\n\nfunction repeat(type: IrType, count: number): IrType[] {\n return Array.from({ length: count }, () => type);\n}\n\ninterface LengthBounds {\n readonly min: number;\n readonly max: number | undefined;\n}\n\nfunction lengthBounds(schema: SchemaObject): LengthBounds {\n const { minItems, maxItems } = schema;\n const min = typeof minItems === \"number\" && minItems >= 0 ? minItems : 0;\n const isMaxValid = typeof maxItems === \"number\" && maxItems >= 0 && min <= maxItems;\n return { min, max: isMaxValid ? maxItems : undefined };\n}\n\n/**\n * Tuples for `--array-length`, as the original builds them. With both bounds it emits tuples of\n * length 0 to `max - min` (not `min` to `max`); the `array-length-tuples` fix corrects it.\n */\nfunction lengthTupleType(schema: SchemaObject, item: IrType, bounds: LengthBounds): IrType {\n const { min, max } = bounds;\n if (min === max) {\n return unionOf([irTuple(repeat(item, min).map((type) => irTupleElement(type)))]);\n }\n if ((schema.maxItems as number) > 0) {\n const lengths = Array.from({ length: Math.max(0, (max ?? 0) - min + 1) }, (_, index) => index);\n return unionOf(\n lengths.map((length) => irTuple(repeat(item, length).map((type) => irTupleElement(type)))),\n );\n }\n const elements = repeat(item, min).map((type) => irTupleElement(type));\n return irTuple([...elements, irTupleElement(irArray(item), true)]);\n}\n\nfunction isLengthTupleWanted(bounds: LengthBounds, request: SchemaRequest): boolean {\n const { min, max } = bounds;\n const estimatedSize = max === undefined ? min : (max * (max + 1) - min * (min - 1)) / 2;\n const hasBounds = min !== 0 || max !== undefined;\n return (\n request.context.options.arrayLength && hasBounds && estimatedSize < MAX_LENGTH_TUPLE_ELEMENTS\n );\n}\n\n/** Applies `--immutable` to one array or tuple type. */\ntype ArrayWrapper = (type: IrType) => IrType;\n\nfunction tupleOf(item: IrType, length: number, isOpen: boolean): IrType {\n const elements = repeat(item, length).map((type) => irTupleElement(type));\n return irTuple(isOpen ? [...elements, irTupleElement(irArray(item), true)] : elements);\n}\n\n/** Tuples of every length from `min` to `max`; without `max`, `min` items and a rest element. */\nfunction fixedLengthTupleType(item: IrType, bounds: LengthBounds, wrap: ArrayWrapper): IrType {\n const { min, max } = bounds;\n if (max === undefined) {\n return wrap(tupleOf(item, min, true));\n }\n const lengths = Array.from({ length: max - min + 1 }, (_, index) => min + index);\n return unionOf(lengths.map((length) => wrap(tupleOf(item, length, false))));\n}\n\n/**\n * `type: array` with `--array-length` and the `array-length-tuples` fix (#2048, #2330, #2546):\n * the tuples have `min` to `max` items, the item type is used as it is (a nested array stays one\n * level deep), a `prefixItems` tuple gets no length tuples around it, and `--immutable` makes\n * every tuple `readonly`.\n */\nfunction fixedArrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n const wrap: ArrayWrapper = (type) =>\n request.context.options.immutable ? irReadonly(type) : type;\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return wrap(tuple);\n }\n const item = singleItemType(schema, request);\n const bounds = lengthBounds(schema);\n return isLengthTupleWanted(bounds, request)\n ? fixedLengthTupleType(item, bounds, wrap)\n : wrap(irArray(item));\n}\n\nfunction isArrayLengthFixed(request: SchemaRequest): boolean {\n const { arrayLength, fixes } = request.context.options;\n return arrayLength && fixes.has(FIX.ARRAY_LENGTH_TUPLES);\n}\n\n/** `type: array`, including tuples (`prefixItems`, array `items`) and `--array-length`. */\nexport function arrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n if (isArrayLengthFixed(request)) {\n return fixedArrayType(schema, request);\n }\n const item = itemType(schema, request);\n const bounds = lengthBounds(schema);\n // A `prefix-items` tuple has its own lengths, so `--array-length` adds no tuples around it.\n if (!isPrefixItemsFixed(schema, request) && isLengthTupleWanted(bounds, request)) {\n return lengthTupleType(schema, item, bounds);\n }\n // A tuple or an array item is used as the array type itself.\n const type = item.kind === \"tuple\" || item.kind === \"array\" ? item : irArray(item);\n return request.context.options.immutable ? irReadonly(type) : type;\n}\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,yBAAA,GAA4B,EAAA;AAMlC,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAuC;AACpF,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,IAAI,MAAA,CAAO,WAAA,IAAe,kBAAA,CAAmB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAC7D,IAAA,OAAO,oBAAA,CAAqB,MAAA,CAAO,WAAA,EAAa,MAAA,EAAQ,OAAO,CAAA;AAAA,EACjE;AACA,EAAA,IAAI,CAAC,MAAA,CAAO,WAAA,IAAe,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAA,GAAc,OAAO,WAAA,IAAgB,KAAA;AAC3C,EAAA,OAAO,OAAA;AAAA,IACL,WAAA,CAAY,GAAA,CAAI,CAAC,IAAA,KAAS,cAAA,CAAe,OAAA,CAAQ,eAAA,CAAgB,IAAA,EAAM,OAAA,CAAQ,QAAQ,CAAC,CAAC;AAAA,GAC3F;AACF;AAGA,SAAS,YAAA,CAAa,QAAgB,OAAA,EAAuC;AAC3E,EAAA,OAAO,WAAW,KAAA,GAAQ,IAAA,GAAO,QAAQ,eAAA,CAAgB,MAAA,EAAQ,QAAQ,QAAQ,CAAA;AACnF;AAOA,SAAS,cAAA,CAAe,QAAsB,OAAA,EAAuC;AACnF,EAAA,MAAM,EAAE,KAAA,EAAO,gBAAA,EAAk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MAAA,GAAS,aAAa,MAAM,CAAA;AAElC,EAAA,IAAI,CAAC,mBAAmB,MAAA,EAAQ,OAAO,KAAK,mBAAA,CAAoB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAChF,IAAA,OAAO,eAAA,CAAgB,MAAA,EAAQ,IAAA,EAAM,MAAM,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAA,GAAO,KAAK,IAAA,KAAS,OAAA,IAAW,KAAK,IAAA,KAAS,OAAA,GAAU,IAAA,GAAO,OAAA,CAAQ,IAAI,CAAA;AACjF,EAAA,OAAO,QAAQ,OAAA,CAAQ,OAAA,CAAQ,SAAA,GAAY,UAAA,CAAW,IAAI,CAAA,GAAI,IAAA;AAChE;;"}
|
|
@@ -16,7 +16,7 @@ function variantTypes(variants, keyword, request) {
|
|
|
16
16
|
return variants.map(
|
|
17
17
|
(variant, index) => request.transformNested(variant, {
|
|
18
18
|
...request.location,
|
|
19
|
-
path: jsonPointer.
|
|
19
|
+
path: jsonPointer.appendPointer(request.location.path, [keyword, index])
|
|
20
20
|
})
|
|
21
21
|
);
|
|
22
22
|
}
|
|
@@ -28,7 +28,7 @@ function keysToRequire(ref, target, required, request) {
|
|
|
28
28
|
if (!request.context.discriminators.isHandled(ref)) {
|
|
29
29
|
return defined;
|
|
30
30
|
}
|
|
31
|
-
if (!request.context.options.fixes.has(outputFixes.
|
|
31
|
+
if (!request.context.options.fixes.has(outputFixes.FIX.DISCRIMINATOR_MEMBER_REQUIRED)) {
|
|
32
32
|
return [];
|
|
33
33
|
}
|
|
34
34
|
return defined.filter((key) => !target.required?.includes(key));
|
|
@@ -66,7 +66,7 @@ function allOfItemType(item, required, request) {
|
|
|
66
66
|
return ownKeywordsType(own, item.$ref, request);
|
|
67
67
|
}
|
|
68
68
|
const type = isRef ? refItemType(item, required, request) : inlineItemType(item, required, request);
|
|
69
|
-
const isUnion = unionItem !== void 0 && !unionItem.isMapped && request.context.options.fixes.has(outputFixes.
|
|
69
|
+
const isUnion = unionItem !== void 0 && !unionItem.isMapped && request.context.options.fixes.has(outputFixes.FIX.ALLOF_DISCRIMINATED_UNION);
|
|
70
70
|
if (!propertyName || isUnion) {
|
|
71
71
|
return type;
|
|
72
72
|
}
|
|
@@ -86,7 +86,7 @@ function anyOfType(previous, schema, request) {
|
|
|
86
86
|
if (variants.length === 0 || previous === null) {
|
|
87
87
|
return variants.length === 0 ? previous : typeCombinators.unionOf(variants);
|
|
88
88
|
}
|
|
89
|
-
if (!request.context.options.fixes.has(outputFixes.
|
|
89
|
+
if (!request.context.options.fixes.has(outputFixes.FIX.ANYOF_PROPERTIES)) {
|
|
90
90
|
return typeCombinators.unionOf([previous, ...variants]);
|
|
91
91
|
}
|
|
92
92
|
return Array.isArray(schema.type) ? previous : typeCombinators.intersectionOf([previous, typeCombinators.unionOf(variants)]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composition-type.cjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { requirableRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { unionItemOf, unionOwnKeywords } from \"./discriminated-union.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport { requiredVariantsType } from \"./required-variants.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: createRef([request.location.path, keyword, String(index)]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/**\n * The parent's `required` keys that the target at `ref` defines. A target that the discriminator\n * scan gave its property got none: the scan made that property required, but the other keys were\n * lost too. With `discriminator-member-required` only keys the target requires already are left\n * out (#2162).\n */\nfunction keysToRequire(\n ref: string,\n target: SchemaObject,\n required: readonly string[],\n request: SchemaRequest,\n): readonly string[] {\n const defined = required.filter((key) => Boolean(target.properties?.[key]));\n if (!request.context.discriminators.isHandled(ref)) {\n return defined;\n }\n if (!request.context.options.fixes.has(OutputFix.DISCRIMINATOR_MEMBER_REQUIRED)) {\n return [];\n }\n return defined.filter((key) => !target.required?.includes(key));\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const resolved = request.context.refs.resolve(item.$ref) as SchemaObject | undefined;\n if (!resolved || typeof resolved !== \"object\" || !(\"properties\" in resolved)) {\n return type;\n }\n const keys = keysToRequire(item.$ref, resolved, required, request);\n if (keys.length === 0) {\n return type;\n }\n request.context.footer.requireWithRequired();\n return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/**\n * The union's own keywords at the union's location, so nested names (enums) stay the union's.\n * Null when the union has none.\n */\nfunction ownKeywordsType(own: SchemaObject, ref: string, request: SchemaRequest): IrType | null {\n return combinedType(own, { ...request, location: { ...request.location, path: ref } });\n}\n\n/**\n * An `allOf` item; one with a discriminator omits that property (the parent redefines it). A\n * `$ref` to a discriminated union is not such a parent: for a member of the union it is the\n * union's own keywords, since the union contains the member (#1665); with\n * `allof-discriminated-union` it is the union, since `Omit` on a union drops keys (#1464), unless\n * the union's mapping names the schema: then it is a member, as the discriminator scan has it.\n */\nfunction allOfItemType(\n item: Schema,\n required: readonly string[],\n request: SchemaRequest,\n): IrType | null {\n const isRef = isRefItem(item);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n const propertyName = discriminator?.propertyName;\n const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : undefined;\n if (isRef && propertyName && unionItem?.isMember) {\n const own = unionOwnKeywords(unionItem.union, propertyName, required);\n return ownKeywordsType(own, item.$ref, request);\n }\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const isUnion =\n unionItem !== undefined &&\n !unionItem.isMapped &&\n request.context.options.fixes.has(OutputFix.ALLOF_DISCRIMINATED_UNION);\n if (!propertyName || isUnion) {\n return type;\n }\n // With `discriminator-values` the schema also redefines the properties of other owners above\n // it, so no item may keep a value of its own for them (a parent mapped as `content`).\n const { path } = request.location;\n const others = path === undefined ? [] : request.context.discriminators.otherPropertiesAt(path);\n return omitKeys(type, [propertyName, ...others]);\n}\n\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.flatMap((item) => allOfItemType(item, required, request) ?? []);\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(OutputFix.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n return variantsType(type, schema, request);\n}\n\n/** `anyOf`, then `oneOf`, applied to the core and `allOf` type (`anyof-oneof-required` first). */\nfunction variantsType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const type =\n requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ??\n anyOfType(previous, schema, request);\n const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);\n if (oneOfRequired !== null) {\n return oneOfRequired;\n }\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_TYPE;\n const type = combinedType(schema, request) ?? empty;\n return type !== UNKNOWN_TYPE && schema.nullable ? nullableOf([type]) : type;\n}\n"],"names":["createRef","OutputFix","withRequiredKeys","requirableRefType","unionItemOf","unionOwnKeywords","omitKeys","isPrimitiveType","unionOf","intersectionOf","coreType","allOfMembers","requiredVariantsType","unevaluatedPropertiesType","irRecord","irKeyword","UNKNOWN_TYPE","nullableOf"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAS,YAAA,CACP,QAAA,EACA,OAAA,EACA,OAAA,EACU;AACV,EAAA,OAAO,QAAA,CAAS,GAAA;AAAA,IAAI,C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AO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAASA,4BAAgB,MAAA,CAAO,QAAA,GAAWC,2BAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
|
|
1
|
+
{"version":3,"file":"composition-type.cjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { requirableRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { unionItemOf, unionOwnKeywords } from \"./discriminated-union.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport { requiredVariantsType } from \"./required-variants.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: appendPointer(request.location.path, [keyword, index]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/**\n * The parent's `required` keys that the target at `ref` defines. A target that the discriminator\n * scan gave its property got none: the scan made that property required, but the other keys were\n * lost too. With `discriminator-member-required` only keys the target requires already are left\n * out (#2162).\n */\nfunction keysToRequire(\n ref: string,\n target: SchemaObject,\n required: readonly string[],\n request: SchemaRequest,\n): readonly string[] {\n const defined = required.filter((key) => Boolean(target.properties?.[key]));\n if (!request.context.discriminators.isHandled(ref)) {\n return defined;\n }\n if (!request.context.options.fixes.has(FIX.DISCRIMINATOR_MEMBER_REQUIRED)) {\n return [];\n }\n return defined.filter((key) => !target.required?.includes(key));\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const resolved = request.context.refs.resolve(item.$ref) as SchemaObject | undefined;\n if (!resolved || typeof resolved !== \"object\" || !(\"properties\" in resolved)) {\n return type;\n }\n const keys = keysToRequire(item.$ref, resolved, required, request);\n if (keys.length === 0) {\n return type;\n }\n request.context.footer.requireWithRequired();\n return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/**\n * The union's own keywords at the union's location, so nested names (enums) stay the union's.\n * Null when the union has none.\n */\nfunction ownKeywordsType(own: SchemaObject, ref: string, request: SchemaRequest): IrType | null {\n return combinedType(own, { ...request, location: { ...request.location, path: ref } });\n}\n\n/**\n * An `allOf` item; one with a discriminator omits that property (the parent redefines it). A\n * `$ref` to a discriminated union is not such a parent: for a member of the union it is the\n * union's own keywords, since the union contains the member (#1665); with\n * `allof-discriminated-union` it is the union, since `Omit` on a union drops keys (#1464), unless\n * the union's mapping names the schema: then it is a member, as the discriminator scan has it.\n */\nfunction allOfItemType(\n item: Schema,\n required: readonly string[],\n request: SchemaRequest,\n): IrType | null {\n const isRef = isRefItem(item);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n const propertyName = discriminator?.propertyName;\n const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : undefined;\n if (isRef && propertyName && unionItem?.isMember) {\n const own = unionOwnKeywords(unionItem.union, propertyName, required);\n return ownKeywordsType(own, item.$ref, request);\n }\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const isUnion =\n unionItem !== undefined &&\n !unionItem.isMapped &&\n request.context.options.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION);\n if (!propertyName || isUnion) {\n return type;\n }\n // With `discriminator-values` the schema also redefines the properties of other owners above\n // it, so no item may keep a value of its own for them (a parent mapped as `content`).\n const { path } = request.location;\n const others = path === undefined ? [] : request.context.discriminators.otherPropertiesAt(path);\n return omitKeys(type, [propertyName, ...others]);\n}\n\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.flatMap((item) => allOfItemType(item, required, request) ?? []);\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(FIX.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n return variantsType(type, schema, request);\n}\n\n/** `anyOf`, then `oneOf`, applied to the core and `allOf` type (`anyof-oneof-required` first). */\nfunction variantsType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const type =\n requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ??\n anyOfType(previous, schema, request);\n const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);\n if (oneOfRequired !== null) {\n return oneOfRequired;\n }\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_TYPE;\n const type = combinedType(schema, request) ?? empty;\n return type !== UNKNOWN_TYPE && schema.nullable ? nullableOf([type]) : type;\n}\n"],"names":["appendPointer","FIX","withRequiredKeys","requirableRefType","unionItemOf","unionOwnKeywords","omitKeys","isPrimitiveType","unionOf","intersectionOf","coreType","allOfMembers","requiredVariantsType","unevaluatedPropertiesType","irRecord","irKeyword","UNKNOWN_TYPE","nullableOf"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAS,YAAA,CACP,QAAA,EACA,OAAA,EACA,OAAA,EACU;AACV,EAAA,OAAO,QAAA,CAAS,GAAA;AAAA,IAAI,CAAC,OAAA,EAAS,KAAA,KAC5B,OAAA,CAAQ,gBAAgB,OAAA,EAAS;AAAA,MAC/B,GAAG,OAAA,CAAQ,QAAA;AAAA,MACX,IAAA,EAAMA,0BAAc,OAAA,CAAQ,QAAA,CAAS,MAAM,CAAC,OAAA,EAAS,KAAK,CAAC;AAAA,KAC5D;AAAA,GACH;AACF;AAMA,SAAS,UAAU,IAAA,EAAiD;AAClE,EAAA,OAAO,MAAA,IAAW,IAAA;AACpB;AAQA,SAAS,aAAA,CACP,GAAA,EACA,MAAA,EACA,QAAA,EACA,OAAA,EACmB;AACnB,EAAA,MAAM,OAAA,GAAU,QAAA,CA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AAA,CAAa,MAAA,EAAQ,OAAO,CAAA;AACzC,EAAA,MAAM,WAAA,GAAcC,+CAAA,CAA0B,MAAA,EAAQ,IAAA,EAAM,OAAO,CAAA;AACnE,EAAA,IAAI,gBAAgB,IAAA,EAAM;AACxB,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,IAAI,SAAS,IAAA,EAAM;AACjB,IAAA,OAAO,WAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAQ,IAAA,CAAK,IAAA,KAAS,iBAAiB,IAAA,CAAK,KAAA,GAAQ,CAAC,IAAI,CAAA;AAC/D,EAAA,OAAOJ,8BAAA,CAAe,CAAC,GAAG,KAAA,EAAO,WAAW,CAAC,CAAA;AAC/C;AAOO,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAgC;AACpF,EAAA,MAAM,EAAE,mBAAA,EAAoB,GAAI,OAAA,CAAQ,OAAA,CAAQ,OAAA;AAChD,EAAA,MAAM,KAAA,GACJ,MAAA,IAAU,MAAA,GACNK,qBAAA,CAASC,sBAAA,CAAU,QAAQ,CAAA,EAAG,mBAAA,GAAsBC,wBAAA,GAAeD,sBAAA,CAAU,OAAO,CAAC,CAAA,GACrFC,wBAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAASA,4BAAgB,MAAA,CAAO,QAAA,GAAWC,2BAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { irRecord, irKeyword } from '../../../domain/ir/constructors.mjs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { appendPointer } from '../../../domain/openapi/json-pointer.mjs';
|
|
3
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
4
4
|
import { requirableRefType } from '../ref-pointer/pointer-type.mjs';
|
|
5
5
|
import { UNKNOWN_TYPE } from '../shared-types.mjs';
|
|
6
6
|
import { nullableOf, intersectionOf, omitKeys, unionOf, isPrimitiveType, withRequiredKeys } from '../type-combinators.mjs';
|
|
@@ -14,7 +14,7 @@ function variantTypes(variants, keyword, request) {
|
|
|
14
14
|
return variants.map(
|
|
15
15
|
(variant, index) => request.transformNested(variant, {
|
|
16
16
|
...request.location,
|
|
17
|
-
path:
|
|
17
|
+
path: appendPointer(request.location.path, [keyword, index])
|
|
18
18
|
})
|
|
19
19
|
);
|
|
20
20
|
}
|
|
@@ -26,7 +26,7 @@ function keysToRequire(ref, target, required, request) {
|
|
|
26
26
|
if (!request.context.discriminators.isHandled(ref)) {
|
|
27
27
|
return defined;
|
|
28
28
|
}
|
|
29
|
-
if (!request.context.options.fixes.has(
|
|
29
|
+
if (!request.context.options.fixes.has(FIX.DISCRIMINATOR_MEMBER_REQUIRED)) {
|
|
30
30
|
return [];
|
|
31
31
|
}
|
|
32
32
|
return defined.filter((key) => !target.required?.includes(key));
|
|
@@ -64,7 +64,7 @@ function allOfItemType(item, required, request) {
|
|
|
64
64
|
return ownKeywordsType(own, item.$ref, request);
|
|
65
65
|
}
|
|
66
66
|
const type = isRef ? refItemType(item, required, request) : inlineItemType(item, required, request);
|
|
67
|
-
const isUnion = unionItem !== void 0 && !unionItem.isMapped && request.context.options.fixes.has(
|
|
67
|
+
const isUnion = unionItem !== void 0 && !unionItem.isMapped && request.context.options.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION);
|
|
68
68
|
if (!propertyName || isUnion) {
|
|
69
69
|
return type;
|
|
70
70
|
}
|
|
@@ -84,7 +84,7 @@ function anyOfType(previous, schema, request) {
|
|
|
84
84
|
if (variants.length === 0 || previous === null) {
|
|
85
85
|
return variants.length === 0 ? previous : unionOf(variants);
|
|
86
86
|
}
|
|
87
|
-
if (!request.context.options.fixes.has(
|
|
87
|
+
if (!request.context.options.fixes.has(FIX.ANYOF_PROPERTIES)) {
|
|
88
88
|
return unionOf([previous, ...variants]);
|
|
89
89
|
}
|
|
90
90
|
return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);
|