openapi-typesafe 1.0.0-rc.3 → 1.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1972 -0
- package/dist/adapters/node-file-system/file-claims.cjs +105 -0
- package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.mjs +95 -0
- package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.cjs +82 -0
- package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.mjs +74 -0
- package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +97 -14
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +97 -14
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs +19 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs.map +1 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs +17 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +48 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +45 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -1
- package/dist/adapters/redocly-loader/component-schemas.cjs +17 -0
- package/dist/adapters/redocly-loader/component-schemas.cjs.map +1 -0
- package/dist/adapters/redocly-loader/component-schemas.mjs +14 -0
- package/dist/adapters/redocly-loader/component-schemas.mjs.map +1 -0
- package/dist/adapters/redocly-loader/loaded-documents.cjs +28 -0
- package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs.map +1 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.cjs +22 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.cjs.map +1 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.mjs +20 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.mjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs +137 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs +134 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +40 -29
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +38 -27
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +45 -4
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +45 -4
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.cjs +52 -10
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.mjs +53 -12
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
- package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +40 -9
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -9
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +61 -0
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +58 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +18 -9
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +20 -11
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +10 -4
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +10 -4
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/default-ports.cjs +14 -2
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +14 -2
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/discriminator-enum-parent.cjs +2 -2
- package/dist/api/discriminator-enum-parent.cjs.map +1 -1
- package/dist/api/discriminator-enum-parent.mjs +3 -3
- package/dist/api/discriminator-enum-parent.mjs.map +1 -1
- package/dist/api/discriminator-other-owners.cjs +5 -3
- package/dist/api/discriminator-other-owners.cjs.map +1 -1
- package/dist/api/discriminator-other-owners.mjs +5 -3
- package/dist/api/discriminator-other-owners.mjs.map +1 -1
- package/dist/api/discriminator-patch.cjs +5 -1
- package/dist/api/discriminator-patch.cjs.map +1 -1
- package/dist/api/discriminator-patch.mjs +5 -1
- package/dist/api/discriminator-patch.mjs.map +1 -1
- package/dist/api/discriminator-scan.cjs +15 -8
- package/dist/api/discriminator-scan.cjs.map +1 -1
- package/dist/api/discriminator-scan.mjs +15 -8
- package/dist/api/discriminator-scan.mjs.map +1 -1
- package/dist/api/document-refs.cjs +16 -1
- package/dist/api/document-refs.cjs.map +1 -1
- package/dist/api/document-refs.mjs +16 -1
- package/dist/api/document-refs.mjs.map +1 -1
- package/dist/api/document-run.cjs +6 -12
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +6 -12
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-utils.cjs.map +1 -1
- package/dist/api/legacy-utils.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +9 -6
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +10 -8
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/ref-limit-options.cjs +63 -0
- package/dist/api/ref-limit-options.cjs.map +1 -0
- package/dist/api/ref-limit-options.mjs +57 -0
- package/dist/api/ref-limit-options.mjs.map +1 -0
- package/dist/api/schema-callbacks.cjs +36 -12
- package/dist/api/schema-callbacks.cjs.map +1 -1
- package/dist/api/schema-callbacks.mjs +36 -12
- package/dist/api/schema-callbacks.mjs.map +1 -1
- package/dist/api/transform-context.cjs +7 -3
- package/dist/api/transform-context.cjs.map +1 -1
- package/dist/api/transform-context.mjs +7 -3
- package/dist/api/transform-context.mjs.map +1 -1
- package/dist/api/transform-schema.cjs +47 -10
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +48 -11
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/print/text-writer.cjs +10 -3
- package/dist/application/print/text-writer.cjs.map +1 -1
- package/dist/application/print/text-writer.mjs +10 -3
- package/dist/application/print/text-writer.mjs.map +1 -1
- package/dist/application/stack-overflow.cjs +2 -1
- package/dist/application/stack-overflow.cjs.map +1 -1
- package/dist/application/stack-overflow.mjs +2 -1
- package/dist/application/stack-overflow.mjs.map +1 -1
- package/dist/application/transform/declared-value-types.cjs +36 -0
- package/dist/application/transform/declared-value-types.cjs.map +1 -0
- package/dist/application/transform/declared-value-types.mjs +34 -0
- package/dist/application/transform/declared-value-types.mjs.map +1 -0
- package/dist/application/transform/document/components.cjs +1 -1
- package/dist/application/transform/document/components.cjs.map +1 -1
- package/dist/application/transform/document/components.mjs +2 -2
- package/dist/application/transform/document/components.mjs.map +1 -1
- package/dist/application/transform/document/declared-type-names.cjs +23 -0
- package/dist/application/transform/document/declared-type-names.cjs.map +1 -0
- package/dist/application/transform/document/declared-type-names.mjs +20 -0
- package/dist/application/transform/document/declared-type-names.mjs.map +1 -0
- package/dist/application/transform/document/defs-root.cjs +1 -1
- package/dist/application/transform/document/defs-root.cjs.map +1 -1
- package/dist/application/transform/document/defs-root.mjs +2 -2
- package/dist/application/transform/document/defs-root.mjs.map +1 -1
- package/dist/application/transform/document/document.cjs +7 -2
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +6 -3
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
- package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
- package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
- package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
- package/dist/application/transform/document/exploded-query-values.cjs +63 -0
- package/dist/application/transform/document/exploded-query-values.cjs.map +1 -0
- package/dist/application/transform/document/exploded-query-values.mjs +59 -0
- package/dist/application/transform/document/exploded-query-values.mjs.map +1 -0
- package/dist/application/transform/document/global-type-references.cjs +1 -0
- package/dist/application/transform/document/global-type-references.cjs.map +1 -1
- package/dist/application/transform/document/global-type-references.mjs +1 -1
- package/dist/application/transform/document/global-type-references.mjs.map +1 -1
- package/dist/application/transform/document/header.cjs +11 -3
- package/dist/application/transform/document/header.cjs.map +1 -1
- package/dist/application/transform/document/header.mjs +10 -2
- package/dist/application/transform/document/header.mjs.map +1 -1
- package/dist/application/transform/document/media-type.cjs +2 -2
- package/dist/application/transform/document/media-type.cjs.map +1 -1
- package/dist/application/transform/document/media-type.mjs +3 -3
- package/dist/application/transform/document/media-type.mjs.map +1 -1
- package/dist/application/transform/document/operation-keys-written.cjs +26 -0
- package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
- package/dist/application/transform/document/operation-keys-written.mjs +24 -0
- package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
- package/dist/application/transform/document/operation.cjs +1 -1
- package/dist/application/transform/document/operation.cjs.map +1 -1
- package/dist/application/transform/document/operation.mjs +2 -2
- package/dist/application/transform/document/operation.mjs.map +1 -1
- package/dist/application/transform/document/parameter-entries.cjs +34 -0
- package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
- package/dist/application/transform/document/parameter-entries.mjs +30 -0
- package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
- package/dist/application/transform/document/parameter.cjs +12 -4
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +13 -5
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +29 -34
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +29 -34
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +15 -17
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +15 -19
- package/dist/application/transform/document/path-item.mjs.map +1 -1
- package/dist/application/transform/document/path-template-key.cjs +84 -0
- package/dist/application/transform/document/path-template-key.cjs.map +1 -0
- package/dist/application/transform/document/path-template-key.mjs +79 -0
- package/dist/application/transform/document/path-template-key.mjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.cjs +70 -0
- package/dist/application/transform/document/path-template-refs.cjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.mjs +67 -0
- package/dist/application/transform/document/path-template-refs.mjs.map +1 -0
- package/dist/application/transform/document/paths-enum.cjs +8 -6
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +8 -7
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +43 -67
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +42 -68
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/referenced-parameter.cjs +80 -0
- package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
- package/dist/application/transform/document/referenced-parameter.mjs +78 -0
- package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
- package/dist/application/transform/document/request-body.cjs +1 -1
- package/dist/application/transform/document/request-body.cjs.map +1 -1
- package/dist/application/transform/document/request-body.mjs +2 -2
- package/dist/application/transform/document/request-body.mjs.map +1 -1
- package/dist/application/transform/document/response.cjs +2 -2
- package/dist/application/transform/document/response.cjs.map +1 -1
- package/dist/application/transform/document/response.mjs +3 -3
- package/dist/application/transform/document/response.mjs.map +1 -1
- package/dist/application/transform/document/responses.cjs +1 -1
- package/dist/application/transform/document/responses.cjs.map +1 -1
- package/dist/application/transform/document/responses.mjs +2 -2
- package/dist/application/transform/document/responses.mjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.cjs +8 -23
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.mjs +8 -24
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
- package/dist/application/transform/document/type-resolution.cjs +3 -1
- package/dist/application/transform/document/type-resolution.cjs.map +1 -1
- package/dist/application/transform/document/type-resolution.mjs +3 -1
- package/dist/application/transform/document/type-resolution.mjs.map +1 -1
- package/dist/application/transform/document/webhooks.cjs +10 -3
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +10 -3
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +16 -5
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +16 -5
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
- package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
- package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
- package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.cjs +23 -0
- package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.mjs +21 -0
- package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.cjs +4 -4
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
- package/dist/application/transform/footer/type-evaluation.mjs +4 -4
- package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
- package/dist/application/transform/helper-types.cjs +3 -3
- package/dist/application/transform/helper-types.cjs.map +1 -1
- package/dist/application/transform/helper-types.mjs +3 -3
- package/dist/application/transform/helper-types.mjs.map +1 -1
- package/dist/application/transform/numbered-names.cjs +9 -0
- package/dist/application/transform/numbered-names.cjs.map +1 -1
- package/dist/application/transform/numbered-names.mjs +9 -1
- package/dist/application/transform/numbered-names.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +5 -5
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +3 -3
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.cjs +47 -66
- package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.mjs +36 -50
- package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.cjs +2 -2
- package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.mjs +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/located-node.cjs +23 -0
- package/dist/application/transform/ref-pointer/located-node.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/located-node.mjs +18 -0
- package/dist/application/transform/ref-pointer/located-node.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/original-index.cjs +68 -13
- package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/original-index.mjs +70 -15
- package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs +2 -2
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-walk.cjs +54 -13
- package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-walk.mjs +46 -7
- package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/property-shape.cjs +52 -0
- package/dist/application/transform/ref-pointer/property-shape.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs +45 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/typed-walk.cjs +79 -21
- package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/typed-walk.mjs +76 -18
- package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -1
- package/dist/application/transform/ref-type.cjs +2 -1
- package/dist/application/transform/ref-type.cjs.map +1 -1
- package/dist/application/transform/ref-type.mjs +2 -1
- package/dist/application/transform/ref-type.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/composition-type.cjs +1 -1
- package/dist/application/transform/schema/composition-type.cjs.map +1 -1
- package/dist/application/transform/schema/composition-type.mjs +2 -2
- package/dist/application/transform/schema/composition-type.mjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.cjs +1 -1
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.mjs +2 -2
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
- package/dist/application/transform/schema/index-signature-type.cjs +21 -0
- package/dist/application/transform/schema/index-signature-type.cjs.map +1 -0
- package/dist/application/transform/schema/index-signature-type.mjs +19 -0
- package/dist/application/transform/schema/index-signature-type.mjs.map +1 -0
- package/dist/application/transform/schema/input-location.cjs +23 -0
- package/dist/application/transform/schema/input-location.cjs.map +1 -0
- package/dist/application/transform/schema/input-location.mjs +21 -0
- package/dist/application/transform/schema/input-location.mjs.map +1 -0
- package/dist/application/transform/schema/object-type.cjs +18 -8
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +19 -9
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/ref-siblings.cjs +47 -0
- package/dist/application/transform/schema/ref-siblings.cjs.map +1 -0
- package/dist/application/transform/schema/ref-siblings.mjs +45 -0
- package/dist/application/transform/schema/ref-siblings.mjs.map +1 -0
- package/dist/application/transform/schema/schema-transform.cjs +6 -3
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +6 -3
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs +2 -30
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.mjs +3 -31
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
- package/dist/application/transform/schema-comment.cjs +5 -1
- package/dist/application/transform/schema-comment.cjs.map +1 -1
- package/dist/application/transform/schema-comment.mjs +5 -1
- package/dist/application/transform/schema-comment.mjs.map +1 -1
- package/dist/cli/api-logger.cjs +13 -0
- package/dist/cli/api-logger.cjs.map +1 -0
- package/dist/cli/api-logger.mjs +11 -0
- package/dist/cli/api-logger.mjs.map +1 -0
- package/dist/cli/api-settings.cjs +57 -9
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +56 -11
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +72 -0
- package/dist/cli/api-writes.cjs.map +1 -0
- package/dist/cli/api-writes.mjs +69 -0
- package/dist/cli/api-writes.mjs.map +1 -0
- package/dist/cli/cli-arguments.cjs +51 -11
- package/dist/cli/cli-arguments.cjs.map +1 -1
- package/dist/cli/cli-arguments.mjs +51 -11
- package/dist/cli/cli-arguments.mjs.map +1 -1
- package/dist/cli/cli-errors.cjs +29 -1
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +29 -2
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +111 -4
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +104 -5
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +13 -3
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +14 -4
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +94 -37
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +99 -42
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/ref-limits.cjs +15 -1
- package/dist/cli/ref-limits.cjs.map +1 -1
- package/dist/cli/ref-limits.mjs +15 -2
- package/dist/cli/ref-limits.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +37 -14
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +39 -16
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/append-all.cjs +10 -0
- package/dist/domain/append-all.cjs.map +1 -0
- package/dist/domain/append-all.mjs +8 -0
- package/dist/domain/append-all.mjs.map +1 -0
- package/dist/domain/cause-secrets.cjs +52 -0
- package/dist/domain/cause-secrets.cjs.map +1 -0
- package/dist/domain/cause-secrets.mjs +50 -0
- package/dist/domain/cause-secrets.mjs.map +1 -0
- package/dist/domain/errors.cjs +11 -3
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +11 -3
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/identifier-text.cjs.map +1 -1
- package/dist/domain/ir/identifier-text.mjs +1 -1
- package/dist/domain/ir/identifier-text.mjs.map +1 -1
- package/dist/domain/ir/ir-shape.cjs +187 -0
- package/dist/domain/ir/ir-shape.cjs.map +1 -0
- package/dist/domain/ir/ir-shape.mjs +184 -0
- package/dist/domain/ir/ir-shape.mjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
- package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
- package/dist/domain/location-text.cjs +9 -0
- package/dist/domain/location-text.cjs.map +1 -0
- package/dist/domain/location-text.mjs +7 -0
- package/dist/domain/location-text.mjs.map +1 -0
- package/dist/domain/openapi/alias-expansion.cjs +3 -1
- package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.mjs +3 -1
- package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.cjs +3 -3
- package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.mjs +4 -4
- package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
- package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
- package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
- package/dist/domain/openapi/document-places.cjs +55 -0
- package/dist/domain/openapi/document-places.cjs.map +1 -0
- package/dist/domain/openapi/document-places.mjs +53 -0
- package/dist/domain/openapi/document-places.mjs.map +1 -0
- package/dist/domain/openapi/json-pointer.cjs +43 -1
- package/dist/domain/openapi/json-pointer.cjs.map +1 -1
- package/dist/domain/openapi/json-pointer.mjs +40 -2
- package/dist/domain/openapi/json-pointer.mjs.map +1 -1
- package/dist/domain/openapi/schema-dialect.cjs +15 -0
- package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
- package/dist/domain/openapi/schema-dialect.mjs +12 -0
- package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.cjs +1 -1
- package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
- package/dist/domain/openapi/unsupported-features.mjs +2 -2
- package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
- package/dist/domain/output-fixes.cjs +20 -0
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +20 -0
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/terminal-text.cjs +31 -0
- package/dist/domain/terminal-text.cjs.map +1 -0
- package/dist/domain/terminal-text.mjs +29 -0
- package/dist/domain/terminal-text.mjs.map +1 -0
- package/dist/domain/url-secrets.cjs +48 -0
- package/dist/domain/url-secrets.cjs.map +1 -0
- package/dist/domain/url-secrets.mjs +45 -0
- package/dist/domain/url-secrets.mjs.map +1 -0
- package/dist/domain/warnings.cjs +1 -0
- package/dist/domain/warnings.cjs.map +1 -1
- package/dist/domain/warnings.mjs +1 -0
- package/dist/domain/warnings.mjs.map +1 -1
- package/dist/index.d.cts +46 -20
- package/dist/index.d.mts +46 -20
- package/dist/index.d.ts +46 -20
- package/package.json +4 -5
- package/src/adapters/node-file-system/file-claims.ts +138 -0
- package/src/adapters/node-file-system/file-identity.ts +137 -0
- package/src/adapters/node-file-system/node-file-system.ts +158 -18
- package/src/adapters/pipe-safe-writer/pipe-safe-writer.ts +29 -0
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +60 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
- package/src/adapters/redocly-loader/component-schemas.ts +19 -0
- package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
- package/src/adapters/redocly-loader/mapping-schema-names.ts +25 -0
- package/src/adapters/redocly-loader/query-named-components.ts +201 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +64 -38
- package/src/adapters/redocly-loader/ref-access.ts +51 -4
- package/src/adapters/redocly-loader/ref-holders.ts +76 -15
- package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +85 -13
- package/src/adapters/redocly-loader/remote-node-limit.ts +102 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
- package/src/adapters/redocly-loader/schema-source.ts +35 -11
- package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
- package/src/adapters/terminal-logger/terminal-logger.ts +17 -6
- package/src/api/default-ports.ts +33 -4
- package/src/api/discriminator-enum-parent.ts +3 -3
- package/src/api/discriminator-other-owners.ts +5 -3
- package/src/api/discriminator-patch.ts +5 -1
- package/src/api/discriminator-scan.ts +16 -8
- package/src/api/document-refs.ts +29 -1
- package/src/api/document-run.ts +10 -19
- package/src/api/legacy-utils.ts +5 -1
- package/src/api/openapi-ts.ts +26 -8
- package/src/api/ref-limit-options.ts +76 -0
- package/src/api/run-context.ts +3 -0
- package/src/api/schema-callbacks.ts +60 -17
- package/src/api/transform-context.ts +7 -3
- package/src/api/transform-schema.ts +79 -12
- package/src/application/ports/file-system.ts +47 -0
- package/src/application/ports/schema-loader.ts +11 -1
- package/src/application/print/text-writer.ts +10 -3
- package/src/application/stack-overflow.ts +9 -5
- package/src/application/transform/declared-value-types.ts +42 -0
- package/src/application/transform/document/components.ts +2 -2
- package/src/application/transform/document/declared-type-names.ts +36 -0
- package/src/application/transform/document/defs-root.ts +2 -2
- package/src/application/transform/document/document.ts +8 -5
- package/src/application/transform/document/enum-names-given-back.ts +91 -0
- package/src/application/transform/document/exploded-query-values.ts +88 -0
- package/src/application/transform/document/global-type-references.ts +1 -1
- package/src/application/transform/document/header.ts +25 -5
- package/src/application/transform/document/media-type.ts +4 -3
- package/src/application/transform/document/operation-keys-written.ts +27 -0
- package/src/application/transform/document/operation.ts +2 -2
- package/src/application/transform/document/parameter-entries.ts +70 -0
- package/src/application/transform/document/parameter.ts +21 -9
- package/src/application/transform/document/parameters.ts +56 -66
- package/src/application/transform/document/path-item.ts +16 -34
- package/src/application/transform/document/path-template-key.ts +152 -0
- package/src/application/transform/document/path-template-refs.ts +106 -0
- package/src/application/transform/document/paths-enum.ts +24 -10
- package/src/application/transform/document/paths.ts +59 -125
- package/src/application/transform/document/referenced-parameter.ts +146 -0
- package/src/application/transform/document/request-body.ts +2 -2
- package/src/application/transform/document/response.ts +3 -3
- package/src/application/transform/document/responses.ts +2 -2
- package/src/application/transform/document/root-type-aliases.ts +17 -38
- package/src/application/transform/document/type-resolution.ts +2 -1
- package/src/application/transform/document/webhooks.ts +19 -6
- package/src/application/transform/footer/document-footer.ts +36 -9
- package/src/application/transform/footer/enum-name-claims.ts +62 -0
- package/src/application/transform/footer/operation-keys.ts +28 -0
- package/src/application/transform/footer/type-evaluation.ts +4 -4
- package/src/application/transform/helper-types.ts +8 -7
- package/src/application/transform/numbered-names.ts +15 -0
- package/src/application/transform/ref-pointer/generated-location.ts +3 -3
- package/src/application/transform/ref-pointer/generated-shape.ts +67 -78
- package/src/application/transform/ref-pointer/inline-cycles.ts +1 -1
- package/src/application/transform/ref-pointer/located-node.ts +38 -0
- package/src/application/transform/ref-pointer/original-index.ts +100 -17
- package/src/application/transform/ref-pointer/pointer-type.ts +1 -1
- package/src/application/transform/ref-pointer/pointer-walk.ts +82 -8
- package/src/application/transform/ref-pointer/property-shape.ts +97 -0
- package/src/application/transform/ref-pointer/typed-walk.ts +117 -25
- package/src/application/transform/ref-type.ts +2 -1
- package/src/application/transform/schema/access-flags.ts +5 -2
- package/src/application/transform/schema/composition-type.ts +2 -2
- package/src/application/transform/schema/enum-rule.ts +6 -2
- package/src/application/transform/schema/index-signature-type.ts +31 -0
- package/src/application/transform/schema/input-location.ts +35 -0
- package/src/application/transform/schema/object-type.ts +22 -12
- package/src/application/transform/schema/ref-siblings.ts +76 -0
- package/src/application/transform/schema/schema-context.ts +3 -0
- package/src/application/transform/schema/schema-transform.ts +6 -3
- package/src/application/transform/schema/unevaluated-properties.ts +4 -44
- package/src/application/transform/schema-comment.ts +5 -1
- package/src/application/transform/transform-context.ts +5 -0
- package/src/cli/api-logger.ts +17 -0
- package/src/cli/api-settings.ts +80 -13
- package/src/cli/api-writes.ts +117 -0
- package/src/cli/cli-arguments.ts +90 -14
- package/src/cli/cli-dependencies.ts +26 -4
- package/src/cli/cli-errors.ts +42 -1
- package/src/cli/cli-output.ts +195 -15
- package/src/cli/main.ts +14 -5
- package/src/cli/redocly-apis.ts +177 -52
- package/src/cli/ref-limits.ts +21 -2
- package/src/cli/run-cli.ts +76 -15
- package/src/domain/append-all.ts +10 -0
- package/src/domain/cause-secrets.ts +86 -0
- package/src/domain/errors.ts +16 -5
- package/src/domain/ir/identifier-text.ts +6 -5
- package/src/domain/ir/ir-shape.ts +299 -0
- package/src/domain/ir/newer-identifier-ranges.ts +183 -30
- package/src/domain/location-text.ts +12 -0
- package/src/domain/openapi/alias-expansion.ts +4 -1
- package/src/domain/openapi/discriminated-union.ts +6 -4
- package/src/domain/openapi/discriminator-conflicts.ts +21 -7
- package/src/domain/openapi/document-object.ts +2 -0
- package/src/domain/openapi/document-places.ts +78 -0
- package/src/domain/openapi/json-pointer.ts +96 -7
- package/src/domain/openapi/schema-dialect.ts +22 -0
- package/src/domain/openapi/unsupported-features.ts +2 -2
- package/src/domain/output-fixes.ts +28 -2
- package/src/domain/terminal-text.ts +44 -0
- package/src/domain/url-secrets.ts +72 -0
- package/src/domain/warnings.ts +1 -0
- package/src/types/generator-options.ts +1 -1
- package/dist/cli/main.d.cts +0 -2
- package/dist/cli/main.d.mts +0 -2
- package/dist/cli/main.d.ts +0 -2
- package/dist/domain/url-credentials.cjs +0 -10
- package/dist/domain/url-credentials.cjs.map +0 -1
- package/dist/domain/url-credentials.mjs +0 -8
- package/dist/domain/url-credentials.mjs.map +0 -1
- package/src/domain/url-credentials.ts +0 -18
|
@@ -1,77 +1,24 @@
|
|
|
1
1
|
import { irObject, irIntersection, irProperty, irRaw } from '../../../domain/ir/constructors.mjs';
|
|
2
2
|
import { toPropertyName } from '../../../domain/ir/property-name.mjs';
|
|
3
|
-
import {
|
|
4
|
-
import { createRef } from '../../../domain/openapi/json-pointer.mjs';
|
|
5
|
-
import { pathItemOperations } from '../../../domain/openapi/path-item-object.mjs';
|
|
6
|
-
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
3
|
+
import { appendPointer, ROOT_POINTER } from '../../../domain/openapi/json-pointer.mjs';
|
|
7
4
|
import { documentEntries } from '../document-entries.mjs';
|
|
8
5
|
import { refType } from '../ref-type.mjs';
|
|
9
6
|
import { NO_DECLARED_TYPES } from './declared-types.mjs';
|
|
10
7
|
import { documentMember } from './document-member.mjs';
|
|
11
8
|
import { pathItemType } from './path-item.mjs';
|
|
12
9
|
import { coveringTemplateKeys } from './path-key-overlaps.mjs';
|
|
13
|
-
import {
|
|
10
|
+
import { plainUrlOf, pathTemplateParts, booleanExpandedKeys, templateText } from './path-template-key.mjs';
|
|
14
11
|
import { assignabilityProof } from './type-assignability.mjs';
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
["integer", "number"],
|
|
20
|
-
["boolean", "boolean"]
|
|
21
|
-
]);
|
|
22
|
-
const STRING_PLACEHOLDER = "string";
|
|
23
|
-
function resolvedParameter(parameter, context) {
|
|
24
|
-
return "$ref" in parameter && parameter.$ref ? context.refs.resolve(parameter.$ref) : parameter;
|
|
13
|
+
function pathKeyOf(parts) {
|
|
14
|
+
const plainUrl = plainUrlOf(parts);
|
|
15
|
+
return plainUrl === null ? { kind: "template", parts } : literalKey(plainUrl);
|
|
25
16
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function pathParameters(pathItem, context) {
|
|
35
|
-
const byName = /* @__PURE__ */ new Map();
|
|
36
|
-
addPathParameters(pathItem.parameters ?? [], byName, context);
|
|
37
|
-
for (const { operation: entry } of pathItemOperations(pathItem)) {
|
|
38
|
-
const operation = entry.$ref ? context.refs.resolve(entry.$ref) : entry;
|
|
39
|
-
addPathParameters(operation?.parameters ?? [], byName, context);
|
|
40
|
-
}
|
|
41
|
-
return byName;
|
|
42
|
-
}
|
|
43
|
-
function splitTemplateParts(url, matches) {
|
|
44
|
-
return url.split(PATH_PARAMETER_RE).flatMap((text, index) => {
|
|
45
|
-
const type = matches[index]?.type;
|
|
46
|
-
const textPart = { kind: "text", text };
|
|
47
|
-
return type === void 0 ? [textPart] : [textPart, { kind: "placeholder", type }];
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function pathTemplateParts(url, pathItem, context) {
|
|
51
|
-
const found = url.match(PATH_PARAMETER_RE);
|
|
52
|
-
if (!found) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
const parameters = pathParameters(pathItem, context);
|
|
56
|
-
const matches = found.map((match) => {
|
|
57
|
-
const schema = parameters.get(match.slice(1, -1))?.schema;
|
|
58
|
-
return { match, type: PLACEHOLDERS.get(schema?.type) ?? STRING_PLACEHOLDER };
|
|
59
|
-
});
|
|
60
|
-
return context.options.fixes.has(FIX.PATH_PARAM_TYPE_NAMES) ? splitTemplateParts(url, matches) : replacedTemplateParts(url, matches);
|
|
61
|
-
}
|
|
62
|
-
function templateText(parts) {
|
|
63
|
-
const text = parts.map(
|
|
64
|
-
(part) => part.kind === "text" ? escapeTemplateText(part.text) : placeholderText(part.type)
|
|
65
|
-
).join("");
|
|
66
|
-
return `\`${text}\``;
|
|
67
|
-
}
|
|
68
|
-
function pathItemMember(url, pathItem, context) {
|
|
69
|
-
const isReadonly = context.options.immutable;
|
|
70
|
-
const type = pathItemType(pathItem, { path: createRef(["paths", url]) }, context);
|
|
71
|
-
const parts = context.options.pathParamsAsTypes && url.includes("{") ? pathTemplateParts(url, pathItem, context) : null;
|
|
72
|
-
if (parts === null) {
|
|
73
|
-
const member2 = irProperty(toPropertyName(url), type, { isReadonly });
|
|
74
|
-
return { url, member: member2, key: literalKey(url), type };
|
|
17
|
+
function keyMember(url, parts, type, isReadonly) {
|
|
18
|
+
const key = pathKeyOf(parts);
|
|
19
|
+
if (key.kind === "literal") {
|
|
20
|
+
const member2 = irProperty(toPropertyName(key.url), type, { isReadonly });
|
|
21
|
+
return { url, member: member2, key, type };
|
|
75
22
|
}
|
|
76
23
|
const member = {
|
|
77
24
|
kind: "indexSignature",
|
|
@@ -81,7 +28,33 @@ function pathItemMember(url, pathItem, context) {
|
|
|
81
28
|
isReadonly,
|
|
82
29
|
comments: []
|
|
83
30
|
};
|
|
84
|
-
return { url, member, key
|
|
31
|
+
return { url, member, key, type };
|
|
32
|
+
}
|
|
33
|
+
function isUntakenKey(url, key, takenUrls) {
|
|
34
|
+
const isExpandedUrl = key.kind === "literal" && key.url !== url;
|
|
35
|
+
if (!isExpandedUrl) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
const isTaken = takenUrls.has(key.url);
|
|
39
|
+
takenUrls.add(key.url);
|
|
40
|
+
return !isTaken;
|
|
41
|
+
}
|
|
42
|
+
function withoutTakenUrls(url, members, takenUrls) {
|
|
43
|
+
return members.filter(({ key }) => isUntakenKey(url, key, takenUrls));
|
|
44
|
+
}
|
|
45
|
+
function pathItemMembers(url, pathItem, context) {
|
|
46
|
+
const isReadonly = context.options.immutable;
|
|
47
|
+
const type = pathItemType(
|
|
48
|
+
pathItem,
|
|
49
|
+
{ path: appendPointer(ROOT_POINTER, ["paths", url]) },
|
|
50
|
+
context
|
|
51
|
+
);
|
|
52
|
+
const parts = context.options.pathParamsAsTypes && url.includes("{") ? pathTemplateParts(url, pathItem, context) : null;
|
|
53
|
+
if (parts === null) {
|
|
54
|
+
const member = irProperty(toPropertyName(url), type, { isReadonly });
|
|
55
|
+
return [{ url, member, key: literalKey(url), type }];
|
|
56
|
+
}
|
|
57
|
+
return booleanExpandedKeys(parts).map((key) => keyMember(url, key, type, isReadonly));
|
|
85
58
|
}
|
|
86
59
|
function literalKey(url) {
|
|
87
60
|
return { kind: "literal", url };
|
|
@@ -122,6 +95,7 @@ function pathsObjectType(paths, lookup = NO_DECLARED_TYPES) {
|
|
|
122
95
|
}
|
|
123
96
|
function pathMembers(paths, context) {
|
|
124
97
|
const members = [];
|
|
98
|
+
const takenUrls = new Set(Object.keys(paths));
|
|
125
99
|
for (const [url, pathItem] of documentEntries(paths, context.options)) {
|
|
126
100
|
if (!pathItem || typeof pathItem !== "object") {
|
|
127
101
|
continue;
|
|
@@ -133,9 +107,9 @@ function pathMembers(paths, context) {
|
|
|
133
107
|
continue;
|
|
134
108
|
}
|
|
135
109
|
const startedAt = context.diagnostics.now();
|
|
136
|
-
const
|
|
137
|
-
members.push(
|
|
138
|
-
if (
|
|
110
|
+
const pathMembersOfUrl = pathItemMembers(url, pathItem, context);
|
|
111
|
+
members.push(...withoutTakenUrls(url, pathMembersOfUrl, takenUrls));
|
|
112
|
+
if (pathMembersOfUrl[0]?.key.kind === "literal" && pathMembersOfUrl[0].key.url === url) {
|
|
139
113
|
context.diagnostics.debug(`Transformed path "${url}"`, context.diagnostics.now() - startedAt);
|
|
140
114
|
}
|
|
141
115
|
}
|
|
@@ -145,5 +119,5 @@ function pathsType(paths, context) {
|
|
|
145
119
|
return pathsObjectType(pathMembers(paths, context));
|
|
146
120
|
}
|
|
147
121
|
|
|
148
|
-
export { pathMembers, pathsObjectType, pathsType };
|
|
122
|
+
export { isUntakenKey, pathKeyOf, pathMembers, pathsObjectType, pathsType };
|
|
149
123
|
//# sourceMappingURL=paths.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.mjs","sources":["../../../../src/application/transform/document/paths.ts"],"sourcesContent":["import { irIntersection, irObject, irProperty, irRaw } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { escapeTemplateText } from \"../../../domain/ir/raw-text-escapes.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 type PathItemObject,\n type PathsObject,\n pathItemOperations,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport type { ReferenceSchema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { type DeclaredTypeLookup, NO_DECLARED_TYPES } from \"./declared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport {\n type CoverRejection,\n coveringTemplateKeys,\n type PathKey,\n type PathKeyPart,\n type PathPlaceholder,\n} from \"./path-key-overlaps.js\";\nimport {\n type PathParameterMatch,\n placeholderText,\n replacedTemplateParts,\n} from \"./path-template-replace.js\";\nimport { assignabilityProof } from \"./type-assignability.js\";\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_PARAMETER_RE = /\\{[^{}]+\\}/g;\n\n/** Placeholders by parameter schema type; anything else is a string placeholder. */\nconst PLACEHOLDERS: ReadonlyMap<unknown, PathPlaceholder> = new Map([\n [\"number\", \"number\"],\n [\"integer\", \"number\"],\n [\"boolean\", \"boolean\"],\n]);\nconst STRING_PLACEHOLDER: PathPlaceholder = \"string\";\n\nfunction resolvedParameter(\n parameter: ParameterOrReference,\n context: TransformContext,\n): ParameterObject | undefined {\n return \"$ref\" in parameter && parameter.$ref\n ? (context.refs.resolve(parameter.$ref) as ParameterObject | undefined)\n : (parameter as ParameterObject);\n}\n\nfunction addPathParameters(\n parameters: readonly ParameterOrReference[],\n byName: Map<string, ParameterObject>,\n context: TransformContext,\n): void {\n for (const parameter of parameters) {\n const resolved = resolvedParameter(parameter, context);\n if (resolved && resolved.in === \"path\") {\n byName.set(resolved.name, resolved);\n }\n }\n}\n\n/** Path parameters of the path item and of its operations; later definitions win. */\nfunction pathParameters(\n pathItem: PathItemObject,\n context: TransformContext,\n): Map<string, ParameterObject> {\n const byName = new Map<string, ParameterObject>();\n addPathParameters(pathItem.parameters ?? [], byName, context);\n for (const { operation: entry } of pathItemOperations(pathItem)) {\n const operation = (entry as ReferenceSchema).$ref\n ? (context.refs.resolve((entry as ReferenceSchema).$ref) as OperationObject | undefined)\n : (entry as OperationObject);\n addPathParameters(operation?.parameters ?? [], byName, context);\n }\n return byName;\n}\n\n/** Each `{name}` of the URL and its own placeholder, from the URL split at the matches. */\nfunction splitTemplateParts(url: string, matches: readonly PathParameterMatch[]): PathKeyPart[] {\n return url.split(PATH_PARAMETER_RE).flatMap((text, index): PathKeyPart[] => {\n const type = matches[index]?.type;\n const textPart: PathKeyPart = { kind: \"text\", text };\n return type === undefined ? [textPart] : [textPart, { kind: \"placeholder\", type }];\n });\n}\n\n/**\n * `--path-params-as-types`: the URL as template parts, each `{name}` replaced by a placeholder for\n * its parameter's type, the way the original replaces them unless the `path-param-type-names` fix\n * is on (see `replacedTemplateParts`). Null when the URL has no complete `{…}` placeholder.\n */\nfunction pathTemplateParts(\n url: string,\n pathItem: PathItemObject,\n context: TransformContext,\n): PathKeyPart[] | null {\n const found = url.match(PATH_PARAMETER_RE);\n if (!found) {\n return null;\n }\n const parameters = pathParameters(pathItem, context);\n const matches = found.map((match): PathParameterMatch => {\n const schema = parameters.get(match.slice(1, -1))?.schema as SchemaObject | undefined;\n return { match, type: PLACEHOLDERS.get(schema?.type) ?? STRING_PLACEHOLDER };\n });\n return context.options.fixes.has(FIX.PATH_PARAM_TYPE_NAMES)\n ? splitTemplateParts(url, matches)\n : replacedTemplateParts(url, matches);\n}\n\n/**\n * The template literal type of the parts. The original escaped only backticks: a backslash or\n * `${` in the URL could end the literal or open a placeholder, and add code to the generated file\n * (intentional fix). So the text parts are escaped.\n */\nfunction templateText(parts: readonly PathKeyPart[]): string {\n const text = parts\n .map((part) =>\n part.kind === \"text\" ? escapeTemplateText(part.text) : placeholderText(part.type),\n )\n .join(\"\");\n return `\\`${text}\\``;\n}\n\n/** A path's member, its key and its path item type for the overlap check. */\nexport interface PathMember {\n readonly url: string;\n readonly member: IrMember;\n readonly key: PathKey;\n readonly type: IrType;\n}\n\nfunction pathItemMember(\n url: string,\n pathItem: PathItemObject,\n context: TransformContext,\n): PathMember {\n const isReadonly = context.options.immutable;\n const type = pathItemType(pathItem, { path: createRef([\"paths\", url]) }, context);\n const parts =\n context.options.pathParamsAsTypes && url.includes(\"{\")\n ? pathTemplateParts(url, pathItem, context)\n : null;\n if (parts === null) {\n const member = irProperty(toPropertyName(url), type, { isReadonly });\n return { url, member, key: literalKey(url), type };\n }\n const member: IrMember = {\n kind: \"indexSignature\",\n parameterName: \"path\",\n parameterType: irRaw(templateText(parts)),\n type,\n isReadonly,\n comments: [],\n };\n return { url, member, key: { kind: \"template\", parts }, type };\n}\n\nfunction literalKey(url: string): PathKey {\n return { kind: \"literal\", url };\n}\n\nconst PATHS_TYPE_NAME = \"paths\";\n\n/** The URL of `paths[\"/apps/{id}\"]`, or null for any other type. */\nfunction pathsIndexOf(type: IrType): string | null {\n if (type.kind !== \"indexedAccess\" || type.index.kind !== \"stringLiteral\") {\n return null;\n }\n const { object } = type;\n const isPaths =\n object.kind === \"reference\" &&\n object.name === PATHS_TYPE_NAME &&\n object.typeArguments.length === 0;\n return isPaths ? type.index.value : null;\n}\n\n/**\n * The lookup, and `paths[\"/apps/{id}\"]` as that path's item. The declarations cannot read it: a\n * templated path is no property of `paths`, and TypeScript finds it through the signature.\n */\nfunction withPathItems(\n paths: readonly PathMember[],\n lookup: DeclaredTypeLookup,\n): DeclaredTypeLookup {\n const byUrl = new Map(paths.map((path) => [path.url, path.type]));\n return (type) => {\n const url = pathsIndexOf(type);\n return (url === null ? undefined : byUrl.get(url)) ?? lookup(type);\n };\n}\n\n/**\n * The rejection of a covered path item: only one proven not assignable to the signature's type\n * counts (ADR-028). A pair the proof cannot decide keeps the original output, which may well\n * compile (`Record<string, never>` fits `{ [key: string]: unknown }`).\n */\nfunction rejectionOf(paths: readonly PathMember[], lookup: DeclaredTypeLookup): CoverRejection {\n const relate = assignabilityProof(withPathItems(paths, lookup));\n return (coveringIndex, coveredIndex) => {\n const coveringPath = paths[coveringIndex];\n const coveredPath = paths[coveredIndex];\n return (\n coveringPath !== undefined &&\n coveredPath !== undefined &&\n relate(coveredPath.type, coveringPath.type) === \"rejected\"\n );\n };\n}\n\n/**\n * The members as one object type. When an index signature covers another key, TypeScript checks\n * the covered key's type against it. Where that check surely fails (TS2411, TS2413), each such\n * signature gets an object of its own in an intersection: an intersection does not check its parts\n * against each other, and every key has the type it had in the one object. Output that compiles\n * keeps the one object. The lookup reads the types that path items reference; without it, a\n * reference decides nothing.\n */\nexport function pathsObjectType(\n paths: readonly PathMember[],\n lookup: DeclaredTypeLookup = NO_DECLARED_TYPES,\n): IrType {\n const keys = paths.map(({ key }) => key);\n const covering = coveringTemplateKeys(keys, rejectionOf(paths, lookup));\n if (covering.size === 0) {\n return irObject(paths.map(({ member }) => member));\n }\n const rest = paths.filter((_, index) => !covering.has(index)).map(({ member }) => member);\n const own = paths\n .filter((_, index) => covering.has(index))\n .map(({ member }) => irObject([member]));\n return irIntersection([irObject(rest), ...own]);\n}\n\n/** The members of the `paths` interface (OpenAPI 3.1 §4.8.8): one per path, by URL. */\nexport function pathMembers(paths: PathsObject, context: TransformContext): PathMember[] {\n const members: PathMember[] = [];\n for (const [url, pathItem] of documentEntries(paths, context.options)) {\n if (!pathItem || typeof pathItem !== \"object\") {\n continue;\n }\n if (\"$ref\" in pathItem) {\n const options = { isReadonly: context.options.immutable };\n const member = documentMember(url, refType(pathItem.$ref), pathItem, options);\n members.push({ url, member, key: literalKey(url), type: member.type });\n continue;\n }\n const startedAt = context.diagnostics.now();\n const path = pathItemMember(url, pathItem, context);\n members.push(path);\n // The original reports only paths written as properties.\n if (path.member.kind === \"property\") {\n context.diagnostics.debug(`Transformed path \"${url}\"`, context.diagnostics.now() - startedAt);\n }\n }\n return members;\n}\n\n/**\n * The `paths` interface body, with only the path items' own types for the overlap check. The\n * document transform checks the overlaps again once the referenced types are declared.\n */\nexport function pathsType(paths: PathsObject, context: TransformContext): IrType {\n return pathsObjectType(pathMembers(paths, context));\n}\n"],"names":["member"],"mappings":";;;;;;;;;;;;;;;AAsCA,MAAM,iBAAA,GAAoB,aAAA;AAG1B,MAAM,YAAA,uBAA0D,GAAA,CAAI;AAAA,EAClE,CAAC,UAAU,QAAQ,CAAA;AAAA,EACnB,CAAC,WAAW,QAAQ,CAAA;AAAA,EACpB,CAAC,WAAW,SAAS;AACvB,CAAC,CAAA;AACD,MAAM,kBAAA,GAAsC,QAAA;AAE5C,SAAS,iBAAA,CACP,WACA,OAAA,EAC6B;AAC7B,EAAA,OAAO,MAAA,IAAU,aAAa,SA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C5E,MAAA,OAAA,CAAQ,IAAA,CAAK,EAAE,GAAA,EAAK,MAAA,EAAQ,GAAA,EAAK,UAAA,CAAW,GAAG,CAAA,EAAG,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,CAAA;AACrE,MAAA;AAAA,IACF;AACA,IAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,WAAA,CAAY,GAAA,EAAI;AAC1C,IAAA,MAAM,IAAA,GAAO,cAAA,CAAe,GAAA,EAAK,QAAA,EAAU,OAAO,CAAA;AAClD,IAAA,OAAA,CAAQ,KAAK,IAAI,CAAA;AAEjB,IAAA,IAAI,IAAA,CAAK,MAAA,CAAO,IAAA,KAAS,UAAA,EAAY;AACnC,MAAA,OAAA,CAAQ,WAAA,CAAY,MAAM,CAAA,kBAAA,EAAqB,GAAG,KAAK,OAAA,CAAQ,WAAA,CAAY,GAAA,EAAI,GAAI,SAAS,CAAA;AAAA,IAC9F;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,SAAA,CAAU,OAAoB,OAAA,EAAmC;AAC/E,EAAA,OAAO,eAAA,CAAgB,WAAA,CAAY,KAAA,EAAO,OAAO,CAAC,CAAA;AACpD;;"}
|
|
1
|
+
{"version":3,"file":"paths.mjs","sources":["../../../../src/application/transform/document/paths.ts"],"sourcesContent":["import { irIntersection, irObject, irProperty, irRaw } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, 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 { PathItemObject, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { type DeclaredTypeLookup, NO_DECLARED_TYPES } from \"./declared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { pathItemType } from \"./path-item.js\";\nimport {\n type CoverRejection,\n coveringTemplateKeys,\n type PathKey,\n type PathKeyPart,\n} from \"./path-key-overlaps.js\";\nimport {\n booleanExpandedKeys,\n pathTemplateParts,\n plainUrlOf,\n templateText,\n} from \"./path-template-key.js\";\nimport { assignabilityProof } from \"./type-assignability.js\";\n\n/** A path's member, its key and its path item type for the overlap check. */\nexport interface PathMember {\n readonly url: string;\n readonly member: IrMember;\n readonly key: PathKey;\n readonly type: IrType;\n}\n\n/** The key of the parts: a plain URL, or a template with placeholders left. */\nexport function pathKeyOf(parts: readonly PathKeyPart[]): PathKey {\n const plainUrl = plainUrlOf(parts);\n return plainUrl === null ? { kind: \"template\", parts } : literalKey(plainUrl);\n}\n\n/** The member of one key of a path: a property for a plain URL, else an index signature. */\nfunction keyMember(url: string, parts: readonly PathKeyPart[], type: IrType, isReadonly: boolean) {\n const key = pathKeyOf(parts);\n if (key.kind === \"literal\") {\n const member = irProperty(toPropertyName(key.url), type, { isReadonly });\n return { url, member, key, type };\n }\n const member: IrMember = {\n kind: \"indexSignature\",\n parameterName: \"path\",\n parameterType: irRaw(templateText(parts)),\n type,\n isReadonly,\n comments: [],\n };\n return { url, member, key, type };\n}\n\n/**\n * Whether a key of the path at `url` is written. A URL that `${boolean}` keys give is not when it\n * is taken already: by a path of the document, which OpenAPI matches before a template (Paths\n * Object), or by the keys of an earlier path. A property written twice does not compile (TS2300).\n * `takenUrls` starts with the document's URLs and gets each expanded URL, in document order.\n */\nexport function isUntakenKey(url: string, key: PathKey, takenUrls: Set<string>): boolean {\n const isExpandedUrl = key.kind === \"literal\" && key.url !== url;\n if (!isExpandedUrl) {\n return true;\n }\n const isTaken = takenUrls.has(key.url);\n takenUrls.add(key.url);\n return !isTaken;\n}\n\nfunction withoutTakenUrls(url: string, members: readonly PathMember[], takenUrls: Set<string>) {\n return members.filter(({ key }) => isUntakenKey(url, key, takenUrls));\n}\n\n/** The members of a path: one, or one per key of its `${boolean}` placeholders. */\nfunction pathItemMembers(\n url: string,\n pathItem: PathItemObject,\n context: TransformContext,\n): PathMember[] {\n const isReadonly = context.options.immutable;\n const type = pathItemType(\n pathItem,\n { path: appendPointer(ROOT_POINTER, [\"paths\", url]) },\n context,\n );\n const parts =\n context.options.pathParamsAsTypes && url.includes(\"{\")\n ? pathTemplateParts(url, pathItem, context)\n : null;\n if (parts === null) {\n const member = irProperty(toPropertyName(url), type, { isReadonly });\n return [{ url, member, key: literalKey(url), type }];\n }\n return booleanExpandedKeys(parts).map((key) => keyMember(url, key, type, isReadonly));\n}\n\nfunction literalKey(url: string): PathKey {\n return { kind: \"literal\", url };\n}\n\nconst PATHS_TYPE_NAME = \"paths\";\n\n/** The URL of `paths[\"/apps/{id}\"]`, or null for any other type. */\nfunction pathsIndexOf(type: IrType): string | null {\n if (type.kind !== \"indexedAccess\" || type.index.kind !== \"stringLiteral\") {\n return null;\n }\n const { object } = type;\n const isPaths =\n object.kind === \"reference\" &&\n object.name === PATHS_TYPE_NAME &&\n object.typeArguments.length === 0;\n return isPaths ? type.index.value : null;\n}\n\n/**\n * The lookup, and `paths[\"/apps/{id}\"]` as that path's item. The declarations cannot read it: a\n * templated path is no property of `paths`, and TypeScript finds it through the signature.\n */\nfunction withPathItems(\n paths: readonly PathMember[],\n lookup: DeclaredTypeLookup,\n): DeclaredTypeLookup {\n const byUrl = new Map(paths.map((path) => [path.url, path.type]));\n return (type) => {\n const url = pathsIndexOf(type);\n return (url === null ? undefined : byUrl.get(url)) ?? lookup(type);\n };\n}\n\n/**\n * The rejection of a covered path item: only one proven not assignable to the signature's type\n * counts (ADR-028). A pair the proof cannot decide keeps the original output, which may well\n * compile (`Record<string, never>` fits `{ [key: string]: unknown }`).\n */\nfunction rejectionOf(paths: readonly PathMember[], lookup: DeclaredTypeLookup): CoverRejection {\n const relate = assignabilityProof(withPathItems(paths, lookup));\n return (coveringIndex, coveredIndex) => {\n const coveringPath = paths[coveringIndex];\n const coveredPath = paths[coveredIndex];\n return (\n coveringPath !== undefined &&\n coveredPath !== undefined &&\n relate(coveredPath.type, coveringPath.type) === \"rejected\"\n );\n };\n}\n\n/**\n * The members as one object type. When an index signature covers another key, TypeScript checks\n * the covered key's type against it. Where that check surely fails (TS2411, TS2413), each such\n * signature gets an object of its own in an intersection: an intersection does not check its parts\n * against each other, and every key has the type it had in the one object. Output that compiles\n * keeps the one object. The lookup reads the types that path items reference; without it, a\n * reference decides nothing.\n */\nexport function pathsObjectType(\n paths: readonly PathMember[],\n lookup: DeclaredTypeLookup = NO_DECLARED_TYPES,\n): IrType {\n const keys = paths.map(({ key }) => key);\n const covering = coveringTemplateKeys(keys, rejectionOf(paths, lookup));\n if (covering.size === 0) {\n return irObject(paths.map(({ member }) => member));\n }\n const rest = paths.filter((_, index) => !covering.has(index)).map(({ member }) => member);\n const own = paths\n .filter((_, index) => covering.has(index))\n .map(({ member }) => irObject([member]));\n return irIntersection([irObject(rest), ...own]);\n}\n\n/** The members of the `paths` interface (OpenAPI 3.1 §4.8.8): one per path, by URL. */\nexport function pathMembers(paths: PathsObject, context: TransformContext): PathMember[] {\n const members: PathMember[] = [];\n const takenUrls = new Set(Object.keys(paths));\n for (const [url, pathItem] of documentEntries(paths, context.options)) {\n if (!pathItem || typeof pathItem !== \"object\") {\n continue;\n }\n if (\"$ref\" in pathItem) {\n const options = { isReadonly: context.options.immutable };\n const member = documentMember(url, refType(pathItem.$ref), pathItem, options);\n members.push({ url, member, key: literalKey(url), type: member.type });\n continue;\n }\n const startedAt = context.diagnostics.now();\n const pathMembersOfUrl = pathItemMembers(url, pathItem, context);\n members.push(...withoutTakenUrls(url, pathMembersOfUrl, takenUrls));\n // The original reports only paths written as properties.\n if (pathMembersOfUrl[0]?.key.kind === \"literal\" && pathMembersOfUrl[0].key.url === url) {\n context.diagnostics.debug(`Transformed path \"${url}\"`, context.diagnostics.now() - startedAt);\n }\n }\n return members;\n}\n\n/**\n * The `paths` interface body, with only the path items' own types for the overlap check. The\n * document transform checks the overlaps again once the referenced types are declared.\n */\nexport function pathsType(paths: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../domain/ir/constructors.cjs');
|
|
4
|
+
const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
|
|
5
|
+
const parameterObject = require('../../../domain/openapi/parameter-object.cjs');
|
|
6
|
+
const pathItemObject = require('../../../domain/openapi/path-item-object.cjs');
|
|
7
|
+
const refType = require('../ref-type.cjs');
|
|
8
|
+
const parameterEntries = require('./parameter-entries.cjs');
|
|
9
|
+
|
|
10
|
+
const INDEX_RE = /^\d+$/;
|
|
11
|
+
const OPERATION_KEYS = /* @__PURE__ */ new Set([...pathItemObject.HTTP_METHODS, pathItemObject.QUERY_METHOD]);
|
|
12
|
+
function listPointerOf(ref) {
|
|
13
|
+
if (!ref.startsWith(`${jsonPointer.ROOT_POINTER}/`)) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const [root, ...segments] = jsonPointer.parseRefPointer(ref);
|
|
17
|
+
const [list, position] = segments.slice(-2);
|
|
18
|
+
const isList = list === "parameters" && position !== void 0 && INDEX_RE.test(position);
|
|
19
|
+
return root !== void 0 && isList ? { root, owner: segments.slice(0, -2) } : null;
|
|
20
|
+
}
|
|
21
|
+
function pointerTo(root, segments) {
|
|
22
|
+
return jsonPointer.appendPointer(jsonPointer.ROOT_POINTER, [root, ...segments]);
|
|
23
|
+
}
|
|
24
|
+
function isPathItemAt(root, segments) {
|
|
25
|
+
const isNamedRoot = root === "paths" || root === "webhooks";
|
|
26
|
+
return isNamedRoot && segments.length === 1 || root === "components" && segments[0] === "pathItems" && segments.length === 2;
|
|
27
|
+
}
|
|
28
|
+
function pathItemOfOperation(root, owner) {
|
|
29
|
+
const method = owner.at(-1) ?? "";
|
|
30
|
+
if (OPERATION_KEYS.has(method) && isPathItemAt(root, owner.slice(0, -1))) {
|
|
31
|
+
return owner.slice(0, -1);
|
|
32
|
+
}
|
|
33
|
+
const isAdditional = owner.at(-2) === pathItemObject.ADDITIONAL_OPERATIONS_KEY;
|
|
34
|
+
return isAdditional && isPathItemAt(root, owner.slice(0, -2)) ? owner.slice(0, -2) : null;
|
|
35
|
+
}
|
|
36
|
+
function documentNode(refs, root, segments) {
|
|
37
|
+
const node = refs.resolve(pointerTo(root, segments));
|
|
38
|
+
const isTypedHere = typeof node === "object" && node !== null && !("$ref" in node);
|
|
39
|
+
return isTypedHere ? node : null;
|
|
40
|
+
}
|
|
41
|
+
function typedParameters(pointer, refs) {
|
|
42
|
+
const { root, owner } = pointer;
|
|
43
|
+
if (isPathItemAt(root, owner)) {
|
|
44
|
+
return documentNode(refs, root, owner)?.parameters ?? null;
|
|
45
|
+
}
|
|
46
|
+
const pathItemSegments = pathItemOfOperation(root, owner);
|
|
47
|
+
const pathItem = pathItemSegments && documentNode(refs, root, pathItemSegments);
|
|
48
|
+
const operation = pathItem && documentNode(refs, root, owner);
|
|
49
|
+
return pathItem && operation ? parameterEntries.mergedParameters(pathItem, operation, refs) : null;
|
|
50
|
+
}
|
|
51
|
+
function isLocationOptional(entries, location) {
|
|
52
|
+
return entries.filter((entry) => entry.resolved?.in === location).every((entry) => location !== "path" && !entry.resolved?.required);
|
|
53
|
+
}
|
|
54
|
+
function correctedType(listType, entries, parameter) {
|
|
55
|
+
if (parameter.in === parameterObject.QUERYSTRING_LOCATION) {
|
|
56
|
+
const isTyped = !entries.some((entry) => entry.resolved?.in === "query");
|
|
57
|
+
return isTyped ? refType.indexBy(listType, "query") : null;
|
|
58
|
+
}
|
|
59
|
+
if (!isLocationOptional(entries, parameter.in)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const location = constructors.irReference("NonNullable", [refType.indexBy(listType, parameter.in)]);
|
|
63
|
+
return refType.indexBy(location, parameter.name);
|
|
64
|
+
}
|
|
65
|
+
function referencedParameterType(ref, resolved, context) {
|
|
66
|
+
if (resolved.$ref) {
|
|
67
|
+
return refType.refType(ref, { parameter: null });
|
|
68
|
+
}
|
|
69
|
+
const original = refType.refType(ref, { parameter: { in: resolved.in, name: resolved.name } });
|
|
70
|
+
const pointer = listPointerOf(ref);
|
|
71
|
+
const parameters = pointer && typedParameters(pointer, context.refs);
|
|
72
|
+
if (pointer === null || parameters === null) {
|
|
73
|
+
return original;
|
|
74
|
+
}
|
|
75
|
+
const listType = refType.refType(pointerTo(pointer.root, [...pointer.owner, "parameters"]));
|
|
76
|
+
return correctedType(listType, parameterEntries.parameterEntries(parameters, context), resolved) ?? original;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
exports.referencedParameterType = referencedParameterType;
|
|
80
|
+
//# sourceMappingURL=referenced-parameter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"referenced-parameter.cjs","sources":["../../../../src/application/transform/document/referenced-parameter.ts"],"sourcesContent":["import { irReference } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport {\n appendPointer,\n parseRefPointer,\n ROOT_POINTER,\n} from \"../../../domain/openapi/json-pointer.js\";\nimport type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport {\n type ParameterObject,\n type ParameterOrReference,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport {\n ADDITIONAL_OPERATIONS_KEY,\n HTTP_METHODS,\n type PathItemObject,\n QUERY_METHOD,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport { indexBy, refType } from \"../ref-type.js\";\nimport type { RefResolver } from \"../schema/schema-context.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { mergedParameters, type ParameterEntry, parameterEntries } from \"./parameter-entries.js\";\n\n/**\n * The type of a parameter `$ref`. The original indexed the parameter's location and name\n * (`refType`): `#/paths/~1a/get/parameters/0` gave\n * `paths[\"/a\"][\"get\"][\"parameters\"][\"query\"][\"q\"]`.\n * Where the generated type differs, that does not compile, and only there it changes:\n *\n * - A location whose parameters are all optional is an optional member (`query?:`), so indexing it\n * fails (TS2339); it is wrapped in `NonNullable` before the name is indexed.\n * - An OpenAPI 3.2 `in: querystring` parameter is the whole `query` member (ADR-020), not a member\n * `querystring`, so the pointer reads `[\"query\"]`.\n *\n * A `$ref` to a component parameter, or into a list the generator types elsewhere (a `$ref` path\n * item or operation, a callback), keeps the original type.\n */\n\nconst INDEX_RE = /^\\d+$/;\nconst OPERATION_KEYS: ReadonlySet<string> = new Set([...HTTP_METHODS, QUERY_METHOD]);\n\n/** A `parameters/N` pointer, split into its root and the segments of the list's owner. */\ninterface ParameterListPointer {\n readonly root: string;\n readonly owner: readonly string[];\n}\n\nfunction listPointerOf(ref: string): ParameterListPointer | null {\n if (!ref.startsWith(`${ROOT_POINTER}/`)) {\n return null;\n }\n const [root, ...segments] = parseRefPointer(ref);\n const [list, position] = segments.slice(-2);\n const isList = list === \"parameters\" && position !== undefined && INDEX_RE.test(position);\n return root !== undefined && isList ? { root, owner: segments.slice(0, -2) } : null;\n}\n\nfunction pointerTo(root: string, segments: readonly string[]): string {\n return appendPointer(ROOT_POINTER, [root, ...segments]);\n}\n\n/** Whether the segments name a path item that `pathItemType` types in place. */\nfunction isPathItemAt(root: string, segments: readonly string[]): boolean {\n const isNamedRoot = root === \"paths\" || root === \"webhooks\";\n return (\n (isNamedRoot && segments.length === 1) ||\n (root === \"components\" && segments[0] === \"pathItems\" && segments.length === 2)\n );\n}\n\n/** The segments of the path item that holds the operation at `owner`, or null. */\nfunction pathItemOfOperation(root: string, owner: readonly string[]): readonly string[] | null {\n const method = owner.at(-1) ?? \"\";\n if (OPERATION_KEYS.has(method) && isPathItemAt(root, owner.slice(0, -1))) {\n return owner.slice(0, -1);\n }\n const isAdditional = owner.at(-2) === ADDITIONAL_OPERATIONS_KEY;\n return isAdditional && isPathItemAt(root, owner.slice(0, -2)) ? owner.slice(0, -2) : null;\n}\n\nfunction documentNode<T>(refs: RefResolver, root: string, segments: readonly string[]): T | null {\n const node = refs.resolve(pointerTo(root, segments));\n const isTypedHere = typeof node === \"object\" && node !== null && !(\"$ref\" in node);\n return isTypedHere ? (node as T) : null;\n}\n\n/** The parameters the generator types at the list's owner; null where it types them elsewhere. */\nfunction typedParameters(\n pointer: ParameterListPointer,\n refs: RefResolver,\n): readonly ParameterOrReference[] | null {\n const { root, owner } = pointer;\n if (isPathItemAt(root, owner)) {\n return documentNode<PathItemObject>(refs, root, owner)?.parameters ?? null;\n }\n const pathItemSegments = pathItemOfOperation(root, owner);\n const pathItem = pathItemSegments && documentNode<PathItemObject>(refs, root, pathItemSegments);\n const operation = pathItem && documentNode<OperationObject>(refs, root, owner);\n return pathItem && operation ? mergedParameters(pathItem, operation, refs) : null;\n}\n\n/** A location member is optional when none of its parameters is required (`locationParts`). */\nfunction isLocationOptional(entries: readonly ParameterEntry[], location: string): boolean {\n return entries\n .filter((entry) => entry.resolved?.in === location)\n .every((entry) => location !== \"path\" && !entry.resolved?.required);\n}\n\n/** The corrected type, or null where the original type compiles or no correction applies. */\nfunction correctedType(\n listType: IrType,\n entries: readonly ParameterEntry[],\n parameter: ParameterObject,\n): IrType | null {\n if (parameter.in === QUERYSTRING_LOCATION) {\n // Next to `in: query` parameters it is not in the generated types (QUERYSTRING_NEXT_TO_QUERY).\n const isTyped = !entries.some((entry) => entry.resolved?.in === \"query\");\n return isTyped ? indexBy(listType, \"query\") : null;\n }\n if (!isLocationOptional(entries, parameter.in)) {\n return null;\n }\n const location = irReference(\"NonNullable\", [indexBy(listType, parameter.in)]);\n return indexBy(location, parameter.name);\n}\n\n/** The type of a parameter `$ref` whose target resolved to `resolved`; see the module comment. */\nexport function referencedParameterType(\n ref: string,\n resolved: ParameterObject,\n context: TransformContext,\n): IrType {\n // A `$ref` that resolves to another `$ref` is not a parameter object yet: index it as a path.\n if ((resolved as { $ref?: unknown }).$ref) {\n return refType(ref, { parameter: null });\n }\n const original = refType(ref, { parameter: { in: resolved.in, name: resolved.name } });\n const pointer = listPointerOf(ref);\n const parameters = pointer && typedParameters(pointer, context.refs);\n if (pointer === null || parameters === null) {\n return original;\n }\n const listType = refType(pointerTo(pointer.root, [...pointer.owner, \"parameters\"]));\n return correctedType(listType, parameterEntries(parameters, context), resolved) ?? original;\n}\n"],"names":["HTTP_METHODS","QUERY_METHOD","ROOT_POINTER","parseRefPointer","appendPointer","ADDITIONAL_OPERATIONS_KEY","mergedParameters","QUERYSTRING_LOCATION","indexBy","irReference","refType","parameterEntries"],"mappings":";;;;;;;;;AAuCA,MAAM,QAAA,GAAW,OAAA;AACjB,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,GAAGA,2BAAA,EAAcC,2BAAY,CAAC,CAAA;AAQnF,SAAS,cAAc,GAAA,EAA0C;AAC/D,EAAA,IAAI,CAAC,GAAA,CAAI,UAAA,CAAW,CAAA,EAAGC,wBAAY,GAAG,CAAA,EAAG;AACvC,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,CAAC,IAAA,EAAM,GAAG,QAAQ,CAAA,GAAIC,4BAAgB,GAAG,CAAA;AAC/C,EAAA,MAAM,CAAC,IAAA,EAAM,QAAQ,CAAA,GAAI,QAAA,CAAS,MAAM,EAAE,CAAA;AAC1C,EAAA,MAAM,SAAS,IAAA,KAAS,YAAA,IAAgB,aAAa,MAAA,IAAa,QAAA,CAAS,KAAK,QAAQ,CAAA;AACxF,EAAA,OAAO,IAAA,KAAS,MAAA,IAAa,MAAA,GAAS,EAAE,IAAA,EAAM,KAAA,EAAO,QAAA,CAAS,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,EAAE,GAAI,IAAA;AACjF;AAEA,SAAS,SAAA,CAAU,MAAc,QAAA,EAAqC;AACpE,EAAA,OAAOC,0BAAcF,wBAAA,EAAc,CAAC,IAAA,EAAM,GAAG,QAAQ,CAAC,CAAA;AACxD;AAGA,SAAS,YAAA,CAAa,MAAc,QAAA,EAAsC;AACxE,EAAA,MAAM,WAAA,GAAc,IAAA,KAAS,OAAA,IAAW,IAAA,KAAS,UAAA;AACjD,EAAA,OACG,WAAA,IAAe,QAAA,CAAS,MAAA,KAAW,CAAA,IACnC,IAAA,KAAS,YAAA,IAAgB,QAAA,CAAS,CAAC,CA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C;AAGO,SAAS,uBAAA,CACd,GAAA,EACA,QAAA,EACA,OAAA,EACQ;AAER,EAAA,IAAK,SAAgC,IAAA,EAAM;AACzC,IAAA,OAAOE,eAAA,CAAQ,GAAA,EAAK,EAAE,SAAA,EAAW,MAAM,CAAA;AAAA,EACzC;AACA,EAAA,MAAM,QAAA,GAAWA,eAAA,CAAQ,GAAA,EAAK,EAAE,SAAA,EAAW,EAAE,EAAA,EAAI,QAAA,CAAS,EAAA,EAAI,IAAA,EAAM,QAAA,CAAS,IAAA,IAAQ,CAAA;AACrF,EAAA,MAAM,OAAA,GAAU,cAAc,GAAG,CAAA;AACjC,EAAA,MAAM,UAAA,GAAa,OAAA,IAAW,eAAA,CAAgB,OAAA,EAAS,QAAQ,IAAI,CAAA;AACnE,EAAA,IAAI,OAAA,KAAY,IAAA,IAAQ,UAAA,KAAe,IAAA,EAAM;AAC3C,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,MAAM,QAAA,GAAWA,eAAA,CAAQ,SAAA,CAAU,OAAA,CAAQ,IAAA,EAAM,CAAC,GAAG,OAAA,CAAQ,KAAA,EAAO,YAAY,CAAC,CAAC,CAAA;AAClF,EAAA,OAAO,cAAc,QAAA,EAAUC,iCAAA,CAAiB,YAAY,OAAO,CAAA,EAAG,QAAQ,CAAA,IAAK,QAAA;AACrF;;"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { irReference } from '../../../domain/ir/constructors.mjs';
|
|
2
|
+
import { ROOT_POINTER, parseRefPointer, appendPointer } from '../../../domain/openapi/json-pointer.mjs';
|
|
3
|
+
import { QUERYSTRING_LOCATION } from '../../../domain/openapi/parameter-object.mjs';
|
|
4
|
+
import { HTTP_METHODS, QUERY_METHOD, ADDITIONAL_OPERATIONS_KEY } from '../../../domain/openapi/path-item-object.mjs';
|
|
5
|
+
import { refType, indexBy } from '../ref-type.mjs';
|
|
6
|
+
import { parameterEntries, mergedParameters } from './parameter-entries.mjs';
|
|
7
|
+
|
|
8
|
+
const INDEX_RE = /^\d+$/;
|
|
9
|
+
const OPERATION_KEYS = /* @__PURE__ */ new Set([...HTTP_METHODS, QUERY_METHOD]);
|
|
10
|
+
function listPointerOf(ref) {
|
|
11
|
+
if (!ref.startsWith(`${ROOT_POINTER}/`)) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const [root, ...segments] = parseRefPointer(ref);
|
|
15
|
+
const [list, position] = segments.slice(-2);
|
|
16
|
+
const isList = list === "parameters" && position !== void 0 && INDEX_RE.test(position);
|
|
17
|
+
return root !== void 0 && isList ? { root, owner: segments.slice(0, -2) } : null;
|
|
18
|
+
}
|
|
19
|
+
function pointerTo(root, segments) {
|
|
20
|
+
return appendPointer(ROOT_POINTER, [root, ...segments]);
|
|
21
|
+
}
|
|
22
|
+
function isPathItemAt(root, segments) {
|
|
23
|
+
const isNamedRoot = root === "paths" || root === "webhooks";
|
|
24
|
+
return isNamedRoot && segments.length === 1 || root === "components" && segments[0] === "pathItems" && segments.length === 2;
|
|
25
|
+
}
|
|
26
|
+
function pathItemOfOperation(root, owner) {
|
|
27
|
+
const method = owner.at(-1) ?? "";
|
|
28
|
+
if (OPERATION_KEYS.has(method) && isPathItemAt(root, owner.slice(0, -1))) {
|
|
29
|
+
return owner.slice(0, -1);
|
|
30
|
+
}
|
|
31
|
+
const isAdditional = owner.at(-2) === ADDITIONAL_OPERATIONS_KEY;
|
|
32
|
+
return isAdditional && isPathItemAt(root, owner.slice(0, -2)) ? owner.slice(0, -2) : null;
|
|
33
|
+
}
|
|
34
|
+
function documentNode(refs, root, segments) {
|
|
35
|
+
const node = refs.resolve(pointerTo(root, segments));
|
|
36
|
+
const isTypedHere = typeof node === "object" && node !== null && !("$ref" in node);
|
|
37
|
+
return isTypedHere ? node : null;
|
|
38
|
+
}
|
|
39
|
+
function typedParameters(pointer, refs) {
|
|
40
|
+
const { root, owner } = pointer;
|
|
41
|
+
if (isPathItemAt(root, owner)) {
|
|
42
|
+
return documentNode(refs, root, owner)?.parameters ?? null;
|
|
43
|
+
}
|
|
44
|
+
const pathItemSegments = pathItemOfOperation(root, owner);
|
|
45
|
+
const pathItem = pathItemSegments && documentNode(refs, root, pathItemSegments);
|
|
46
|
+
const operation = pathItem && documentNode(refs, root, owner);
|
|
47
|
+
return pathItem && operation ? mergedParameters(pathItem, operation, refs) : null;
|
|
48
|
+
}
|
|
49
|
+
function isLocationOptional(entries, location) {
|
|
50
|
+
return entries.filter((entry) => entry.resolved?.in === location).every((entry) => location !== "path" && !entry.resolved?.required);
|
|
51
|
+
}
|
|
52
|
+
function correctedType(listType, entries, parameter) {
|
|
53
|
+
if (parameter.in === QUERYSTRING_LOCATION) {
|
|
54
|
+
const isTyped = !entries.some((entry) => entry.resolved?.in === "query");
|
|
55
|
+
return isTyped ? indexBy(listType, "query") : null;
|
|
56
|
+
}
|
|
57
|
+
if (!isLocationOptional(entries, parameter.in)) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const location = irReference("NonNullable", [indexBy(listType, parameter.in)]);
|
|
61
|
+
return indexBy(location, parameter.name);
|
|
62
|
+
}
|
|
63
|
+
function referencedParameterType(ref, resolved, context) {
|
|
64
|
+
if (resolved.$ref) {
|
|
65
|
+
return refType(ref, { parameter: null });
|
|
66
|
+
}
|
|
67
|
+
const original = refType(ref, { parameter: { in: resolved.in, name: resolved.name } });
|
|
68
|
+
const pointer = listPointerOf(ref);
|
|
69
|
+
const parameters = pointer && typedParameters(pointer, context.refs);
|
|
70
|
+
if (pointer === null || parameters === null) {
|
|
71
|
+
return original;
|
|
72
|
+
}
|
|
73
|
+
const listType = refType(pointerTo(pointer.root, [...pointer.owner, "parameters"]));
|
|
74
|
+
return correctedType(listType, parameterEntries(parameters, context), resolved) ?? original;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { referencedParameterType };
|
|
78
|
+
//# sourceMappingURL=referenced-parameter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"referenced-parameter.mjs","sources":["../../../../src/application/transform/document/referenced-parameter.ts"],"sourcesContent":["import { irReference } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport {\n appendPointer,\n parseRefPointer,\n ROOT_POINTER,\n} from \"../../../domain/openapi/json-pointer.js\";\nimport type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport {\n type ParameterObject,\n type ParameterOrReference,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport {\n ADDITIONAL_OPERATIONS_KEY,\n HTTP_METHODS,\n type PathItemObject,\n QUERY_METHOD,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport { indexBy, refType } from \"../ref-type.js\";\nimport type { RefResolver } from \"../schema/schema-context.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { mergedParameters, type ParameterEntry, parameterEntries } from \"./parameter-entries.js\";\n\n/**\n * The type of a parameter `$ref`. The original indexed the parameter's location and name\n * (`refType`): `#/paths/~1a/get/parameters/0` gave\n * `paths[\"/a\"][\"get\"][\"parameters\"][\"query\"][\"q\"]`.\n * Where the generated type differs, that does not compile, and only there it changes:\n *\n * - A location whose parameters are all optional is an optional member (`query?:`), so indexing it\n * fails (TS2339); it is wrapped in `NonNullable` before the name is indexed.\n * - An OpenAPI 3.2 `in: querystring` parameter is the whole `query` member (ADR-020), not a member\n * `querystring`, so the pointer reads `[\"query\"]`.\n *\n * A `$ref` to a component parameter, or into a list the generator types elsewhere (a `$ref` path\n * item or operation, a callback), keeps the original type.\n */\n\nconst INDEX_RE = /^\\d+$/;\nconst OPERATION_KEYS: ReadonlySet<string> = new Set([...HTTP_METHODS, QUERY_METHOD]);\n\n/** A `parameters/N` pointer, split into its root and the segments of the list's owner. */\ninterface ParameterListPointer {\n readonly root: string;\n readonly owner: readonly string[];\n}\n\nfunction listPointerOf(ref: string): ParameterListPointer | null {\n if (!ref.startsWith(`${ROOT_POINTER}/`)) {\n return null;\n }\n const [root, ...segments] = parseRefPointer(ref);\n const [list, position] = segments.slice(-2);\n const isList = list === \"parameters\" && position !== undefined && INDEX_RE.test(position);\n return root !== undefined && isList ? { root, owner: segments.slice(0, -2) } : null;\n}\n\nfunction pointerTo(root: string, segments: readonly string[]): string {\n return appendPointer(ROOT_POINTER, [root, ...segments]);\n}\n\n/** Whether the segments name a path item that `pathItemType` types in place. */\nfunction isPathItemAt(root: string, segments: readonly string[]): boolean {\n const isNamedRoot = root === \"paths\" || root === \"webhooks\";\n return (\n (isNamedRoot && segments.length === 1) ||\n (root === \"components\" && segments[0] === \"pathItems\" && segments.length === 2)\n );\n}\n\n/** The segments of the path item that holds the operation at `owner`, or null. */\nfunction pathItemOfOperation(root: string, owner: readonly string[]): readonly string[] | null {\n const method = owner.at(-1) ?? \"\";\n if (OPERATION_KEYS.has(method) && isPathItemAt(root, owner.slice(0, -1))) {\n return owner.slice(0, -1);\n }\n const isAdditional = owner.at(-2) === ADDITIONAL_OPERATIONS_KEY;\n return isAdditional && isPathItemAt(root, owner.slice(0, -2)) ? owner.slice(0, -2) : null;\n}\n\nfunction documentNode<T>(refs: RefResolver, root: string, segments: readonly string[]): T | null {\n const node = refs.resolve(pointerTo(root, segments));\n const isTypedHere = typeof node === \"object\" && node !== null && !(\"$ref\" in node);\n return isTypedHere ? (node as T) : null;\n}\n\n/** The parameters the generator types at the list's owner; null where it types them elsewhere. */\nfunction typedParameters(\n pointer: ParameterListPointer,\n refs: RefResolver,\n): readonly ParameterOrReference[] | null {\n const { root, owner } = pointer;\n if (isPathItemAt(root, owner)) {\n return documentNode<PathItemObject>(refs, root, owner)?.parameters ?? null;\n }\n const pathItemSegments = pathItemOfOperation(root, owner);\n const pathItem = pathItemSegments && documentNode<PathItemObject>(refs, root, pathItemSegments);\n const operation = pathItem && documentNode<OperationObject>(refs, root, owner);\n return pathItem && operation ? mergedParameters(pathItem, operation, refs) : null;\n}\n\n/** A location member is optional when none of its parameters is required (`locationParts`). */\nfunction isLocationOptional(entries: readonly ParameterEntry[], location: string): boolean {\n return entries\n .filter((entry) => entry.resolved?.in === location)\n .every((entry) => location !== \"path\" && !entry.resolved?.required);\n}\n\n/** The corrected type, or null where the original type compiles or no correction applies. */\nfunction correctedType(\n listType: IrType,\n entries: readonly ParameterEntry[],\n parameter: ParameterObject,\n): IrType | null {\n if (parameter.in === QUERYSTRING_LOCATION) {\n // Next to `in: query` parameters it is not in the generated types (QUERYSTRING_NEXT_TO_QUERY).\n const isTyped = !entries.some((entry) => entry.resolved?.in === \"query\");\n return isTyped ? indexBy(listType, \"query\") : null;\n }\n if (!isLocationOptional(entries, parameter.in)) {\n return null;\n }\n const location = irReference(\"NonNullable\", [indexBy(listType, parameter.in)]);\n return indexBy(location, parameter.name);\n}\n\n/** The type of a parameter `$ref` whose target resolved to `resolved`; see the module comment. */\nexport function referencedParameterType(\n ref: string,\n resolved: ParameterObject,\n context: TransformContext,\n): IrType {\n // A `$ref` that resolves to another `$ref` is not a parameter object yet: index it as a path.\n if ((resolved as { $ref?: unknown }).$ref) {\n return refType(ref, { parameter: null });\n }\n const original = refType(ref, { parameter: { in: resolved.in, name: resolved.name } });\n const pointer = listPointerOf(ref);\n const parameters = pointer && typedParameters(pointer, context.refs);\n if (pointer === null || parameters === null) {\n return original;\n }\n const listType = refType(pointerTo(pointer.root, [...pointer.owner, \"parameters\"]));\n return correctedType(listType, parameterEntries(parameters, context), resolved) ?? original;\n}\n"],"names":[],"mappings":";;;;;;;AAuCA,MAAM,QAAA,GAAW,OAAA;AACjB,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,GAAG,YAAA,EAAc,YAAY,CAAC,CAAA;AAQnF,SAAS,cAAc,GAAA,EAA0C;AAC/D,EAAA,IAAI,CAAC,GAAA,CAAI,UAAA,CAAW,CAAA,EAAG,YAAY,GAAG,CAAA,EAAG;AACvC,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,CAAC,IAAA,EAAM,GAAG,QAAQ,CAAA,GAAI,gBAAg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IAAA,EAAM;AAC3C,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,SAAA,CAAU,OAAA,CAAQ,IAAA,EAAM,CAAC,GAAG,OAAA,CAAQ,KAAA,EAAO,YAAY,CAAC,CAAC,CAAA;AAClF,EAAA,OAAO,cAAc,QAAA,EAAU,gBAAA,CAAiB,YAAY,OAAO,CAAA,EAAG,QAAQ,CAAA,IAAK,QAAA;AACrF;;"}
|
|
@@ -11,7 +11,7 @@ const ANY_MEDIA_TYPE = "*/*";
|
|
|
11
11
|
function contentMembers(requestBody, location, context) {
|
|
12
12
|
const entries = documentEntries.documentEntries(requestBody.content ?? {}, context.options);
|
|
13
13
|
return entries.map(([contentType, entry]) => {
|
|
14
|
-
const path = jsonPointer.
|
|
14
|
+
const path = jsonPointer.appendPointer(location.path, ["content", contentType]);
|
|
15
15
|
const type = mediaType.contentEntryType(entry, { ...location, path }, context);
|
|
16
16
|
return documentMember.documentMember(contentType, type, entry, { isReadonly: context.options.immutable });
|
|
17
17
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-body.cjs","sources":["../../../../src/application/transform/document/request-body.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"request-body.cjs","sources":["../../../../src/application/transform/document/request-body.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { RequestBodyObject } from \"../../../domain/openapi/request-body-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { contentEntryType, itemContentMember } from \"./media-type.js\";\n\n/** Stands in for the media types of a body that defines none: `\"*\\/*\"?: never`. */\nconst ANY_MEDIA_TYPE = \"*/*\";\n\nfunction contentMembers(\n requestBody: RequestBodyObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrMember[] {\n const entries = documentEntries(requestBody.content ?? {}, context.options);\n return entries.map(([contentType, entry]) => {\n const path = appendPointer(location.path, [\"content\", contentType]);\n const type = contentEntryType(entry, { ...location, path }, context);\n return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });\n });\n}\n\n/**\n * A request body (OpenAPI 3.2 §4.8.13): `{ content: { [mediaType]: T } }`, and `itemContent` when a\n * media type has an `itemSchema`.\n */\nexport function requestBodyType(\n requestBody: RequestBodyObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const members = contentMembers(requestBody, location, context);\n // The placeholder is never readonly, even with --immutable, as in the original.\n const placeholder = irProperty(toPropertyName(ANY_MEDIA_TYPE), irKeyword(\"never\"), {\n isOptional: true,\n });\n const content = irObject(members.length > 0 ? members : [placeholder]);\n const isReadonly = context.options.immutable;\n const itemContent = itemContentMember(requestBody.content ?? {}, location, context, {\n isReadonly,\n });\n return irObject([\n irProperty(toPropertyName(\"content\"), content, { isReadonly }),\n ...(itemContent ? [itemContent] : []),\n ]);\n}\n"],"names":["documentEntries","appendPointer","contentEntryType","documentMember","irProperty","toPropertyName","irKeyword","irObject","itemContentMember"],"mappings":";;;;;;;;;AAWA,MAAM,cAAA,GAAiB,KAAA;AAEvB,SAAS,cAAA,CACP,WAAA,EACA,QAAA,EACA,OAAA,EACY;AACZ,EAAA,MAAM,UAAUA,+BAAA,CAAgB,WAAA,CAAY,WAAW,EAAC,EAAG,QAAQ,OAAO,CAAA;AAC1E,EAAA,OAAO,QAAQ,GAAA,CAAI,CAAC,CAAC,WAAA,EAAa,KAAK,CAAA,KAAM;AAC3C,IAAA,MAAM,OAAOC,yBAAA,CAAc,QAAA,CAAS,MAAM,CAAC,SAAA,EAAW,WAAW,CAAC,CAAA;AAClE,IAAA,MAAM,IAAA,GAAOC,2BAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AACnE,IAAA,OAAOC,6BAAA,CAAe,aAAa,IAAA,EAAM,KAAA,EAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EAC3F,CAAC,CAAA;AACH;AAMO,SAAS,eAAA,CACd,WAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,OAAA,GAAU,cAAA,CAAe,WAAA,EAAa,QAAA,EAAU,OAAO,CAAA;AAE7D,EAAA,MAAM,cAAcC,uBAAA,CAAWC,2BAAA,CAAe,cAAc,CAAA,EAAGC,sBAAA,CAAU,OAAO,CAAA,EAAG;AAAA,IACjF,UAAA,EAAY;AAAA,GACb,CAAA;AACD,EAAA,MAAM,OAAA,GAAUC,sBAAS,OAAA,CAAQ,MAAA,GAAS,IAAI,OAAA,GAAU,CAAC,WAAW,CAAC,CAAA;AACrE,EAAA,MAAM,UAAA,GAAa,QAAQ,OAAA,CAAQ,SAAA;AACnC,EAAA,MAAM,cAAcC,2BAAA,CAAkB,WAAA,CAAY,WAAW,EAAC,EAAG,UAAU,OAAA,EAAS;AAAA,IAClF;AAAA,GACD,CAAA;AACD,EAAA,OAAOD,qBAAA,CAAS;AAAA,IACdH,wBAAWC,2BAAA,CAAe,SAAS,GAAG,OAAA,EAAS,EAAE,YAAY,CAAA;AAAA,IAC7D,GAAI,WAAA,GAAc,CAAC,WAAW,IAAI;AAAC,GACpC,CAAA;AACH;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { irProperty, irKeyword, irObject } 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 { documentEntries } from '../document-entries.mjs';
|
|
5
5
|
import { documentMember } from './document-member.mjs';
|
|
6
6
|
import { itemContentMember, contentEntryType } from './media-type.mjs';
|
|
@@ -9,7 +9,7 @@ const ANY_MEDIA_TYPE = "*/*";
|
|
|
9
9
|
function contentMembers(requestBody, location, context) {
|
|
10
10
|
const entries = documentEntries(requestBody.content ?? {}, context.options);
|
|
11
11
|
return entries.map(([contentType, entry]) => {
|
|
12
|
-
const path =
|
|
12
|
+
const path = appendPointer(location.path, ["content", contentType]);
|
|
13
13
|
const type = contentEntryType(entry, { ...location, path }, context);
|
|
14
14
|
return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });
|
|
15
15
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-body.mjs","sources":["../../../../src/application/transform/document/request-body.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"request-body.mjs","sources":["../../../../src/application/transform/document/request-body.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { RequestBodyObject } from \"../../../domain/openapi/request-body-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { contentEntryType, itemContentMember } from \"./media-type.js\";\n\n/** Stands in for the media types of a body that defines none: `\"*\\/*\"?: never`. */\nconst ANY_MEDIA_TYPE = \"*/*\";\n\nfunction contentMembers(\n requestBody: RequestBodyObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrMember[] {\n const entries = documentEntries(requestBody.content ?? {}, context.options);\n return entries.map(([contentType, entry]) => {\n const path = appendPointer(location.path, [\"content\", contentType]);\n const type = contentEntryType(entry, { ...location, path }, context);\n return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });\n });\n}\n\n/**\n * A request body (OpenAPI 3.2 §4.8.13): `{ content: { [mediaType]: T } }`, and `itemContent` when a\n * media type has an `itemSchema`.\n */\nexport function requestBodyType(\n requestBody: RequestBodyObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const members = contentMembers(requestBody, location, context);\n // The placeholder is never readonly, even with --immutable, as in the original.\n const placeholder = irProperty(toPropertyName(ANY_MEDIA_TYPE), irKeyword(\"never\"), {\n isOptional: true,\n });\n const content = irObject(members.length > 0 ? members : [placeholder]);\n const isReadonly = context.options.immutable;\n const itemContent = itemContentMember(requestBody.content ?? {}, location, context, {\n isReadonly,\n });\n return irObject([\n irProperty(toPropertyName(\"content\"), content, { isReadonly }),\n ...(itemContent ? [itemContent] : []),\n ]);\n}\n"],"names":[],"mappings":";;;;;;;AAWA,MAAM,cAAA,GAAiB,KAAA;AAEvB,SAAS,cAAA,CACP,WAAA,EACA,QAAA,EACA,OAAA,EACY;AACZ,EAAA,MAAM,UAAU,eAAA,CAAgB,WAAA,CAAY,WAAW,EAAC,EAAG,QAAQ,OAAO,CAAA;AAC1E,EAAA,OAAO,QAAQ,GAAA,CAAI,CAAC,CAAC,WAAA,EAAa,KAAK,CAAA,KAAM;AAC3C,IAAA,MAAM,OAAO,aAAA,CAAc,QAAA,CAAS,MAAM,CAAC,SAAA,EAAW,WAAW,CAAC,CAAA;AAClE,IAAA,MAAM,IAAA,GAAO,iBAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AACnE,IAAA,OAAO,cAAA,CAAe,aAAa,IAAA,EAAM,KAAA,EAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EAC3F,CAAC,CAAA;AACH;AAMO,SAAS,eAAA,CACd,WAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,OAAA,GAAU,cAAA,CAAe,WAAA,EAAa,QAAA,EAAU,OAAO,CAAA;AAE7D,EAAA,MAAM,cAAc,UAAA,CAAW,cAAA,CAAe,cAAc,CAAA,EAAG,SAAA,CAAU,OAAO,CAAA,EAAG;AAAA,IACjF,UAAA,EAAY;AAAA,GACb,CAAA;AACD,EAAA,MAAM,OAAA,GAAU,SAAS,OAAA,CAAQ,MAAA,GAAS,IAAI,OAAA,GAAU,CAAC,WAAW,CAAC,CAAA;AACrE,EAAA,MAAM,UAAA,GAAa,QAAQ,OAAA,CAAQ,SAAA;AACnC,EAAA,MAAM,cAAc,iBAAA,CAAkB,WAAA,CAAY,WAAW,EAAC,EAAG,UAAU,OAAA,EAAS;AAAA,IAClF;AAAA,GACD,CAAA;AACD,EAAA,OAAO,QAAA,CAAS;AAAA,IACd,WAAW,cAAA,CAAe,SAAS,GAAG,OAAA,EAAS,EAAE,YAAY,CAAA;AAAA,IAC7D,GAAI,WAAA,GAAc,CAAC,WAAW,IAAI;AAAC,GACpC,CAAA;AACH;;"}
|
|
@@ -15,7 +15,7 @@ function headerMember(name, header$1, location, context) {
|
|
|
15
15
|
const isReference = "$ref" in header$1;
|
|
16
16
|
const type = isReference ? refType.refType(header$1.$ref) : header.headerType(
|
|
17
17
|
header$1,
|
|
18
|
-
{ ...location, path: jsonPointer.
|
|
18
|
+
{ ...location, path: jsonPointer.appendPointer(location.path, ["headers", name]) },
|
|
19
19
|
context
|
|
20
20
|
);
|
|
21
21
|
return documentMember.documentMember(name, type, header$1, {
|
|
@@ -37,7 +37,7 @@ function mediaTypeEntryType(entry, location, context) {
|
|
|
37
37
|
function contentMember(response, location, context) {
|
|
38
38
|
const entries = documentEntries.documentEntries(response.content ?? {}, context.options);
|
|
39
39
|
const members = entries.map(([contentType, entry]) => {
|
|
40
|
-
const path = jsonPointer.
|
|
40
|
+
const path = jsonPointer.appendPointer(location.path, ["content", contentType]);
|
|
41
41
|
const type = mediaTypeEntryType(entry, { ...location, path }, context);
|
|
42
42
|
return documentMember.documentMember(contentType, type, entry, { isReadonly: context.options.immutable });
|
|
43
43
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.cjs","sources":["../../../../src/application/transform/document/response.ts"],"sourcesContent":["import {\n irKeyword,\n irObject,\n irProperty,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"response.cjs","sources":["../../../../src/application/transform/document/response.ts"],"sourcesContent":["import {\n irKeyword,\n irObject,\n irProperty,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n isMediaTypeComponentRef,\n type MediaTypeObject,\n} from \"../../../domain/openapi/media-type-object.js\";\nimport type { ResponseObject } from \"../../../domain/openapi/response-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { headerType } from \"./header.js\";\nimport { contentEntryType, itemContentMember, mediaTypeType } from \"./media-type.js\";\n\ntype HeaderEntry = NonNullable<ResponseObject[\"headers\"]>[string];\n\nfunction headerMember(\n name: string,\n header: HeaderEntry,\n location: SchemaLocation,\n context: SchemaContext,\n): IrPropertySignature {\n // A referenced header counts as required: the reference does not say otherwise.\n const isReference = \"$ref\" in header;\n const type = isReference\n ? refType(header.$ref)\n : headerType(\n header,\n { ...location, path: appendPointer(location.path, [\"headers\", name]) },\n context,\n );\n return documentMember(name, type, header, {\n isReadonly: context.options.immutable,\n isOptional: !isReference && !header.required,\n });\n}\n\n/** The listed headers, then `[name: string]: unknown`, because servers may send others. */\nfunction headersMember(\n response: ResponseObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrPropertySignature {\n const entries = documentEntries(response.headers ?? {}, context.options);\n const members: IrMember[] = entries.map(([name, header]) =>\n headerMember(name, header, location, context),\n );\n members.push(irStringIndexSignature(\"name\", UNKNOWN_TYPE, context.options.immutable));\n return irProperty(toPropertyName(\"headers\"), irObject(members));\n}\n\n/**\n * One media type of a response. The original reads a `$ref` entry as a media type without a\n * schema, so it is `unknown`; a `$ref` to an OpenAPI 3.2 media type component is typed as it.\n */\nfunction mediaTypeEntryType(\n entry: NonNullable<ResponseObject[\"content\"]>[string],\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n return \"$ref\" in entry && isMediaTypeComponentRef(entry.$ref)\n ? contentEntryType(entry, location, context)\n : mediaTypeType(entry as MediaTypeObject, location, context);\n}\n\n/** `content` with one member per media type, or `content?: never` when there are none. */\nfunction contentMember(\n response: ResponseObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrPropertySignature {\n const entries = documentEntries(response.content ?? {}, context.options);\n const members = entries.map(([contentType, entry]) => {\n const path = appendPointer(location.path, [\"content\", contentType]);\n const type = mediaTypeEntryType(entry, { ...location, path }, context);\n return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });\n });\n const name = toPropertyName(\"content\");\n return members.length > 0\n ? irProperty(name, irObject(members))\n : irProperty(name, irKeyword(\"never\"), { isOptional: true });\n}\n\n/**\n * A response (OpenAPI 3.2 §4.8.17): `{ headers: {…}; content: {…} }`, and `itemContent` when a\n * media type has an `itemSchema`. No member is readonly, even with --immutable, as in the original.\n */\nexport function responseType(\n response: ResponseObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const itemContent = itemContentMember(response.content ?? {}, location, context, {\n isReadonly: false,\n });\n return irObject([\n headersMember(response, location, context),\n contentMember(response, location, context),\n ...(itemContent ? [itemContent] : []),\n ]);\n}\n"],"names":["header","refType","headerType","appendPointer","documentMember","documentEntries","irStringIndexSignature","UNKNOWN_TYPE","irProperty","toPropertyName","irObject","isMediaTypeComponentRef","contentEntryType","mediaTypeType","irKeyword","itemContentMember"],"mappings":";;;;;;;;;;;;;AAwBA,SAAS,YAAA,CACP,IAAA,EACAA,QAAA,EACA,QAAA,EACA,OAAA,EACqB;AAErB,EAAA,MAAM,cAAc,MAAA,IAAUA,QAAA;AAC9B,EAAA,MAAM,IAAA,GAAO,WAAA,GACTC,eAAA,CAAQD,QAAA,CAAO,IAAI,CAAA,GACnBE,iBAAA;AAAA,IACEF,QAAA;AAAA,IACA,EAAE,GAAG,QAAA,EAAU,IAAA,EAAMG,yBAAA,CAAc,QAAA,CAAS,IAAA,EAAM,CAAC,SAAA,EAAW,IAAI,CAAC,CAAA,EAAE;AAAA,IACrE;AAAA,GACF;AACJ,EAAA,OAAOC,6BAAA,CAAe,IAAA,EAAM,IAAA,EAAMJ,QAAA,EAAQ;AAAA,IACxC,UAAA,EAAY,QAAQ,OAAA,CAAQ,SAAA;AAAA,IAC5B,UAAA,EAAY,CAAC,WAAA,IAAe,CAACA,QAAA,CAAO;AAAA,GACrC,CAAA;AACH;AAGA,SAAS,aAAA,CACP,QAAA,EACA,QAAA,EACA,OAAA,EACqB;AACrB,EAAA,MAAM,UAAUK,+BAAA,CAAgB,QAAA,CAAS,WAAW,EAAC,EAAG,QAAQ,OAAO,CAAA;AACvE,EAAA,MAAM,UAAsB,OAAA,CAAQ,GAAA;AAAA,IAAI,CAAC,CAAC,IAAA,EAAM,MAAM,MACpD,YAAA,CAAa,IAAA,EAAM,MAAA,EAAQ,QAAA,EAAU,OAAO;AAAA,GAC9C;AACA,EAAA,OAAA,CAAQ,KAAKC,mCAAA,CAAuB,MAAA,EAAQC,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AS,YAAA,CACd,QAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,cAAcC,2BAAA,CAAkB,QAAA,CAAS,WAAW,EAAC,EAAG,UAAU,OAAA,EAAS;AAAA,IAC/E,UAAA,EAAY;AAAA,GACb,CAAA;AACD,EAAA,OAAOL,qBAAA,CAAS;AAAA,IACd,aAAA,CAAc,QAAA,EAAU,QAAA,EAAU,OAAO,CAAA;AAAA,IACzC,aAAA,CAAc,QAAA,EAAU,QAAA,EAAU,OAAO,CAAA;AAAA,IACzC,GAAI,WAAA,GAAc,CAAC,WAAW,IAAI;AAAC,GACpC,CAAA;AACH;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { irObject, irStringIndexSignature, irProperty, irKeyword } 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 { isMediaTypeComponentRef } from '../../../domain/openapi/media-type-object.mjs';
|
|
5
5
|
import { documentEntries } from '../document-entries.mjs';
|
|
6
6
|
import { refType } from '../ref-type.mjs';
|
|
@@ -13,7 +13,7 @@ function headerMember(name, header, location, context) {
|
|
|
13
13
|
const isReference = "$ref" in header;
|
|
14
14
|
const type = isReference ? refType(header.$ref) : headerType(
|
|
15
15
|
header,
|
|
16
|
-
{ ...location, path:
|
|
16
|
+
{ ...location, path: appendPointer(location.path, ["headers", name]) },
|
|
17
17
|
context
|
|
18
18
|
);
|
|
19
19
|
return documentMember(name, type, header, {
|
|
@@ -35,7 +35,7 @@ function mediaTypeEntryType(entry, location, context) {
|
|
|
35
35
|
function contentMember(response, location, context) {
|
|
36
36
|
const entries = documentEntries(response.content ?? {}, context.options);
|
|
37
37
|
const members = entries.map(([contentType, entry]) => {
|
|
38
|
-
const path =
|
|
38
|
+
const path = appendPointer(location.path, ["content", contentType]);
|
|
39
39
|
const type = mediaTypeEntryType(entry, { ...location, path }, context);
|
|
40
40
|
return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });
|
|
41
41
|
});
|