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
|
@@ -31,7 +31,8 @@ function indexKeyword(type, segment, isLast) {
|
|
|
31
31
|
return segment === DEFS_KEYWORD && !isLast ? constructors.irReference("NonNullable", [indexed]) : indexed;
|
|
32
32
|
}
|
|
33
33
|
function rootType(rootSegment, isDeep) {
|
|
34
|
-
|
|
34
|
+
const root = constructors.irReference(rootSegment);
|
|
35
|
+
return isDeep ? constructors.irReference("FlattenedDeepRequired", [root]) : root;
|
|
35
36
|
}
|
|
36
37
|
function refType(ref, options = {}) {
|
|
37
38
|
const [rootSegment, ...pointer] = jsonPointer.parseRefPointer(ref);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref-type.cjs","sources":["../../../src/application/transform/ref-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport {\n irIndexedAccess,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n irString,\n} from \"../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../domain/openapi/json-pointer.js\";\n\n/** Where a referenced parameter lives in the generated `parameters` type. */\nexport interface RefParameterTarget {\n readonly in: string;\n readonly name: string;\n}\n\nexport interface RefTypeOptions {\n /** Wrap the root in `FlattenedDeepRequired<…>`. */\n readonly isDeep?: boolean;\n /** Segments to narrow with `Extract<T, { segment: unknown }>` before indexing. */\n readonly extractProperties?: readonly string[];\n /** Set when the `$ref` resolves to a parameter object: its last segment indexes `in`, `name`. */\n readonly parameter?: RefParameterTarget | null;\n}\n\nexport class InvalidRefError extends OpenAPITypesafeError {\n constructor(ref: string) {\n super({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: `Error parsing $ref: ${ref}. Is this a valid $ref?`,\n details: { ref },\n });\n this.name = \"InvalidRefError\";\n }\n}\n\n/** Segments that index into the root type, always as escaped string literal types. */\nexport function indexBy(type: IrType, ...segments: readonly string[]): IrType {\n return segments.reduce<IrType>(\n (object, segment) => irIndexedAccess(object, irString(segment, \"escaped\")),\n type,\n );\n}\n\n/**\n * `Extract<T, { name: unknown }>`. The original wrote the name as an identifier even when it is\n * not one (`{ content-type: unknown }`), which is a syntax error; it is now quoted like any other\n * property name, and an identifier stays as it was.\n */\nexport function extractVariantsWith(type: IrType, propertyName: string): IrType {\n const probe = irProperty(toPropertyName(propertyName), irKeyword(\"unknown\"));\n return irReference(\"Extract\", [type, irObject([probe])]);\n}\n\nconst DEFS_KEYWORD = \"$defs\";\n\n/**\n * Index by `segment`. A `$defs` member is optional (it is a keyword, not data), so when more\n * segments follow it is wrapped in `NonNullable<…>` first; otherwise the next index fails on\n * `undefined` (upstream #2664).\n */\nexport function indexKeyword(type: IrType, segment: string, isLast: boolean): IrType {\n const indexed = indexBy(type, segment);\n return segment === DEFS_KEYWORD && !isLast ? irReference(\"NonNullable\", [indexed]) : indexed;\n}\n\nexport function rootType(rootSegment: string, isDeep: boolean): IrType {\n
|
|
1
|
+
{"version":3,"file":"ref-type.cjs","sources":["../../../src/application/transform/ref-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport {\n irIndexedAccess,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n irString,\n} from \"../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../domain/openapi/json-pointer.js\";\n\n/** Where a referenced parameter lives in the generated `parameters` type. */\nexport interface RefParameterTarget {\n readonly in: string;\n readonly name: string;\n}\n\nexport interface RefTypeOptions {\n /** Wrap the root in `FlattenedDeepRequired<…>`. */\n readonly isDeep?: boolean;\n /** Segments to narrow with `Extract<T, { segment: unknown }>` before indexing. */\n readonly extractProperties?: readonly string[];\n /** Set when the `$ref` resolves to a parameter object: its last segment indexes `in`, `name`. */\n readonly parameter?: RefParameterTarget | null;\n}\n\nexport class InvalidRefError extends OpenAPITypesafeError {\n constructor(ref: string) {\n super({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: `Error parsing $ref: ${ref}. Is this a valid $ref?`,\n details: { ref },\n });\n this.name = \"InvalidRefError\";\n }\n}\n\n/** Segments that index into the root type, always as escaped string literal types. */\nexport function indexBy(type: IrType, ...segments: readonly string[]): IrType {\n return segments.reduce<IrType>(\n (object, segment) => irIndexedAccess(object, irString(segment, \"escaped\")),\n type,\n );\n}\n\n/**\n * `Extract<T, { name: unknown }>`. The original wrote the name as an identifier even when it is\n * not one (`{ content-type: unknown }`), which is a syntax error; it is now quoted like any other\n * property name, and an identifier stays as it was.\n */\nexport function extractVariantsWith(type: IrType, propertyName: string): IrType {\n const probe = irProperty(toPropertyName(propertyName), irKeyword(\"unknown\"));\n return irReference(\"Extract\", [type, irObject([probe])]);\n}\n\nconst DEFS_KEYWORD = \"$defs\";\n\n/**\n * Index by `segment`. A `$defs` member is optional (it is a keyword, not data), so when more\n * segments follow it is wrapped in `NonNullable<…>` first; otherwise the next index fails on\n * `undefined` (upstream #2664).\n */\nexport function indexKeyword(type: IrType, segment: string, isLast: boolean): IrType {\n const indexed = indexBy(type, segment);\n return segment === DEFS_KEYWORD && !isLast ? irReference(\"NonNullable\", [indexed]) : indexed;\n}\n\nexport function rootType(rootSegment: string, isDeep: boolean): IrType {\n const root = irReference(rootSegment);\n return isDeep ? irReference(\"FlattenedDeepRequired\", [root]) : root;\n}\n\n/**\n * The indexed-access type of a `$ref` into the generated types (the original `oapiRef`), for\n * example `components[\"schemas\"][\"Foo\"]`. The first three segments index directly. After them,\n * `properties` segments are skipped (objects are flattened, upstream issue 1742), a parameter's\n * last segment becomes `[in][name]`, and listed segments are narrowed with `Extract` first.\n *\n * Throws InvalidRefError when the `$ref` has no pointer.\n */\nexport function refType(ref: string, options: RefTypeOptions = {}): IrType {\n const [rootSegment, ...pointer] = parseRefPointer(ref);\n if (rootSegment === undefined) {\n throw new InvalidRefError(ref);\n }\n const extracted = new Set(options.extractProperties ?? []);\n const lastIndex = pointer.length - 1;\n const leading = indexBy(rootType(rootSegment, options.isDeep ?? false), ...pointer.slice(0, 2));\n return pointer.slice(2).reduce<IrType>((type, segment, offset) => {\n if (segment === \"properties\") {\n return type;\n }\n if (options.parameter && offset + 2 === lastIndex) {\n return indexBy(type, options.parameter.in, options.parameter.name);\n }\n const isLast = offset + 2 === lastIndex;\n return extracted.has(segment)\n ? indexBy(extractVariantsWith(type, segment), segment)\n : indexKeyword(type, segment, isLast);\n }, leading);\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","irIndexedAccess","irString","propertyName","irProperty","toPropertyName","irKeyword","irReference","irObject","parseRefPointer"],"mappings":";;;;;;;AA4BO,MAAM,wBAAwBA,2BAAA,CAAqB;AAAA,EACxD,YAAY,GAAA,EAAa;AACvB,IAAA,KAAA,CAAM;AAAA,MACJ,MAAMC,kBAAA,CAAY,kBAAA;AAAA,MAClB,OAAA,EAAS,uBAAuB,GAAG,CAAA,uBAAA,CAAA;AAAA,MACnC,OAAA,EAAS,EAAE,GAAA;AAAI,KAChB,CAA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AA,EAC/B;AACA,EAAA,MAAM,YAAY,IAAI,GAAA,CAAI,OAAA,CAAQ,iBAAA,IAAqB,EAAE,CAAA;AACzD,EAAA,MAAM,SAAA,GAAY,QAAQ,MAAA,GAAS,CAAA;AACnC,EAAA,MAAM,OAAA,GAAU,OAAA,CAAQ,QAAA,CAAS,WAAA,EAAa,OAAA,CAAQ,MAAA,IAAU,KAAK,CAAA,EAAG,GAAG,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA;AAC9F,EAAA,OAAO,OAAA,CAAQ,MAAM,CAAC,CAAA,CAAE,OAAe,CAAC,IAAA,EAAM,SAAS,MAAA,KAAW;AAChE,IAAA,IAAI,YAAY,YAAA,EAAc;AAC5B,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,IAAI,OAAA,CAAQ,SAAA,IAAa,MAAA,GAAS,CAAA,KAAM,SAAA,EAAW;AACjD,MAAA,OAAO,QAAQ,IAAA,EAAM,OAAA,CAAQ,UAAU,EAAA,EAAI,OAAA,CAAQ,UAAU,IAAI,CAAA;AAAA,IACnE;AACA,IAAA,MAAM,MAAA,GAAS,SAAS,CAAA,KAAM,SAAA;AAC9B,IAAA,OAAO,SAAA,CAAU,GAAA,CAAI,OAAO,CAAA,GACxB,QAAQ,mBAAA,CAAoB,IAAA,EAAM,OAAO,CAAA,EAAG,OAAO,CAAA,GACnD,YAAA,CAAa,IAAA,EAAM,SAAS,MAAM,CAAA;AAAA,EACxC,GAAG,OAAO,CAAA;AACZ;;;;;;;"}
|
|
@@ -29,7 +29,8 @@ function indexKeyword(type, segment, isLast) {
|
|
|
29
29
|
return segment === DEFS_KEYWORD && !isLast ? irReference("NonNullable", [indexed]) : indexed;
|
|
30
30
|
}
|
|
31
31
|
function rootType(rootSegment, isDeep) {
|
|
32
|
-
|
|
32
|
+
const root = irReference(rootSegment);
|
|
33
|
+
return isDeep ? irReference("FlattenedDeepRequired", [root]) : root;
|
|
33
34
|
}
|
|
34
35
|
function refType(ref, options = {}) {
|
|
35
36
|
const [rootSegment, ...pointer] = parseRefPointer(ref);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref-type.mjs","sources":["../../../src/application/transform/ref-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport {\n irIndexedAccess,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n irString,\n} from \"../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../domain/openapi/json-pointer.js\";\n\n/** Where a referenced parameter lives in the generated `parameters` type. */\nexport interface RefParameterTarget {\n readonly in: string;\n readonly name: string;\n}\n\nexport interface RefTypeOptions {\n /** Wrap the root in `FlattenedDeepRequired<…>`. */\n readonly isDeep?: boolean;\n /** Segments to narrow with `Extract<T, { segment: unknown }>` before indexing. */\n readonly extractProperties?: readonly string[];\n /** Set when the `$ref` resolves to a parameter object: its last segment indexes `in`, `name`. */\n readonly parameter?: RefParameterTarget | null;\n}\n\nexport class InvalidRefError extends OpenAPITypesafeError {\n constructor(ref: string) {\n super({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: `Error parsing $ref: ${ref}. Is this a valid $ref?`,\n details: { ref },\n });\n this.name = \"InvalidRefError\";\n }\n}\n\n/** Segments that index into the root type, always as escaped string literal types. */\nexport function indexBy(type: IrType, ...segments: readonly string[]): IrType {\n return segments.reduce<IrType>(\n (object, segment) => irIndexedAccess(object, irString(segment, \"escaped\")),\n type,\n );\n}\n\n/**\n * `Extract<T, { name: unknown }>`. The original wrote the name as an identifier even when it is\n * not one (`{ content-type: unknown }`), which is a syntax error; it is now quoted like any other\n * property name, and an identifier stays as it was.\n */\nexport function extractVariantsWith(type: IrType, propertyName: string): IrType {\n const probe = irProperty(toPropertyName(propertyName), irKeyword(\"unknown\"));\n return irReference(\"Extract\", [type, irObject([probe])]);\n}\n\nconst DEFS_KEYWORD = \"$defs\";\n\n/**\n * Index by `segment`. A `$defs` member is optional (it is a keyword, not data), so when more\n * segments follow it is wrapped in `NonNullable<…>` first; otherwise the next index fails on\n * `undefined` (upstream #2664).\n */\nexport function indexKeyword(type: IrType, segment: string, isLast: boolean): IrType {\n const indexed = indexBy(type, segment);\n return segment === DEFS_KEYWORD && !isLast ? irReference(\"NonNullable\", [indexed]) : indexed;\n}\n\nexport function rootType(rootSegment: string, isDeep: boolean): IrType {\n
|
|
1
|
+
{"version":3,"file":"ref-type.mjs","sources":["../../../src/application/transform/ref-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport {\n irIndexedAccess,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n irString,\n} from \"../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../domain/ir/property-name.js\";\nimport { parseRefPointer } from \"../../domain/openapi/json-pointer.js\";\n\n/** Where a referenced parameter lives in the generated `parameters` type. */\nexport interface RefParameterTarget {\n readonly in: string;\n readonly name: string;\n}\n\nexport interface RefTypeOptions {\n /** Wrap the root in `FlattenedDeepRequired<…>`. */\n readonly isDeep?: boolean;\n /** Segments to narrow with `Extract<T, { segment: unknown }>` before indexing. */\n readonly extractProperties?: readonly string[];\n /** Set when the `$ref` resolves to a parameter object: its last segment indexes `in`, `name`. */\n readonly parameter?: RefParameterTarget | null;\n}\n\nexport class InvalidRefError extends OpenAPITypesafeError {\n constructor(ref: string) {\n super({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: `Error parsing $ref: ${ref}. Is this a valid $ref?`,\n details: { ref },\n });\n this.name = \"InvalidRefError\";\n }\n}\n\n/** Segments that index into the root type, always as escaped string literal types. */\nexport function indexBy(type: IrType, ...segments: readonly string[]): IrType {\n return segments.reduce<IrType>(\n (object, segment) => irIndexedAccess(object, irString(segment, \"escaped\")),\n type,\n );\n}\n\n/**\n * `Extract<T, { name: unknown }>`. The original wrote the name as an identifier even when it is\n * not one (`{ content-type: unknown }`), which is a syntax error; it is now quoted like any other\n * property name, and an identifier stays as it was.\n */\nexport function extractVariantsWith(type: IrType, propertyName: string): IrType {\n const probe = irProperty(toPropertyName(propertyName), irKeyword(\"unknown\"));\n return irReference(\"Extract\", [type, irObject([probe])]);\n}\n\nconst DEFS_KEYWORD = \"$defs\";\n\n/**\n * Index by `segment`. A `$defs` member is optional (it is a keyword, not data), so when more\n * segments follow it is wrapped in `NonNullable<…>` first; otherwise the next index fails on\n * `undefined` (upstream #2664).\n */\nexport function indexKeyword(type: IrType, segment: string, isLast: boolean): IrType {\n const indexed = indexBy(type, segment);\n return segment === DEFS_KEYWORD && !isLast ? irReference(\"NonNullable\", [indexed]) : indexed;\n}\n\nexport function rootType(rootSegment: string, isDeep: boolean): IrType {\n const root = irReference(rootSegment);\n return isDeep ? irReference(\"FlattenedDeepRequired\", [root]) : root;\n}\n\n/**\n * The indexed-access type of a `$ref` into the generated types (the original `oapiRef`), for\n * example `components[\"schemas\"][\"Foo\"]`. The first three segments index directly. After them,\n * `properties` segments are skipped (objects are flattened, upstream issue 1742), a parameter's\n * last segment becomes `[in][name]`, and listed segments are narrowed with `Extract` first.\n *\n * Throws InvalidRefError when the `$ref` has no pointer.\n */\nexport function refType(ref: string, options: RefTypeOptions = {}): IrType {\n const [rootSegment, ...pointer] = parseRefPointer(ref);\n if (rootSegment === undefined) {\n throw new InvalidRefError(ref);\n }\n const extracted = new Set(options.extractProperties ?? []);\n const lastIndex = pointer.length - 1;\n const leading = indexBy(rootType(rootSegment, options.isDeep ?? false), ...pointer.slice(0, 2));\n return pointer.slice(2).reduce<IrType>((type, segment, offset) => {\n if (segment === \"properties\") {\n return type;\n }\n if (options.parameter && offset + 2 === lastIndex) {\n return indexBy(type, options.parameter.in, options.parameter.name);\n }\n const isLast = offset + 2 === lastIndex;\n return extracted.has(segment)\n ? indexBy(extractVariantsWith(type, segment), segment)\n : indexKey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
|
1
|
-
{"version":3,"file":"access-flags.cjs","sources":["../../../../src/application/transform/schema/access-flags.ts"],"sourcesContent":["import type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext } from \"./schema-context.js\";\n\n/** Whether a property is `readOnly` or `writeOnly` (JSON Schema 2020-12 Validation §9.4). */\nexport interface AccessFlags {\n readonly isReadOnly: boolean;\n readonly isWriteOnly: boolean;\n}\n\nconst NO_FLAGS: AccessFlags = { isReadOnly: false, isWriteOnly: false };\n\nfunction ownFlags(schema: SchemaObject): AccessFlags {\n return { isReadOnly: Boolean(schema.readOnly), isWriteOnly: Boolean(schema.writeOnly) };\n}\n\nfunction merged(left: AccessFlags, right: AccessFlags): AccessFlags {\n return {\n isReadOnly: left.isReadOnly || right.isReadOnly,\n isWriteOnly: left.isWriteOnly || right.isWriteOnly,\n };\n}\n\n/**\n * The flags of a schema and of the schemas that always apply to the same value: the one its\n * `$ref` names and its `allOf` members, followed until a schema repeats. `readOnly` is an\n * annotation, and the annotations of those schemas are the value's (2020-12 Core §7.7.1); in\n * OpenAPI 3.0 a referenced schema is the property's definition. `anyOf` and `oneOf` members apply\n * only when they match, which the type cannot tell, so they are not read.\n */\nfunction appliedFlags(\n schema: Schema | undefined,\n context: SchemaContext
|
|
1
|
+
{"version":3,"file":"access-flags.cjs","sources":["../../../../src/application/transform/schema/access-flags.ts"],"sourcesContent":["import type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext } from \"./schema-context.js\";\n\n/** Whether a property is `readOnly` or `writeOnly` (JSON Schema 2020-12 Validation §9.4). */\nexport interface AccessFlags {\n readonly isReadOnly: boolean;\n readonly isWriteOnly: boolean;\n}\n\nconst NO_FLAGS: AccessFlags = { isReadOnly: false, isWriteOnly: false };\n\nfunction ownFlags(schema: SchemaObject): AccessFlags {\n return { isReadOnly: Boolean(schema.readOnly), isWriteOnly: Boolean(schema.writeOnly) };\n}\n\nfunction merged(left: AccessFlags, right: AccessFlags): AccessFlags {\n return {\n isReadOnly: left.isReadOnly || right.isReadOnly,\n isWriteOnly: left.isWriteOnly || right.isWriteOnly,\n };\n}\n\n/**\n * The flags of a schema and of the schemas that always apply to the same value: the one its\n * `$ref` names and its `allOf` members, followed until a schema repeats. `readOnly` is an\n * annotation, and the annotations of those schemas are the value's (2020-12 Core §7.7.1); in\n * OpenAPI 3.0 a referenced schema is the property's definition. `anyOf` and `oneOf` members apply\n * only when they match, which the type cannot tell, so they are not read.\n */\nfunction appliedFlags(\n schema: Schema | undefined,\n context: Pick<SchemaContext, \"refs\">,\n seen: ReadonlySet<Schema>,\n): AccessFlags {\n if (typeof schema !== \"object\" || schema === null || seen.has(schema)) {\n return NO_FLAGS;\n }\n const inner = new Set([...seen, schema]);\n // `readOnly` next to a `$ref` is read too, as the generator always has.\n const object = schema as SchemaObject & { readonly $ref?: unknown };\n const target =\n typeof object.$ref === \"string\" ? (context.refs.resolve(object.$ref) as Schema) : undefined;\n return (object.allOf ?? []).reduce<AccessFlags>(\n (flags, member) => merged(flags, appliedFlags(member, context, inner)),\n merged(ownFlags(object), appliedFlags(target, context, inner)),\n );\n}\n\n/**\n * The flags of a property schema. Without the `read-write-refs` fix only the keywords written on\n * it count, as in openapi-typescript; with it, also those of the schemas its `$ref` and `allOf`\n * apply (upstream #1938).\n */\nexport function propertyAccessFlags(\n value: Schema,\n context: Pick<SchemaContext, \"options\" | \"refs\">,\n): AccessFlags {\n if (typeof value !== \"object\") {\n return NO_FLAGS;\n }\n if (!context.options.fixes.has(FIX.READ_WRITE_REFS)) {\n return ownFlags(value as SchemaObject);\n }\n return appliedFlags(value, context, new Set());\n}\n"],"names":["FIX"],"mappings":";;;;AAUA,MAAM,QAAA,GAAwB,EAAE,UAAA,EAAY,KAAA,EAAO,aAAa,KAAA,EAAM;AAEtE,SAAS,SAAS,MAAA,EAAmC;AACnD,EAAA,O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,MAAM,GAAA,CAAIA,eAAA,CAAI,eAAe,CAAA,EAAG;AACnD,IAAA,OAAO,SAAS,KAAqB,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,YAAA,CAAa,KAAA,EAAO,OAAA,kBAAS,IAAI,KAAK,CAAA;AAC/C;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-flags.mjs","sources":["../../../../src/application/transform/schema/access-flags.ts"],"sourcesContent":["import type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext } from \"./schema-context.js\";\n\n/** Whether a property is `readOnly` or `writeOnly` (JSON Schema 2020-12 Validation §9.4). */\nexport interface AccessFlags {\n readonly isReadOnly: boolean;\n readonly isWriteOnly: boolean;\n}\n\nconst NO_FLAGS: AccessFlags = { isReadOnly: false, isWriteOnly: false };\n\nfunction ownFlags(schema: SchemaObject): AccessFlags {\n return { isReadOnly: Boolean(schema.readOnly), isWriteOnly: Boolean(schema.writeOnly) };\n}\n\nfunction merged(left: AccessFlags, right: AccessFlags): AccessFlags {\n return {\n isReadOnly: left.isReadOnly || right.isReadOnly,\n isWriteOnly: left.isWriteOnly || right.isWriteOnly,\n };\n}\n\n/**\n * The flags of a schema and of the schemas that always apply to the same value: the one its\n * `$ref` names and its `allOf` members, followed until a schema repeats. `readOnly` is an\n * annotation, and the annotations of those schemas are the value's (2020-12 Core §7.7.1); in\n * OpenAPI 3.0 a referenced schema is the property's definition. `anyOf` and `oneOf` members apply\n * only when they match, which the type cannot tell, so they are not read.\n */\nfunction appliedFlags(\n schema: Schema | undefined,\n context: SchemaContext
|
|
1
|
+
{"version":3,"file":"access-flags.mjs","sources":["../../../../src/application/transform/schema/access-flags.ts"],"sourcesContent":["import type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext } from \"./schema-context.js\";\n\n/** Whether a property is `readOnly` or `writeOnly` (JSON Schema 2020-12 Validation §9.4). */\nexport interface AccessFlags {\n readonly isReadOnly: boolean;\n readonly isWriteOnly: boolean;\n}\n\nconst NO_FLAGS: AccessFlags = { isReadOnly: false, isWriteOnly: false };\n\nfunction ownFlags(schema: SchemaObject): AccessFlags {\n return { isReadOnly: Boolean(schema.readOnly), isWriteOnly: Boolean(schema.writeOnly) };\n}\n\nfunction merged(left: AccessFlags, right: AccessFlags): AccessFlags {\n return {\n isReadOnly: left.isReadOnly || right.isReadOnly,\n isWriteOnly: left.isWriteOnly || right.isWriteOnly,\n };\n}\n\n/**\n * The flags of a schema and of the schemas that always apply to the same value: the one its\n * `$ref` names and its `allOf` members, followed until a schema repeats. `readOnly` is an\n * annotation, and the annotations of those schemas are the value's (2020-12 Core §7.7.1); in\n * OpenAPI 3.0 a referenced schema is the property's definition. `anyOf` and `oneOf` members apply\n * only when they match, which the type cannot tell, so they are not read.\n */\nfunction appliedFlags(\n schema: Schema | undefined,\n context: Pick<SchemaContext, \"refs\">,\n seen: ReadonlySet<Schema>,\n): AccessFlags {\n if (typeof schema !== \"object\" || schema === null || seen.has(schema)) {\n return NO_FLAGS;\n }\n const inner = new Set([...seen, schema]);\n // `readOnly` next to a `$ref` is read too, as the generator always has.\n const object = schema as SchemaObject & { readonly $ref?: unknown };\n const target =\n typeof object.$ref === \"string\" ? (context.refs.resolve(object.$ref) as Schema) : undefined;\n return (object.allOf ?? []).reduce<AccessFlags>(\n (flags, member) => merged(flags, appliedFlags(member, context, inner)),\n merged(ownFlags(object), appliedFlags(target, context, inner)),\n );\n}\n\n/**\n * The flags of a property schema. Without the `read-write-refs` fix only the keywords written on\n * it count, as in openapi-typescript; with it, also those of the schemas its `$ref` and `allOf`\n * apply (upstream #1938).\n */\nexport function propertyAccessFlags(\n value: Schema,\n context: Pick<SchemaContext, \"options\" | \"refs\">,\n): AccessFlags {\n if (typeof value !== \"object\") {\n return NO_FLAGS;\n }\n if (!context.options.fixes.has(FIX.READ_W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,EAAS,KAAK,CAAC;AAAA,GAC/D;AACF;AAOO,SAAS,mBAAA,CACd,OACA,OAAA,EACa;AACb,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,OAAA,CAAQ,OAAA,CAAQ,MAAM,GAAA,CAAI,GAAA,CAAI,eAAe,CAAA,EAAG;AACnD,IAAA,OAAO,SAAS,KAAqB,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,YAAA,CAAa,KAAA,EAAO,OAAA,kBAAS,IAAI,KAAK,CAAA;AAC/C;;"}
|
|
@@ -16,7 +16,7 @@ function variantTypes(variants, keyword, request) {
|
|
|
16
16
|
return variants.map(
|
|
17
17
|
(variant, index) => request.transformNested(variant, {
|
|
18
18
|
...request.location,
|
|
19
|
-
path: jsonPointer.
|
|
19
|
+
path: jsonPointer.appendPointer(request.location.path, [keyword, index])
|
|
20
20
|
})
|
|
21
21
|
);
|
|
22
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composition-type.cjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { requirableRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { unionItemOf, unionOwnKeywords } from \"./discriminated-union.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport { requiredVariantsType } from \"./required-variants.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: createRef([request.location.path, keyword, String(index)]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/**\n * The parent's `required` keys that the target at `ref` defines. A target that the discriminator\n * scan gave its property got none: the scan made that property required, but the other keys were\n * lost too. With `discriminator-member-required` only keys the target requires already are left\n * out (#2162).\n */\nfunction keysToRequire(\n ref: string,\n target: SchemaObject,\n required: readonly string[],\n request: SchemaRequest,\n): readonly string[] {\n const defined = required.filter((key) => Boolean(target.properties?.[key]));\n if (!request.context.discriminators.isHandled(ref)) {\n return defined;\n }\n if (!request.context.options.fixes.has(FIX.DISCRIMINATOR_MEMBER_REQUIRED)) {\n return [];\n }\n return defined.filter((key) => !target.required?.includes(key));\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const resolved = request.context.refs.resolve(item.$ref) as SchemaObject | undefined;\n if (!resolved || typeof resolved !== \"object\" || !(\"properties\" in resolved)) {\n return type;\n }\n const keys = keysToRequire(item.$ref, resolved, required, request);\n if (keys.length === 0) {\n return type;\n }\n request.context.footer.requireWithRequired();\n return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/**\n * The union's own keywords at the union's location, so nested names (enums) stay the union's.\n * Null when the union has none.\n */\nfunction ownKeywordsType(own: SchemaObject, ref: string, request: SchemaRequest): IrType | null {\n return combinedType(own, { ...request, location: { ...request.location, path: ref } });\n}\n\n/**\n * An `allOf` item; one with a discriminator omits that property (the parent redefines it). A\n * `$ref` to a discriminated union is not such a parent: for a member of the union it is the\n * union's own keywords, since the union contains the member (#1665); with\n * `allof-discriminated-union` it is the union, since `Omit` on a union drops keys (#1464), unless\n * the union's mapping names the schema: then it is a member, as the discriminator scan has it.\n */\nfunction allOfItemType(\n item: Schema,\n required: readonly string[],\n request: SchemaRequest,\n): IrType | null {\n const isRef = isRefItem(item);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n const propertyName = discriminator?.propertyName;\n const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : undefined;\n if (isRef && propertyName && unionItem?.isMember) {\n const own = unionOwnKeywords(unionItem.union, propertyName, required);\n return ownKeywordsType(own, item.$ref, request);\n }\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const isUnion =\n unionItem !== undefined &&\n !unionItem.isMapped &&\n request.context.options.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION);\n if (!propertyName || isUnion) {\n return type;\n }\n // With `discriminator-values` the schema also redefines the properties of other owners above\n // it, so no item may keep a value of its own for them (a parent mapped as `content`).\n const { path } = request.location;\n const others = path === undefined ? [] : request.context.discriminators.otherPropertiesAt(path);\n return omitKeys(type, [propertyName, ...others]);\n}\n\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.flatMap((item) => allOfItemType(item, required, request) ?? []);\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(FIX.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n return variantsType(type, schema, request);\n}\n\n/** `anyOf`, then `oneOf`, applied to the core and `allOf` type (`anyof-oneof-required` first). */\nfunction variantsType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const type =\n requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ??\n anyOfType(previous, schema, request);\n const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);\n if (oneOfRequired !== null) {\n return oneOfRequired;\n }\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_TYPE;\n const type = combinedType(schema, request) ?? empty;\n return type !== UNKNOWN_TYPE && schema.nullable ? nullableOf([type]) : type;\n}\n"],"names":["createRef","FIX","withRequiredKeys","requirableRefType","unionItemOf","unionOwnKeywords","omitKeys","isPrimitiveType","unionOf","intersectionOf","coreType","allOfMembers","requiredVariantsType","unevaluatedPropertiesType","irRecord","irKeyword","UNKNOWN_TYPE","nullableOf"],"mappings":";;;;;;;;;;;;;;AAuBA,SA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U,OAAO,CAAC,CAAA,GACrFC,wBAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAASA,4BAAgB,MAAA,CAAO,QAAA,GAAWC,2BAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
|
|
1
|
+
{"version":3,"file":"composition-type.cjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { requirableRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { unionItemOf, unionOwnKeywords } from \"./discriminated-union.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport { requiredVariantsType } from \"./required-variants.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: appendPointer(request.location.path, [keyword, index]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/**\n * The parent's `required` keys that the target at `ref` defines. A target that the discriminator\n * scan gave its property got none: the scan made that property required, but the other keys were\n * lost too. With `discriminator-member-required` only keys the target requires already are left\n * out (#2162).\n */\nfunction keysToRequire(\n ref: string,\n target: SchemaObject,\n required: readonly string[],\n request: SchemaRequest,\n): readonly string[] {\n const defined = required.filter((key) => Boolean(target.properties?.[key]));\n if (!request.context.discriminators.isHandled(ref)) {\n return defined;\n }\n if (!request.context.options.fixes.has(FIX.DISCRIMINATOR_MEMBER_REQUIRED)) {\n return [];\n }\n return defined.filter((key) => !target.required?.includes(key));\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const resolved = request.context.refs.resolve(item.$ref) as SchemaObject | undefined;\n if (!resolved || typeof resolved !== \"object\" || !(\"properties\" in resolved)) {\n return type;\n }\n const keys = keysToRequire(item.$ref, resolved, required, request);\n if (keys.length === 0) {\n return type;\n }\n request.context.footer.requireWithRequired();\n return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/**\n * The union's own keywords at the union's location, so nested names (enums) stay the union's.\n * Null when the union has none.\n */\nfunction ownKeywordsType(own: SchemaObject, ref: string, request: SchemaRequest): IrType | null {\n return combinedType(own, { ...request, location: { ...request.location, path: ref } });\n}\n\n/**\n * An `allOf` item; one with a discriminator omits that property (the parent redefines it). A\n * `$ref` to a discriminated union is not such a parent: for a member of the union it is the\n * union's own keywords, since the union contains the member (#1665); with\n * `allof-discriminated-union` it is the union, since `Omit` on a union drops keys (#1464), unless\n * the union's mapping names the schema: then it is a member, as the discriminator scan has it.\n */\nfunction allOfItemType(\n item: Schema,\n required: readonly string[],\n request: SchemaRequest,\n): IrType | null {\n const isRef = isRefItem(item);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n const propertyName = discriminator?.propertyName;\n const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : undefined;\n if (isRef && propertyName && unionItem?.isMember) {\n const own = unionOwnKeywords(unionItem.union, propertyName, required);\n return ownKeywordsType(own, item.$ref, request);\n }\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const isUnion =\n unionItem !== undefined &&\n !unionItem.isMapped &&\n request.context.options.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION);\n if (!propertyName || isUnion) {\n return type;\n }\n // With `discriminator-values` the schema also redefines the properties of other owners above\n // it, so no item may keep a value of its own for them (a parent mapped as `content`).\n const { path } = request.location;\n const others = path === undefined ? [] : request.context.discriminators.otherPropertiesAt(path);\n return omitKeys(type, [propertyName, ...others]);\n}\n\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.flatMap((item) => allOfItemType(item, required, request) ?? []);\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(FIX.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n return variantsType(type, schema, request);\n}\n\n/** `anyOf`, then `oneOf`, applied to the core and `allOf` type (`anyof-oneof-required` first). */\nfunction variantsType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const type =\n requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ??\n anyOfType(previous, schema, request);\n const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);\n if (oneOfRequired !== null) {\n return oneOfRequired;\n }\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_TYPE;\n const type = combinedType(schema, request) ?? empty;\n return type !== UNKNOWN_TYPE && schema.nullable ? nullableOf([type]) : type;\n}\n"],"names":["appendPointer","FIX","withRequiredKeys","requirableRefType","unionItemOf","unionOwnKeywords","omitKeys","isPrimitiveType","unionOf","intersectionOf","coreType","allOfMembers","requiredVariantsType","unevaluatedPropertiesType","irRecord","irKeyword","UNKNOWN_TYPE","nullableOf"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAS,YAAA,CACP,QAAA,EACA,OAAA,EACA,OAAA,EACU;AACV,EAAA,OAAO,QAAA,CAAS,GAAA;AAAA,IAAI,CAAC,OAAA,EAAS,KAAA,KAC5B,OAAA,CAAQ,gBAAgB,OAAA,EAAS;AAAA,MAC/B,GAAG,OAAA,CAAQ,QAAA;AAAA,MACX,IAAA,EAAMA,0BAAc,OAAA,CAAQ,QAAA,CAAS,MAAM,CAAC,OAAA,EAAS,KAAK,CAAC;AAAA,KAC5D;AAAA,GACH;AACF;AAMA,SAAS,UAAU,IAAA,EAAiD;AAClE,EAAA,OAAO,MAAA,IAAW,IAAA;AACpB;AAQA,SAAS,aA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AI,IAAA;AACrD;AAGA,SAAS,YAAA,CAAa,QAAsB,OAAA,EAAuC;AACjF,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA;AACzC,EAAA,MAAM,WAAA,GAAcC,+CAAA,CAA0B,MAAA,EAAQ,IAAA,EAAM,OAAO,CAAA;AACnE,EAAA,IAAI,gBAAgB,IAAA,EAAM;AACxB,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,IAAI,SAAS,IAAA,EAAM;AACjB,IAAA,OAAO,WAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAQ,IAAA,CAAK,IAAA,KAAS,iBAAiB,IAAA,CAAK,KAAA,GAAQ,CAAC,IAAI,CAAA;AAC/D,EAAA,OAAOJ,8BAAA,CAAe,CAAC,GAAG,KAAA,EAAO,WAAW,CAAC,CAAA;AAC/C;AAOO,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAgC;AACpF,EAAA,MAAM,EAAE,mBAAA,EAAoB,GAAI,OAAA,CAAQ,OAAA,CAAQ,OAAA;AAChD,EAAA,MAAM,KAAA,GACJ,MAAA,IAAU,MAAA,GACNK,qBAAA,CAASC,sBAAA,CAAU,QAAQ,CAAA,EAAG,mBAAA,GAAsBC,wBAAA,GAAeD,sBAAA,CAAU,OAAO,CAAC,CAAA,GACrFC,wBAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAASA,4BAAgB,MAAA,CAAO,QAAA,GAAWC,2BAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { irRecord, irKeyword } from '../../../domain/ir/constructors.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { appendPointer } from '../../../domain/openapi/json-pointer.mjs';
|
|
3
3
|
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
4
4
|
import { requirableRefType } from '../ref-pointer/pointer-type.mjs';
|
|
5
5
|
import { UNKNOWN_TYPE } from '../shared-types.mjs';
|
|
@@ -14,7 +14,7 @@ function variantTypes(variants, keyword, request) {
|
|
|
14
14
|
return variants.map(
|
|
15
15
|
(variant, index) => request.transformNested(variant, {
|
|
16
16
|
...request.location,
|
|
17
|
-
path:
|
|
17
|
+
path: appendPointer(request.location.path, [keyword, index])
|
|
18
18
|
})
|
|
19
19
|
);
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composition-type.mjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { requirableRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { unionItemOf, unionOwnKeywords } from \"./discriminated-union.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport { requiredVariantsType } from \"./required-variants.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: createRef([request.location.path, keyword, String(index)]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/**\n * The parent's `required` keys that the target at `ref` defines. A target that the discriminator\n * scan gave its property got none: the scan made that property required, but the other keys were\n * lost too. With `discriminator-member-required` only keys the target requires already are left\n * out (#2162).\n */\nfunction keysToRequire(\n ref: string,\n target: SchemaObject,\n required: readonly string[],\n request: SchemaRequest,\n): readonly string[] {\n const defined = required.filter((key) => Boolean(target.properties?.[key]));\n if (!request.context.discriminators.isHandled(ref)) {\n return defined;\n }\n if (!request.context.options.fixes.has(FIX.DISCRIMINATOR_MEMBER_REQUIRED)) {\n return [];\n }\n return defined.filter((key) => !target.required?.includes(key));\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const resolved = request.context.refs.resolve(item.$ref) as SchemaObject | undefined;\n if (!resolved || typeof resolved !== \"object\" || !(\"properties\" in resolved)) {\n return type;\n }\n const keys = keysToRequire(item.$ref, resolved, required, request);\n if (keys.length === 0) {\n return type;\n }\n request.context.footer.requireWithRequired();\n return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/**\n * The union's own keywords at the union's location, so nested names (enums) stay the union's.\n * Null when the union has none.\n */\nfunction ownKeywordsType(own: SchemaObject, ref: string, request: SchemaRequest): IrType | null {\n return combinedType(own, { ...request, location: { ...request.location, path: ref } });\n}\n\n/**\n * An `allOf` item; one with a discriminator omits that property (the parent redefines it). A\n * `$ref` to a discriminated union is not such a parent: for a member of the union it is the\n * union's own keywords, since the union contains the member (#1665); with\n * `allof-discriminated-union` it is the union, since `Omit` on a union drops keys (#1464), unless\n * the union's mapping names the schema: then it is a member, as the discriminator scan has it.\n */\nfunction allOfItemType(\n item: Schema,\n required: readonly string[],\n request: SchemaRequest,\n): IrType | null {\n const isRef = isRefItem(item);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n const propertyName = discriminator?.propertyName;\n const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : undefined;\n if (isRef && propertyName && unionItem?.isMember) {\n const own = unionOwnKeywords(unionItem.union, propertyName, required);\n return ownKeywordsType(own, item.$ref, request);\n }\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const isUnion =\n unionItem !== undefined &&\n !unionItem.isMapped &&\n request.context.options.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION);\n if (!propertyName || isUnion) {\n return type;\n }\n // With `discriminator-values` the schema also redefines the properties of other owners above\n // it, so no item may keep a value of its own for them (a parent mapped as `content`).\n const { path } = request.location;\n const others = path === undefined ? [] : request.context.discriminators.otherPropertiesAt(path);\n return omitKeys(type, [propertyName, ...others]);\n}\n\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.flatMap((item) => allOfItemType(item, required, request) ?? []);\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(FIX.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n return variantsType(type, schema, request);\n}\n\n/** `anyOf`, then `oneOf`, applied to the core and `allOf` type (`anyof-oneof-required` first). */\nfunction variantsType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const type =\n requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ??\n anyOfType(previous, schema, request);\n const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);\n if (oneOfRequired !== null) {\n return oneOfRequired;\n }\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_TYPE;\n const type = combinedType(schema, request) ?? empty;\n return type !== UNKNOWN_TYPE && schema.nullable ? nullableOf([type]) : type;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAuBA,SAAS,YAAA,CACP,QAAA,EACA,OAAA,EACA,OAAA,EACU;AACV,EAAA,OAAO,QAAA,CAAS,GAAA;AAAA,IAAI,CAAC,OAAA,EAAS,KAAA,KAC5B,OAAA,CAAQ,gBAAgB,OAAA,EAAS;AAAA,MAC/B,GAAG,OAAA,CAAQ,QAAA;AAAA,MACX,IAAA,EAAM,SAAA,CAAU,CAAC,OAAA,CAAQ,QAAA,CAAS,MAAM,OAAA,EAAS,MAAA,CAAO,KAAK,CAAC,CAAC;AAAA,KAChE;AAAA,GACH;AACF;AAMA,SAAS,UAAU,IAAA,EAAiD;AAClE,EAAA,OAAO,MAAA,IAAW,IAAA;AACpB;AAQA,SAAS,aAAA,CACP,GAAA,EACA,MAAA,EACA,QAAA,EACA,OAAA,EACmB;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A,CAAa,MAAA,EAAQ,OAAO,CAAA;AACzC,EAAA,MAAM,WAAA,GAAc,yBAAA,CAA0B,MAAA,EAAQ,IAAA,EAAM,OAAO,CAAA;AACnE,EAAA,IAAI,gBAAgB,IAAA,EAAM;AACxB,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,IAAI,SAAS,IAAA,EAAM;AACjB,IAAA,OAAO,WAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAQ,IAAA,CAAK,IAAA,KAAS,iBAAiB,IAAA,CAAK,KAAA,GAAQ,CAAC,IAAI,CAAA;AAC/D,EAAA,OAAO,cAAA,CAAe,CAAC,GAAG,KAAA,EAAO,WAAW,CAAC,CAAA;AAC/C;AAOO,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAgC;AACpF,EAAA,MAAM,EAAE,mBAAA,EAAoB,GAAI,OAAA,CAAQ,OAAA,CAAQ,OAAA;AAChD,EAAA,MAAM,KAAA,GACJ,MAAA,IAAU,MAAA,GACN,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA,EAAG,mBAAA,GAAsB,YAAA,GAAe,SAAA,CAAU,OAAO,CAAC,CAAA,GACrF,YAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAAS,gBAAgB,MAAA,CAAO,QAAA,GAAW,WAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
|
|
1
|
+
{"version":3,"file":"composition-type.mjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { requirableRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { unionItemOf, unionOwnKeywords } from \"./discriminated-union.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport { requiredVariantsType } from \"./required-variants.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: appendPointer(request.location.path, [keyword, index]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/**\n * The parent's `required` keys that the target at `ref` defines. A target that the discriminator\n * scan gave its property got none: the scan made that property required, but the other keys were\n * lost too. With `discriminator-member-required` only keys the target requires already are left\n * out (#2162).\n */\nfunction keysToRequire(\n ref: string,\n target: SchemaObject,\n required: readonly string[],\n request: SchemaRequest,\n): readonly string[] {\n const defined = required.filter((key) => Boolean(target.properties?.[key]));\n if (!request.context.discriminators.isHandled(ref)) {\n return defined;\n }\n if (!request.context.options.fixes.has(FIX.DISCRIMINATOR_MEMBER_REQUIRED)) {\n return [];\n }\n return defined.filter((key) => !target.required?.includes(key));\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const resolved = request.context.refs.resolve(item.$ref) as SchemaObject | undefined;\n if (!resolved || typeof resolved !== \"object\" || !(\"properties\" in resolved)) {\n return type;\n }\n const keys = keysToRequire(item.$ref, resolved, required, request);\n if (keys.length === 0) {\n return type;\n }\n request.context.footer.requireWithRequired();\n return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/**\n * The union's own keywords at the union's location, so nested names (enums) stay the union's.\n * Null when the union has none.\n */\nfunction ownKeywordsType(own: SchemaObject, ref: string, request: SchemaRequest): IrType | null {\n return combinedType(own, { ...request, location: { ...request.location, path: ref } });\n}\n\n/**\n * An `allOf` item; one with a discriminator omits that property (the parent redefines it). A\n * `$ref` to a discriminated union is not such a parent: for a member of the union it is the\n * union's own keywords, since the union contains the member (#1665); with\n * `allof-discriminated-union` it is the union, since `Omit` on a union drops keys (#1464), unless\n * the union's mapping names the schema: then it is a member, as the discriminator scan has it.\n */\nfunction allOfItemType(\n item: Schema,\n required: readonly string[],\n request: SchemaRequest,\n): IrType | null {\n const isRef = isRefItem(item);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n const propertyName = discriminator?.propertyName;\n const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : undefined;\n if (isRef && propertyName && unionItem?.isMember) {\n const own = unionOwnKeywords(unionItem.union, propertyName, required);\n return ownKeywordsType(own, item.$ref, request);\n }\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const isUnion =\n unionItem !== undefined &&\n !unionItem.isMapped &&\n request.context.options.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION);\n if (!propertyName || isUnion) {\n return type;\n }\n // With `discriminator-values` the schema also redefines the properties of other owners above\n // it, so no item may keep a value of its own for them (a parent mapped as `content`).\n const { path } = request.location;\n const others = path === undefined ? [] : request.context.discriminators.otherPropertiesAt(path);\n return omitKeys(type, [propertyName, ...others]);\n}\n\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.flatMap((item) => allOfItemType(item, required, request) ?? []);\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(FIX.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n return variantsType(type, schema, request);\n}\n\n/** `anyOf`, then `oneOf`, applied to the core and `allOf` type (`anyof-oneof-required` first). */\nfunction variantsType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const type =\n requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ??\n anyOfType(previous, schema, request);\n const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);\n if (oneOfRequired !== null) {\n return oneOfRequired;\n }\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_T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EAAG,mBAAA,GAAsB,YAAA,GAAe,SAAA,CAAU,OAAO,CAAC,CAAA,GACrF,YAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAAS,gBAAgB,MAAA,CAAO,QAAA,GAAW,WAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
|
|
@@ -120,7 +120,7 @@ function enumValuesPointer(path) {
|
|
|
120
120
|
kept.push(pointer[index]);
|
|
121
121
|
}
|
|
122
122
|
const extract = firstVariantStart === null ? [] : pointer.slice(firstVariantStart).filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));
|
|
123
|
-
return { ref: jsonPointer.
|
|
123
|
+
return { ref: jsonPointer.appendPointer(jsonPointer.ROOT_POINTER, kept), extract };
|
|
124
124
|
}
|
|
125
125
|
function addEnumValues(schema, request) {
|
|
126
126
|
const { ref, extract } = enumValuesPointer(request.location.path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-rule.cjs","sources":["../../../../src/application/transform/schema/enum-rule.ts"],"sourcesContent":["import {\n irIndexedAccess,\n irKeyword,\n irObject,\n irReference,\n irString,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef, parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { refType } from \"../ref-type.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport type {\n DiscriminatorEnumParent,\n EnumDeclarationRequest,\n EnumMemberMetadata,\n SchemaOptions,\n} from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\n/** Removed from generated names, so `#/components/schemas/Status` gives `Status`. */\nconst COMPONENT_SCHEMAS_PREFIX = \"components/schemas\";\nconst UNION_KEYWORDS: ReadonlySet<string> = new Set([\"anyOf\", \"oneOf\"]);\nconst INDEX_RE = /^\\d+$/;\n\nfunction hasAdditionalProperties(schema: SchemaObject): boolean {\n return \"additionalProperties\" in schema && Boolean(schema.additionalProperties);\n}\n\n/** A name from the schema's pointer: `#/components/schemas/Pet/status` → `/Pet/status`. */\nfunction nameFromPath(path: string | undefined): string {\n return parseRefPointer(path ?? \"\")\n .join(\"/\")\n .replace(COMPONENT_SCHEMAS_PREFIX, \"\");\n}\n\n/** `#/components/schemas/Name`, and no deeper pointer. */\nconst COMPONENT_SCHEMA_RE = /^#\\/components\\/schemas\\/[^/]+$/;\n\nfunction hasEnumMetadata(schema: SchemaObject): boolean {\n return [\n schema[\"x-enum-varnames\"],\n schema[\"x-enumNames\"],\n schema[\"x-enum-descriptions\"],\n schema[\"x-enumDescriptions\"],\n ].some(Array.isArray);\n}\n\n/**\n * The values a TypeScript enum declares, with their positions in `enum`. With the\n * `nullable-enums` fix a `null` value is left out (upstream #1872): an enum member cannot be\n * `null`, so the type adds it as `| null` instead (`tsEnumType`).\n */\nfunction tsEnumEntries(schema: SchemaObject, options: SchemaOptions): [unknown, number][] {\n const entries = (schema.enum ?? []).map((value, index): [unknown, number] => [value, index]);\n return options.fixes.has(FIX.NULLABLE_ENUMS)\n ? entries.filter(([value]) => value !== null)\n : entries;\n}\n\n/**\n * `--enum`: string and number enums become TypeScript enums. The original meant to allow `null`\n * too, but tested `typeof value` against `null`, so an enum containing null stays a union; the\n * `nullable-enums` fix declares its other values.\n */\nfunction isTsEnum(schema: SchemaObject, options: SchemaOptions): boolean {\n if (!options.enum || !schema.enum) {\n return false;\n }\n const entries = tsEnumEntries(schema, options);\n // An empty `enum` stays an empty TypeScript enum, as the original made it; an enum of only\n // `null` has no member left once the fix drops `null`, so it stays a union.\n const isOnlyNull = entries.length === 0 && schema.enum.length > 0;\n const isSupported =\n !isOnlyNull && entries.every(([value]) => [\"string\", \"number\"].includes(typeof value));\n // `--conditional-enums` converts only enums that carry x-enum-* metadata.\n return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));\n}\n\nfunction enumMetadata(\n schema: SchemaObject,\n entries: readonly [unknown, number][],\n): EnumMemberMetadata[] {\n return entries.map(([, index]) => ({\n name: schema[\"x-enum-varnames\"]?.[index] ?? schema[\"x-enumNames\"]?.[index],\n description: schema[\"x-enum-descriptions\"]?.[index] ?? schema[\"x-enumDescriptions\"]?.[index],\n }));\n}\n\n/**\n * Whether `null` is a valid value: it is in `enum` and the schema's type admits it (`type`\n * absent or listing `\"null\"`, or OpenAPI 3.0 `nullable: true`). Both keywords must pass.\n */\nfunction isNullAllowed(schema: SchemaObject): boolean {\n const { type } = schema;\n const isTypeNullable =\n type === undefined ||\n (Array.isArray(type) && type.includes(\"null\")) ||\n Boolean(schema.nullable);\n return (schema.enum ?? []).includes(null) && isTypeNullable;\n}\n\n/**\n * `additionalProperties: true` on a string enum keeps other strings allowed but still offers the\n * listed values in editors: `\"a\" | \"b\" | (string & {})`.\n */\nfunction withOtherStrings(type: IrType, schema: SchemaObject): IrType {\n if (!hasAdditionalProperties(schema) || schema.type !== \"string\") {\n return type;\n }\n return unionOf([type, intersectionOf([irKeyword(\"string\"), irObject([])])]);\n}\n\n/** The enum declaration of `schema` typed at `path`; its values are strings and numbers. */\nfunction enumRequest(\n schema: SchemaObject,\n path: string | undefined,\n options: SchemaOptions,\n): EnumDeclarationRequest {\n const entries = tsEnumEntries(schema, options);\n return {\n name: nameFromPath(path),\n isComponentSchema: COMPONENT_SCHEMA_RE.test(path ?? \"\"),\n values: entries.map(([value]) => value as string | number),\n metadata: enumMetadata(schema, entries),\n };\n}\n\n/** One member's type; a quoted member cannot follow a dot, `typeof E[\"+\"]` is the same type. */\nfunction enumMemberType(enumName: string, member: string): IrType {\n return member.startsWith('\"')\n ? irIndexedAccess(irReference(`typeof ${enumName}`), irString(JSON.parse(member), \"escaped\"))\n : irReference(`${enumName}.${member}`);\n}\n\n/**\n * The `discriminator-values` fix: a member's discriminator value is typed with members of\n * the owner's enum (`PetType.Cat`), so the member is one of the owner's type (#1700). `key` is the\n * enum the scan added or the inherited discriminator object. Null when the fix is off, or the\n * owner's property is no TypeScript enum with every value.\n */\nexport function ownerEnumMembersType(\n key: object,\n values: readonly unknown[],\n request: SchemaRequest,\n): IrType | null {\n const { options, discriminators, footer } = request.context;\n const parent: DiscriminatorEnumParent | undefined = options.fixes.has(FIX.DISCRIMINATOR_VALUES)\n ? discriminators.enumParentOf(key)\n : undefined;\n if (parent === undefined || !isTsEnum(parent.schema, options)) {\n return null;\n }\n const reference = { ...enumRequest(parent.schema, parent.path, options), isOwnerReference: true };\n const name = footer.addEnum(reference);\n const members = footer.enumMembers(name);\n const names = values.map((value) => members.get(value as string | number));\n if (names.length === 0 || names.some((member) => member === undefined)) {\n return null;\n }\n return unionOf(names.map((member) => enumMemberType(name, member as string)));\n}\n\nfunction tsEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { options, footer } = request.context;\n // `isTsEnum` admits only strings and numbers, and the fix leaves `null` out of the members.\n const values = tsEnumEntries(schema, options).map(([value]) => value);\n const type =\n ownerEnumMembersType(schema, values, request) ??\n withOtherStrings(\n irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),\n schema,\n );\n return options.fixes.has(FIX.NULLABLE_ENUMS) && isNullAllowed(schema)\n ? unionOf([type, irKeyword(\"null\")])\n : type;\n}\n\nfunction isUnionPosition(pointer: readonly string[], index: number): boolean {\n const next = pointer[index + 1];\n return UNION_KEYWORDS.has(pointer[index] as string) && next !== undefined && INDEX_RE.test(next);\n}\n\nconst PARAMETERS = \"parameters\";\n\n/** Where the `parameters` of a path item sit in its pointer: `paths/<key>/…`, `components/…`. */\nfunction pathItemParametersIndex(pointer: readonly string[]): number | null {\n if (pointer[0] === \"paths\" || pointer[0] === \"webhooks\") {\n return 2;\n }\n return pointer[0] === \"components\" && pointer[1] === \"pathItems\" ? 3 : null;\n}\n\n/**\n * The location of a path item parameter repeats `parameters` (`paths/~1a/parameters/parameters/\n * path/id`), which keeps the generated names as they were. The generated type has the segment\n * once: `paths[\"/a\"][\"parameters\"][\"path\"][\"id\"]`.\n */\nfunction withSingleParametersSegment(pointer: readonly string[]): readonly string[] {\n const index = pathItemParametersIndex(pointer);\n const isRepeated =\n index !== null && pointer[index] === PARAMETERS && pointer[index + 1] === PARAMETERS;\n return isRepeated ? [...pointer.slice(0, index), ...pointer.slice(index + 1)] : pointer;\n}\n\n/**\n * The pointer of `--enum-values` arrays without union positions (`anyOf/0`), so names stay\n * stable. Every property after the first union position is narrowed with `Extract`: a no-op where\n * all variants have it, and the needed narrowing where only some do.\n */\nfunction enumValuesPointer(path: string | undefined): { ref: string; extract: string[] } {\n const pointer = withSingleParametersSegment(parseRefPointer(path ?? \"\"));\n const kept: string[] = [];\n let firstVariantStart: number | null = null;\n for (let index = 0; index < pointer.length; index++) {\n if (isUnionPosition(pointer, index)) {\n firstVariantStart ??= index + 2;\n index++;\n continue;\n }\n kept.push(pointer[index] as string);\n }\n const extract =\n firstVariantStart === null\n ? []\n : pointer\n .slice(firstVariantStart)\n .filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));\n return { ref: createRef(kept), extract };\n}\n\nfunction addEnumValues(schema: SchemaObject, request: SchemaRequest): void {\n const { ref, extract } = enumValuesPointer(request.location.path);\n const valuesType = refType(ref, { isDeep: true, extractProperties: extract });\n request.context.footer.addEnumValues({\n name: `${nameFromPath(request.location.path)}Values`,\n // A record value (`additionalProperties`) is reached by indexing with `string`.\n type: request.isFromAdditionalProperties\n ? irIndexedAccess(valuesType, irReference(\"string\"))\n : valuesType,\n values: (schema.enum ?? []) as (string | number)[],\n });\n}\n\nfunction literalEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const values = schema.enum ?? [];\n const isNullable =\n (Array.isArray(schema.type) && schema.type.includes(\"null\")) || Boolean(schema.nullable);\n const literals = [...values.map(literalType), ...(isNullable ? [irKeyword(\"null\")] : [])];\n const type = withOtherStrings(unionOf(literals), schema);\n const isListable = values.every(\n (value) => typeof value === \"string\" || typeof value === \"number\",\n );\n if (request.context.options.enumValues && isListable) {\n addEnumValues(schema, request);\n }\n return type;\n}\n\n/**\n * `enum` on anything but an object (object enums are handled as `oneOf`). With\n * `additionalProperties`, only string enums are handled here; others fall through to composition.\n */\nexport const enumRule: SchemaRule = {\n name: \"enum\",\n matches(schema) {\n const isCandidate =\n Array.isArray(schema.enum) && schema.type !== \"object\" && !(\"properties\" in schema);\n return isCandidate && (!hasAdditionalProperties(schema) || schema.type === \"string\");\n },\n transform(schema, request) {\n return isTsEnum(schema, request.context.options)\n ? tsEnumType(schema, request)\n : literalEnumType(schema, request);\n },\n};\n"],"names":["parseRefPointer","FIX","unionOf","intersectionOf","irKeyword","irObject","irIndexedAccess","irReference","irString","createRef","refType","literalType"],"mappings":";;;;;;;;;AAuBA,MAAM,wBAAA,GAA2B,oBAAA;AACjC,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,OAAO,CAAC,CAAA;AACtE,MAAM,QAAA,GAAW,OAAA;AAEjB,SAAS,wBAAwB,MAAA,EAA+B;AAC9D,EAAA,OAAO,sBAAA,IAA0B,MAAA,IAAU,OAAA,CAAQ,MAAA,CAAO,oBAAoB,CAAA;AAChF;AAGA,SAAS,aAAa,IAAA,EAAkC;AACtD,EAAA,OAAOA,2BAAA,CAAgB,QAAQ,EAAE,CAAA,CAC9B,KAAK,GAAG,CAAA,CACR,OAAA,CAAQ,wBAAA,EAA0B,EAAE,CAAA;AACzC;AAGA,MAAM,mBAAA,GAAsB,iCAAA;AAE5B,SAAS,gBAAgB,MAAA,EAA+B;AACtD,EAAA,OAAO;AAAA,IACL,OAAO,iBAAiB,CAAA;AAAA,IACxB,OAAO,aAAa,CAAA;AAAA,IACpB,OAAO,qBAAqB,CAAA;AAAA,IAC5B,OAAO,oBAAoB;AAAA,GAC7B,CAAE,IAAA,C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Q,QAAQ,GAAG,MAAM,CAAA;AACvD,EAAA,MAAM,aAAa,MAAA,CAAO,KAAA;AAAA,IACxB,CAAC,KAAA,KAAU,OAAO,KAAA,KAAU,QAAA,IAAY,OAAO,KAAA,KAAU;AAAA,GAC3D;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,OAAA,CAAQ,UAAA,IAAc,UAAA,EAAY;AACpD,IAAA,aAAA,CAAc,QAAQ,OAAO,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,IAAA;AACT;AAMO,MAAM,QAAA,GAAuB;AAAA,EAClC,IAAA,EAAM,MAAA;AAAA,EACN,QAAQ,MAAA,EAAQ;AACd,IAAA,MAAM,WAAA,GACJ,KAAA,CAAM,OAAA,CAAQ,MAAA,CAAO,IAAI,KAAK,MAAA,CAAO,IAAA,KAAS,QAAA,IAAY,EAAE,YAAA,IAAgB,MAAA,CAAA;AAC9E,IAAA,OAAO,gBAAgB,CAAC,uBAAA,CAAwB,MAAM,CAAA,IAAK,OAAO,IAAA,KAAS,QAAA,CAAA;AAAA,EAC7E,CAAA;AAAA,EACA,SAAA,CAAU,QAAQ,OAAA,EAAS;AACzB,IAAA,OAAO,QAAA,CAAS,MAAA,EAAQ,OAAA,CAAQ,OAAA,CAAQ,OAAO,CAAA,GAC3C,UAAA,CAAW,MAAA,EAAQ,OAAO,CAAA,GAC1B,eAAA,CAAgB,MAAA,EAAQ,OAAO,CAAA;AAAA,EACrC;AACF;;;"}
|
|
1
|
+
{"version":3,"file":"enum-rule.cjs","sources":["../../../../src/application/transform/schema/enum-rule.ts"],"sourcesContent":["import {\n irIndexedAccess,\n irKeyword,\n irObject,\n irReference,\n irString,\n} 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 { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { refType } from \"../ref-type.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport type {\n DiscriminatorEnumParent,\n EnumDeclarationRequest,\n EnumMemberMetadata,\n SchemaOptions,\n} from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\n/** Removed from generated names, so `#/components/schemas/Status` gives `Status`. */\nconst COMPONENT_SCHEMAS_PREFIX = \"components/schemas\";\nconst UNION_KEYWORDS: ReadonlySet<string> = new Set([\"anyOf\", \"oneOf\"]);\nconst INDEX_RE = /^\\d+$/;\n\nfunction hasAdditionalProperties(schema: SchemaObject): boolean {\n return \"additionalProperties\" in schema && Boolean(schema.additionalProperties);\n}\n\n/** A name from the schema's pointer: `#/components/schemas/Pet/status` → `/Pet/status`. */\nfunction nameFromPath(path: string | undefined): string {\n return parseRefPointer(path ?? \"\")\n .join(\"/\")\n .replace(COMPONENT_SCHEMAS_PREFIX, \"\");\n}\n\n/** `#/components/schemas/Name`, and no deeper pointer. */\nconst COMPONENT_SCHEMA_RE = /^#\\/components\\/schemas\\/[^/]+$/;\n\nfunction hasEnumMetadata(schema: SchemaObject): boolean {\n return [\n schema[\"x-enum-varnames\"],\n schema[\"x-enumNames\"],\n schema[\"x-enum-descriptions\"],\n schema[\"x-enumDescriptions\"],\n ].some(Array.isArray);\n}\n\n/**\n * The values a TypeScript enum declares, with their positions in `enum`. With the\n * `nullable-enums` fix a `null` value is left out (upstream #1872): an enum member cannot be\n * `null`, so the type adds it as `| null` instead (`tsEnumType`).\n */\nfunction tsEnumEntries(schema: SchemaObject, options: SchemaOptions): [unknown, number][] {\n const entries = (schema.enum ?? []).map((value, index): [unknown, number] => [value, index]);\n return options.fixes.has(FIX.NULLABLE_ENUMS)\n ? entries.filter(([value]) => value !== null)\n : entries;\n}\n\n/**\n * `--enum`: string and number enums become TypeScript enums. The original meant to allow `null`\n * too, but tested `typeof value` against `null`, so an enum containing null stays a union; the\n * `nullable-enums` fix declares its other values.\n */\nfunction isTsEnum(schema: SchemaObject, options: SchemaOptions): boolean {\n if (!options.enum || !schema.enum) {\n return false;\n }\n const entries = tsEnumEntries(schema, options);\n // An empty `enum` stays an empty TypeScript enum, as the original made it; an enum of only\n // `null` has no member left once the fix drops `null`, so it stays a union.\n const isOnlyNull = entries.length === 0 && schema.enum.length > 0;\n const isSupported =\n !isOnlyNull && entries.every(([value]) => [\"string\", \"number\"].includes(typeof value));\n // `--conditional-enums` converts only enums that carry x-enum-* metadata.\n return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));\n}\n\nfunction enumMetadata(\n schema: SchemaObject,\n entries: readonly [unknown, number][],\n): EnumMemberMetadata[] {\n return entries.map(([, index]) => ({\n name: schema[\"x-enum-varnames\"]?.[index] ?? schema[\"x-enumNames\"]?.[index],\n description: schema[\"x-enum-descriptions\"]?.[index] ?? schema[\"x-enumDescriptions\"]?.[index],\n }));\n}\n\n/**\n * Whether `null` is a valid value: it is in `enum` and the schema's type admits it (`type`\n * absent or listing `\"null\"`, or OpenAPI 3.0 `nullable: true`). Both keywords must pass.\n */\nfunction isNullAllowed(schema: SchemaObject): boolean {\n const { type } = schema;\n const isTypeNullable =\n type === undefined ||\n (Array.isArray(type) && type.includes(\"null\")) ||\n Boolean(schema.nullable);\n return (schema.enum ?? []).includes(null) && isTypeNullable;\n}\n\n/**\n * `additionalProperties: true` on a string enum keeps other strings allowed but still offers the\n * listed values in editors: `\"a\" | \"b\" | (string & {})`.\n */\nfunction withOtherStrings(type: IrType, schema: SchemaObject): IrType {\n if (!hasAdditionalProperties(schema) || schema.type !== \"string\") {\n return type;\n }\n return unionOf([type, intersectionOf([irKeyword(\"string\"), irObject([])])]);\n}\n\n/** The enum declaration of `schema` typed at `path`; its values are strings and numbers. */\nfunction enumRequest(\n schema: SchemaObject,\n path: string | undefined,\n options: SchemaOptions,\n): EnumDeclarationRequest {\n const entries = tsEnumEntries(schema, options);\n return {\n name: nameFromPath(path),\n isComponentSchema: COMPONENT_SCHEMA_RE.test(path ?? \"\"),\n values: entries.map(([value]) => value as string | number),\n metadata: enumMetadata(schema, entries),\n };\n}\n\n/** One member's type; a quoted member cannot follow a dot, `typeof E[\"+\"]` is the same type. */\nfunction enumMemberType(enumName: string, member: string): IrType {\n return member.startsWith('\"')\n ? irIndexedAccess(irReference(`typeof ${enumName}`), irString(JSON.parse(member), \"escaped\"))\n : irReference(`${enumName}.${member}`);\n}\n\n/**\n * The `discriminator-values` fix: a member's discriminator value is typed with members of\n * the owner's enum (`PetType.Cat`), so the member is one of the owner's type (#1700). `key` is the\n * enum the scan added or the inherited discriminator object. Null when the fix is off, or the\n * owner's property is no TypeScript enum with every value.\n */\nexport function ownerEnumMembersType(\n key: object,\n values: readonly unknown[],\n request: SchemaRequest,\n): IrType | null {\n const { options, discriminators, footer } = request.context;\n const parent: DiscriminatorEnumParent | undefined = options.fixes.has(FIX.DISCRIMINATOR_VALUES)\n ? discriminators.enumParentOf(key)\n : undefined;\n if (parent === undefined || !isTsEnum(parent.schema, options)) {\n return null;\n }\n const reference = { ...enumRequest(parent.schema, parent.path, options), isOwnerReference: true };\n const name = footer.addEnum(reference);\n const members = footer.enumMembers(name);\n const names = values.map((value) => members.get(value as string | number));\n if (names.length === 0 || names.some((member) => member === undefined)) {\n return null;\n }\n return unionOf(names.map((member) => enumMemberType(name, member as string)));\n}\n\nfunction tsEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { options, footer } = request.context;\n // `isTsEnum` admits only strings and numbers, and the fix leaves `null` out of the members.\n const values = tsEnumEntries(schema, options).map(([value]) => value);\n const type =\n ownerEnumMembersType(schema, values, request) ??\n withOtherStrings(\n irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),\n schema,\n );\n return options.fixes.has(FIX.NULLABLE_ENUMS) && isNullAllowed(schema)\n ? unionOf([type, irKeyword(\"null\")])\n : type;\n}\n\nfunction isUnionPosition(pointer: readonly string[], index: number): boolean {\n const next = pointer[index + 1];\n return UNION_KEYWORDS.has(pointer[index] as string) && next !== undefined && INDEX_RE.test(next);\n}\n\nconst PARAMETERS = \"parameters\";\n\n/** Where the `parameters` of a path item sit in its pointer: `paths/<key>/…`, `components/…`. */\nfunction pathItemParametersIndex(pointer: readonly string[]): number | null {\n if (pointer[0] === \"paths\" || pointer[0] === \"webhooks\") {\n return 2;\n }\n return pointer[0] === \"components\" && pointer[1] === \"pathItems\" ? 3 : null;\n}\n\n/**\n * The location of a path item parameter repeats `parameters` (`paths/~1a/parameters/parameters/\n * path/id`), which keeps the generated names as they were. The generated type has the segment\n * once: `paths[\"/a\"][\"parameters\"][\"path\"][\"id\"]`.\n */\nfunction withSingleParametersSegment(pointer: readonly string[]): readonly string[] {\n const index = pathItemParametersIndex(pointer);\n const isRepeated =\n index !== null && pointer[index] === PARAMETERS && pointer[index + 1] === PARAMETERS;\n return isRepeated ? [...pointer.slice(0, index), ...pointer.slice(index + 1)] : pointer;\n}\n\n/**\n * The pointer of `--enum-values` arrays without union positions (`anyOf/0`), so names stay\n * stable. Every property after the first union position is narrowed with `Extract`: a no-op where\n * all variants have it, and the needed narrowing where only some do.\n */\nfunction enumValuesPointer(path: string | undefined): { ref: string; extract: string[] } {\n const pointer = withSingleParametersSegment(parseRefPointer(path ?? \"\"));\n const kept: string[] = [];\n let firstVariantStart: number | null = null;\n for (let index = 0; index < pointer.length; index++) {\n if (isUnionPosition(pointer, index)) {\n firstVariantStart ??= index + 2;\n index++;\n continue;\n }\n kept.push(pointer[index] as string);\n }\n const extract =\n firstVariantStart === null\n ? []\n : pointer\n .slice(firstVariantStart)\n .filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));\n return { ref: appendPointer(ROOT_POINTER, kept), extract };\n}\n\nfunction addEnumValues(schema: SchemaObject, request: SchemaRequest): void {\n const { ref, extract } = enumValuesPointer(request.location.path);\n const valuesType = refType(ref, { isDeep: true, extractProperties: extract });\n request.context.footer.addEnumValues({\n name: `${nameFromPath(request.location.path)}Values`,\n // A record value (`additionalProperties`) is reached by indexing with `string`.\n type: request.isFromAdditionalProperties\n ? irIndexedAccess(valuesType, irReference(\"string\"))\n : valuesType,\n values: (schema.enum ?? []) as (string | number)[],\n });\n}\n\nfunction literalEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const values = schema.enum ?? [];\n const isNullable =\n (Array.isArray(schema.type) && schema.type.includes(\"null\")) || Boolean(schema.nullable);\n const literals = [...values.map(literalType), ...(isNullable ? [irKeyword(\"null\")] : [])];\n const type = withOtherStrings(unionOf(literals), schema);\n const isListable = values.every(\n (value) => typeof value === \"string\" || typeof value === \"number\",\n );\n if (request.context.options.enumValues && isListable) {\n addEnumValues(schema, request);\n }\n return type;\n}\n\n/**\n * `enum` on anything but an object (object enums are handled as `oneOf`). With\n * `additionalProperties`, only string enums are handled here; others fall through to composition.\n */\nexport const enumRule: SchemaRule = {\n name: \"enum\",\n matches(schema) {\n const isCandidate =\n Array.isArray(schema.enum) && schema.type !== \"object\" && !(\"properties\" in schema);\n return isCandidate && (!hasAdditionalProperties(schema) || schema.type === \"string\");\n },\n transform(schema, request) {\n return isTsEnum(schema, request.context.options)\n ? tsEnumType(schema, request)\n : literalEnumType(schema, request);\n },\n};\n"],"names":["parseRefPointer","FIX","unionOf","intersectionOf","irKeyword","irObject","irIndexedAccess","irReference","irString","appendPointer","ROOT_POINTER","refType","literalType"],"mappings":";;;;;;;;;AA2BA,MAAM,wBAAA,GAA2B,oBAAA;AACjC,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,OAAO,CAAC,CAAA;AACtE,MAAM,QAAA,GAAW,OAAA;AAEjB,SAAS,wBAAwB,MAAA,EAA+B;AAC9D,EAAA,OAAO,sBAAA,IAA0B,MAAA,IAAU,OAAA,CAAQ,MAAA,CAAO,oBAAoB,CAAA;AAChF;AAGA,SAAS,aAAa,IAAA,EAAkC;AACtD,EAAA,OAAOA,2BAAA,CAAgB,QAAQ,EAAE,CAAA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;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { irReference, irKeyword, irIndexedAccess, irString, irObject } from '../../../domain/ir/constructors.mjs';
|
|
2
|
-
import { parseRefPointer,
|
|
2
|
+
import { parseRefPointer, appendPointer, ROOT_POINTER } from '../../../domain/openapi/json-pointer.mjs';
|
|
3
3
|
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
4
4
|
import { literalType } from '../literal-type.mjs';
|
|
5
5
|
import { refType } from '../ref-type.mjs';
|
|
@@ -118,7 +118,7 @@ function enumValuesPointer(path) {
|
|
|
118
118
|
kept.push(pointer[index]);
|
|
119
119
|
}
|
|
120
120
|
const extract = firstVariantStart === null ? [] : pointer.slice(firstVariantStart).filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));
|
|
121
|
-
return { ref:
|
|
121
|
+
return { ref: appendPointer(ROOT_POINTER, kept), extract };
|
|
122
122
|
}
|
|
123
123
|
function addEnumValues(schema, request) {
|
|
124
124
|
const { ref, extract } = enumValuesPointer(request.location.path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-rule.mjs","sources":["../../../../src/application/transform/schema/enum-rule.ts"],"sourcesContent":["import {\n irIndexedAccess,\n irKeyword,\n irObject,\n irReference,\n irString,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef, parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { refType } from \"../ref-type.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport type {\n DiscriminatorEnumParent,\n EnumDeclarationRequest,\n EnumMemberMetadata,\n SchemaOptions,\n} from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\n/** Removed from generated names, so `#/components/schemas/Status` gives `Status`. */\nconst COMPONENT_SCHEMAS_PREFIX = \"components/schemas\";\nconst UNION_KEYWORDS: ReadonlySet<string> = new Set([\"anyOf\", \"oneOf\"]);\nconst INDEX_RE = /^\\d+$/;\n\nfunction hasAdditionalProperties(schema: SchemaObject): boolean {\n return \"additionalProperties\" in schema && Boolean(schema.additionalProperties);\n}\n\n/** A name from the schema's pointer: `#/components/schemas/Pet/status` → `/Pet/status`. */\nfunction nameFromPath(path: string | undefined): string {\n return parseRefPointer(path ?? \"\")\n .join(\"/\")\n .replace(COMPONENT_SCHEMAS_PREFIX, \"\");\n}\n\n/** `#/components/schemas/Name`, and no deeper pointer. */\nconst COMPONENT_SCHEMA_RE = /^#\\/components\\/schemas\\/[^/]+$/;\n\nfunction hasEnumMetadata(schema: SchemaObject): boolean {\n return [\n schema[\"x-enum-varnames\"],\n schema[\"x-enumNames\"],\n schema[\"x-enum-descriptions\"],\n schema[\"x-enumDescriptions\"],\n ].some(Array.isArray);\n}\n\n/**\n * The values a TypeScript enum declares, with their positions in `enum`. With the\n * `nullable-enums` fix a `null` value is left out (upstream #1872): an enum member cannot be\n * `null`, so the type adds it as `| null` instead (`tsEnumType`).\n */\nfunction tsEnumEntries(schema: SchemaObject, options: SchemaOptions): [unknown, number][] {\n const entries = (schema.enum ?? []).map((value, index): [unknown, number] => [value, index]);\n return options.fixes.has(FIX.NULLABLE_ENUMS)\n ? entries.filter(([value]) => value !== null)\n : entries;\n}\n\n/**\n * `--enum`: string and number enums become TypeScript enums. The original meant to allow `null`\n * too, but tested `typeof value` against `null`, so an enum containing null stays a union; the\n * `nullable-enums` fix declares its other values.\n */\nfunction isTsEnum(schema: SchemaObject, options: SchemaOptions): boolean {\n if (!options.enum || !schema.enum) {\n return false;\n }\n const entries = tsEnumEntries(schema, options);\n // An empty `enum` stays an empty TypeScript enum, as the original made it; an enum of only\n // `null` has no member left once the fix drops `null`, so it stays a union.\n const isOnlyNull = entries.length === 0 && schema.enum.length > 0;\n const isSupported =\n !isOnlyNull && entries.every(([value]) => [\"string\", \"number\"].includes(typeof value));\n // `--conditional-enums` converts only enums that carry x-enum-* metadata.\n return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));\n}\n\nfunction enumMetadata(\n schema: SchemaObject,\n entries: readonly [unknown, number][],\n): EnumMemberMetadata[] {\n return entries.map(([, index]) => ({\n name: schema[\"x-enum-varnames\"]?.[index] ?? schema[\"x-enumNames\"]?.[index],\n description: schema[\"x-enum-descriptions\"]?.[index] ?? schema[\"x-enumDescriptions\"]?.[index],\n }));\n}\n\n/**\n * Whether `null` is a valid value: it is in `enum` and the schema's type admits it (`type`\n * absent or listing `\"null\"`, or OpenAPI 3.0 `nullable: true`). Both keywords must pass.\n */\nfunction isNullAllowed(schema: SchemaObject): boolean {\n const { type } = schema;\n const isTypeNullable =\n type === undefined ||\n (Array.isArray(type) && type.includes(\"null\")) ||\n Boolean(schema.nullable);\n return (schema.enum ?? []).includes(null) && isTypeNullable;\n}\n\n/**\n * `additionalProperties: true` on a string enum keeps other strings allowed but still offers the\n * listed values in editors: `\"a\" | \"b\" | (string & {})`.\n */\nfunction withOtherStrings(type: IrType, schema: SchemaObject): IrType {\n if (!hasAdditionalProperties(schema) || schema.type !== \"string\") {\n return type;\n }\n return unionOf([type, intersectionOf([irKeyword(\"string\"), irObject([])])]);\n}\n\n/** The enum declaration of `schema` typed at `path`; its values are strings and numbers. */\nfunction enumRequest(\n schema: SchemaObject,\n path: string | undefined,\n options: SchemaOptions,\n): EnumDeclarationRequest {\n const entries = tsEnumEntries(schema, options);\n return {\n name: nameFromPath(path),\n isComponentSchema: COMPONENT_SCHEMA_RE.test(path ?? \"\"),\n values: entries.map(([value]) => value as string | number),\n metadata: enumMetadata(schema, entries),\n };\n}\n\n/** One member's type; a quoted member cannot follow a dot, `typeof E[\"+\"]` is the same type. */\nfunction enumMemberType(enumName: string, member: string): IrType {\n return member.startsWith('\"')\n ? irIndexedAccess(irReference(`typeof ${enumName}`), irString(JSON.parse(member), \"escaped\"))\n : irReference(`${enumName}.${member}`);\n}\n\n/**\n * The `discriminator-values` fix: a member's discriminator value is typed with members of\n * the owner's enum (`PetType.Cat`), so the member is one of the owner's type (#1700). `key` is the\n * enum the scan added or the inherited discriminator object. Null when the fix is off, or the\n * owner's property is no TypeScript enum with every value.\n */\nexport function ownerEnumMembersType(\n key: object,\n values: readonly unknown[],\n request: SchemaRequest,\n): IrType | null {\n const { options, discriminators, footer } = request.context;\n const parent: DiscriminatorEnumParent | undefined = options.fixes.has(FIX.DISCRIMINATOR_VALUES)\n ? discriminators.enumParentOf(key)\n : undefined;\n if (parent === undefined || !isTsEnum(parent.schema, options)) {\n return null;\n }\n const reference = { ...enumRequest(parent.schema, parent.path, options), isOwnerReference: true };\n const name = footer.addEnum(reference);\n const members = footer.enumMembers(name);\n const names = values.map((value) => members.get(value as string | number));\n if (names.length === 0 || names.some((member) => member === undefined)) {\n return null;\n }\n return unionOf(names.map((member) => enumMemberType(name, member as string)));\n}\n\nfunction tsEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { options, footer } = request.context;\n // `isTsEnum` admits only strings and numbers, and the fix leaves `null` out of the members.\n const values = tsEnumEntries(schema, options).map(([value]) => value);\n const type =\n ownerEnumMembersType(schema, values, request) ??\n withOtherStrings(\n irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),\n schema,\n );\n return options.fixes.has(FIX.NULLABLE_ENUMS) && isNullAllowed(schema)\n ? unionOf([type, irKeyword(\"null\")])\n : type;\n}\n\nfunction isUnionPosition(pointer: readonly string[], index: number): boolean {\n const next = pointer[index + 1];\n return UNION_KEYWORDS.has(pointer[index] as string) && next !== undefined && INDEX_RE.test(next);\n}\n\nconst PARAMETERS = \"parameters\";\n\n/** Where the `parameters` of a path item sit in its pointer: `paths/<key>/…`, `components/…`. */\nfunction pathItemParametersIndex(pointer: readonly string[]): number | null {\n if (pointer[0] === \"paths\" || pointer[0] === \"webhooks\") {\n return 2;\n }\n return pointer[0] === \"components\" && pointer[1] === \"pathItems\" ? 3 : null;\n}\n\n/**\n * The location of a path item parameter repeats `parameters` (`paths/~1a/parameters/parameters/\n * path/id`), which keeps the generated names as they were. The generated type has the segment\n * once: `paths[\"/a\"][\"parameters\"][\"path\"][\"id\"]`.\n */\nfunction withSingleParametersSegment(pointer: readonly string[]): readonly string[] {\n const index = pathItemParametersIndex(pointer);\n const isRepeated =\n index !== null && pointer[index] === PARAMETERS && pointer[index + 1] === PARAMETERS;\n return isRepeated ? [...pointer.slice(0, index), ...pointer.slice(index + 1)] : pointer;\n}\n\n/**\n * The pointer of `--enum-values` arrays without union positions (`anyOf/0`), so names stay\n * stable. Every property after the first union position is narrowed with `Extract`: a no-op where\n * all variants have it, and the needed narrowing where only some do.\n */\nfunction enumValuesPointer(path: string | undefined): { ref: string; extract: string[] } {\n const pointer = withSingleParametersSegment(parseRefPointer(path ?? \"\"));\n const kept: string[] = [];\n let firstVariantStart: number | null = null;\n for (let index = 0; index < pointer.length; index++) {\n if (isUnionPosition(pointer, index)) {\n firstVariantStart ??= index + 2;\n index++;\n continue;\n }\n kept.push(pointer[index] as string);\n }\n const extract =\n firstVariantStart === null\n ? []\n : pointer\n .slice(firstVariantStart)\n .filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));\n return { ref: createRef(kept), extract };\n}\n\nfunction addEnumValues(schema: SchemaObject, request: SchemaRequest): void {\n const { ref, extract } = enumValuesPointer(request.location.path);\n const valuesType = refType(ref, { isDeep: true, extractProperties: extract });\n request.context.footer.addEnumValues({\n name: `${nameFromPath(request.location.path)}Values`,\n // A record value (`additionalProperties`) is reached by indexing with `string`.\n type: request.isFromAdditionalProperties\n ? irIndexedAccess(valuesType, irReference(\"string\"))\n : valuesType,\n values: (schema.enum ?? []) as (string | number)[],\n });\n}\n\nfunction literalEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const values = schema.enum ?? [];\n const isNullable =\n (Array.isArray(schema.type) && schema.type.includes(\"null\")) || Boolean(schema.nullable);\n const literals = [...values.map(literalType), ...(isNullable ? [irKeyword(\"null\")] : [])];\n const type = withOtherStrings(unionOf(literals), schema);\n const isListable = values.every(\n (value) => typeof value === \"string\" || typeof value === \"number\",\n );\n if (request.context.options.enumValues && isListable) {\n addEnumValues(schema, request);\n }\n return type;\n}\n\n/**\n * `enum` on anything but an object (object enums are handled as `oneOf`). With\n * `additionalProperties`, only string enums are handled here; others fall through to composition.\n */\nexport const enumRule: SchemaRule = {\n name: \"enum\",\n matches(schema) {\n const isCandidate =\n Array.isArray(schema.enum) && schema.type !== \"object\" && !(\"properties\" in schema);\n return isCandidate && (!hasAdditionalProperties(schema) || schema.type === \"string\");\n },\n transform(schema, request) {\n return isTsEnum(schema, request.context.options)\n ? tsEnumType(schema, request)\n : literalEnumType(schema, request);\n },\n};\n"],"names":[],"mappings":";;;;;;;AAuBA,MAAM,wBAAA,GAA2B,oBAAA;AACjC,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,OAAO,CAAC,CAAA;AACtE,MAAM,QAAA,GAAW,OAAA;AAEjB,SAAS,wBAAwB,MAAA,EAA+B;AAC9D,EAAA,OAAO,sBAAA,IAA0B,MAAA,IAAU,OAAA,CAAQ,MAAA,CAAO,oBAAoB,CAAA;AAChF;AAGA,SAAS,aAAa,IAAA,EAAkC;AACtD,EAAA,OAAO,eAAA,CAAgB,QAAQ,EAAE,CAAA,CAC9B,KAAK,GAAG,CAAA,CACR,OAAA,CAAQ,wBAAA,EAA0B,EAAE,CAAA;AACzC;AAGA,MAAM,mBAAA,GAAsB,iCAAA;AAE5B,SAAS,gBAAgB,MAAA,EAA+B;AACtD,EAAA,OAAO;AAAA,IACL,OAAO,iBAAiB,CAAA;AAAA,IACxB,OAAO,aAAa,CAAA;AAAA,IACpB,OAAO,qBAAqB,CAAA;AAAA,IAC5B,OAAO,oBAAoB;AAAA,GAC7B,CAAE,IAAA,CAAK,KAAA,CAAM,OAAO,CAAA;AACtB;AAOA,SAAS,aAAA,CAAc,QAA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A,KAAU,QAAA,IAAY,OAAO,KAAA,KAAU;AAAA,GAC3D;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,OAAA,CAAQ,UAAA,IAAc,UAAA,EAAY;AACpD,IAAA,aAAA,CAAc,QAAQ,OAAO,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,IAAA;AACT;AAMO,MAAM,QAAA,GAAuB;AAAA,EAClC,IAAA,EAAM,MAAA;AAAA,EACN,QAAQ,MAAA,EAAQ;AACd,IAAA,MAAM,WAAA,GACJ,KAAA,CAAM,OAAA,CAAQ,MAAA,CAAO,IAAI,KAAK,MAAA,CAAO,IAAA,KAAS,QAAA,IAAY,EAAE,YAAA,IAAgB,MAAA,CAAA;AAC9E,IAAA,OAAO,gBAAgB,CAAC,uBAAA,CAAwB,MAAM,CAAA,IAAK,OAAO,IAAA,KAAS,QAAA,CAAA;AAAA,EAC7E,CAAA;AAAA,EACA,SAAA,CAAU,QAAQ,OAAA,EAAS;AACzB,IAAA,OAAO,QAAA,CAAS,MAAA,EAAQ,OAAA,CAAQ,OAAA,CAAQ,OAAO,CAAA,GAC3C,UAAA,CAAW,MAAA,EAAQ,OAAO,CAAA,GAC1B,eAAA,CAAgB,MAAA,EAAQ,OAAO,CAAA;AAAA,EACrC;AACF;;"}
|
|
1
|
+
{"version":3,"file":"enum-rule.mjs","sources":["../../../../src/application/transform/schema/enum-rule.ts"],"sourcesContent":["import {\n irIndexedAccess,\n irKeyword,\n irObject,\n irReference,\n irString,\n} 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 { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { refType } from \"../ref-type.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport type {\n DiscriminatorEnumParent,\n EnumDeclarationRequest,\n EnumMemberMetadata,\n SchemaOptions,\n} from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\n/** Removed from generated names, so `#/components/schemas/Status` gives `Status`. */\nconst COMPONENT_SCHEMAS_PREFIX = \"components/schemas\";\nconst UNION_KEYWORDS: ReadonlySet<string> = new Set([\"anyOf\", \"oneOf\"]);\nconst INDEX_RE = /^\\d+$/;\n\nfunction hasAdditionalProperties(schema: SchemaObject): boolean {\n return \"additionalProperties\" in schema && Boolean(schema.additionalProperties);\n}\n\n/** A name from the schema's pointer: `#/components/schemas/Pet/status` → `/Pet/status`. */\nfunction nameFromPath(path: string | undefined): string {\n return parseRefPointer(path ?? \"\")\n .join(\"/\")\n .replace(COMPONENT_SCHEMAS_PREFIX, \"\");\n}\n\n/** `#/components/schemas/Name`, and no deeper pointer. */\nconst COMPONENT_SCHEMA_RE = /^#\\/components\\/schemas\\/[^/]+$/;\n\nfunction hasEnumMetadata(schema: SchemaObject): boolean {\n return [\n schema[\"x-enum-varnames\"],\n schema[\"x-enumNames\"],\n schema[\"x-enum-descriptions\"],\n schema[\"x-enumDescriptions\"],\n ].some(Array.isArray);\n}\n\n/**\n * The values a TypeScript enum declares, with their positions in `enum`. With the\n * `nullable-enums` fix a `null` value is left out (upstream #1872): an enum member cannot be\n * `null`, so the type adds it as `| null` instead (`tsEnumType`).\n */\nfunction tsEnumEntries(schema: SchemaObject, options: SchemaOptions): [unknown, number][] {\n const entries = (schema.enum ?? []).map((value, index): [unknown, number] => [value, index]);\n return options.fixes.has(FIX.NULLABLE_ENUMS)\n ? entries.filter(([value]) => value !== null)\n : entries;\n}\n\n/**\n * `--enum`: string and number enums become TypeScript enums. The original meant to allow `null`\n * too, but tested `typeof value` against `null`, so an enum containing null stays a union; the\n * `nullable-enums` fix declares its other values.\n */\nfunction isTsEnum(schema: SchemaObject, options: SchemaOptions): boolean {\n if (!options.enum || !schema.enum) {\n return false;\n }\n const entries = tsEnumEntries(schema, options);\n // An empty `enum` stays an empty TypeScript enum, as the original made it; an enum of only\n // `null` has no member left once the fix drops `null`, so it stays a union.\n const isOnlyNull = entries.length === 0 && schema.enum.length > 0;\n const isSupported =\n !isOnlyNull && entries.every(([value]) => [\"string\", \"number\"].includes(typeof value));\n // `--conditional-enums` converts only enums that carry x-enum-* metadata.\n return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));\n}\n\nfunction enumMetadata(\n schema: SchemaObject,\n entries: readonly [unknown, number][],\n): EnumMemberMetadata[] {\n return entries.map(([, index]) => ({\n name: schema[\"x-enum-varnames\"]?.[index] ?? schema[\"x-enumNames\"]?.[index],\n description: schema[\"x-enum-descriptions\"]?.[index] ?? schema[\"x-enumDescriptions\"]?.[index],\n }));\n}\n\n/**\n * Whether `null` is a valid value: it is in `enum` and the schema's type admits it (`type`\n * absent or listing `\"null\"`, or OpenAPI 3.0 `nullable: true`). Both keywords must pass.\n */\nfunction isNullAllowed(schema: SchemaObject): boolean {\n const { type } = schema;\n const isTypeNullable =\n type === undefined ||\n (Array.isArray(type) && type.includes(\"null\")) ||\n Boolean(schema.nullable);\n return (schema.enum ?? []).includes(null) && isTypeNullable;\n}\n\n/**\n * `additionalProperties: true` on a string enum keeps other strings allowed but still offers the\n * listed values in editors: `\"a\" | \"b\" | (string & {})`.\n */\nfunction withOtherStrings(type: IrType, schema: SchemaObject): IrType {\n if (!hasAdditionalProperties(schema) || schema.type !== \"string\") {\n return type;\n }\n return unionOf([type, intersectionOf([irKeyword(\"string\"), irObject([])])]);\n}\n\n/** The enum declaration of `schema` typed at `path`; its values are strings and numbers. */\nfunction enumRequest(\n schema: SchemaObject,\n path: string | undefined,\n options: SchemaOptions,\n): EnumDeclarationRequest {\n const entries = tsEnumEntries(schema, options);\n return {\n name: nameFromPath(path),\n isComponentSchema: COMPONENT_SCHEMA_RE.test(path ?? \"\"),\n values: entries.map(([value]) => value as string | number),\n metadata: enumMetadata(schema, entries),\n };\n}\n\n/** One member's type; a quoted member cannot follow a dot, `typeof E[\"+\"]` is the same type. */\nfunction enumMemberType(enumName: string, member: string): IrType {\n return member.startsWith('\"')\n ? irIndexedAccess(irReference(`typeof ${enumName}`), irString(JSON.parse(member), \"escaped\"))\n : irReference(`${enumName}.${member}`);\n}\n\n/**\n * The `discriminator-values` fix: a member's discriminator value is typed with members of\n * the owner's enum (`PetType.Cat`), so the member is one of the owner's type (#1700). `key` is the\n * enum the scan added or the inherited discriminator object. Null when the fix is off, or the\n * owner's property is no TypeScript enum with every value.\n */\nexport function ownerEnumMembersType(\n key: object,\n values: readonly unknown[],\n request: SchemaRequest,\n): IrType | null {\n const { options, discriminators, footer } = request.context;\n const parent: DiscriminatorEnumParent | undefined = options.fixes.has(FIX.DISCRIMINATOR_VALUES)\n ? discriminators.enumParentOf(key)\n : undefined;\n if (parent === undefined || !isTsEnum(parent.schema, options)) {\n return null;\n }\n const reference = { ...enumRequest(parent.schema, parent.path, options), isOwnerReference: true };\n const name = footer.addEnum(reference);\n const members = footer.enumMembers(name);\n const names = values.map((value) => members.get(value as string | number));\n if (names.length === 0 || names.some((member) => member === undefined)) {\n return null;\n }\n return unionOf(names.map((member) => enumMemberType(name, member as string)));\n}\n\nfunction tsEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { options, footer } = request.context;\n // `isTsEnum` admits only strings and numbers, and the fix leaves `null` out of the members.\n const values = tsEnumEntries(schema, options).map(([value]) => value);\n const type =\n ownerEnumMembersType(schema, values, request) ??\n withOtherStrings(\n irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),\n schema,\n );\n return options.fixes.has(FIX.NULLABLE_ENUMS) && isNullAllowed(schema)\n ? unionOf([type, irKeyword(\"null\")])\n : type;\n}\n\nfunction isUnionPosition(pointer: readonly string[], index: number): boolean {\n const next = pointer[index + 1];\n return UNION_KEYWORDS.has(pointer[index] as string) && next !== undefined && INDEX_RE.test(next);\n}\n\nconst PARAMETERS = \"parameters\";\n\n/** Where the `parameters` of a path item sit in its pointer: `paths/<key>/…`, `components/…`. */\nfunction pathItemParametersIndex(pointer: readonly string[]): number | null {\n if (pointer[0] === \"paths\" || pointer[0] === \"webhooks\") {\n return 2;\n }\n return pointer[0] === \"components\" && pointer[1] === \"pathItems\" ? 3 : null;\n}\n\n/**\n * The location of a path item parameter repeats `parameters` (`paths/~1a/parameters/parameters/\n * path/id`), which keeps the generated names as they were. The generated type has the segment\n * once: `paths[\"/a\"][\"parameters\"][\"path\"][\"id\"]`.\n */\nfunction withSingleParametersSegment(pointer: readonly string[]): readonly string[] {\n const index = pathItemParametersIndex(pointer);\n const isRepeated =\n index !== null && pointer[index] === PARAMETERS && pointer[index + 1] === PARAMETERS;\n return isRepeated ? [...pointer.slice(0, index), ...pointer.slice(index + 1)] : pointer;\n}\n\n/**\n * The pointer of `--enum-values` arrays without union positions (`anyOf/0`), so names stay\n * stable. Every property after the first union position is narrowed with `Extract`: a no-op where\n * all variants have it, and the needed narrowing where only some do.\n */\nfunction enumValuesPointer(path: string | undefined): { ref: string; extract: string[] } {\n const pointer = withSingleParametersSegment(parseRefPointer(path ?? \"\"));\n const kept: string[] = [];\n let firstVariantStart: number | null = null;\n for (let index = 0; index < pointer.length; index++) {\n if (isUnionPosition(pointer, index)) {\n firstVariantStart ??= index + 2;\n index++;\n continue;\n }\n kept.push(pointer[index] as string);\n }\n const extract =\n firstVariantStart === null\n ? []\n : pointer\n .slice(firstVariantStart)\n .filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));\n return { ref: appendPointer(ROOT_POINTER, kept), extract };\n}\n\nfunction addEnumValues(schema: SchemaObject, request: SchemaRequest): void {\n const { ref, extract } = enumValuesPointer(request.location.path);\n const valuesType = refType(ref, { isDeep: true, extractProperties: extract });\n request.context.footer.addEnumValues({\n name: `${nameFromPath(request.location.path)}Values`,\n // A record value (`additionalProperties`) is reached by indexing with `string`.\n type: request.isFromAdditionalProperties\n ? irIndexedAccess(valuesType, irReference(\"string\"))\n : valuesType,\n values: (schema.enum ?? []) as (string | number)[],\n });\n}\n\nfunction literalEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const values = schema.enum ?? [];\n const isNullable =\n (Array.isArray(schema.type) && schema.type.includes(\"null\")) || Boolean(schema.nullable);\n const literals = [...values.map(literalType), ...(isNullable ? [irKeyword(\"null\")] : [])];\n const type = withOtherStrings(unionOf(literals), schema);\n const isListable = values.every(\n (value) => typeof value === \"string\" || typeof value === \"number\",\n );\n if (request.context.options.enumValues && isListable) {\n addEnumValues(schema, request);\n }\n return type;\n}\n\n/**\n * `enum` on anything but an object (object enums are handled as `oneOf`). With\n * `additionalProperties`, only string enums are handled here; others fall through to composition.\n */\nexport const enumRule: SchemaRule = {\n name: \"enum\",\n matches(schema) {\n const isCandidate =\n Array.isArray(schema.enum) && schema.type !== \"object\" && !(\"properties\" in schema);\n return isCandidate && (!hasAdditionalProperties(schema) || schema.type === \"string\");\n },\n transform(schema, request) {\n return isTsEnum(schema, request.context.options)\n ? tsEnumType(schema, request)\n : literalEnumType(schema, request);\n },\n};\n"],"names":[],"mappings":";;;;;;;AA2BA,MAAM,wBAAA,GAA2B,oBAAA;AACjC,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,OAAO,CAAC,CAAA;AACtE,MAAM,QAAA,GAAW,OAAA;AAEjB,SAAS,wBAAwB,MAAA,EAA+B;AAC9D,EAAA,OAAO,sBAAA,IAA0B,MAAA,IAAU,OAAA,CAAQ,MAAA,CAAO,oBAAoB,CAAA;AAChF;AAGA,SAAS,aAAa,IAAA,EAAkC;AACtD,EAAA,OAAO,eAAA,CAAgB,QAAQ,EAAE,CAAA,CAC9B,KAAK,GAAG,CAAA,CACR,OAAA,CAAQ,wBAAA,EAA0B,EAAE,CAAA;AACzC;AAGA,MAAM,mBAAA,GAAsB,iCAAA;AAE5B,SAAS,gBAAgB,MAAA,EAA+B;AACtD,EAAA,OAAO;AAAA,IACL,OAAO,iBAAiB,CAAA;AAAA,IACx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GAAI,EAAG,CAAA;AACxF,EAAA,MAAM,IAAA,GAAO,gBAAA,CAAiB,OAAA,CAAQ,QAAQ,GAAG,MAAM,CAAA;AACvD,EAAA,MAAM,aAAa,MAAA,CAAO,KAAA;AAAA,IACxB,CAAC,KAAA,KAAU,OAAO,KAAA,KAAU,QAAA,IAAY,OAAO,KAAA,KAAU;AAAA,GAC3D;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,OAAA,CAAQ,UAAA,IAAc,UAAA,EAAY;AACpD,IAAA,aAAA,CAAc,QAAQ,OAAO,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,IAAA;AACT;AAMO,MAAM,QAAA,GAAuB;AAAA,EAClC,IAAA,EAAM,MAAA;AAAA,EACN,QAAQ,MAAA,EAAQ;AACd,IAAA,MAAM,WAAA,GACJ,KAAA,CAAM,OAAA,CAAQ,MAAA,CAAO,IAAI,KAAK,MAAA,CAAO,IAAA,KAAS,QAAA,IAAY,EAAE,YAAA,IAAgB,MAAA,CAAA;AAC9E,IAAA,OAAO,gBAAgB,CAAC,uBAAA,CAAwB,MAAM,CAAA,IAAK,OAAO,IAAA,KAAS,QAAA,CAAA;AAAA,EAC7E,CAAA;AAAA,EACA,SAAA,CAAU,QAAQ,OAAA,EAAS;AACzB,IAAA,OAAO,QAAA,CAAS,MAAA,EAAQ,OAAA,CAAQ,OAAA,CAAQ,OAAO,CAAA,GAC3C,UAAA,CAAW,MAAA,EAAQ,OAAO,CAAA,GAC1B,eAAA,CAAgB,MAAA,EAAQ,OAAO,CAAA;AAAA,EACrC;AACF;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const declaredTypes = require('../document/declared-types.cjs');
|
|
4
|
+
const typeAssignability = require('../document/type-assignability.cjs');
|
|
5
|
+
const typeCombinators = require('../type-combinators.cjs');
|
|
6
|
+
|
|
7
|
+
function withPropertyTypes(indexType, propertyTypes) {
|
|
8
|
+
const relate = typeAssignability.assignabilityProof(declaredTypes.NO_DECLARED_TYPES);
|
|
9
|
+
const members = unionMembers(indexType);
|
|
10
|
+
const added = [];
|
|
11
|
+
for (const member of propertyTypes.flatMap(unionMembers)) {
|
|
12
|
+
if (relate(member, typeCombinators.unionOf([...members, ...added])) !== "assignable") {
|
|
13
|
+
added.push(member);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return added.length === 0 ? indexType : typeCombinators.unionOf([...members, ...added]);
|
|
17
|
+
}
|
|
18
|
+
const unionMembers = (type) => type.kind === "union" ? type.types : [type];
|
|
19
|
+
|
|
20
|
+
exports.withPropertyTypes = withPropertyTypes;
|
|
21
|
+
//# sourceMappingURL=index-signature-type.cjs.map
|