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
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
function resolveParameter(parameter, refs) {
|
|
2
|
+
return "$ref" in parameter ? refs.resolve(parameter.$ref) : parameter;
|
|
3
|
+
}
|
|
4
|
+
function isDeprecatedParameter(parameter) {
|
|
5
|
+
const schema = parameter?.schema;
|
|
6
|
+
return Boolean(parameter?.deprecated || schema?.deprecated);
|
|
7
|
+
}
|
|
8
|
+
function parameterEntries(parameters, context) {
|
|
9
|
+
const entries = parameters.map((original) => ({
|
|
10
|
+
original,
|
|
11
|
+
resolved: resolveParameter(original, context.refs)
|
|
12
|
+
}));
|
|
13
|
+
if (context.options.alphabetize) {
|
|
14
|
+
entries.sort(
|
|
15
|
+
(left, right) => (left.resolved?.name ?? "").localeCompare(right.resolved?.name ?? "")
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
return context.options.excludeDeprecated ? entries.filter(({ resolved }) => !isDeprecatedParameter(resolved)) : entries;
|
|
19
|
+
}
|
|
20
|
+
function mergedParameters(pathItem, operation, refs) {
|
|
21
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
22
|
+
for (const parameter of [...pathItem.parameters ?? [], ...operation.parameters ?? []]) {
|
|
23
|
+
const resolved = resolveParameter(parameter, refs);
|
|
24
|
+
byKey.set(`${resolved?.in}-${resolved?.name}`, parameter);
|
|
25
|
+
}
|
|
26
|
+
return [...byKey.values()];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { mergedParameters, parameterEntries, resolveParameter };
|
|
30
|
+
//# sourceMappingURL=parameter-entries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameter-entries.mjs","sources":["../../../../src/application/transform/document/parameter-entries.ts"],"sourcesContent":["import type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport type {\n ParameterObject,\n ParameterOrReference,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport type { PathItemObject } from \"../../../domain/openapi/path-item-object.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport type { RefResolver } from \"../schema/schema-context.js\";\nimport type { TransformContext } from \"../transform-context.js\";\n\n/** A parameter as written in the document, and the object its `$ref` points to. */\nexport interface ParameterEntry {\n readonly original: ParameterOrReference;\n readonly resolved: ParameterObject | undefined;\n}\n\n/** An entry whose `$ref` resolved, so its location and name are known. */\nexport type ResolvedEntry = ParameterEntry & { readonly resolved: ParameterObject };\n\n/** The parameter object itself, or the one its `$ref` points to. */\nexport function resolveParameter(\n parameter: ParameterOrReference,\n refs: RefResolver,\n): ParameterObject | undefined {\n return \"$ref\" in parameter\n ? (refs.resolve(parameter.$ref) as ParameterObject | undefined)\n : parameter;\n}\n\nfunction isDeprecatedParameter(parameter: ParameterObject | undefined): boolean {\n const schema = parameter?.schema as SchemaObject | undefined;\n return Boolean(parameter?.deprecated || schema?.deprecated);\n}\n\n/** Resolved parameters, sorted for `--alphabetize`, without deprecated ones if excluded. */\nexport function parameterEntries(\n parameters: readonly ParameterOrReference[],\n context: TransformContext,\n): ParameterEntry[] {\n const entries = parameters.map((original) => ({\n original,\n resolved: resolveParameter(original, context.refs),\n }));\n if (context.options.alphabetize) {\n // Unlike map keys, the original sorts parameters with the default locale's `localeCompare`.\n entries.sort((left, right) =>\n (left.resolved?.name ?? \"\").localeCompare(right.resolved?.name ?? \"\"),\n );\n }\n return context.options.excludeDeprecated\n ? entries.filter(({ resolved }) => !isDeprecatedParameter(resolved))\n : entries;\n}\n\n/**\n * Path item parameters followed by the operation's, keyed by location and name, so an operation\n * parameter replaces the path item parameter it redefines (upstream issue #1798).\n */\nexport function mergedParameters(\n pathItem: PathItemObject,\n operation: OperationObject,\n refs: RefResolver,\n): ParameterOrReference[] {\n const byKey = new Map<string, ParameterOrReference>();\n for (const parameter of [...(pathItem.parameters ?? []), ...(operation.parameters ?? [])]) {\n const resolved = resolveParameter(parameter, refs);\n byKey.set(`${resolved?.in}-${resolved?.name}`, parameter);\n }\n return [...byKey.values()];\n}\n"],"names":[],"mappings":"AAoBO,SAAS,gBAAA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AAW,IAAI,CAAA;AACjD,IAAA,KAAA,CAAM,GAAA,CAAI,GAAG,QAAA,EAAU,EAAE,IAAI,QAAA,EAAU,IAAI,IAAI,SAAS,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,CAAC,GAAG,KAAA,CAAM,MAAA,EAAQ,CAAA;AAC3B;;"}
|
|
@@ -3,20 +3,28 @@
|
|
|
3
3
|
const constructors = require('../../../domain/ir/constructors.cjs');
|
|
4
4
|
const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
|
|
5
5
|
const parameterObject = require('../../../domain/openapi/parameter-object.cjs');
|
|
6
|
+
const outputFixes = require('../../../domain/output-fixes.cjs');
|
|
6
7
|
const schemaTransform = require('../schema/schema-transform.cjs');
|
|
7
8
|
const mediaType = require('./media-type.cjs');
|
|
8
9
|
|
|
9
|
-
function
|
|
10
|
+
function contentParameterType(parameter, location, context) {
|
|
10
11
|
const [mediaType$1, entry] = Object.entries(parameter.content ?? {})[0] ?? [];
|
|
11
12
|
if (mediaType$1 === void 0 || entry === void 0) {
|
|
12
13
|
return constructors.irKeyword("string");
|
|
13
14
|
}
|
|
14
|
-
const path = jsonPointer.
|
|
15
|
+
const path = jsonPointer.appendPointer(location.path, ["content", mediaType$1]);
|
|
15
16
|
return mediaType.contentEntryType(entry, { ...location, path }, context);
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
+
function isTypedByContent(parameter, context) {
|
|
18
19
|
if (parameter.in === parameterObject.QUERYSTRING_LOCATION) {
|
|
19
|
-
return
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
const hasContent = parameter.schema === void 0 && parameter.content !== void 0;
|
|
23
|
+
return hasContent && context.options.fixes.has(outputFixes.FIX.PARAMETER_CONTENT);
|
|
24
|
+
}
|
|
25
|
+
function parameterType(parameter, location, context) {
|
|
26
|
+
if (isTypedByContent(parameter, context)) {
|
|
27
|
+
return contentParameterType(parameter, location, context);
|
|
20
28
|
}
|
|
21
29
|
return parameter.schema ? schemaTransform.transformSchema(parameter.schema, location, context) : constructors.irKeyword("string");
|
|
22
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameter.cjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"parameter.cjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ParameterObject,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A parameter typed by the schema of its one `content` media type. An `in: querystring` parameter\n * (OpenAPI 3.2) is the whole query string (ADR-020); without a media type it is `string`, the\n * query string as text. With the `parameter-content` fix, any other parameter with `content`\n * (OpenAPI 3.0 and later, for a JSON value in a query parameter) is typed the same way.\n */\nfunction contentParameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const [mediaType, entry] = Object.entries(parameter.content ?? {})[0] ?? [];\n if (mediaType === undefined || entry === undefined) {\n return irKeyword(\"string\");\n }\n const path = appendPointer(location.path, [\"content\", mediaType]);\n return contentEntryType(entry, { ...location, path }, context);\n}\n\nfunction isTypedByContent(parameter: ParameterObject, context: SchemaContext): boolean {\n if (parameter.in === QUERYSTRING_LOCATION) {\n return true;\n }\n const hasContent = parameter.schema === undefined && parameter.content !== undefined;\n return hasContent && context.options.fixes.has(FIX.PARAMETER_CONTENT);\n}\n\n/**\n * A parameter's type (OpenAPI 3.2 §4.8.12). Without a schema it is `string`, not `unknown`:\n * query, path, header and cookie values all arrive as text. `content` is read for\n * `in: querystring`, and with the `parameter-content` fix for every parameter; without the fix\n * other parameters with `content` keep the original's `string`.\n */\nexport function parameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (isTypedByContent(parameter, context)) {\n return contentParameterType(parameter, location, context);\n }\n return parameter.schema\n ? transformSchema(parameter.schema, location, context)\n : irKeyword(\"string\");\n}\n"],"names":["mediaType","irKeyword","appendPointer","contentEntryType","QUERYSTRING_LOCATION","FIX","transformSchema"],"mappings":";;;;;;;;;AAkBA,SAAS,oBAAA,CACP,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,CAACA,WAAA,EAAW,KAAK,CAAA,GAAI,MAAA,CAAO,OAAA,CAAQ,SAAA,CAAU,OAAA,IAAW,EAAE,CAAA,CAAE,CAAC,KAAK,EAAC;AAC1E,EAAA,IAAIA,WAAA,KAAc,MAAA,IAAa,KAAA,KAAU,MAAA,EAAW;AAClD,IAAA,OAAOC,uBAAU,QAAQ,CAAA;AAAA,EAC3B;AACA,EAAA,MAAM,OAAOC,yBAAA,CAAc,QAAA,CAAS,MAAM,CAAC,SAAA,EAAWF,WAAS,CAAC,CAAA;AAChE,EAAA,OAAOG,2BAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AAC/D;AAEA,SAAS,gBAAA,CAAiB,WAA4B,OAAA,EAAiC;AACrF,EAAA,IAAI,SAAA,CAAU,OAAOC,oCAAA,EAAsB;AACzC,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,UAAA,GAAa,SAAA,CAAU,MAAA,KAAW,MAAA,IAAa,UAAU,OAAA,KAAY,MAAA;AAC3E,EAAA,OAAO,cAAc,OAAA,CAAQ,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAIC,gBAAI,iBAAiB,CAAA;AACtE;AAQO,SAAS,aAAA,CACd,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,gBAAA,CAAiB,SAAA,EAAW,OAAO,CAAA,EAAG;AACxC,IAAA,OAAO,oBAAA,CAAqB,SAAA,EAAW,QAAA,EAAU,OAAO,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,SAAA,CAAU,SACbC,+BAAA,CAAgB,SAAA,CAAU,QAAQ,QAAA,EAAU,OAAO,CAAA,GACnDL,sBAAA,CAAU,QAAQ,CAAA;AACxB;;"}
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { irKeyword } from '../../../domain/ir/constructors.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { appendPointer } from '../../../domain/openapi/json-pointer.mjs';
|
|
3
3
|
import { QUERYSTRING_LOCATION } from '../../../domain/openapi/parameter-object.mjs';
|
|
4
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
4
5
|
import { transformSchema } from '../schema/schema-transform.mjs';
|
|
5
6
|
import { contentEntryType } from './media-type.mjs';
|
|
6
7
|
|
|
7
|
-
function
|
|
8
|
+
function contentParameterType(parameter, location, context) {
|
|
8
9
|
const [mediaType, entry] = Object.entries(parameter.content ?? {})[0] ?? [];
|
|
9
10
|
if (mediaType === void 0 || entry === void 0) {
|
|
10
11
|
return irKeyword("string");
|
|
11
12
|
}
|
|
12
|
-
const path =
|
|
13
|
+
const path = appendPointer(location.path, ["content", mediaType]);
|
|
13
14
|
return contentEntryType(entry, { ...location, path }, context);
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
+
function isTypedByContent(parameter, context) {
|
|
16
17
|
if (parameter.in === QUERYSTRING_LOCATION) {
|
|
17
|
-
return
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
const hasContent = parameter.schema === void 0 && parameter.content !== void 0;
|
|
21
|
+
return hasContent && context.options.fixes.has(FIX.PARAMETER_CONTENT);
|
|
22
|
+
}
|
|
23
|
+
function parameterType(parameter, location, context) {
|
|
24
|
+
if (isTypedByContent(parameter, context)) {
|
|
25
|
+
return contentParameterType(parameter, location, context);
|
|
18
26
|
}
|
|
19
27
|
return parameter.schema ? transformSchema(parameter.schema, location, context) : irKeyword("string");
|
|
20
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameter.mjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"parameter.mjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ParameterObject,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A parameter typed by the schema of its one `content` media type. An `in: querystring` parameter\n * (OpenAPI 3.2) is the whole query string (ADR-020); without a media type it is `string`, the\n * query string as text. With the `parameter-content` fix, any other parameter with `content`\n * (OpenAPI 3.0 and later, for a JSON value in a query parameter) is typed the same way.\n */\nfunction contentParameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const [mediaType, entry] = Object.entries(parameter.content ?? {})[0] ?? [];\n if (mediaType === undefined || entry === undefined) {\n return irKeyword(\"string\");\n }\n const path = appendPointer(location.path, [\"content\", mediaType]);\n return contentEntryType(entry, { ...location, path }, context);\n}\n\nfunction isTypedByContent(parameter: ParameterObject, context: SchemaContext): boolean {\n if (parameter.in === QUERYSTRING_LOCATION) {\n return true;\n }\n const hasContent = parameter.schema === undefined && parameter.content !== undefined;\n return hasContent && context.options.fixes.has(FIX.PARAMETER_CONTENT);\n}\n\n/**\n * A parameter's type (OpenAPI 3.2 §4.8.12). Without a schema it is `string`, not `unknown`:\n * query, path, header and cookie values all arrive as text. `content` is read for\n * `in: querystring`, and with the `parameter-content` fix for every parameter; without the fix\n * other parameters with `content` keep the original's `string`.\n */\nexport function parameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (isTypedByContent(parameter, context)) {\n return contentParameterType(parameter, location, context);\n }\n return parameter.schema\n ? transformSchema(parameter.schema, location, context)\n : irKeyword(\"string\");\n}\n"],"names":[],"mappings":";;;;;;;AAkBA,SAAS,oBAAA,CACP,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,CAAC,SAAA,EAAW,KAAK,CAAA,GAAI,MAAA,CAAO,OAAA,CAAQ,SAAA,CAAU,OAAA,IAAW,EAAE,CAAA,CAAE,CAAC,KAAK,EAAC;AAC1E,EAAA,IAAI,SAAA,KAAc,MAAA,IAAa,KAAA,KAAU,MAAA,EAAW;AAClD,IAAA,OAAO,UAAU,QAAQ,CAAA;AAAA,EAC3B;AACA,EAAA,MAAM,OAAO,aAAA,CAAc,QAAA,CAAS,MAAM,CAAC,SAAA,EAAW,SAAS,CAAC,CAAA;AAChE,EAAA,OAAO,iBAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AAC/D;AAEA,SAAS,gBAAA,CAAiB,WAA4B,OAAA,EAAiC;AACrF,EAAA,IAAI,SAAA,CAAU,OAAO,oBAAA,EAAsB;AACzC,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,UAAA,GAAa,SAAA,CAAU,MAAA,KAAW,MAAA,IAAa,UAAU,OAAA,KAAY,MAAA;AAC3E,EAAA,OAAO,cAAc,OAAA,CAAQ,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAI,IAAI,iBAAiB,CAAA;AACtE;AAQO,SAAS,aAAA,CACd,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,gBAAA,CAAiB,SAAA,EAAW,OAAO,CAAA,EAAG;AACxC,IAAA,OAAO,oBAAA,CAAqB,SAAA,EAAW,QAAA,EAAU,OAAO,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,SAAA,CAAU,SACb,eAAA,CAAgB,SAAA,CAAU,QAAQ,QAAA,EAAU,OAAO,CAAA,GACnD,SAAA,CAAU,QAAQ,CAAA;AACxB;;"}
|
|
@@ -5,15 +5,13 @@ const propertyName = require('../../../domain/ir/property-name.cjs');
|
|
|
5
5
|
const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
|
|
6
6
|
const parameterObject = require('../../../domain/openapi/parameter-object.cjs');
|
|
7
7
|
const outputFixes = require('../../../domain/output-fixes.cjs');
|
|
8
|
-
const refType = require('../ref-type.cjs');
|
|
9
8
|
const schemaComment = require('../schema-comment.cjs');
|
|
10
9
|
const explodedQuery = require('./exploded-query.cjs');
|
|
11
10
|
const parameter = require('./parameter.cjs');
|
|
11
|
+
const parameterEntries = require('./parameter-entries.cjs');
|
|
12
|
+
const referencedParameter = require('./referenced-parameter.cjs');
|
|
12
13
|
|
|
13
14
|
const PATH_TEMPLATE_RE = /\{([^{}]+)\}/g;
|
|
14
|
-
function resolveParameter(parameter, context) {
|
|
15
|
-
return "$ref" in parameter ? context.refs.resolve(parameter.$ref) : parameter;
|
|
16
|
-
}
|
|
17
15
|
function pathTemplateParameters(path) {
|
|
18
16
|
return (path.match(PATH_TEMPLATE_RE) ?? []).map((match) => ({
|
|
19
17
|
name: match.slice(1, -1),
|
|
@@ -29,7 +27,7 @@ function withPathTemplateParameters(parameters, location, context) {
|
|
|
29
27
|
}
|
|
30
28
|
for (const parameter of pathTemplateParameters(location.path)) {
|
|
31
29
|
const isDefined = result.some((candidate) => {
|
|
32
|
-
const resolved = resolveParameter(candidate, context);
|
|
30
|
+
const resolved = parameterEntries.resolveParameter(candidate, context.refs);
|
|
33
31
|
return resolved?.in === "path" && resolved.name === parameter.name;
|
|
34
32
|
});
|
|
35
33
|
if (!isDefined) {
|
|
@@ -38,33 +36,12 @@ function withPathTemplateParameters(parameters, location, context) {
|
|
|
38
36
|
}
|
|
39
37
|
return result;
|
|
40
38
|
}
|
|
41
|
-
function isDeprecatedParameter(parameter) {
|
|
42
|
-
const schema = parameter?.schema;
|
|
43
|
-
return Boolean(parameter?.deprecated || schema?.deprecated);
|
|
44
|
-
}
|
|
45
|
-
function parameterEntries(parameters, context) {
|
|
46
|
-
const entries = parameters.map((original) => ({
|
|
47
|
-
original,
|
|
48
|
-
resolved: resolveParameter(original, context)
|
|
49
|
-
}));
|
|
50
|
-
if (context.options.alphabetize) {
|
|
51
|
-
entries.sort(
|
|
52
|
-
(left, right) => (left.resolved?.name ?? "").localeCompare(right.resolved?.name ?? "")
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return context.options.excludeDeprecated ? entries.filter(({ resolved }) => !isDeprecatedParameter(resolved)) : entries;
|
|
56
|
-
}
|
|
57
39
|
function parameterName(name) {
|
|
58
40
|
return typeof name === "string" || typeof name === "number" ? propertyName.toPropertyName(name) : { kind: "string", value: String(name) };
|
|
59
41
|
}
|
|
60
|
-
function referencedParameterType(ref, resolved) {
|
|
61
|
-
const isParameter = !resolved.$ref;
|
|
62
|
-
const parameter = isParameter ? { in: resolved.in, name: resolved.name } : null;
|
|
63
|
-
return refType.refType(ref, { parameter });
|
|
64
|
-
}
|
|
65
42
|
function entryType({ original, resolved }, location, context) {
|
|
66
|
-
const path = jsonPointer.
|
|
67
|
-
return "$ref" in original ? referencedParameterType(original.$ref, resolved) : parameter.parameterType(resolved, { ...location, path }, context);
|
|
43
|
+
const path = jsonPointer.appendPointer(location.path, ["parameters", resolved.in, resolved.name]);
|
|
44
|
+
return "$ref" in original ? referencedParameter.referencedParameterType(original.$ref, resolved, context) : parameter.parameterType(resolved, { ...location, path }, context);
|
|
68
45
|
}
|
|
69
46
|
function parameterMember(entry, location, context) {
|
|
70
47
|
const { resolved } = entry;
|
|
@@ -88,7 +65,7 @@ function querystringMember(entries, location, context) {
|
|
|
88
65
|
return schemaComment.withSchemaComment(property, querystring.resolved);
|
|
89
66
|
}
|
|
90
67
|
function isExplodedEntry(entry, context) {
|
|
91
|
-
return context.options.fixes.has(outputFixes.
|
|
68
|
+
return context.options.fixes.has(outputFixes.FIX.EXPLODED_QUERY_OBJECTS) && explodedQuery.isExplodedQueryObject(entry.resolved, context.refs);
|
|
92
69
|
}
|
|
93
70
|
function explodedPart(entry, location, context) {
|
|
94
71
|
const type = entryType(entry, location, context);
|
|
@@ -129,7 +106,7 @@ function locationMember(parameterIn, entries, location, context) {
|
|
|
129
106
|
});
|
|
130
107
|
}
|
|
131
108
|
function parametersMember(parameters, location, context) {
|
|
132
|
-
const entries = parameterEntries(
|
|
109
|
+
const entries = parameterEntries.parameterEntries(
|
|
133
110
|
withPathTemplateParameters(parameters, location, context),
|
|
134
111
|
context
|
|
135
112
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameters.cjs","sources":["../../../../src/application/transform/document/parameters.ts"],"sourcesContent":["import {\n irIntersection,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertyName, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n PARAMETER_LOCATIONS,\n type ParameterLocation,\n type ParameterObject,\n type ParameterOrReference,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { isExplodedQueryObject } from \"./exploded-query.js\";\nimport { parameterType } from \"./parameter.js\";\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_TEMPLATE_RE = /\\{([^{}]+)\\}/g;\n\n/** A parameter as written in the document, and the object its `$ref` points to. */\ninterface ParameterEntry {\n readonly original: ParameterOrReference;\n readonly resolved: ParameterObject | undefined;\n}\n\n/** An entry whose `$ref` resolved, so its location and name are known. */\ntype ResolvedEntry = ParameterEntry & { readonly resolved: ParameterObject };\n\nfunction resolveParameter(\n parameter: ParameterOrReference,\n context: TransformContext,\n): ParameterObject | undefined {\n return \"$ref\" in parameter\n ? (context.refs.resolve(parameter.$ref) as ParameterObject | undefined)\n : parameter;\n}\n\n/** Required string parameters for every `{name}` in a path template. */\nfunction pathTemplateParameters(path: string): ParameterObject[] {\n return (path.match(PATH_TEMPLATE_RE) ?? []).map((match) => ({\n name: match.slice(1, -1),\n in: \"path\",\n required: true,\n schema: { type: \"string\" },\n }));\n}\n\n/** `--generate-path-params`: add the path template parameters the list does not define. */\nfunction withPathTemplateParameters(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): ParameterOrReference[] {\n const result = [...parameters];\n if (!context.options.generatePathParams || !location.path) {\n return result;\n }\n for (const parameter of pathTemplateParameters(location.path)) {\n const isDefined = result.some((candidate) => {\n const resolved = resolveParameter(candidate, context);\n return resolved?.in === \"path\" && resolved.name === parameter.name;\n });\n if (!isDefined) {\n result.push(parameter);\n }\n }\n return result;\n}\n\nfunction isDeprecatedParameter(parameter: ParameterObject | undefined): boolean {\n const schema = parameter?.schema as SchemaObject | undefined;\n return Boolean(parameter?.deprecated || schema?.deprecated);\n}\n\n/** Resolved parameters, sorted for `--alphabetize`, without deprecated ones if excluded. */\nfunction parameterEntries(\n parameters: readonly ParameterOrReference[],\n context: TransformContext,\n): ParameterEntry[] {\n const entries = parameters.map((original) => ({\n original,\n resolved: resolveParameter(original, context),\n }));\n if (context.options.alphabetize) {\n // Unlike map keys, the original sorts parameters with the default locale's `localeCompare`.\n entries.sort((left, right) =>\n (left.resolved?.name ?? \"\").localeCompare(right.resolved?.name ?? \"\"),\n );\n }\n return context.options.excludeDeprecated\n ? entries.filter(({ resolved }) => !isDeprecatedParameter(resolved))\n : entries;\n}\n\n/** The original quotes a name that is not text (a missing name prints as `\"undefined\"`). */\nfunction parameterName(name: unknown): IrPropertyName {\n return typeof name === \"string\" || typeof name === \"number\"\n ? toPropertyName(name)\n : { kind: \"string\", value: String(name) };\n}\n\nfunction referencedParameterType(ref: string, resolved: ParameterObject): IrType {\n // A `$ref` that resolves to another `$ref` is not a parameter object yet: index it as a path.\n const isParameter = !(resolved as { $ref?: unknown }).$ref;\n const parameter = isParameter ? { in: resolved.in, name: resolved.name } : null;\n return refType(ref, { parameter });\n}\n\nfunction entryType(\n { original, resolved }: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const path = createRef([location.path, \"parameters\", resolved.in, resolved.name]);\n return \"$ref\" in original\n ? referencedParameterType(original.$ref, resolved)\n : parameterType(resolved, { ...location, path }, context);\n}\n\nfunction parameterMember(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const { resolved } = entry;\n const property = irProperty(parameterName(resolved.name), entryType(entry, location, context), {\n isOptional: resolved.in !== \"path\" && !resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, resolved);\n}\n\n/**\n * The `query` member typed by an `in: querystring` parameter (OpenAPI 3.2, ADR-020): the parameter\n * is the whole query string. Null when there is none, or when `in: query` parameters sit next to\n * it, which 3.2 does not allow; those keep their types, and a warning names the parameter.\n */\nfunction querystringMember(\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const querystring = entries.find(\n (entry): entry is ResolvedEntry => entry.resolved?.in === QUERYSTRING_LOCATION,\n );\n if (!querystring || entries.some((entry) => entry.resolved?.in === \"query\")) {\n return null;\n }\n const property = irProperty(toPropertyName(\"query\"), entryType(querystring, location, context), {\n isOptional: !querystring.resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, querystring.resolved);\n}\n\n/** With `exploded-query-objects`, whether the parameter's object keys are keys of `query`. */\nfunction isExplodedEntry(entry: ResolvedEntry, context: TransformContext): boolean {\n return (\n context.options.fixes.has(OutputFix.EXPLODED_QUERY_OBJECTS) &&\n isExplodedQueryObject(entry.resolved, context.refs)\n );\n}\n\n/**\n * An exploded object parameter's part of `query`: its object type. A parameter that may be left\n * out sends none of its keys then, so they are optional: `Partial<…>`.\n */\nfunction explodedPart(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const type = entryType(entry, location, context);\n return entry.resolved.required ? type : irReference(\"Partial\", [type]);\n}\n\n/** A location's parameters as members, and the object types of its exploded parameters. */\ninterface LocationParts {\n readonly members: readonly IrPropertySignature[];\n readonly exploded: readonly IrType[];\n readonly isOptional: boolean;\n}\n\n/** Each parameter in document order, so the declarations they add keep their order. */\nfunction locationParts(\n entries: readonly ResolvedEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): LocationParts {\n const members: IrPropertySignature[] = [];\n const exploded: IrType[] = [];\n let isOptional = true;\n for (const entry of entries) {\n if (isExplodedEntry(entry, context)) {\n exploded.push(explodedPart(entry, location, context));\n isOptional &&= !entry.resolved.required;\n continue;\n }\n const member = parameterMember(entry, location, context);\n members.push(member);\n isOptional &&= member.isOptional;\n }\n return { members, exploded, isOptional };\n}\n\n/** The members' object, intersected with the exploded parameters' types; `never` for none. */\nfunction locationType({ members, exploded }: LocationParts): IrType {\n const types = [...(members.length > 0 ? [irObject(members)] : []), ...exploded];\n const [first] = types;\n if (first === undefined) {\n return irKeyword(\"never\");\n }\n return types.length === 1 ? first : irIntersection(types);\n}\n\n/** One location's parameters; optional when all of them are, and `never` when there are none. */\nfunction locationMember(\n parameterIn: ParameterLocation,\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const located = entries.filter(\n (entry): entry is ResolvedEntry => entry.resolved?.in === parameterIn,\n );\n const parts = locationParts(located, location, context);\n return irProperty(toPropertyName(parameterIn), locationType(parts), {\n isOptional: parts.isOptional,\n isReadonly: context.options.immutable,\n });\n}\n\n/**\n * The `parameters` property of an operation or path item: one member per location, each an object\n * of that location's parameters. `location.path` is the path template for\n * `--generate-path-params`.\n */\nexport function parametersMember(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const entries = parameterEntries(\n withPathTemplateParameters(parameters, location, context),\n context,\n );\n const querystring = querystringMember(entries, location, context);\n const members = PARAMETER_LOCATIONS.map((parameterIn) =>\n parameterIn === \"query\" && querystring\n ? querystring\n : locationMember(parameterIn, entries, location, context),\n );\n return irProperty(toPropertyName(\"parameters\"), irObject(members), {\n isReadonly: context.options.immutable,\n });\n}\n"],"names":["toPropertyName","refType","createRef","parameterType","irProperty","withSchemaComment","QUERYSTRING_LOCATION","OutputFix","isExplodedQueryObject","irReference","irObject","irKeyword","irIntersection","PARAMETER_LOCATIONS"],"mappings":";;;;;;;;;;;;AA2BA,MAAM,gBAAA,GAAmB,eAAA;AAWzB,SAAS,gBAAA,CACP,WACA,OAAA,EAC6B;AAC7B,EAAA,OAAO,UAAU,SAAA,GACZ,OAAA,CAAQ,KAAK,OAAA,CAAQ,SAAA,CAAU,IAAI,CAAA,GACpC,SAAA;AACN;AAGA,SAAS,uBAAuB,IAAA,EAAiC;AAC/D,EAAA,OAAA,CAAQ,IAAA,CAAK,MAAM,gBAAgB,CAAA,IAAK,EAAC,EAAG,GAAA,CAAI,CAAC,KAAA,MAAW;AAAA,IAC1D,IAAA,EAAM,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,IACvB,EAAA,EAAI,MAAA;AAAA,IACJ,QAAA,EAAU,IAAA;AAAA,IACV,MAAA,EAAQ,EAAE,IAAA,EAAM,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CAAQ;AAAA,GAC7B,CAAA;AACH;;"}
|
|
1
|
+
{"version":3,"file":"parameters.cjs","sources":["../../../../src/application/transform/document/parameters.ts"],"sourcesContent":["import {\n irIntersection,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertyName, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n PARAMETER_LOCATIONS,\n type ParameterLocation,\n type ParameterObject,\n type ParameterOrReference,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { isExplodedQueryObject } from \"./exploded-query.js\";\nimport { parameterType } from \"./parameter.js\";\nimport {\n type ParameterEntry,\n parameterEntries,\n type ResolvedEntry,\n resolveParameter,\n} from \"./parameter-entries.js\";\nimport { referencedParameterType } from \"./referenced-parameter.js\";\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_TEMPLATE_RE = /\\{([^{}]+)\\}/g;\n\n/** Required string parameters for every `{name}` in a path template. */\nfunction pathTemplateParameters(path: string): ParameterObject[] {\n return (path.match(PATH_TEMPLATE_RE) ?? []).map((match) => ({\n name: match.slice(1, -1),\n in: \"path\",\n required: true,\n schema: { type: \"string\" },\n }));\n}\n\n/** `--generate-path-params`: add the path template parameters the list does not define. */\nfunction withPathTemplateParameters(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): ParameterOrReference[] {\n const result = [...parameters];\n if (!context.options.generatePathParams || !location.path) {\n return result;\n }\n for (const parameter of pathTemplateParameters(location.path)) {\n const isDefined = result.some((candidate) => {\n const resolved = resolveParameter(candidate, context.refs);\n return resolved?.in === \"path\" && resolved.name === parameter.name;\n });\n if (!isDefined) {\n result.push(parameter);\n }\n }\n return result;\n}\n\n/** The original quotes a name that is not text (a missing name prints as `\"undefined\"`). */\nfunction parameterName(name: unknown): IrPropertyName {\n return typeof name === \"string\" || typeof name === \"number\"\n ? toPropertyName(name)\n : { kind: \"string\", value: String(name) };\n}\n\nfunction entryType(\n { original, resolved }: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const path = appendPointer(location.path, [\"parameters\", resolved.in, resolved.name]);\n return \"$ref\" in original\n ? referencedParameterType(original.$ref, resolved, context)\n : parameterType(resolved, { ...location, path }, context);\n}\n\nfunction parameterMember(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const { resolved } = entry;\n const property = irProperty(parameterName(resolved.name), entryType(entry, location, context), {\n isOptional: resolved.in !== \"path\" && !resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, resolved);\n}\n\n/**\n * The `query` member typed by an `in: querystring` parameter (OpenAPI 3.2, ADR-020): the parameter\n * is the whole query string. Null when there is none, or when `in: query` parameters sit next to\n * it, which 3.2 does not allow; those keep their types, and a warning names the parameter.\n */\nfunction querystringMember(\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const querystring = entries.find(\n (entry): entry is ResolvedEntry => entry.resolved?.in === QUERYSTRING_LOCATION,\n );\n if (!querystring || entries.some((entry) => entry.resolved?.in === \"query\")) {\n return null;\n }\n const property = irProperty(toPropertyName(\"query\"), entryType(querystring, location, context), {\n isOptional: !querystring.resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, querystring.resolved);\n}\n\n/** With `exploded-query-objects`, whether the parameter's object keys are keys of `query`. */\nfunction isExplodedEntry(entry: ResolvedEntry, context: TransformContext): boolean {\n return (\n context.options.fixes.has(FIX.EXPLODED_QUERY_OBJECTS) &&\n isExplodedQueryObject(entry.resolved, context.refs)\n );\n}\n\n/**\n * An exploded object parameter's part of `query`: its object type. A parameter that may be left\n * out sends none of its keys then, so they are optional: `Partial<…>`.\n */\nfunction explodedPart(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const type = entryType(entry, location, context);\n return entry.resolved.required ? type : irReference(\"Partial\", [type]);\n}\n\n/** A location's parameters as members, and the object types of its exploded parameters. */\ninterface LocationParts {\n readonly members: readonly IrPropertySignature[];\n readonly exploded: readonly IrType[];\n readonly isOptional: boolean;\n}\n\n/** Each parameter in document order, so the declarations they add keep their order. */\nfunction locationParts(\n entries: readonly ResolvedEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): LocationParts {\n const members: IrPropertySignature[] = [];\n const exploded: IrType[] = [];\n let isOptional = true;\n for (const entry of entries) {\n if (isExplodedEntry(entry, context)) {\n exploded.push(explodedPart(entry, location, context));\n isOptional &&= !entry.resolved.required;\n continue;\n }\n const member = parameterMember(entry, location, context);\n members.push(member);\n isOptional &&= member.isOptional;\n }\n return { members, exploded, isOptional };\n}\n\n/** The members' object, intersected with the exploded parameters' types; `never` for none. */\nfunction locationType({ members, exploded }: LocationParts): IrType {\n const types = [...(members.length > 0 ? [irObject(members)] : []), ...exploded];\n const [first] = types;\n if (first === undefined) {\n return irKeyword(\"never\");\n }\n return types.length === 1 ? first : irIntersection(types);\n}\n\n/** One location's parameters; optional when all of them are, and `never` when there are none. */\nfunction locationMember(\n parameterIn: ParameterLocation,\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const located = entries.filter(\n (entry): entry is ResolvedEntry => entry.resolved?.in === parameterIn,\n );\n const parts = locationParts(located, location, context);\n return irProperty(toPropertyName(parameterIn), locationType(parts), {\n isOptional: parts.isOptional,\n isReadonly: context.options.immutable,\n });\n}\n\n/**\n * The `parameters` property of an operation or path item: one member per location, each an object\n * of that location's parameters. `location.path` is the path template for\n * `--generate-path-params`.\n */\nexport function parametersMember(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const entries = parameterEntries(\n withPathTemplateParameters(parameters, location, context),\n context,\n );\n const querystring = querystringMember(entries, location, context);\n const members = PARAMETER_LOCATIONS.map((parameterIn) =>\n parameterIn === \"query\" && querystring\n ? querystring\n : locationMember(parameterIn, entries, location, context),\n );\n return irProperty(toPropertyName(\"parameters\"), irObject(members), {\n isReadonly: context.options.immutable,\n });\n}\n"],"names":["resolveParameter","toPropertyName","appendPointer","referencedParameterType","parameterType","irProperty","withSchemaComment","QUERYSTRING_LOCATION","FIX","isExplodedQueryObject","irReference","irObject","irKeyword","irIntersection","parameterEntries","PARAMETER_LOCATIONS"],"mappings":";;;;;;;;;;;;;AAgCA,MAAM,gBAAA,GAAmB,eAAA;AAGzB,SAAS,uBAAuB,IAAA,EAAiC;AAC/D,EAAA,OAAA,CAAQ,IAAA,CAAK,MAAM,gBAAgB,CAAA,IAAK,EAAC,EAAG,GAAA,CAAI,CAAC,KAAA,MAAW;AAAA,IAC1D,IAAA,EAAM,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,IACvB,EAAA,EAAI,MAAA;AAAA,IACJ,QAAA,EAAU,IAAA;AAAA,IACV,MAAA,EAAQ,EAAE,IAAA,EAAM,QAAA;AAAS,GAC3B,CAAE,CAAA;AACJ;AAGA,SAAS,0BAAA,CACP,UAAA,EACA,QAAA,EACA,OAAA,EACwB;AACxB,EAAA,MAAM,MAAA,GAAS,CAAC,GAAG,UAAU,CAAA;AAC7B,EAAA,IAAI,CAAC,OAAA,CAAQ,OAAA,CAAQ,kBAAA,IAAsB,CAAC,SAAS,IAAA,EAAM;AACzD,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,KAAA,MAAW,SAAA,IAAa,sBAAA,CAAuB,QAAA,CAAS,IAAI,CAAA,EAAG;AAC7D,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,C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qB;AACrB,EAAA,MAAM,UAAU,OAAA,CAAQ,MAAA;AAAA,IACtB,CAAC,KAAA,KAAkC,KAAA,CAAM,QAAA,EAAU,EAAA,KAAO;AAAA,GAC5D;AACA,EAAA,MAAM,KAAA,GAAQ,aAAA,CAAc,OAAA,EAAS,QAAA,EAAU,OAAO,CAAA;AACtD,EAAA,OAAOR,wBAAWJ,2BAAA,CAAe,WAAW,CAAA,EAAG,YAAA,CAAa,KAAK,CAAA,EAAG;AAAA,IAClE,YAAY,KAAA,CAAM,UAAA;AAAA,IAClB,UAAA,EAAY,QAAQ,OAAA,CAAQ;AAAA,GAC7B,CAAA;AACH;AAOO,SAAS,gBAAA,CACd,UAAA,EACA,QAAA,EACA,OAAA,EACqB;AACrB,EAAA,MAAM,OAAA,GAAUa,iCAAA;AAAA,IACd,0BAAA,CAA2B,UAAA,EAAY,QAAA,EAAU,OAAO,CAAA;AAAA,IACxD;AAAA,GACF;AACA,EAAA,MAAM,WAAA,GAAc,iBAAA,CAAkB,OAAA,EAAS,QAAA,EAAU,OAAO,CAAA;AAChE,EAAA,MAAM,UAAUC,mCAAA,CAAoB,GAAA;AAAA,IAAI,CAAC,WAAA,KACvC,WAAA,KAAgB,OAAA,IAAW,WAAA,GACvB,cACA,cAAA,CAAe,WAAA,EAAa,OAAA,EAAS,QAAA,EAAU,OAAO;AAAA,GAC5D;AACA,EAAA,OAAOV,wBAAWJ,2BAAA,CAAe,YAAY,CAAA,EAAGU,qBAAA,CAAS,OAAO,CAAA,EAAG;AAAA,IACjE,UAAA,EAAY,QAAQ,OAAA,CAAQ;AAAA,GAC7B,CAAA;AACH;;"}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { irProperty, irObject, irKeyword, irIntersection, irReference } from '../../../domain/ir/constructors.mjs';
|
|
2
2
|
import { toPropertyName } from '../../../domain/ir/property-name.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { appendPointer } from '../../../domain/openapi/json-pointer.mjs';
|
|
4
4
|
import { PARAMETER_LOCATIONS, QUERYSTRING_LOCATION } from '../../../domain/openapi/parameter-object.mjs';
|
|
5
|
-
import {
|
|
6
|
-
import { refType } from '../ref-type.mjs';
|
|
5
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
7
6
|
import { withSchemaComment } from '../schema-comment.mjs';
|
|
8
7
|
import { isExplodedQueryObject } from './exploded-query.mjs';
|
|
9
8
|
import { parameterType } from './parameter.mjs';
|
|
9
|
+
import { parameterEntries, resolveParameter } from './parameter-entries.mjs';
|
|
10
|
+
import { referencedParameterType } from './referenced-parameter.mjs';
|
|
10
11
|
|
|
11
12
|
const PATH_TEMPLATE_RE = /\{([^{}]+)\}/g;
|
|
12
|
-
function resolveParameter(parameter, context) {
|
|
13
|
-
return "$ref" in parameter ? context.refs.resolve(parameter.$ref) : parameter;
|
|
14
|
-
}
|
|
15
13
|
function pathTemplateParameters(path) {
|
|
16
14
|
return (path.match(PATH_TEMPLATE_RE) ?? []).map((match) => ({
|
|
17
15
|
name: match.slice(1, -1),
|
|
@@ -27,7 +25,7 @@ function withPathTemplateParameters(parameters, location, context) {
|
|
|
27
25
|
}
|
|
28
26
|
for (const parameter of pathTemplateParameters(location.path)) {
|
|
29
27
|
const isDefined = result.some((candidate) => {
|
|
30
|
-
const resolved = resolveParameter(candidate, context);
|
|
28
|
+
const resolved = resolveParameter(candidate, context.refs);
|
|
31
29
|
return resolved?.in === "path" && resolved.name === parameter.name;
|
|
32
30
|
});
|
|
33
31
|
if (!isDefined) {
|
|
@@ -36,33 +34,12 @@ function withPathTemplateParameters(parameters, location, context) {
|
|
|
36
34
|
}
|
|
37
35
|
return result;
|
|
38
36
|
}
|
|
39
|
-
function isDeprecatedParameter(parameter) {
|
|
40
|
-
const schema = parameter?.schema;
|
|
41
|
-
return Boolean(parameter?.deprecated || schema?.deprecated);
|
|
42
|
-
}
|
|
43
|
-
function parameterEntries(parameters, context) {
|
|
44
|
-
const entries = parameters.map((original) => ({
|
|
45
|
-
original,
|
|
46
|
-
resolved: resolveParameter(original, context)
|
|
47
|
-
}));
|
|
48
|
-
if (context.options.alphabetize) {
|
|
49
|
-
entries.sort(
|
|
50
|
-
(left, right) => (left.resolved?.name ?? "").localeCompare(right.resolved?.name ?? "")
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
return context.options.excludeDeprecated ? entries.filter(({ resolved }) => !isDeprecatedParameter(resolved)) : entries;
|
|
54
|
-
}
|
|
55
37
|
function parameterName(name) {
|
|
56
38
|
return typeof name === "string" || typeof name === "number" ? toPropertyName(name) : { kind: "string", value: String(name) };
|
|
57
39
|
}
|
|
58
|
-
function referencedParameterType(ref, resolved) {
|
|
59
|
-
const isParameter = !resolved.$ref;
|
|
60
|
-
const parameter = isParameter ? { in: resolved.in, name: resolved.name } : null;
|
|
61
|
-
return refType(ref, { parameter });
|
|
62
|
-
}
|
|
63
40
|
function entryType({ original, resolved }, location, context) {
|
|
64
|
-
const path =
|
|
65
|
-
return "$ref" in original ? referencedParameterType(original.$ref, resolved) : parameterType(resolved, { ...location, path }, context);
|
|
41
|
+
const path = appendPointer(location.path, ["parameters", resolved.in, resolved.name]);
|
|
42
|
+
return "$ref" in original ? referencedParameterType(original.$ref, resolved, context) : parameterType(resolved, { ...location, path }, context);
|
|
66
43
|
}
|
|
67
44
|
function parameterMember(entry, location, context) {
|
|
68
45
|
const { resolved } = entry;
|
|
@@ -86,7 +63,7 @@ function querystringMember(entries, location, context) {
|
|
|
86
63
|
return withSchemaComment(property, querystring.resolved);
|
|
87
64
|
}
|
|
88
65
|
function isExplodedEntry(entry, context) {
|
|
89
|
-
return context.options.fixes.has(
|
|
66
|
+
return context.options.fixes.has(FIX.EXPLODED_QUERY_OBJECTS) && isExplodedQueryObject(entry.resolved, context.refs);
|
|
90
67
|
}
|
|
91
68
|
function explodedPart(entry, location, context) {
|
|
92
69
|
const type = entryType(entry, location, context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameters.mjs","sources":["../../../../src/application/transform/document/parameters.ts"],"sourcesContent":["import {\n irIntersection,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertyName, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n PARAMETER_LOCATIONS,\n type ParameterLocation,\n type ParameterObject,\n type ParameterOrReference,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { isExplodedQueryObject } from \"./exploded-query.js\";\nimport { parameterType } from \"./parameter.js\";\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_TEMPLATE_RE = /\\{([^{}]+)\\}/g;\n\n/** A parameter as written in the document, and the object its `$ref` points to. */\ninterface ParameterEntry {\n readonly original: ParameterOrReference;\n readonly resolved: ParameterObject | undefined;\n}\n\n/** An entry whose `$ref` resolved, so its location and name are known. */\ntype ResolvedEntry = ParameterEntry & { readonly resolved: ParameterObject };\n\nfunction resolveParameter(\n parameter: ParameterOrReference,\n context: TransformContext,\n): ParameterObject | undefined {\n return \"$ref\" in parameter\n ? (context.refs.resolve(parameter.$ref) as ParameterObject | undefined)\n : parameter;\n}\n\n/** Required string parameters for every `{name}` in a path template. */\nfunction pathTemplateParameters(path: string): ParameterObject[] {\n return (path.match(PATH_TEMPLATE_RE) ?? []).map((match) => ({\n name: match.slice(1, -1),\n in: \"path\",\n required: true,\n schema: { type: \"string\" },\n }));\n}\n\n/** `--generate-path-params`: add the path template parameters the list does not define. */\nfunction withPathTemplateParameters(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): ParameterOrReference[] {\n const result = [...parameters];\n if (!context.options.generatePathParams || !location.path) {\n return result;\n }\n for (const parameter of pathTemplateParameters(location.path)) {\n const isDefined = result.some((candidate) => {\n const resolved = resolveParameter(candidate, context);\n return resolved?.in === \"path\" && resolved.name === parameter.name;\n });\n if (!isDefined) {\n result.push(parameter);\n }\n }\n return result;\n}\n\nfunction isDeprecatedParameter(parameter: ParameterObject | undefined): boolean {\n const schema = parameter?.schema as SchemaObject | undefined;\n return Boolean(parameter?.deprecated || schema?.deprecated);\n}\n\n/** Resolved parameters, sorted for `--alphabetize`, without deprecated ones if excluded. */\nfunction parameterEntries(\n parameters: readonly ParameterOrReference[],\n context: TransformContext,\n): ParameterEntry[] {\n const entries = parameters.map((original) => ({\n original,\n resolved: resolveParameter(original, context),\n }));\n if (context.options.alphabetize) {\n // Unlike map keys, the original sorts parameters with the default locale's `localeCompare`.\n entries.sort((left, right) =>\n (left.resolved?.name ?? \"\").localeCompare(right.resolved?.name ?? \"\"),\n );\n }\n return context.options.excludeDeprecated\n ? entries.filter(({ resolved }) => !isDeprecatedParameter(resolved))\n : entries;\n}\n\n/** The original quotes a name that is not text (a missing name prints as `\"undefined\"`). */\nfunction parameterName(name: unknown): IrPropertyName {\n return typeof name === \"string\" || typeof name === \"number\"\n ? toPropertyName(name)\n : { kind: \"string\", value: String(name) };\n}\n\nfunction referencedParameterType(ref: string, resolved: ParameterObject): IrType {\n // A `$ref` that resolves to another `$ref` is not a parameter object yet: index it as a path.\n const isParameter = !(resolved as { $ref?: unknown }).$ref;\n const parameter = isParameter ? { in: resolved.in, name: resolved.name } : null;\n return refType(ref, { parameter });\n}\n\nfunction entryType(\n { original, resolved }: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const path = createRef([location.path, \"parameters\", resolved.in, resolved.name]);\n return \"$ref\" in original\n ? referencedParameterType(original.$ref, resolved)\n : parameterType(resolved, { ...location, path }, context);\n}\n\nfunction parameterMember(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const { resolved } = entry;\n const property = irProperty(parameterName(resolved.name), entryType(entry, location, context), {\n isOptional: resolved.in !== \"path\" && !resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, resolved);\n}\n\n/**\n * The `query` member typed by an `in: querystring` parameter (OpenAPI 3.2, ADR-020): the parameter\n * is the whole query string. Null when there is none, or when `in: query` parameters sit next to\n * it, which 3.2 does not allow; those keep their types, and a warning names the parameter.\n */\nfunction querystringMember(\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const querystring = entries.find(\n (entry): entry is ResolvedEntry => entry.resolved?.in === QUERYSTRING_LOCATION,\n );\n if (!querystring || entries.some((entry) => entry.resolved?.in === \"query\")) {\n return null;\n }\n const property = irProperty(toPropertyName(\"query\"), entryType(querystring, location, context), {\n isOptional: !querystring.resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, querystring.resolved);\n}\n\n/** With `exploded-query-objects`, whether the parameter's object keys are keys of `query`. */\nfunction isExplodedEntry(entry: ResolvedEntry, context: TransformContext): boolean {\n return (\n context.options.fixes.has(OutputFix.EXPLODED_QUERY_OBJECTS) &&\n isExplodedQueryObject(entry.resolved, context.refs)\n );\n}\n\n/**\n * An exploded object parameter's part of `query`: its object type. A parameter that may be left\n * out sends none of its keys then, so they are optional: `Partial<…>`.\n */\nfunction explodedPart(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const type = entryType(entry, location, context);\n return entry.resolved.required ? type : irReference(\"Partial\", [type]);\n}\n\n/** A location's parameters as members, and the object types of its exploded parameters. */\ninterface LocationParts {\n readonly members: readonly IrPropertySignature[];\n readonly exploded: readonly IrType[];\n readonly isOptional: boolean;\n}\n\n/** Each parameter in document order, so the declarations they add keep their order. */\nfunction locationParts(\n entries: readonly ResolvedEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): LocationParts {\n const members: IrPropertySignature[] = [];\n const exploded: IrType[] = [];\n let isOptional = true;\n for (const entry of entries) {\n if (isExplodedEntry(entry, context)) {\n exploded.push(explodedPart(entry, location, context));\n isOptional &&= !entry.resolved.required;\n continue;\n }\n const member = parameterMember(entry, location, context);\n members.push(member);\n isOptional &&= member.isOptional;\n }\n return { members, exploded, isOptional };\n}\n\n/** The members' object, intersected with the exploded parameters' types; `never` for none. */\nfunction locationType({ members, exploded }: LocationParts): IrType {\n const types = [...(members.length > 0 ? [irObject(members)] : []), ...exploded];\n const [first] = types;\n if (first === undefined) {\n return irKeyword(\"never\");\n }\n return types.length === 1 ? first : irIntersection(types);\n}\n\n/** One location's parameters; optional when all of them are, and `never` when there are none. */\nfunction locationMember(\n parameterIn: ParameterLocation,\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const located = entries.filter(\n (entry): entry is ResolvedEntry => entry.resolved?.in === parameterIn,\n );\n const parts = locationParts(located, location, context);\n return irProperty(toPropertyName(parameterIn), locationType(parts), {\n isOptional: parts.isOptional,\n isReadonly: context.options.immutable,\n });\n}\n\n/**\n * The `parameters` property of an operation or path item: one member per location, each an object\n * of that location's parameters. `location.path` is the path template for\n * `--generate-path-params`.\n */\nexport function parametersMember(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const entries = parameterEntries(\n withPathTemplateParameters(parameters, location, context),\n context,\n );\n const querystring = querystringMember(entries, location, context);\n const members = PARAMETER_LOCATIONS.map((parameterIn) =>\n parameterIn === \"query\" && querystring\n ? querystring\n : locationMember(parameterIn, entries, location, context),\n );\n return irProperty(toPropertyName(\"parameters\"), irObject(members), {\n isReadonly: context.options.immutable,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;AA2BA,MAAM,gBAAA,GAAmB,eAAA;AAWzB,SAAS,gBAAA,CACP,WACA,OAAA,EA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;AACA,EAAA,MAAM,WAAA,GAAc,iBAAA,CAAkB,OAAA,EAAS,QAAA,EAAU,OAAO,CAAA;AAChE,EAAA,MAAM,UAAU,mBAAA,CAAoB,GAAA;AAAA,IAAI,CAAC,WAAA,KACvC,WAAA,KAAgB,OAAA,IAAW,WAAA,GACvB,cACA,cAAA,CAAe,WAAA,EAAa,OAAA,EAAS,QAAA,EAAU,OAAO;AAAA,GAC5D;AACA,EAAA,OAAO,WAAW,cAAA,CAAe,YAAY,CAAA,EAAG,QAAA,CAAS,OAAO,CAAA,EAAG;AAAA,IACjE,UAAA,EAAY,QAAQ,OAAA,CAAQ;AAAA,GAC7B,CAAA;AACH;;"}
|
|
1
|
+
{"version":3,"file":"parameters.mjs","sources":["../../../../src/application/transform/document/parameters.ts"],"sourcesContent":["import {\n irIntersection,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertyName, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n PARAMETER_LOCATIONS,\n type ParameterLocation,\n type ParameterObject,\n type ParameterOrReference,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { isExplodedQueryObject } from \"./exploded-query.js\";\nimport { parameterType } from \"./parameter.js\";\nimport {\n type ParameterEntry,\n parameterEntries,\n type ResolvedEntry,\n resolveParameter,\n} from \"./parameter-entries.js\";\nimport { referencedParameterType } from \"./referenced-parameter.js\";\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_TEMPLATE_RE = /\\{([^{}]+)\\}/g;\n\n/** Required string parameters for every `{name}` in a path template. */\nfunction pathTemplateParameters(path: string): ParameterObject[] {\n return (path.match(PATH_TEMPLATE_RE) ?? []).map((match) => ({\n name: match.slice(1, -1),\n in: \"path\",\n required: true,\n schema: { type: \"string\" },\n }));\n}\n\n/** `--generate-path-params`: add the path template parameters the list does not define. */\nfunction withPathTemplateParameters(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): ParameterOrReference[] {\n const result = [...parameters];\n if (!context.options.generatePathParams || !location.path) {\n return result;\n }\n for (const parameter of pathTemplateParameters(location.path)) {\n const isDefined = result.some((candidate) => {\n const resolved = resolveParameter(candidate, context.refs);\n return resolved?.in === \"path\" && resolved.name === parameter.name;\n });\n if (!isDefined) {\n result.push(parameter);\n }\n }\n return result;\n}\n\n/** The original quotes a name that is not text (a missing name prints as `\"undefined\"`). */\nfunction parameterName(name: unknown): IrPropertyName {\n return typeof name === \"string\" || typeof name === \"number\"\n ? toPropertyName(name)\n : { kind: \"string\", value: String(name) };\n}\n\nfunction entryType(\n { original, resolved }: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const path = appendPointer(location.path, [\"parameters\", resolved.in, resolved.name]);\n return \"$ref\" in original\n ? referencedParameterType(original.$ref, resolved, context)\n : parameterType(resolved, { ...location, path }, context);\n}\n\nfunction parameterMember(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const { resolved } = entry;\n const property = irProperty(parameterName(resolved.name), entryType(entry, location, context), {\n isOptional: resolved.in !== \"path\" && !resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, resolved);\n}\n\n/**\n * The `query` member typed by an `in: querystring` parameter (OpenAPI 3.2, ADR-020): the parameter\n * is the whole query string. Null when there is none, or when `in: query` parameters sit next to\n * it, which 3.2 does not allow; those keep their types, and a warning names the parameter.\n */\nfunction querystringMember(\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const querystring = entries.find(\n (entry): entry is ResolvedEntry => entry.resolved?.in === QUERYSTRING_LOCATION,\n );\n if (!querystring || entries.some((entry) => entry.resolved?.in === \"query\")) {\n return null;\n }\n const property = irProperty(toPropertyName(\"query\"), entryType(querystring, location, context), {\n isOptional: !querystring.resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, querystring.resolved);\n}\n\n/** With `exploded-query-objects`, whether the parameter's object keys are keys of `query`. */\nfunction isExplodedEntry(entry: ResolvedEntry, context: TransformContext): boolean {\n return (\n context.options.fixes.has(FIX.EXPLODED_QUERY_OBJECTS) &&\n isExplodedQueryObject(entry.resolved, context.refs)\n );\n}\n\n/**\n * An exploded object parameter's part of `query`: its object type. A parameter that may be left\n * out sends none of its keys then, so they are optional: `Partial<…>`.\n */\nfunction explodedPart(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const type = entryType(entry, location, context);\n return entry.resolved.required ? type : irReference(\"Partial\", [type]);\n}\n\n/** A location's parameters as members, and the object types of its exploded parameters. */\ninterface LocationParts {\n readonly members: readonly IrPropertySignature[];\n readonly exploded: readonly IrType[];\n readonly isOptional: boolean;\n}\n\n/** Each parameter in document order, so the declarations they add keep their order. */\nfunction locationParts(\n entries: readonly ResolvedEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): LocationParts {\n const members: IrPropertySignature[] = [];\n const exploded: IrType[] = [];\n let isOptional = true;\n for (const entry of entries) {\n if (isExplodedEntry(entry, context)) {\n exploded.push(explodedPart(entry, location, context));\n isOptional &&= !entry.resolved.required;\n continue;\n }\n const member = parameterMember(entry, location, context);\n members.push(member);\n isOptional &&= member.isOptional;\n }\n return { members, exploded, isOptional };\n}\n\n/** The members' object, intersected with the exploded parameters' types; `never` for none. */\nfunction locationType({ members, exploded }: LocationParts): IrType {\n const types = [...(members.length > 0 ? [irObject(members)] : []), ...exploded];\n const [first] = types;\n if (first === undefined) {\n return irKeyword(\"never\");\n }\n return types.length === 1 ? first : irIntersection(types);\n}\n\n/** One location's parameters; optional when all of them are, and `never` when there are none. */\nfunction locationMember(\n parameterIn: ParameterLocation,\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const located = entries.filter(\n (entry): entry is ResolvedEntry => entry.resolved?.in === parameterIn,\n );\n const parts = locationParts(located, location, context);\n return irProperty(toPropertyName(parameterIn), locationType(parts), {\n isOptional: parts.isOptional,\n isReadonly: context.options.immutable,\n });\n}\n\n/**\n * The `parameters` property of an operation or path item: one member per location, each an object\n * of that location's parameters. `location.path` is the path template for\n * `--generate-path-params`.\n */\nexport function parametersMember(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const entries = parameterEntries(\n withPathTemplateParameters(parameters, location, context),\n context,\n );\n const querystring = querystringMember(entries, location, context);\n const members = PARAMETER_LOCATIONS.map((parameterIn) =>\n parameterIn === \"query\" && querystring\n ? querystring\n : locationMember(parameterIn, entries, location, context),\n );\n return irProperty(toPropertyName(\"parameters\"), irObject(members), {\n isReadonly: context.options.immutable,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAgCA,MAAM,gBAAA,GAAmB,eAAA;AAGzB,SAAS,uBAAuB,IAAA,EAAiC;AAC/D,EAAA,OAAA,CAAQ,IAAA,CAAK,MAAM,gBAAgB,CAAA,IAAK,EAAC,EAAG,GAAA,CAAI,CAAC,KAAA,MAAW;AAAA,IAC1D,IAAA,EAAM,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,IACvB,EAAA,EAAI,MAAA;AAAA,IACJ,QAAA,EAAU,IAAA;AAAA,IACV,MAAA,EAAQ,EAAE,IAAA,EAAM,QAAA;AAAS,GAC3B,CAAE,CAAA;AACJ;AAGA,SAAS,0BAAA,CACP,UAAA,EACA,QAAA,EACA,OAAA,EACwB;AACxB,EAAA,MAAM,MAAA,GAAS,CAAC,GAAG,UAAU,CAAA;AAC7B,EAAA,I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ntries = require('../document-entries.cjs');
|
|
|
8
8
|
const refType = require('../ref-type.cjs');
|
|
9
9
|
const documentMember = require('./document-member.cjs');
|
|
10
10
|
const operation = require('./operation.cjs');
|
|
11
|
+
const parameterEntries = require('./parameter-entries.cjs');
|
|
11
12
|
const parameters = require('./parameters.cjs');
|
|
12
13
|
|
|
13
14
|
const HASH_RE = /#/g;
|
|
15
|
+
function operationKeyOf(operationId) {
|
|
16
|
+
return operationId.replace(HASH_RE, "/");
|
|
17
|
+
}
|
|
14
18
|
function isIncluded(operation, context) {
|
|
15
19
|
if (!operation) {
|
|
16
20
|
return false;
|
|
@@ -18,26 +22,18 @@ function isIncluded(operation, context) {
|
|
|
18
22
|
const resolved = "$ref" in operation ? context.refs.resolve(operation.$ref) : operation;
|
|
19
23
|
return !(context.options.excludeDeprecated && resolved?.deprecated);
|
|
20
24
|
}
|
|
21
|
-
function mergedParameters(pathItem, operation, context) {
|
|
22
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
23
|
-
for (const parameter of [...pathItem.parameters ?? [], ...operation.parameters ?? []]) {
|
|
24
|
-
const resolved = "$ref" in parameter ? context.refs.resolve(parameter.$ref) : parameter;
|
|
25
|
-
byKey.set(`${resolved?.in}-${resolved?.name}`, parameter);
|
|
26
|
-
}
|
|
27
|
-
return [...byKey.values()];
|
|
28
|
-
}
|
|
29
25
|
function operationType(pathItem, operation$1, location, context) {
|
|
30
|
-
const merged = { ...operation$1, parameters: mergedParameters(pathItem, operation$1, context) };
|
|
26
|
+
const merged = { ...operation$1, parameters: parameterEntries.mergedParameters(pathItem, operation$1, context.refs) };
|
|
31
27
|
if (!operation$1.operationId) {
|
|
32
28
|
return constructors.irObject(operation.operationMembers(merged, location, context));
|
|
33
29
|
}
|
|
34
|
-
const operationId = operation$1.operationId
|
|
30
|
+
const operationId = context.footer.operationKey(operationKeyOf(operation$1.operationId));
|
|
35
31
|
context.footer.addOperation(
|
|
36
32
|
() => constructors.irProperty(propertyName.toPropertyName(operationId), constructors.irObject(operation.operationMembers(merged, location, context)), {
|
|
37
33
|
isReadonly: context.options.immutable
|
|
38
34
|
})
|
|
39
35
|
);
|
|
40
|
-
return refType.refType(jsonPointer.
|
|
36
|
+
return refType.refType(jsonPointer.appendPointer(jsonPointer.ROOT_POINTER, ["operations", operationId]));
|
|
41
37
|
}
|
|
42
38
|
function operationMember({ name, operation, path }, pathItem, location, context) {
|
|
43
39
|
const type = "$ref" in operation ? refType.refType(operation.$ref) : operationType(pathItem, operation, { ...location, path }, context);
|
|
@@ -49,13 +45,13 @@ function methodMember(method, pathItem, location, context) {
|
|
|
49
45
|
const isReadonly = context.options.immutable;
|
|
50
46
|
return constructors.irProperty(propertyName.toPropertyName(method), constructors.irKeyword("never"), { isOptional: true, isReadonly });
|
|
51
47
|
}
|
|
52
|
-
const path = jsonPointer.
|
|
48
|
+
const path = jsonPointer.appendPointer(location.path, [method]);
|
|
53
49
|
return operationMember({ name: method, operation, path }, pathItem, location, context);
|
|
54
50
|
}
|
|
55
51
|
function additionalOperationsMember(pathItem, location, context) {
|
|
56
52
|
const entries = documentEntries.documentEntries(pathItem.additionalOperations ?? {}, context.options);
|
|
57
53
|
const members = entries.filter(([, operation]) => isIncluded(operation, context)).map(([method, operation]) => {
|
|
58
|
-
const path = jsonPointer.
|
|
54
|
+
const path = jsonPointer.appendPointer(location.path, [pathItemObject.ADDITIONAL_OPERATIONS_KEY, method]);
|
|
59
55
|
return operationMember({ name: method, operation, path }, pathItem, location, context);
|
|
60
56
|
});
|
|
61
57
|
return members.length > 0 ? constructors.irProperty(propertyName.toPropertyName(pathItemObject.ADDITIONAL_OPERATIONS_KEY), constructors.irObject(members), {
|
|
@@ -63,7 +59,7 @@ function additionalOperationsMember(pathItem, location, context) {
|
|
|
63
59
|
}) : null;
|
|
64
60
|
}
|
|
65
61
|
function pathItemType(pathItem, location, context) {
|
|
66
|
-
const parametersLocation = { ...location, path: jsonPointer.
|
|
62
|
+
const parametersLocation = { ...location, path: jsonPointer.appendPointer(location.path, ["parameters"]) };
|
|
67
63
|
const members = [
|
|
68
64
|
parameters.parametersMember(pathItem.parameters ?? [], parametersLocation, context),
|
|
69
65
|
...pathItemObject.HTTP_METHODS.map((method) => methodMember(method, pathItem, location, context))
|
|
@@ -78,5 +74,6 @@ function pathItemType(pathItem, location, context) {
|
|
|
78
74
|
return constructors.irObject(members);
|
|
79
75
|
}
|
|
80
76
|
|
|
77
|
+
exports.operationKeyOf = operationKeyOf;
|
|
81
78
|
exports.pathItemType = pathItemType;
|
|
82
79
|
//# sourceMappingURL=path-item.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-item.cjs","sources":["../../../../src/application/transform/document/path-item.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport type {\n ParameterObject,\n ParameterOrReference,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport {\n ADDITIONAL_OPERATIONS_KEY,\n HTTP_METHODS,\n type OperationEntry,\n type PathItemMethod,\n type PathItemObject,\n QUERY_METHOD,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { operationMembers } from \"./operation.js\";\nimport { parametersMember } from \"./parameters.js\";\n\n/** Redocly reads `#` in an operation ID as a pointer, so it is replaced (upstream issue #1542). */\nconst HASH_RE = /#/g;\n\n/** Whether the method has an operation, not removed by `--exclude-deprecated`. */\nfunction isIncluded(\n operation: OperationEntry | undefined,\n context: TransformContext,\n): operation is OperationEntry {\n if (!operation) {\n return false;\n }\n const resolved =\n \"$ref\" in operation\n ? (context.refs.resolve(operation.$ref) as OperationObject | undefined)\n : operation;\n return !(context.options.excludeDeprecated && resolved?.deprecated);\n}\n\n/**\n * Path item parameters followed by the operation's, keyed by location and name, so an operation\n * parameter replaces the path item parameter it redefines (upstream issue #1798).\n */\nfunction mergedParameters(\n pathItem: PathItemObject,\n operation: OperationObject,\n context: TransformContext,\n): ParameterOrReference[] {\n const byKey = new Map<string, ParameterOrReference>();\n for (const parameter of [...(pathItem.parameters ?? []), ...(operation.parameters ?? [])]) {\n const resolved =\n \"$ref\" in parameter\n ? (context.refs.resolve(parameter.$ref) as ParameterObject | undefined)\n : parameter;\n byKey.set(`${resolved?.in}-${resolved?.name}`, parameter);\n }\n return [...byKey.values()];\n}\n\n/**\n * An operation with an `operationId` goes into the `operations` interface and is referenced from\n * the path item; others are written inline.\n */\nfunction operationType(\n pathItem: PathItemObject,\n operation: OperationObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const merged = { ...operation, parameters: mergedParameters(pathItem, operation, context) };\n if (!operation.operationId) {\n return irObject(operationMembers(merged, location, context));\n }\n const operationId = operation.operationId.replace(HASH_RE, \"/\");\n context.footer.addOperation(() =>\n irProperty(toPropertyName(operationId), irObject(operationMembers(merged, location, context)), {\n isReadonly: context.options.immutable,\n }),\n );\n return refType(createRef([\"operations\", operationId]));\n}\n\n/** An included operation, the member name it gets and its location below the path item. */\ninterface DeclaredOperation {\n readonly name: string;\n readonly operation: OperationEntry;\n readonly path: string;\n}\n\nfunction operationMember(\n { name, operation, path }: DeclaredOperation,\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const type =\n \"$ref\" in operation\n ? refType(operation.$ref)\n : operationType(pathItem, operation, { ...location, path }, context);\n return documentMember(name, type, operation, { isReadonly: context.options.immutable });\n}\n\n/** A method member: the operation, or `?: never` when there is none or it is excluded. */\nfunction methodMember(\n method: PathItemMethod,\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const operation = pathItem[method];\n if (!isIncluded(operation, context)) {\n const isReadonly = context.options.immutable;\n return irProperty(toPropertyName(method), irKeyword(\"never\"), { isOptional: true, isReadonly });\n }\n const path = createRef([location.path, method]);\n return operationMember({ name: method, operation, path }, pathItem, location, context);\n}\n\n/**\n * `additionalOperations` (OpenAPI 3.2): the included operations keyed by their exact method name,\n * or null when the path item has none left.\n */\nfunction additionalOperationsMember(\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const entries = documentEntries(pathItem.additionalOperations ?? {}, context.options);\n const members = entries\n .filter(([, operation]) => isIncluded(operation, context))\n .map(([method, operation]) => {\n const path = createRef([location.path, ADDITIONAL_OPERATIONS_KEY, method]);\n return operationMember({ name: method, operation, path }, pathItem, location, context);\n });\n return members.length > 0\n ? irProperty(toPropertyName(ADDITIONAL_OPERATIONS_KEY), irObject(members), {\n isReadonly: context.options.immutable,\n })\n : null;\n}\n\n/**\n * A path item (OpenAPI 3.2 §4.8.9): its `parameters`, one member per HTTP method, then `query` and\n * `additionalOperations` when the path item declares them (ADR-020).\n */\nexport function pathItemType(\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const parametersLocation = { ...location, path: createRef([location.path, \"parameters\"]) };\n const members: IrMember[] = [\n parametersMember(pathItem.parameters ?? [], parametersLocation, context),\n ...HTTP_METHODS.map((method) => methodMember(method, pathItem, location, context)),\n ];\n if (pathItem[QUERY_METHOD] !== undefined) {\n members.push(methodMember(QUERY_METHOD, pathItem, location, context));\n }\n const additionalOperations = additionalOperationsMember(pathItem, location, context);\n if (additionalOperations) {\n members.push(additionalOperations);\n }\n return irObject(members);\n}\n"],"names":["operation","irObject","operationMembers","irProperty","toPropertyName","refType","createRef","documentMember","irKeyword","documentEntries","ADDITIONAL_OPERATIONS_KEY","parametersMember","HTTP_METHODS","QUERY_METHOD"],"mappings":";;;;;;;;;;;;AA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AA,IAAc,EAAC,EAAG,oBAAoB,OAAO,CAAA;AAAA,IACvE,GAAGC,2BAAA,CAAa,GAAA,CAAI,CAAC,MAAA,KAAW,aAAa,MAAA,EAAQ,QAAA,EAAU,QAAA,EAAU,OAAO,CAAC;AAAA,GACnF;AACA,EAAA,IAAI,QAAA,CAASC,2BAAY,CAAA,KAAM,MAAA,EAAW;AACxC,IAAA,OAAA,CAAQ,KAAK,YAAA,CAAaA,2BAAA,EAAc,QAAA,EAAU,QAAA,EAAU,OAAO,CAAC,CAAA;AAAA,EACtE;AACA,EAAA,MAAM,oBAAA,GAAuB,0BAAA,CAA2B,QAAA,EAAU,QAAA,EAAU,OAAO,CAAA;AACnF,EAAA,IAAI,oBAAA,EAAsB;AACxB,IAAA,OAAA,CAAQ,KAAK,oBAAoB,CAAA;AAAA,EACnC;AACA,EAAA,OAAOZ,sBAAS,OAAO,CAAA;AACzB;;"}
|
|
1
|
+
{"version":3,"file":"path-item.cjs","sources":["../../../../src/application/transform/document/path-item.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport {\n ADDITIONAL_OPERATIONS_KEY,\n HTTP_METHODS,\n type OperationEntry,\n type PathItemMethod,\n type PathItemObject,\n QUERY_METHOD,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { operationMembers } from \"./operation.js\";\nimport { mergedParameters } from \"./parameter-entries.js\";\nimport { parametersMember } from \"./parameters.js\";\n\n/** Redocly reads `#` in an operation ID as a pointer, so it is replaced (upstream issue #1542). */\nconst HASH_RE = /#/g;\n\n/** The `operations` key an `operationId` asks for, before a repeated one gets a number. */\nexport function operationKeyOf(operationId: string): string {\n return operationId.replace(HASH_RE, \"/\");\n}\n\n/** Whether the method has an operation, not removed by `--exclude-deprecated`. */\nfunction isIncluded(\n operation: OperationEntry | undefined,\n context: TransformContext,\n): operation is OperationEntry {\n if (!operation) {\n return false;\n }\n const resolved =\n \"$ref\" in operation\n ? (context.refs.resolve(operation.$ref) as OperationObject | undefined)\n : operation;\n return !(context.options.excludeDeprecated && resolved?.deprecated);\n}\n\n/**\n * An operation with an `operationId` goes into the `operations` interface and is referenced from\n * the path item; others are written inline.\n */\nfunction operationType(\n pathItem: PathItemObject,\n operation: OperationObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const merged = { ...operation, parameters: mergedParameters(pathItem, operation, context.refs) };\n if (!operation.operationId) {\n return irObject(operationMembers(merged, location, context));\n }\n const operationId = context.footer.operationKey(operationKeyOf(operation.operationId));\n context.footer.addOperation(() =>\n irProperty(toPropertyName(operationId), irObject(operationMembers(merged, location, context)), {\n isReadonly: context.options.immutable,\n }),\n );\n return refType(appendPointer(ROOT_POINTER, [\"operations\", operationId]));\n}\n\n/** An included operation, the member name it gets and its location below the path item. */\ninterface DeclaredOperation {\n readonly name: string;\n readonly operation: OperationEntry;\n readonly path: string;\n}\n\nfunction operationMember(\n { name, operation, path }: DeclaredOperation,\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const type =\n \"$ref\" in operation\n ? refType(operation.$ref)\n : operationType(pathItem, operation, { ...location, path }, context);\n return documentMember(name, type, operation, { isReadonly: context.options.immutable });\n}\n\n/** A method member: the operation, or `?: never` when there is none or it is excluded. */\nfunction methodMember(\n method: PathItemMethod,\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const operation = pathItem[method];\n if (!isIncluded(operation, context)) {\n const isReadonly = context.options.immutable;\n return irProperty(toPropertyName(method), irKeyword(\"never\"), { isOptional: true, isReadonly });\n }\n const path = appendPointer(location.path, [method]);\n return operationMember({ name: method, operation, path }, pathItem, location, context);\n}\n\n/**\n * `additionalOperations` (OpenAPI 3.2): the included operations keyed by their exact method name,\n * or null when the path item has none left.\n */\nfunction additionalOperationsMember(\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const entries = documentEntries(pathItem.additionalOperations ?? {}, context.options);\n const members = entries\n .filter(([, operation]) => isIncluded(operation, context))\n .map(([method, operation]) => {\n const path = appendPointer(location.path, [ADDITIONAL_OPERATIONS_KEY, method]);\n return operationMember({ name: method, operation, path }, pathItem, location, context);\n });\n return members.length > 0\n ? irProperty(toPropertyName(ADDITIONAL_OPERATIONS_KEY), irObject(members), {\n isReadonly: context.options.immutable,\n })\n : null;\n}\n\n/**\n * A path item (OpenAPI 3.2 §4.8.9): its `parameters`, one member per HTTP method, then `query` and\n * `additionalOperations` when the path item declares them (ADR-020).\n */\nexport function pathItemType(\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const parametersLocation = { ...location, path: appendPointer(location.path, [\"parameters\"]) };\n const members: IrMember[] = [\n parametersMember(pathItem.parameters ?? [], parametersLocation, context),\n ...HTTP_METHODS.map((method) => methodMember(method, pathItem, location, context)),\n ];\n if (pathItem[QUERY_METHOD] !== undefined) {\n members.push(methodMember(QUERY_METHOD, pathItem, location, context));\n }\n const additionalOperations = additionalOperationsMember(pathItem, location, context);\n if (additionalOperations) {\n members.push(additionalOperations);\n }\n return irObject(members);\n}\n"],"names":["operation","mergedParameters","irObject","operationMembers","irProperty","toPropertyName","refType","appendPointer","ROOT_POINTER","documentMember","irKeyword","documentEntries","ADDITIONAL_OPERATIONS_KEY","parametersMember","HTTP_METHODS","QUERY_METHOD"],"mappings":";;;;;;;;;;;;;AAuBA,MAAM,OAAA,GAAU,IAAA;AAGT,S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