openapi-typesafe 1.0.0-rc.3 → 1.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1831 -0
- package/dist/adapters/node-file-system/file-claims.cjs +105 -0
- package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.mjs +95 -0
- package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.cjs +82 -0
- package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.mjs +74 -0
- package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +90 -14
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +90 -14
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +75 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +72 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -1
- package/dist/adapters/redocly-loader/loaded-documents.cjs +28 -0
- package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +14 -15
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +12 -13
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.cjs +2 -2
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.mjs +3 -3
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
- package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +47 -0
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +44 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +11 -7
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +12 -8
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/default-ports.cjs +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-run.cjs +2 -2
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +2 -2
- 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 +8 -4
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +8 -5
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/schema-callbacks.cjs +36 -12
- package/dist/api/schema-callbacks.cjs.map +1 -1
- package/dist/api/schema-callbacks.mjs +36 -12
- package/dist/api/schema-callbacks.mjs.map +1 -1
- package/dist/api/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 +40 -10
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +41 -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/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 +4 -1
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +3 -2
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
- package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
- package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
- package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
- package/dist/application/transform/document/global-type-references.cjs +1 -0
- package/dist/application/transform/document/global-type-references.cjs.map +1 -1
- package/dist/application/transform/document/global-type-references.mjs +1 -1
- package/dist/application/transform/document/global-type-references.mjs.map +1 -1
- package/dist/application/transform/document/media-type.cjs +2 -2
- package/dist/application/transform/document/media-type.cjs.map +1 -1
- package/dist/application/transform/document/media-type.mjs +3 -3
- package/dist/application/transform/document/media-type.mjs.map +1 -1
- package/dist/application/transform/document/operation-keys-written.cjs +26 -0
- package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
- package/dist/application/transform/document/operation-keys-written.mjs +24 -0
- package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
- package/dist/application/transform/document/operation.cjs +1 -1
- package/dist/application/transform/document/operation.cjs.map +1 -1
- package/dist/application/transform/document/operation.mjs +2 -2
- package/dist/application/transform/document/operation.mjs.map +1 -1
- package/dist/application/transform/document/parameter-entries.cjs +34 -0
- package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
- package/dist/application/transform/document/parameter-entries.mjs +30 -0
- package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
- package/dist/application/transform/document/parameter.cjs +12 -4
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +13 -5
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +6 -29
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +6 -29
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +11 -14
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +12 -16
- package/dist/application/transform/document/path-item.mjs.map +1 -1
- package/dist/application/transform/document/paths-enum.cjs +1 -0
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +1 -1
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +5 -1
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +6 -2
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/referenced-parameter.cjs +80 -0
- package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
- package/dist/application/transform/document/referenced-parameter.mjs +78 -0
- package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
- package/dist/application/transform/document/request-body.cjs +1 -1
- package/dist/application/transform/document/request-body.cjs.map +1 -1
- package/dist/application/transform/document/request-body.mjs +2 -2
- package/dist/application/transform/document/request-body.mjs.map +1 -1
- package/dist/application/transform/document/response.cjs +2 -2
- package/dist/application/transform/document/response.cjs.map +1 -1
- package/dist/application/transform/document/response.mjs +3 -3
- package/dist/application/transform/document/response.mjs.map +1 -1
- package/dist/application/transform/document/responses.cjs +1 -1
- package/dist/application/transform/document/responses.cjs.map +1 -1
- package/dist/application/transform/document/responses.mjs +2 -2
- package/dist/application/transform/document/responses.mjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.cjs +8 -23
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.mjs +8 -24
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
- package/dist/application/transform/document/type-resolution.cjs +3 -1
- package/dist/application/transform/document/type-resolution.cjs.map +1 -1
- package/dist/application/transform/document/type-resolution.mjs +3 -1
- package/dist/application/transform/document/type-resolution.mjs.map +1 -1
- package/dist/application/transform/document/webhooks.cjs +1 -1
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +2 -2
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +10 -2
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +10 -2
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
- package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
- package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
- package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.cjs +23 -0
- package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.mjs +21 -0
- package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.cjs +4 -4
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
- package/dist/application/transform/footer/type-evaluation.mjs +4 -4
- package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
- package/dist/application/transform/helper-types.cjs +1 -1
- package/dist/application/transform/helper-types.cjs.map +1 -1
- package/dist/application/transform/helper-types.mjs +1 -1
- package/dist/application/transform/helper-types.mjs.map +1 -1
- package/dist/application/transform/numbered-names.cjs +9 -0
- package/dist/application/transform/numbered-names.cjs.map +1 -1
- package/dist/application/transform/numbered-names.mjs +9 -1
- package/dist/application/transform/numbered-names.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +2 -2
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-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/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/object-type.cjs +3 -3
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +4 -4
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/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 +4 -2
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +4 -2
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema-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-settings.cjs +62 -6
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +60 -7
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +72 -0
- package/dist/cli/api-writes.cjs.map +1 -0
- package/dist/cli/api-writes.mjs +69 -0
- package/dist/cli/api-writes.mjs.map +1 -0
- package/dist/cli/cli-errors.cjs +12 -1
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +12 -1
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +106 -1
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +99 -2
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +5 -1
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +6 -2
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +82 -36
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +85 -39
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +13 -7
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +14 -8
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/append-all.cjs +10 -0
- package/dist/domain/append-all.cjs.map +1 -0
- package/dist/domain/append-all.mjs +8 -0
- package/dist/domain/append-all.mjs.map +1 -0
- package/dist/domain/cause-secrets.cjs +37 -0
- package/dist/domain/cause-secrets.cjs.map +1 -0
- package/dist/domain/cause-secrets.mjs +35 -0
- package/dist/domain/cause-secrets.mjs.map +1 -0
- package/dist/domain/errors.cjs +9 -3
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +9 -3
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/identifier-text.cjs.map +1 -1
- package/dist/domain/ir/identifier-text.mjs +1 -1
- package/dist/domain/ir/identifier-text.mjs.map +1 -1
- package/dist/domain/ir/ir-shape.cjs +187 -0
- package/dist/domain/ir/ir-shape.cjs.map +1 -0
- package/dist/domain/ir/ir-shape.mjs +184 -0
- package/dist/domain/ir/ir-shape.mjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
- package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.cjs +3 -1
- package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.mjs +3 -1
- package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.cjs +3 -3
- package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.mjs +4 -4
- package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
- package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
- package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
- package/dist/domain/openapi/json-pointer.cjs +43 -1
- package/dist/domain/openapi/json-pointer.cjs.map +1 -1
- package/dist/domain/openapi/json-pointer.mjs +40 -2
- package/dist/domain/openapi/json-pointer.mjs.map +1 -1
- package/dist/domain/openapi/schema-dialect.cjs +15 -0
- package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
- package/dist/domain/openapi/schema-dialect.mjs +12 -0
- package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.cjs +1 -1
- package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
- package/dist/domain/openapi/unsupported-features.mjs +2 -2
- package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
- package/dist/domain/output-fixes.cjs +14 -0
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +14 -0
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/url-secrets.cjs +48 -0
- package/dist/domain/url-secrets.cjs.map +1 -0
- package/dist/domain/url-secrets.mjs +45 -0
- package/dist/domain/url-secrets.mjs.map +1 -0
- package/dist/index.d.cts +22 -4
- package/dist/index.d.mts +22 -4
- package/dist/index.d.ts +22 -4
- 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 +145 -18
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +95 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
- package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +18 -24
- package/src/adapters/redocly-loader/ref-access.ts +37 -3
- package/src/adapters/redocly-loader/ref-holders.ts +3 -3
- package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +74 -11
- package/src/adapters/redocly-loader/remote-node-limit.ts +62 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
- package/src/adapters/redocly-loader/schema-source.ts +20 -8
- package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
- package/src/adapters/terminal-logger/terminal-logger.ts +10 -5
- package/src/api/default-ports.ts +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-run.ts +4 -3
- package/src/api/legacy-utils.ts +5 -1
- package/src/api/openapi-ts.ts +20 -5
- 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 +64 -12
- package/src/application/ports/file-system.ts +39 -0
- package/src/application/ports/schema-loader.ts +11 -1
- package/src/application/print/text-writer.ts +10 -3
- package/src/application/stack-overflow.ts +9 -5
- package/src/application/transform/document/components.ts +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 +4 -3
- package/src/application/transform/document/enum-names-given-back.ts +91 -0
- package/src/application/transform/document/global-type-references.ts +1 -1
- package/src/application/transform/document/media-type.ts +4 -3
- package/src/application/transform/document/operation-keys-written.ts +27 -0
- package/src/application/transform/document/operation.ts +2 -2
- package/src/application/transform/document/parameter-entries.ts +70 -0
- package/src/application/transform/document/parameter.ts +21 -9
- package/src/application/transform/document/parameters.ts +11 -56
- package/src/application/transform/document/path-item.ts +13 -31
- package/src/application/transform/document/paths-enum.ts +1 -1
- package/src/application/transform/document/paths.ts +6 -2
- package/src/application/transform/document/referenced-parameter.ts +146 -0
- package/src/application/transform/document/request-body.ts +2 -2
- package/src/application/transform/document/response.ts +3 -3
- package/src/application/transform/document/responses.ts +2 -2
- package/src/application/transform/document/root-type-aliases.ts +17 -38
- package/src/application/transform/document/type-resolution.ts +2 -1
- package/src/application/transform/document/webhooks.ts +2 -2
- package/src/application/transform/footer/document-footer.ts +18 -1
- package/src/application/transform/footer/enum-name-claims.ts +62 -0
- package/src/application/transform/footer/operation-keys.ts +28 -0
- package/src/application/transform/footer/type-evaluation.ts +4 -4
- package/src/application/transform/helper-types.ts +6 -5
- package/src/application/transform/numbered-names.ts +15 -0
- package/src/application/transform/ref-pointer/generated-location.ts +2 -2
- package/src/application/transform/ref-type.ts +2 -1
- 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/object-type.ts +4 -4
- 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 +4 -2
- package/src/application/transform/schema-comment.ts +5 -1
- package/src/application/transform/transform-context.ts +5 -0
- package/src/cli/api-settings.ts +82 -7
- package/src/cli/api-writes.ts +117 -0
- package/src/cli/cli-dependencies.ts +21 -4
- package/src/cli/cli-errors.ts +20 -1
- package/src/cli/cli-output.ts +186 -7
- package/src/cli/main.ts +6 -3
- package/src/cli/redocly-apis.ts +153 -48
- package/src/cli/run-cli.ts +37 -8
- package/src/domain/append-all.ts +10 -0
- package/src/domain/cause-secrets.ts +52 -0
- package/src/domain/errors.ts +14 -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/openapi/alias-expansion.ts +4 -1
- package/src/domain/openapi/discriminated-union.ts +6 -4
- package/src/domain/openapi/discriminator-conflicts.ts +21 -7
- package/src/domain/openapi/document-object.ts +2 -0
- package/src/domain/openapi/json-pointer.ts +96 -7
- package/src/domain/openapi/schema-dialect.ts +22 -0
- package/src/domain/openapi/unsupported-features.ts +2 -2
- package/src/domain/output-fixes.ts +21 -2
- package/src/domain/url-secrets.ts +72 -0
- package/src/types/generator-options.ts +1 -1
- package/dist/cli/main.d.cts +0 -2
- package/dist/cli/main.d.mts +0 -2
- package/dist/cli/main.d.ts +0 -2
- package/dist/domain/url-credentials.cjs +0 -10
- package/dist/domain/url-credentials.cjs.map +0 -1
- package/dist/domain/url-credentials.mjs +0 -8
- package/dist/domain/url-credentials.mjs.map +0 -1
- package/src/domain/url-credentials.ts +0 -18
|
@@ -1 +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,QAAsB,OAAA,EAA6C;AACxF,EAAA,MAAM,OAAA,GAAA,CAAW,MAAA,CAAO,IAAA,IAAQ,EAAC,EAAG,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,KAA6B,CAAC,KAAA,EAAO,KAAK,CAAC,CAAA;AAC3F,EAAA,OAAO,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAI,GAAA,CAAI,cAAc,CAAA,GACvC,OAAA,CAAQ,MAAA,CAAO,CAAC,CAAC,KAAK,CAAA,KAAM,KAAA,KAAU,IAAI,CAAA,GAC1C,OAAA;AACN;AAOA,SAAS,QAAA,CAAS,QAAsB,OAA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AAO,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,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,QAAsB,OAAA,EAA6C;AACxF,EAAA,MAAM,OAAA,GAAA,CAAW,MAAA,CAAO,IAAA,IAAQ,EAAC,EAAG,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,KAA6B,CAAC,KAAA,EAAO,KAAK,CAAC,CAAA;AAC3F,EAAA,OAAO,OAAA,CAAQ,KAAA,CAAM,GAAA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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;;"}
|
|
@@ -62,7 +62,7 @@ function isExcluded(value, facts, request) {
|
|
|
62
62
|
return Boolean(resolved?.deprecated);
|
|
63
63
|
}
|
|
64
64
|
function propertyType(key, value, facts, request) {
|
|
65
|
-
const path = jsonPointer.
|
|
65
|
+
const path = jsonPointer.appendPointer(request.location.path, [key]);
|
|
66
66
|
const type = facts.ref ? pointerType.schemaRefType(facts.ref, request) : request.transformNested(value, { ...request.location, path });
|
|
67
67
|
const custom = request.context.callbacks.transform(value, request.location);
|
|
68
68
|
return custom === null ? { type, isOptional: null } : { type: custom.type, isOptional: custom.isOptional || null };
|
|
@@ -86,7 +86,7 @@ function propertyMember(key, value, schema, request) {
|
|
|
86
86
|
isReadonly: options.immutable || !options.readWriteMarkers && facts.flags.isReadOnly
|
|
87
87
|
}
|
|
88
88
|
);
|
|
89
|
-
return finishProperty(property, value, jsonPointer.
|
|
89
|
+
return finishProperty(property, value, jsonPointer.appendPointer(request.location.path, [key]), request);
|
|
90
90
|
}
|
|
91
91
|
function propertyMembers(schema, request) {
|
|
92
92
|
const members = [];
|
|
@@ -101,7 +101,7 @@ function propertyMembers(schema, request) {
|
|
|
101
101
|
function defsMember(defs, request) {
|
|
102
102
|
const { options } = request.context;
|
|
103
103
|
const members = Object.entries(defs).map(([key, value]) => {
|
|
104
|
-
const path = jsonPointer.
|
|
104
|
+
const path = jsonPointer.appendPointer(request.location.path, ["$defs", key]);
|
|
105
105
|
const flags = accessFlags.propertyAccessFlags(value, request.context);
|
|
106
106
|
const type = withReadWriteMarker(
|
|
107
107
|
request.transformNested(value, { ...request.location, path }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-type.cjs","sources":["../../../../src/application/transform/schema/object-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport {\n irObject,\n irProperty,\n irReference,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport { type AccessFlags, propertyAccessFlags } from \"./access-flags.js\";\nimport { discriminatorMember, inheritedDiscriminator } from \"./inherited-discriminator.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/** Path parts where a default value cannot make a property required (inputs may omit it). */\nconst INPUT_PATH_PARTS = [\"parameters\", \"requestBody\", \"requestBodies\"] as const;\n\nexport class InvalidPropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined, key: string, value: unknown) {\n const received = Array.isArray(value) ? \"Array\" : typeof value;\n super({\n code: ERROR_CODES.SCHEMA_PROPERTY_INVALID,\n message:\n `${path}: invalid property ${key}. ` + `Expected Schema Object or boolean, got ${received}`,\n details: { path, property: key, received },\n });\n this.name = \"InvalidPropertyError\";\n }\n}\n\n/** `--read-write-markers`: `$Read<T>` / `$Write<T>`, unless the property is both or neither. */\nfunction withReadWriteMarker(type: IrType, flags: AccessFlags, options: SchemaOptions): IrType {\n if (!options.readWriteMarkers || flags.isReadOnly === flags.isWriteOnly) {\n return type;\n }\n return irReference(flags.isReadOnly ? \"$Read\" : \"$Write\", [type]);\n}\n\n/** Apply `transformProperty`, then the schema's JSDoc. */\nfunction finishProperty(\n property: IrPropertySignature,\n schema: Schema,\n path: string,\n request: SchemaRequest,\n): IrPropertySignature {\n const location = { ...request.location, path };\n const transformed =\n request.context.callbacks.transformProperty(property, schema, location) ?? property;\n // The original adds the schema's comment after any comment the callback set.\n return withSchemaComment(\n transformed,\n schema,\n schemaCommentOptionsOf(request.context.options.fixes),\n );\n}\n\n/** What the property loop reads from a property schema, in the original order. */\ninterface PropertyFacts {\n readonly ref: string | undefined;\n readonly flags: AccessFlags;\n readonly hasDefault: boolean;\n}\n\nfunction propertyFacts(value: Schema, request: SchemaRequest): PropertyFacts {\n if (typeof value !== \"object\") {\n return { ref: undefined, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };\n }\n // `in` throws for a null value, as in the original (which also reads `$ref` first).\n const ref = \"$ref\" in value && value.$ref ? value.$ref : undefined;\n const flags = propertyAccessFlags(value, request.context);\n return { ref, flags, hasDefault: \"default\" in value && value.default !== undefined };\n}\n\nfunction isOptionalProperty(\n key: string,\n facts: PropertyFacts,\n schema: SchemaObject,\n request: SchemaRequest,\n): boolean {\n const { options } = request.context;\n const path = request.location.path;\n const isDefaultRequired =\n facts.hasDefault &&\n options.defaultNonNullable &&\n !INPUT_PATH_PARTS.some((part) => path?.includes(part));\n const isRequired =\n schema.required?.includes(key) ||\n (schema.required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\nfunction isExcluded(value: Schema, facts: PropertyFacts, request: SchemaRequest): boolean {\n if (!request.context.options.excludeDeprecated) {\n return false;\n }\n const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;\n return Boolean((resolved as SchemaObject | undefined)?.deprecated);\n}\n\n/** A type, and whether a callback forced the property optional (null: no override). */\ninterface CustomResult {\n readonly type: IrType;\n readonly isOptional: true | null;\n}\n\nfunction propertyType(\n key: string,\n value: Schema,\n facts: PropertyFacts,\n request: SchemaRequest,\n): CustomResult {\n const path = createRef([request.location.path, key]);\n const type = facts.ref\n ? schemaRefType(facts.ref, request)\n : request.transformNested(value, { ...request.location, path });\n const custom = request.context.callbacks.transform(value, request.location);\n return custom === null\n ? { type, isOptional: null }\n : { type: custom.type, isOptional: custom.isOptional || null };\n}\n\nfunction propertyMember(\n key: string,\n value: Schema,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrMember | null {\n if ((typeof value !== \"object\" && typeof value !== \"boolean\") || Array.isArray(value)) {\n throw new InvalidPropertyError(request.location.path, key, value);\n }\n const facts = propertyFacts(value, request);\n if (isExcluded(value, facts, request)) {\n return null;\n }\n const { options } = request.context;\n const isOptional = isOptionalProperty(key, facts, schema, request);\n const result = propertyType(key, value, facts, request);\n const property = irProperty(\n toPropertyName(key),\n withReadWriteMarker(result.type, facts.flags, options),\n {\n isOptional: result.isOptional ?? isOptional,\n isReadonly: options.immutable || (!options.readWriteMarkers && facts.flags.isReadOnly),\n },\n );\n return finishProperty(property, value, createRef([request.location.path, key]), request);\n}\n\nfunction propertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const members: IrMember[] = [];\n for (const [key, value] of documentEntries(schema.properties ?? {}, request.context.options)) {\n const member = propertyMember(key, value, schema, request);\n if (member !== null) {\n members.push(member);\n }\n }\n return members;\n}\n\n/**\n * `$defs` as a nested `$defs?: { … }` member, in document order (never alphabetized). It is\n * optional because `$defs` is a schema keyword, not data: the original made it required, so a\n * value of the type needed a `$defs` key (research/legacy-bugs.md, item 17, upstream #2664).\n */\nfunction defsMember(\n defs: Readonly<Record<string, SchemaObject>>,\n request: SchemaRequest,\n): IrMember {\n const { options } = request.context;\n const members = Object.entries(defs).map(([key, value]) => {\n const path = createRef([request.location.path, \"$defs\", key]);\n const flags = propertyAccessFlags(value, request.context);\n const type = withReadWriteMarker(\n request.transformNested(value, { ...request.location, path }),\n flags,\n options,\n );\n const property = irProperty(toPropertyName(key), type, {\n isReadonly: options.immutable || (!options.readWriteMarkers && flags.isReadOnly),\n });\n return finishProperty(property, value, path, request);\n });\n return irProperty(toPropertyName(\"$defs\"), irObject(members), { isOptional: true });\n}\n\nfunction hasObjectKeywords(schema: SchemaObject): boolean {\n const hasProperties = Boolean(schema.properties && Object.keys(schema.properties).length);\n return (\n hasProperties ||\n Boolean(schema.additionalProperties || schema.patternProperties || schema.$defs)\n );\n}\n\n/** Value types of the `[key: string]` index signature, in the original order. */\nfunction indexValueTypes(schema: SchemaObject, request: SchemaRequest): IrType[] {\n const { additionalProperties } = schema;\n const isObject = typeof additionalProperties === \"object\";\n const hasExplicit = isObject && Object.keys(additionalProperties).length > 0;\n const hasImplicit =\n additionalProperties === true || (isObject && Object.keys(additionalProperties).length === 0);\n const types: IrType[] = [];\n if (hasExplicit) {\n types.push(request.transformNested(additionalProperties as Schema, request.location, true));\n }\n if (hasImplicit || (!additionalProperties && request.context.options.additionalProperties)) {\n types.push(UNKNOWN_TYPE);\n }\n const patterns = schema.patternProperties;\n if (typeof patterns === \"object\" && patterns !== null && Object.keys(patterns).length > 0) {\n for (const [, value] of documentEntries(patterns, request.context.options)) {\n types.push(request.transformNested(value, request.location));\n }\n }\n return types;\n}\n\n/**\n * Whether the schema declares property `key` and the type keeps it: `--exclude-deprecated` drops\n * a deprecated one.\n */\nexport function isKeptProperty(schema: SchemaObject, key: string, request: SchemaRequest): boolean {\n const properties = schema.properties ?? {};\n if (!Object.hasOwn(properties, key)) {\n return false;\n }\n const value = properties[key] as Schema;\n const isExcludable = request.context.options.excludeDeprecated && typeof value === \"object\";\n return !isExcludable || !isExcluded(value, propertyFacts(value, request), request);\n}\n\n/**\n * The members for the discriminator and `properties`. A schema that declares the discriminator\n * property itself keeps its own declaration, required as the discriminator needs: both in one\n * object type do not compile (TS2300, the Apple SiriKit Cloud Media API). A declaration that\n * `--exclude-deprecated` drops does not count, so the discriminator property stays.\n */\nfunction discriminatorAndPropertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const inherited = inheritedDiscriminator(schema, request);\n if (inherited === undefined) {\n return propertyMembers(schema, request);\n }\n const name = inherited.discriminator.propertyName;\n if (!isKeptProperty(schema, name, request)) {\n return [discriminatorMember(inherited, request), ...propertyMembers(schema, request)];\n }\n // Without `required`, `--properties-required-by-default` requires every property already; a\n // list of one would make the others optional.\n const isAllRequired =\n schema.required === undefined && request.context.options.propertiesRequiredByDefault;\n const required = isAllRequired ? undefined : [...(schema.required ?? []), name];\n return propertyMembers({ ...schema, required } as SchemaObject, request);\n}\n\n/**\n * Object keywords: discriminator, `properties`, `$defs`, and an index signature for\n * `additionalProperties` / `patternProperties` (or `--additional-properties`). Null when the schema\n * has none of them.\n */\nexport function objectType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (!hasObjectKeywords(schema)) {\n const inherited = inheritedDiscriminator(schema, request);\n return inherited ? irObject([discriminatorMember(inherited, request)]) : null;\n }\n const members = discriminatorAndPropertyMembers(schema, request);\n // As in the original, a null `$defs` throws here (Object.keys) instead of being skipped.\n if (\n \"$defs\" in schema &&\n typeof schema.$defs === \"object\" &&\n Object.keys(schema.$defs).length > 0\n ) {\n members.push(defsMember(schema.$defs, request));\n }\n const valueTypes = indexValueTypes(schema, request);\n if (valueTypes.length === 0) {\n return members.length > 0 ? irObject(members) : null;\n }\n const index = irObject([\n irStringIndexSignature(\"key\", unionOf(valueTypes), request.context.options.immutable),\n ]);\n return intersectionOf([...(members.length > 0 ? [irObject(members)] : []), index]);\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","irReference","withSchemaComment","schemaCommentOptionsOf","propertyAccessFlags","createRef","schemaRefType","irProperty","toPropertyName","documentEntries","irObject","UNKNOWN_TYPE","inheritedDiscriminator","discriminatorMember","irStringIndexSignature","unionOf","intersectionOf"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAM,gBAAA,GAAmB,CAAC,YAAA,EAAc,aAAA,EAAe,eAAe,CAAA;AAE/D,MAAM,6BAA6BA,2BAAA,CAAqB;AAAA,EAC7D,WAAA,CAAY,IAAA,EAA0B,GAAA,EAAa,KAAA,EAAgB;AACjE,IAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,UAAU,OAAO,KAAA;AACzD,IAAA,KAAA,CAAM;AAAA,MACJ,MAAMC,kBAAA,CAAY,uBAAA;AAAA,MAClB,SACE,CAAA,EAAG,IAAI,CAAA,mBAAA,EAAsB,GAAG,4CAAiD,QAAQ,CAAA,CAAA;AAAA,MAC3F,OAAA,EAAS,EAAE,IAAA,EAAM,QAAA,EAAU,KAAK,QAAA;AAAS,KAC1C,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,sBAAA;AAAA,EACd;AACF;AAGA,SAAS,mBAAA,CAAoB,IAAA,EAAc,KAAA,EAAoB,OAAA,EAAgC;AAC7F,EAAA,IAAI,CAAC,OAAA,CAAQ,gBAAA,IAAoB,KAAA,CAAM,UAAA,KAAe,MAAM,WAAA,EAAa;AACvE,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAOC,yBAAY,KAAA,CAAM,UAAA,GAAa,UAAU,QAAA,EAAU,CAAC,IAAI,CAAC,CAAA;AAClE;AAGA,SAAS,cAAA,CACP,QAAA,EACA,MAAA,EACA,IAAA,EACA,OAAA,EACqB;AACrB,EAAA,MAAM,QAAA,GAAW,EAAE,GAAG,OAAA,CAAQ,UAAU,IAAA,EAAK;AAC7C,EA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C,8BAAA,CAAe,CAAC,GAAI,OAAA,CAAQ,SAAS,CAAA,GAAI,CAACN,qBAAA,CAAS,OAAO,CAAC,CAAA,GAAI,EAAC,EAAI,KAAK,CAAC,CAAA;AACnF;;;;"}
|
|
1
|
+
{"version":3,"file":"object-type.cjs","sources":["../../../../src/application/transform/schema/object-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport {\n irObject,\n irProperty,\n irReference,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport { type AccessFlags, propertyAccessFlags } from \"./access-flags.js\";\nimport { discriminatorMember, inheritedDiscriminator } from \"./inherited-discriminator.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/** Path parts where a default value cannot make a property required (inputs may omit it). */\nconst INPUT_PATH_PARTS = [\"parameters\", \"requestBody\", \"requestBodies\"] as const;\n\nexport class InvalidPropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined, key: string, value: unknown) {\n const received = Array.isArray(value) ? \"Array\" : typeof value;\n super({\n code: ERROR_CODES.SCHEMA_PROPERTY_INVALID,\n message:\n `${path}: invalid property ${key}. ` + `Expected Schema Object or boolean, got ${received}`,\n details: { path, property: key, received },\n });\n this.name = \"InvalidPropertyError\";\n }\n}\n\n/** `--read-write-markers`: `$Read<T>` / `$Write<T>`, unless the property is both or neither. */\nfunction withReadWriteMarker(type: IrType, flags: AccessFlags, options: SchemaOptions): IrType {\n if (!options.readWriteMarkers || flags.isReadOnly === flags.isWriteOnly) {\n return type;\n }\n return irReference(flags.isReadOnly ? \"$Read\" : \"$Write\", [type]);\n}\n\n/** Apply `transformProperty`, then the schema's JSDoc. */\nfunction finishProperty(\n property: IrPropertySignature,\n schema: Schema,\n path: string,\n request: SchemaRequest,\n): IrPropertySignature {\n const location = { ...request.location, path };\n const transformed =\n request.context.callbacks.transformProperty(property, schema, location) ?? property;\n // The original adds the schema's comment after any comment the callback set.\n return withSchemaComment(\n transformed,\n schema,\n schemaCommentOptionsOf(request.context.options.fixes),\n );\n}\n\n/** What the property loop reads from a property schema, in the original order. */\ninterface PropertyFacts {\n readonly ref: string | undefined;\n readonly flags: AccessFlags;\n readonly hasDefault: boolean;\n}\n\nfunction propertyFacts(value: Schema, request: SchemaRequest): PropertyFacts {\n if (typeof value !== \"object\") {\n return { ref: undefined, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };\n }\n // `in` throws for a null value, as in the original (which also reads `$ref` first).\n const ref = \"$ref\" in value && value.$ref ? value.$ref : undefined;\n const flags = propertyAccessFlags(value, request.context);\n return { ref, flags, hasDefault: \"default\" in value && value.default !== undefined };\n}\n\nfunction isOptionalProperty(\n key: string,\n facts: PropertyFacts,\n schema: SchemaObject,\n request: SchemaRequest,\n): boolean {\n const { options } = request.context;\n const path = request.location.path;\n const isDefaultRequired =\n facts.hasDefault &&\n options.defaultNonNullable &&\n !INPUT_PATH_PARTS.some((part) => path?.includes(part));\n const isRequired =\n schema.required?.includes(key) ||\n (schema.required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\nfunction isExcluded(value: Schema, facts: PropertyFacts, request: SchemaRequest): boolean {\n if (!request.context.options.excludeDeprecated) {\n return false;\n }\n const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;\n return Boolean((resolved as SchemaObject | undefined)?.deprecated);\n}\n\n/** A type, and whether a callback forced the property optional (null: no override). */\ninterface CustomResult {\n readonly type: IrType;\n readonly isOptional: true | null;\n}\n\nfunction propertyType(\n key: string,\n value: Schema,\n facts: PropertyFacts,\n request: SchemaRequest,\n): CustomResult {\n const path = appendPointer(request.location.path, [key]);\n const type = facts.ref\n ? schemaRefType(facts.ref, request)\n : request.transformNested(value, { ...request.location, path });\n const custom = request.context.callbacks.transform(value, request.location);\n return custom === null\n ? { type, isOptional: null }\n : { type: custom.type, isOptional: custom.isOptional || null };\n}\n\nfunction propertyMember(\n key: string,\n value: Schema,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrMember | null {\n if ((typeof value !== \"object\" && typeof value !== \"boolean\") || Array.isArray(value)) {\n throw new InvalidPropertyError(request.location.path, key, value);\n }\n const facts = propertyFacts(value, request);\n if (isExcluded(value, facts, request)) {\n return null;\n }\n const { options } = request.context;\n const isOptional = isOptionalProperty(key, facts, schema, request);\n const result = propertyType(key, value, facts, request);\n const property = irProperty(\n toPropertyName(key),\n withReadWriteMarker(result.type, facts.flags, options),\n {\n isOptional: result.isOptional ?? isOptional,\n isReadonly: options.immutable || (!options.readWriteMarkers && facts.flags.isReadOnly),\n },\n );\n return finishProperty(property, value, appendPointer(request.location.path, [key]), request);\n}\n\nfunction propertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const members: IrMember[] = [];\n for (const [key, value] of documentEntries(schema.properties ?? {}, request.context.options)) {\n const member = propertyMember(key, value, schema, request);\n if (member !== null) {\n members.push(member);\n }\n }\n return members;\n}\n\n/**\n * `$defs` as a nested `$defs?: { … }` member, in document order (never alphabetized). It is\n * optional because `$defs` is a schema keyword, not data: the original made it required, so a\n * value of the type needed a `$defs` key (research/legacy-bugs.md, item 17, upstream #2664).\n */\nfunction defsMember(\n defs: Readonly<Record<string, SchemaObject>>,\n request: SchemaRequest,\n): IrMember {\n const { options } = request.context;\n const members = Object.entries(defs).map(([key, value]) => {\n const path = appendPointer(request.location.path, [\"$defs\", key]);\n const flags = propertyAccessFlags(value, request.context);\n const type = withReadWriteMarker(\n request.transformNested(value, { ...request.location, path }),\n flags,\n options,\n );\n const property = irProperty(toPropertyName(key), type, {\n isReadonly: options.immutable || (!options.readWriteMarkers && flags.isReadOnly),\n });\n return finishProperty(property, value, path, request);\n });\n return irProperty(toPropertyName(\"$defs\"), irObject(members), { isOptional: true });\n}\n\nfunction hasObjectKeywords(schema: SchemaObject): boolean {\n const hasProperties = Boolean(schema.properties && Object.keys(schema.properties).length);\n return (\n hasProperties ||\n Boolean(schema.additionalProperties || schema.patternProperties || schema.$defs)\n );\n}\n\n/** Value types of the `[key: string]` index signature, in the original order. */\nfunction indexValueTypes(schema: SchemaObject, request: SchemaRequest): IrType[] {\n const { additionalProperties } = schema;\n const isObject = typeof additionalProperties === \"object\";\n const hasExplicit = isObject && Object.keys(additionalProperties).length > 0;\n const hasImplicit =\n additionalProperties === true || (isObject && Object.keys(additionalProperties).length === 0);\n const types: IrType[] = [];\n if (hasExplicit) {\n types.push(request.transformNested(additionalProperties as Schema, request.location, true));\n }\n if (hasImplicit || (!additionalProperties && request.context.options.additionalProperties)) {\n types.push(UNKNOWN_TYPE);\n }\n const patterns = schema.patternProperties;\n if (typeof patterns === \"object\" && patterns !== null && Object.keys(patterns).length > 0) {\n for (const [, value] of documentEntries(patterns, request.context.options)) {\n types.push(request.transformNested(value, request.location));\n }\n }\n return types;\n}\n\n/**\n * Whether the schema declares property `key` and the type keeps it: `--exclude-deprecated` drops\n * a deprecated one.\n */\nexport function isKeptProperty(schema: SchemaObject, key: string, request: SchemaRequest): boolean {\n const properties = schema.properties ?? {};\n if (!Object.hasOwn(properties, key)) {\n return false;\n }\n const value = properties[key] as Schema;\n const isExcludable = request.context.options.excludeDeprecated && typeof value === \"object\";\n return !isExcludable || !isExcluded(value, propertyFacts(value, request), request);\n}\n\n/**\n * The members for the discriminator and `properties`. A schema that declares the discriminator\n * property itself keeps its own declaration, required as the discriminator needs: both in one\n * object type do not compile (TS2300, the Apple SiriKit Cloud Media API). A declaration that\n * `--exclude-deprecated` drops does not count, so the discriminator property stays.\n */\nfunction discriminatorAndPropertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const inherited = inheritedDiscriminator(schema, request);\n if (inherited === undefined) {\n return propertyMembers(schema, request);\n }\n const name = inherited.discriminator.propertyName;\n if (!isKeptProperty(schema, name, request)) {\n return [discriminatorMember(inherited, request), ...propertyMembers(schema, request)];\n }\n // Without `required`, `--properties-required-by-default` requires every property already; a\n // list of one would make the others optional.\n const isAllRequired =\n schema.required === undefined && request.context.options.propertiesRequiredByDefault;\n const required = isAllRequired ? undefined : [...(schema.required ?? []), name];\n return propertyMembers({ ...schema, required } as SchemaObject, request);\n}\n\n/**\n * Object keywords: discriminator, `properties`, `$defs`, and an index signature for\n * `additionalProperties` / `patternProperties` (or `--additional-properties`). Null when the schema\n * has none of them.\n */\nexport function objectType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (!hasObjectKeywords(schema)) {\n const inherited = inheritedDiscriminator(schema, request);\n return inherited ? irObject([discriminatorMember(inherited, request)]) : null;\n }\n const members = discriminatorAndPropertyMembers(schema, request);\n // As in the original, a null `$defs` throws here (Object.keys) instead of being skipped.\n if (\n \"$defs\" in schema &&\n typeof schema.$defs === \"object\" &&\n Object.keys(schema.$defs).length > 0\n ) {\n members.push(defsMember(schema.$defs, request));\n }\n const valueTypes = indexValueTypes(schema, request);\n if (valueTypes.length === 0) {\n return members.length > 0 ? irObject(members) : null;\n }\n const index = irObject([\n irStringIndexSignature(\"key\", unionOf(valueTypes), request.context.options.immutable),\n ]);\n return intersectionOf([...(members.length > 0 ? [irObject(members)] : []), index]);\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","irReference","withSchemaComment","schemaCommentOptionsOf","propertyAccessFlags","appendPointer","schemaRefType","irProperty","toPropertyName","documentEntries","irObject","UNKNOWN_TYPE","inheritedDiscriminator","discriminatorMember","irStringIndexSignature","unionOf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ERROR_CODES } from '../../../domain/errors.mjs';
|
|
2
2
|
import { irObject, irStringIndexSignature, irProperty, irReference } from '../../../domain/ir/constructors.mjs';
|
|
3
3
|
import { toPropertyName } from '../../../domain/ir/property-name.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { appendPointer } from '../../../domain/openapi/json-pointer.mjs';
|
|
5
5
|
import { documentEntries } from '../document-entries.mjs';
|
|
6
6
|
import { schemaRefType } from '../ref-pointer/pointer-type.mjs';
|
|
7
7
|
import { withSchemaComment, schemaCommentOptionsOf } from '../schema-comment.mjs';
|
|
@@ -60,7 +60,7 @@ function isExcluded(value, facts, request) {
|
|
|
60
60
|
return Boolean(resolved?.deprecated);
|
|
61
61
|
}
|
|
62
62
|
function propertyType(key, value, facts, request) {
|
|
63
|
-
const path =
|
|
63
|
+
const path = appendPointer(request.location.path, [key]);
|
|
64
64
|
const type = facts.ref ? schemaRefType(facts.ref, request) : request.transformNested(value, { ...request.location, path });
|
|
65
65
|
const custom = request.context.callbacks.transform(value, request.location);
|
|
66
66
|
return custom === null ? { type, isOptional: null } : { type: custom.type, isOptional: custom.isOptional || null };
|
|
@@ -84,7 +84,7 @@ function propertyMember(key, value, schema, request) {
|
|
|
84
84
|
isReadonly: options.immutable || !options.readWriteMarkers && facts.flags.isReadOnly
|
|
85
85
|
}
|
|
86
86
|
);
|
|
87
|
-
return finishProperty(property, value,
|
|
87
|
+
return finishProperty(property, value, appendPointer(request.location.path, [key]), request);
|
|
88
88
|
}
|
|
89
89
|
function propertyMembers(schema, request) {
|
|
90
90
|
const members = [];
|
|
@@ -99,7 +99,7 @@ function propertyMembers(schema, request) {
|
|
|
99
99
|
function defsMember(defs, request) {
|
|
100
100
|
const { options } = request.context;
|
|
101
101
|
const members = Object.entries(defs).map(([key, value]) => {
|
|
102
|
-
const path =
|
|
102
|
+
const path = appendPointer(request.location.path, ["$defs", key]);
|
|
103
103
|
const flags = propertyAccessFlags(value, request.context);
|
|
104
104
|
const type = withReadWriteMarker(
|
|
105
105
|
request.transformNested(value, { ...request.location, path }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-type.mjs","sources":["../../../../src/application/transform/schema/object-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport {\n irObject,\n irProperty,\n irReference,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport { type AccessFlags, propertyAccessFlags } from \"./access-flags.js\";\nimport { discriminatorMember, inheritedDiscriminator } from \"./inherited-discriminator.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/** Path parts where a default value cannot make a property required (inputs may omit it). */\nconst INPUT_PATH_PARTS = [\"parameters\", \"requestBody\", \"requestBodies\"] as const;\n\nexport class InvalidPropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined, key: string, value: unknown) {\n const received = Array.isArray(value) ? \"Array\" : typeof value;\n super({\n code: ERROR_CODES.SCHEMA_PROPERTY_INVALID,\n message:\n `${path}: invalid property ${key}. ` + `Expected Schema Object or boolean, got ${received}`,\n details: { path, property: key, received },\n });\n this.name = \"InvalidPropertyError\";\n }\n}\n\n/** `--read-write-markers`: `$Read<T>` / `$Write<T>`, unless the property is both or neither. */\nfunction withReadWriteMarker(type: IrType, flags: AccessFlags, options: SchemaOptions): IrType {\n if (!options.readWriteMarkers || flags.isReadOnly === flags.isWriteOnly) {\n return type;\n }\n return irReference(flags.isReadOnly ? \"$Read\" : \"$Write\", [type]);\n}\n\n/** Apply `transformProperty`, then the schema's JSDoc. */\nfunction finishProperty(\n property: IrPropertySignature,\n schema: Schema,\n path: string,\n request: SchemaRequest,\n): IrPropertySignature {\n const location = { ...request.location, path };\n const transformed =\n request.context.callbacks.transformProperty(property, schema, location) ?? property;\n // The original adds the schema's comment after any comment the callback set.\n return withSchemaComment(\n transformed,\n schema,\n schemaCommentOptionsOf(request.context.options.fixes),\n );\n}\n\n/** What the property loop reads from a property schema, in the original order. */\ninterface PropertyFacts {\n readonly ref: string | undefined;\n readonly flags: AccessFlags;\n readonly hasDefault: boolean;\n}\n\nfunction propertyFacts(value: Schema, request: SchemaRequest): PropertyFacts {\n if (typeof value !== \"object\") {\n return { ref: undefined, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };\n }\n // `in` throws for a null value, as in the original (which also reads `$ref` first).\n const ref = \"$ref\" in value && value.$ref ? value.$ref : undefined;\n const flags = propertyAccessFlags(value, request.context);\n return { ref, flags, hasDefault: \"default\" in value && value.default !== undefined };\n}\n\nfunction isOptionalProperty(\n key: string,\n facts: PropertyFacts,\n schema: SchemaObject,\n request: SchemaRequest,\n): boolean {\n const { options } = request.context;\n const path = request.location.path;\n const isDefaultRequired =\n facts.hasDefault &&\n options.defaultNonNullable &&\n !INPUT_PATH_PARTS.some((part) => path?.includes(part));\n const isRequired =\n schema.required?.includes(key) ||\n (schema.required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\nfunction isExcluded(value: Schema, facts: PropertyFacts, request: SchemaRequest): boolean {\n if (!request.context.options.excludeDeprecated) {\n return false;\n }\n const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;\n return Boolean((resolved as SchemaObject | undefined)?.deprecated);\n}\n\n/** A type, and whether a callback forced the property optional (null: no override). */\ninterface CustomResult {\n readonly type: IrType;\n readonly isOptional: true | null;\n}\n\nfunction propertyType(\n key: string,\n value: Schema,\n facts: PropertyFacts,\n request: SchemaRequest,\n): CustomResult {\n const path = createRef([request.location.path, key]);\n const type = facts.ref\n ? schemaRefType(facts.ref, request)\n : request.transformNested(value, { ...request.location, path });\n const custom = request.context.callbacks.transform(value, request.location);\n return custom === null\n ? { type, isOptional: null }\n : { type: custom.type, isOptional: custom.isOptional || null };\n}\n\nfunction propertyMember(\n key: string,\n value: Schema,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrMember | null {\n if ((typeof value !== \"object\" && typeof value !== \"boolean\") || Array.isArray(value)) {\n throw new InvalidPropertyError(request.location.path, key, value);\n }\n const facts = propertyFacts(value, request);\n if (isExcluded(value, facts, request)) {\n return null;\n }\n const { options } = request.context;\n const isOptional = isOptionalProperty(key, facts, schema, request);\n const result = propertyType(key, value, facts, request);\n const property = irProperty(\n toPropertyName(key),\n withReadWriteMarker(result.type, facts.flags, options),\n {\n isOptional: result.isOptional ?? isOptional,\n isReadonly: options.immutable || (!options.readWriteMarkers && facts.flags.isReadOnly),\n },\n );\n return finishProperty(property, value, createRef([request.location.path, key]), request);\n}\n\nfunction propertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const members: IrMember[] = [];\n for (const [key, value] of documentEntries(schema.properties ?? {}, request.context.options)) {\n const member = propertyMember(key, value, schema, request);\n if (member !== null) {\n members.push(member);\n }\n }\n return members;\n}\n\n/**\n * `$defs` as a nested `$defs?: { … }` member, in document order (never alphabetized). It is\n * optional because `$defs` is a schema keyword, not data: the original made it required, so a\n * value of the type needed a `$defs` key (research/legacy-bugs.md, item 17, upstream #2664).\n */\nfunction defsMember(\n defs: Readonly<Record<string, SchemaObject>>,\n request: SchemaRequest,\n): IrMember {\n const { options } = request.context;\n const members = Object.entries(defs).map(([key, value]) => {\n const path = createRef([request.location.path, \"$defs\", key]);\n const flags = propertyAccessFlags(value, request.context);\n const type = withReadWriteMarker(\n request.transformNested(value, { ...request.location, path }),\n flags,\n options,\n );\n const property = irProperty(toPropertyName(key), type, {\n isReadonly: options.immutable || (!options.readWriteMarkers && flags.isReadOnly),\n });\n return finishProperty(property, value, path, request);\n });\n return irProperty(toPropertyName(\"$defs\"), irObject(members), { isOptional: true });\n}\n\nfunction hasObjectKeywords(schema: SchemaObject): boolean {\n const hasProperties = Boolean(schema.properties && Object.keys(schema.properties).length);\n return (\n hasProperties ||\n Boolean(schema.additionalProperties || schema.patternProperties || schema.$defs)\n );\n}\n\n/** Value types of the `[key: string]` index signature, in the original order. */\nfunction indexValueTypes(schema: SchemaObject, request: SchemaRequest): IrType[] {\n const { additionalProperties } = schema;\n const isObject = typeof additionalProperties === \"object\";\n const hasExplicit = isObject && Object.keys(additionalProperties).length > 0;\n const hasImplicit =\n additionalProperties === true || (isObject && Object.keys(additionalProperties).length === 0);\n const types: IrType[] = [];\n if (hasExplicit) {\n types.push(request.transformNested(additionalProperties as Schema, request.location, true));\n }\n if (hasImplicit || (!additionalProperties && request.context.options.additionalProperties)) {\n types.push(UNKNOWN_TYPE);\n }\n const patterns = schema.patternProperties;\n if (typeof patterns === \"object\" && patterns !== null && Object.keys(patterns).length > 0) {\n for (const [, value] of documentEntries(patterns, request.context.options)) {\n types.push(request.transformNested(value, request.location));\n }\n }\n return types;\n}\n\n/**\n * Whether the schema declares property `key` and the type keeps it: `--exclude-deprecated` drops\n * a deprecated one.\n */\nexport function isKeptProperty(schema: SchemaObject, key: string, request: SchemaRequest): boolean {\n const properties = schema.properties ?? {};\n if (!Object.hasOwn(properties, key)) {\n return false;\n }\n const value = properties[key] as Schema;\n const isExcludable = request.context.options.excludeDeprecated && typeof value === \"object\";\n return !isExcludable || !isExcluded(value, propertyFacts(value, request), request);\n}\n\n/**\n * The members for the discriminator and `properties`. A schema that declares the discriminator\n * property itself keeps its own declaration, required as the discriminator needs: both in one\n * object type do not compile (TS2300, the Apple SiriKit Cloud Media API). A declaration that\n * `--exclude-deprecated` drops does not count, so the discriminator property stays.\n */\nfunction discriminatorAndPropertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const inherited = inheritedDiscriminator(schema, request);\n if (inherited === undefined) {\n return propertyMembers(schema, request);\n }\n const name = inherited.discriminator.propertyName;\n if (!isKeptProperty(schema, name, request)) {\n return [discriminatorMember(inherited, request), ...propertyMembers(schema, request)];\n }\n // Without `required`, `--properties-required-by-default` requires every property already; a\n // list of one would make the others optional.\n const isAllRequired =\n schema.required === undefined && request.context.options.propertiesRequiredByDefault;\n const required = isAllRequired ? undefined : [...(schema.required ?? []), name];\n return propertyMembers({ ...schema, required } as SchemaObject, request);\n}\n\n/**\n * Object keywords: discriminator, `properties`, `$defs`, and an index signature for\n * `additionalProperties` / `patternProperties` (or `--additional-properties`). Null when the schema\n * has none of them.\n */\nexport function objectType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (!hasObjectKeywords(schema)) {\n const inherited = inheritedDiscriminator(schema, request);\n return inherited ? irObject([discriminatorMember(inherited, request)]) : null;\n }\n const members = discriminatorAndPropertyMembers(schema, request);\n // As in the original, a null `$defs` throws here (Object.keys) instead of being skipped.\n if (\n \"$defs\" in schema &&\n typeof schema.$defs === \"object\" &&\n Object.keys(schema.$defs).length > 0\n ) {\n members.push(defsMember(schema.$defs, request));\n }\n const valueTypes = indexValueTypes(schema, request);\n if (valueTypes.length === 0) {\n return members.length > 0 ? irObject(members) : null;\n }\n const index = irObject([\n irStringIndexSignature(\"key\", unionOf(valueTypes), request.context.options.immutable),\n ]);\n return intersectionOf([...(members.length > 0 ? [irObject(members)] : []), index]);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAsBA,MAAM,gBAAA,GAAmB,CAAC,YAAA,EAAc,aAAA,EAAe,eAAe,CAAA;AAE/D,MAAM,6BAA6B,oBAAA,CAAqB;AAAA,EAC7D,WAAA,CAAY,IAAA,EAA0B,GAAA,EAAa,KAAA,EAAgB;AACjE,IAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,UAAU,OAAO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AU,+BAAA,CAAgC,MAAA,EAAQ,OAAO,CAAA;AAE/D,EAAA,IACE,OAAA,IAAW,MAAA,IACX,OAAO,MAAA,CAAO,KAAA,KAAU,QAAA,IACxB,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA,CAAE,MAAA,GAAS,CAAA,EACnC;AACA,IAAA,OAAA,CAAQ,IAAA,CAAK,UAAA,CAAW,MAAA,CAAO,KAAA,EAAO,OAAO,CAAC,CAAA;AAAA,EAChD;AACA,EAAA,MAAM,UAAA,GAAa,eAAA,CAAgB,MAAA,EAAQ,OAAO,CAAA;AAClD,EAAA,IAAI,UAAA,CAAW,WAAW,CAAA,EAAG;AAC3B,IAAA,OAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,GAAI,QAAA,CAAS,OAAO,CAAA,GAAI,IAAA;AAAA,EAClD;AACA,EAAA,MAAM,QAAQ,QAAA,CAAS;AAAA,IACrB,sBAAA,CAAuB,OAAO,OAAA,CAAQ,UAAU,GAAG,OAAA,CAAQ,OAAA,CAAQ,QAAQ,SAAS;AAAA,GACrF,CAAA;AACD,EAAA,OAAO,cAAA,CAAe,CAAC,GAAI,OAAA,CAAQ,SAAS,CAAA,GAAI,CAAC,QAAA,CAAS,OAAO,CAAC,CAAA,GAAI,EAAC,EAAI,KAAK,CAAC,CAAA;AACnF;;"}
|
|
1
|
+
{"version":3,"file":"object-type.mjs","sources":["../../../../src/application/transform/schema/object-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport {\n irObject,\n irProperty,\n irReference,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport { type AccessFlags, propertyAccessFlags } from \"./access-flags.js\";\nimport { discriminatorMember, inheritedDiscriminator } from \"./inherited-discriminator.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/** Path parts where a default value cannot make a property required (inputs may omit it). */\nconst INPUT_PATH_PARTS = [\"parameters\", \"requestBody\", \"requestBodies\"] as const;\n\nexport class InvalidPropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined, key: string, value: unknown) {\n const received = Array.isArray(value) ? \"Array\" : typeof value;\n super({\n code: ERROR_CODES.SCHEMA_PROPERTY_INVALID,\n message:\n `${path}: invalid property ${key}. ` + `Expected Schema Object or boolean, got ${received}`,\n details: { path, property: key, received },\n });\n this.name = \"InvalidPropertyError\";\n }\n}\n\n/** `--read-write-markers`: `$Read<T>` / `$Write<T>`, unless the property is both or neither. */\nfunction withReadWriteMarker(type: IrType, flags: AccessFlags, options: SchemaOptions): IrType {\n if (!options.readWriteMarkers || flags.isReadOnly === flags.isWriteOnly) {\n return type;\n }\n return irReference(flags.isReadOnly ? \"$Read\" : \"$Write\", [type]);\n}\n\n/** Apply `transformProperty`, then the schema's JSDoc. */\nfunction finishProperty(\n property: IrPropertySignature,\n schema: Schema,\n path: string,\n request: SchemaRequest,\n): IrPropertySignature {\n const location = { ...request.location, path };\n const transformed =\n request.context.callbacks.transformProperty(property, schema, location) ?? property;\n // The original adds the schema's comment after any comment the callback set.\n return withSchemaComment(\n transformed,\n schema,\n schemaCommentOptionsOf(request.context.options.fixes),\n );\n}\n\n/** What the property loop reads from a property schema, in the original order. */\ninterface PropertyFacts {\n readonly ref: string | undefined;\n readonly flags: AccessFlags;\n readonly hasDefault: boolean;\n}\n\nfunction propertyFacts(value: Schema, request: SchemaRequest): PropertyFacts {\n if (typeof value !== \"object\") {\n return { ref: undefined, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };\n }\n // `in` throws for a null value, as in the original (which also reads `$ref` first).\n const ref = \"$ref\" in value && value.$ref ? value.$ref : undefined;\n const flags = propertyAccessFlags(value, request.context);\n return { ref, flags, hasDefault: \"default\" in value && value.default !== undefined };\n}\n\nfunction isOptionalProperty(\n key: string,\n facts: PropertyFacts,\n schema: SchemaObject,\n request: SchemaRequest,\n): boolean {\n const { options } = request.context;\n const path = request.location.path;\n const isDefaultRequired =\n facts.hasDefault &&\n options.defaultNonNullable &&\n !INPUT_PATH_PARTS.some((part) => path?.includes(part));\n const isRequired =\n schema.required?.includes(key) ||\n (schema.required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\nfunction isExcluded(value: Schema, facts: PropertyFacts, request: SchemaRequest): boolean {\n if (!request.context.options.excludeDeprecated) {\n return false;\n }\n const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;\n return Boolean((resolved as SchemaObject | undefined)?.deprecated);\n}\n\n/** A type, and whether a callback forced the property optional (null: no override). */\ninterface CustomResult {\n readonly type: IrType;\n readonly isOptional: true | null;\n}\n\nfunction propertyType(\n key: string,\n value: Schema,\n facts: PropertyFacts,\n request: SchemaRequest,\n): CustomResult {\n const path = appendPointer(request.location.path, [key]);\n const type = facts.ref\n ? schemaRefType(facts.ref, request)\n : request.transformNested(value, { ...request.location, path });\n const custom = request.context.callbacks.transform(value, request.location);\n return custom === null\n ? { type, isOptional: null }\n : { type: custom.type, isOptional: custom.isOptional || null };\n}\n\nfunction propertyMember(\n key: string,\n value: Schema,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrMember | null {\n if ((typeof value !== \"object\" && typeof value !== \"boolean\") || Array.isArray(value)) {\n throw new InvalidPropertyError(request.location.path, key, value);\n }\n const facts = propertyFacts(value, request);\n if (isExcluded(value, facts, request)) {\n return null;\n }\n const { options } = request.context;\n const isOptional = isOptionalProperty(key, facts, schema, request);\n const result = propertyType(key, value, facts, request);\n const property = irProperty(\n toPropertyName(key),\n withReadWriteMarker(result.type, facts.flags, options),\n {\n isOptional: result.isOptional ?? isOptional,\n isReadonly: options.immutable || (!options.readWriteMarkers && facts.flags.isReadOnly),\n },\n );\n return finishProperty(property, value, appendPointer(request.location.path, [key]), request);\n}\n\nfunction propertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const members: IrMember[] = [];\n for (const [key, value] of documentEntries(schema.properties ?? {}, request.context.options)) {\n const member = propertyMember(key, value, schema, request);\n if (member !== null) {\n members.push(member);\n }\n }\n return members;\n}\n\n/**\n * `$defs` as a nested `$defs?: { … }` member, in document order (never alphabetized). It is\n * optional because `$defs` is a schema keyword, not data: the original made it required, so a\n * value of the type needed a `$defs` key (research/legacy-bugs.md, item 17, upstream #2664).\n */\nfunction defsMember(\n defs: Readonly<Record<string, SchemaObject>>,\n request: SchemaRequest,\n): IrMember {\n const { options } = request.context;\n const members = Object.entries(defs).map(([key, value]) => {\n const path = appendPointer(request.location.path, [\"$defs\", key]);\n const flags = propertyAccessFlags(value, request.context);\n const type = withReadWriteMarker(\n request.transformNested(value, { ...request.location, path }),\n flags,\n options,\n );\n const property = irProperty(toPropertyName(key), type, {\n isReadonly: options.immutable || (!options.readWriteMarkers && flags.isReadOnly),\n });\n return finishProperty(property, value, path, request);\n });\n return irProperty(toPropertyName(\"$defs\"), irObject(members), { isOptional: true });\n}\n\nfunction hasObjectKeywords(schema: SchemaObject): boolean {\n const hasProperties = Boolean(schema.properties && Object.keys(schema.properties).length);\n return (\n hasProperties ||\n Boolean(schema.additionalProperties || schema.patternProperties || schema.$defs)\n );\n}\n\n/** Value types of the `[key: string]` index signature, in the original order. */\nfunction indexValueTypes(schema: SchemaObject, request: SchemaRequest): IrType[] {\n const { additionalProperties } = schema;\n const isObject = typeof additionalProperties === \"object\";\n const hasExplicit = isObject && Object.keys(additionalProperties).length > 0;\n const hasImplicit =\n additionalProperties === true || (isObject && Object.keys(additionalProperties).length === 0);\n const types: IrType[] = [];\n if (hasExplicit) {\n types.push(request.transformNested(additionalProperties as Schema, request.location, true));\n }\n if (hasImplicit || (!additionalProperties && request.context.options.additionalProperties)) {\n types.push(UNKNOWN_TYPE);\n }\n const patterns = schema.patternProperties;\n if (typeof patterns === \"object\" && patterns !== null && Object.keys(patterns).length > 0) {\n for (const [, value] of documentEntries(patterns, request.context.options)) {\n types.push(request.transformNested(value, request.location));\n }\n }\n return types;\n}\n\n/**\n * Whether the schema declares property `key` and the type keeps it: `--exclude-deprecated` drops\n * a deprecated one.\n */\nexport function isKeptProperty(schema: SchemaObject, key: string, request: SchemaRequest): boolean {\n const properties = schema.properties ?? {};\n if (!Object.hasOwn(properties, key)) {\n return false;\n }\n const value = properties[key] as Schema;\n const isExcludable = request.context.options.excludeDeprecated && typeof value === \"object\";\n return !isExcludable || !isExcluded(value, propertyFacts(value, request), request);\n}\n\n/**\n * The members for the discriminator and `properties`. A schema that declares the discriminator\n * property itself keeps its own declaration, required as the discriminator needs: both in one\n * object type do not compile (TS2300, the Apple SiriKit Cloud Media API). A declaration that\n * `--exclude-deprecated` drops does not count, so the discriminator property stays.\n */\nfunction discriminatorAndPropertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const inherited = inheritedDiscriminator(schema, request);\n if (inherited === undefined) {\n return propertyMembers(schema, request);\n }\n const name = inherited.discriminator.propertyName;\n if (!isKeptProperty(schema, name, request)) {\n return [discriminatorMember(inherited, request), ...propertyMembers(schema, request)];\n }\n // Without `required`, `--properties-required-by-default` requires every property already; a\n // list of one would make the others optional.\n const isAllRequired =\n schema.required === undefined && request.context.options.propertiesRequiredByDefault;\n const required = isAllRequired ? undefined : [...(schema.required ?? []), name];\n return propertyMembers({ ...schema, required } as SchemaObject, request);\n}\n\n/**\n * Object keywords: discriminator, `properties`, `$defs`, and an index signature for\n * `additionalProperties` / `patternProperties` (or `--additional-properties`). Null when the schema\n * has none of them.\n */\nexport function objectType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (!hasObjectKeywords(schema)) {\n const inherited = inheritedDiscriminator(schema, request);\n return inherited ? irObject([discriminatorMember(inherited, request)]) : null;\n }\n const members = discriminatorAndPropertyMembers(schema, request);\n // As in the original, a null `$defs` throws here (Object.keys) instead of being skipped.\n if (\n \"$defs\" in schema &&\n typeof schema.$defs === \"object\" &&\n Object.keys(schema.$defs).length > 0\n ) {\n members.push(defsMember(schema.$defs, request));\n }\n const valueTypes = indexValueTypes(schema, request);\n if (valueTypes.length === 0) {\n return members.length > 0 ? irObject(members) : null;\n }\n const index = irObject([\n irStringIndexSignature(\"key\", unionOf(valueTypes), request.context.options.immutable),\n ]);\n return intersectionOf([...(members.length > 0 ? [irObject(members)] : []), index]);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAsBA,MAAM,gBAAA,GAAmB,CAAC,YAAA,EAAc,aAAA,EAAe,eAAe,CAAA;AAE/D,MAAM,6BAA6B,oBAAA,CAAqB;AAAA,EAC7D,WAAA,CAAY,IAAA,EAA0B,GAAA,EAAa,KAAA,EAAgB;AACjE,IAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,UAAU,OAAO,KAAA;AACzD,IAAA,KAAA,CAAM;AAAA,MACJ,MAAM,WAAA,CAAY,uBAAA;AAAA,MAClB,SACE,CAAA,EAAG,IAAI,CAAA,mBAAA,EAAsB,GAAG,4CAAiD,QAAQ,CAAA,CAAA;AAAA,MAC3F,OAAA,EAAS,EAAE,IAAA,EAAM,QAAA,EAAU,KAAK,QAAA;AAAS,KAC1C,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,sBAAA;AAAA,EACd;AACF;AAGA,SAAS,mBAAA,CAAoB,IAAA,EAAc,KAAA,EAAoB,OAAA,EAAgC;AAC7F,EAAA,IAAI,CAAC,OAAA,CAAQ,gBAAA,IAAoB,KAAA,CAAM,UAAA,K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O,OAAA,CAAQ,MAAA,GAAS,CAAA,GAAI,QAAA,CAAS,OAAO,CAAA,GAAI,IAAA;AAAA,EAClD;AACA,EAAA,MAAM,QAAQ,QAAA,CAAS;AAAA,IACrB,sBAAA,CAAuB,OAAO,OAAA,CAAQ,UAAU,GAAG,OAAA,CAAQ,OAAA,CAAQ,QAAQ,SAAS;AAAA,GACrF,CAAA;AACD,EAAA,OAAO,cAAA,CAAe,CAAC,GAAI,OAAA,CAAQ,SAAS,CAAA,GAAI,CAAC,QAAA,CAAS,OAAO,CAAC,CAAA,GAAI,EAAC,EAAI,KAAK,CAAC,CAAA;AACnF;;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const schemaDialect = require('../../../domain/openapi/schema-dialect.cjs');
|
|
4
|
+
const outputFixes = require('../../../domain/output-fixes.cjs');
|
|
5
|
+
|
|
6
|
+
const ANNOTATION_KEYWORDS = /* @__PURE__ */ new Set([
|
|
7
|
+
"$anchor",
|
|
8
|
+
"$comment",
|
|
9
|
+
"$defs",
|
|
10
|
+
"$dynamicAnchor",
|
|
11
|
+
"$id",
|
|
12
|
+
"$ref",
|
|
13
|
+
"$schema",
|
|
14
|
+
"contentEncoding",
|
|
15
|
+
"contentMediaType",
|
|
16
|
+
"default",
|
|
17
|
+
"deprecated",
|
|
18
|
+
"description",
|
|
19
|
+
"discriminator",
|
|
20
|
+
"example",
|
|
21
|
+
"examples",
|
|
22
|
+
"externalDocs",
|
|
23
|
+
"format",
|
|
24
|
+
"readOnly",
|
|
25
|
+
"title",
|
|
26
|
+
"writeOnly",
|
|
27
|
+
"xml"
|
|
28
|
+
]);
|
|
29
|
+
const EXTENSION_PREFIX = "x-";
|
|
30
|
+
function hasRef(schema) {
|
|
31
|
+
return typeof schema.$ref === "string";
|
|
32
|
+
}
|
|
33
|
+
function isTypeKeyword(keyword) {
|
|
34
|
+
return !ANNOTATION_KEYWORDS.has(keyword) && !keyword.startsWith(EXTENSION_PREFIX);
|
|
35
|
+
}
|
|
36
|
+
function refWithSiblingsAsAllOf(schema, options) {
|
|
37
|
+
const isApplied = options.fixes.has(outputFixes.FIX.REF_SIBLINGS) && options.schemaDialect === schemaDialect.SCHEMA_DIALECTS.JSON_SCHEMA_2020_12;
|
|
38
|
+
if (!isApplied || !hasRef(schema) || !Object.keys(schema).some(isTypeKeyword)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const { $ref, allOf = [], ...siblings } = schema;
|
|
42
|
+
const members = [{ $ref }, ...allOf];
|
|
43
|
+
return { ...siblings, allOf: members };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.refWithSiblingsAsAllOf = refWithSiblingsAsAllOf;
|
|
47
|
+
//# sourceMappingURL=ref-siblings.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref-siblings.cjs","sources":["../../../../src/application/transform/schema/ref-siblings.ts"],"sourcesContent":["import { SCHEMA_DIALECTS } from \"../../../domain/openapi/schema-dialect.js\";\nimport type {\n ReferenceSchema,\n Schema,\n SchemaObject,\n} from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\n\n/**\n * The `ref-siblings` fix (ADR-021 amendment 2, RC4 G16): in JSON Schema 2020-12 (OpenAPI 3.1 and\n * 3.2) the keywords next to a `$ref` apply too, so `{ $ref: Base, required: [extra], properties:\n * { extra } }` is a `Base` that also has a required `extra`. That is what `allOf: [{ $ref: Base }]`\n * next to the same keywords means, so the schema is typed as that `allOf`, with every rule the\n * generator has for `allOf` and its siblings (`WithRequired`, intersections).\n */\n\n/**\n * Keywords that only annotate (JSON Schema 2020-12 meta-data, format-annotation and content\n * vocabularies, OpenAPI fixed fields), or that change no type on their own (`discriminator`\n * without `oneOf`). Next to a `$ref` they stay where they were, so the output keeps the plain\n * reference with its comment. Extension keywords (`x-…`) count as annotations too.\n */\nconst ANNOTATION_KEYWORDS: ReadonlySet<string> = new Set([\n \"$anchor\",\n \"$comment\",\n \"$defs\",\n \"$dynamicAnchor\",\n \"$id\",\n \"$ref\",\n \"$schema\",\n \"contentEncoding\",\n \"contentMediaType\",\n \"default\",\n \"deprecated\",\n \"description\",\n \"discriminator\",\n \"example\",\n \"examples\",\n \"externalDocs\",\n \"format\",\n \"readOnly\",\n \"title\",\n \"writeOnly\",\n \"xml\",\n]);\n\nconst EXTENSION_PREFIX = \"x-\";\n\nfunction hasRef(schema: SchemaObject): schema is SchemaObject & ReferenceSchema {\n return typeof (schema as Partial<ReferenceSchema>).$ref === \"string\";\n}\n\nfunction isTypeKeyword(keyword: string): boolean {\n return !ANNOTATION_KEYWORDS.has(keyword) && !keyword.startsWith(EXTENSION_PREFIX);\n}\n\n/**\n * A `$ref` schema as the `allOf` it means, or null where nothing changes: a schema without `$ref`,\n * no fix, an OpenAPI 3.0 document, or no sibling that changes the type. The result has no\n * `$ref`, so the shape rules type it as `enum`, `const` or a composition.\n */\nexport function refWithSiblingsAsAllOf(\n schema: SchemaObject,\n options: SchemaOptions,\n): SchemaObject | null {\n const isApplied =\n options.fixes.has(FIX.REF_SIBLINGS) &&\n options.schemaDialect === SCHEMA_DIALECTS.JSON_SCHEMA_2020_12;\n if (!isApplied || !hasRef(schema) || !Object.keys(schema).some(isTypeKeyword)) {\n return null;\n }\n const { $ref, allOf = [], ...siblings } = schema;\n const members: readonly Schema[] = [{ $ref }, ...allOf];\n return { ...siblings, allOf: members };\n}\n"],"names":["FIX","SCHEMA_DIALECTS"],"mappings":";;;;;AAuBA,MAAM,mBAAA,uBAA+C,GAAA,CAAI;AAAA,EACvD,SAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,gBAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,iBAAA;AAAA,EACA,kBAAA;AAAA,EACA,SAAA;AAAA,EACA,YAAA;AAAA,EACA,aAAA;AAAA,EACA,eAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,MAAM,gBAAA,GAAmB,IAAA;AAEzB,SAAS,OAAO,MAAA,EAAgE;AAC9E,EAAA,OAAO,OAAQ,OAAoC,IAAA,KAAS,QAAA;AAC9D;AAEA,SAAS,cAAc,OAAA,EAA0B;AAC/C,EAAA,OAAO,CAAC,oBAAoB,GAAA,CAAI,OAAO,KAAK,CAAC,OAAA,CAAQ,WAAW,gBAAgB,CAAA;AAClF;AAOO,SAAS,sBAAA,CACd,QACA,OAAA,EACqB;AACrB,EAAA,MAAM,SAAA,GACJ,QAAQ,KAAA,CAAM,GAAA,CAAIA,gBAAI,YAAY,CAAA,IAClC,OAAA,CAAQ,aAAA,KAAkBC,6BAAA,CAAgB,mBAAA;AAC5C,EAAA,IAAI,CAAC,SAAA,IAAa,CAAC,MAAA,CAAO,MAAM,CAAA,IAAK,CAAC,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,CAAE,IAAA,CAAK,aAAa,CAAA,EAAG;AAC7E,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,EAAE,IAAA,EAAM,KAAA,GAAQ,EAAC,EAAG,GAAG,UAAS,GAAI,MAAA;AAC1C,EAAA,MAAM,UAA6B,CAAC,EAAE,IAAA,EAAK,EAAG,GAAG,KAAK,CAAA;AACtD,EAAA,OAAO,EAAE,GAAG,QAAA,EAAU,KAAA,EAAO,OAAA,EAAQ;AACvC;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SCHEMA_DIALECTS } from '../../../domain/openapi/schema-dialect.mjs';
|
|
2
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
3
|
+
|
|
4
|
+
const ANNOTATION_KEYWORDS = /* @__PURE__ */ new Set([
|
|
5
|
+
"$anchor",
|
|
6
|
+
"$comment",
|
|
7
|
+
"$defs",
|
|
8
|
+
"$dynamicAnchor",
|
|
9
|
+
"$id",
|
|
10
|
+
"$ref",
|
|
11
|
+
"$schema",
|
|
12
|
+
"contentEncoding",
|
|
13
|
+
"contentMediaType",
|
|
14
|
+
"default",
|
|
15
|
+
"deprecated",
|
|
16
|
+
"description",
|
|
17
|
+
"discriminator",
|
|
18
|
+
"example",
|
|
19
|
+
"examples",
|
|
20
|
+
"externalDocs",
|
|
21
|
+
"format",
|
|
22
|
+
"readOnly",
|
|
23
|
+
"title",
|
|
24
|
+
"writeOnly",
|
|
25
|
+
"xml"
|
|
26
|
+
]);
|
|
27
|
+
const EXTENSION_PREFIX = "x-";
|
|
28
|
+
function hasRef(schema) {
|
|
29
|
+
return typeof schema.$ref === "string";
|
|
30
|
+
}
|
|
31
|
+
function isTypeKeyword(keyword) {
|
|
32
|
+
return !ANNOTATION_KEYWORDS.has(keyword) && !keyword.startsWith(EXTENSION_PREFIX);
|
|
33
|
+
}
|
|
34
|
+
function refWithSiblingsAsAllOf(schema, options) {
|
|
35
|
+
const isApplied = options.fixes.has(FIX.REF_SIBLINGS) && options.schemaDialect === SCHEMA_DIALECTS.JSON_SCHEMA_2020_12;
|
|
36
|
+
if (!isApplied || !hasRef(schema) || !Object.keys(schema).some(isTypeKeyword)) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const { $ref, allOf = [], ...siblings } = schema;
|
|
40
|
+
const members = [{ $ref }, ...allOf];
|
|
41
|
+
return { ...siblings, allOf: members };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { refWithSiblingsAsAllOf };
|
|
45
|
+
//# sourceMappingURL=ref-siblings.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref-siblings.mjs","sources":["../../../../src/application/transform/schema/ref-siblings.ts"],"sourcesContent":["import { SCHEMA_DIALECTS } from \"../../../domain/openapi/schema-dialect.js\";\nimport type {\n ReferenceSchema,\n Schema,\n SchemaObject,\n} from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\n\n/**\n * The `ref-siblings` fix (ADR-021 amendment 2, RC4 G16): in JSON Schema 2020-12 (OpenAPI 3.1 and\n * 3.2) the keywords next to a `$ref` apply too, so `{ $ref: Base, required: [extra], properties:\n * { extra } }` is a `Base` that also has a required `extra`. That is what `allOf: [{ $ref: Base }]`\n * next to the same keywords means, so the schema is typed as that `allOf`, with every rule the\n * generator has for `allOf` and its siblings (`WithRequired`, intersections).\n */\n\n/**\n * Keywords that only annotate (JSON Schema 2020-12 meta-data, format-annotation and content\n * vocabularies, OpenAPI fixed fields), or that change no type on their own (`discriminator`\n * without `oneOf`). Next to a `$ref` they stay where they were, so the output keeps the plain\n * reference with its comment. Extension keywords (`x-…`) count as annotations too.\n */\nconst ANNOTATION_KEYWORDS: ReadonlySet<string> = new Set([\n \"$anchor\",\n \"$comment\",\n \"$defs\",\n \"$dynamicAnchor\",\n \"$id\",\n \"$ref\",\n \"$schema\",\n \"contentEncoding\",\n \"contentMediaType\",\n \"default\",\n \"deprecated\",\n \"description\",\n \"discriminator\",\n \"example\",\n \"examples\",\n \"externalDocs\",\n \"format\",\n \"readOnly\",\n \"title\",\n \"writeOnly\",\n \"xml\",\n]);\n\nconst EXTENSION_PREFIX = \"x-\";\n\nfunction hasRef(schema: SchemaObject): schema is SchemaObject & ReferenceSchema {\n return typeof (schema as Partial<ReferenceSchema>).$ref === \"string\";\n}\n\nfunction isTypeKeyword(keyword: string): boolean {\n return !ANNOTATION_KEYWORDS.has(keyword) && !keyword.startsWith(EXTENSION_PREFIX);\n}\n\n/**\n * A `$ref` schema as the `allOf` it means, or null where nothing changes: a schema without `$ref`,\n * no fix, an OpenAPI 3.0 document, or no sibling that changes the type. The result has no\n * `$ref`, so the shape rules type it as `enum`, `const` or a composition.\n */\nexport function refWithSiblingsAsAllOf(\n schema: SchemaObject,\n options: SchemaOptions,\n): SchemaObject | null {\n const isApplied =\n options.fixes.has(FIX.REF_SIBLINGS) &&\n options.schemaDialect === SCHEMA_DIALECTS.JSON_SCHEMA_2020_12;\n if (!isApplied || !hasRef(schema) || !Object.keys(schema).some(isTypeKeyword)) {\n return null;\n }\n const { $ref, allOf = [], ...siblings } = schema;\n const members: readonly Schema[] = [{ $ref }, ...allOf];\n return { ...siblings, allOf: members };\n}\n"],"names":[],"mappings":";;;AAuBA,MAAM,mBAAA,uBAA+C,GAAA,CAAI;AAAA,EACvD,SAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,gBAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,iBAAA;AAAA,EACA,kBAAA;AAAA,EACA,SAAA;AAAA,EACA,YAAA;AAAA,EACA,aAAA;AAAA,EACA,eAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,MAAM,gBAAA,GAAmB,IAAA;AAEzB,SAAS,OAAO,MAAA,EAAgE;AAC9E,EAAA,OAAO,OAAQ,OAAoC,IAAA,KAAS,QAAA;AAC9D;AAEA,SAAS,cAAc,OAAA,EAA0B;AAC/C,EAAA,OAAO,CAAC,oBAAoB,GAAA,CAAI,OAAO,KAAK,CAAC,OAAA,CAAQ,WAAW,gBAAgB,CAAA;AAClF;AAOO,SAAS,sBAAA,CACd,QACA,OAAA,EACqB;AACrB,EAAA,MAAM,SAAA,GACJ,QAAQ,KAAA,CAAM,GAAA,CAAI,IAAI,YAAY,CAAA,IAClC,OAAA,CAAQ,aAAA,KAAkB,eAAA,CAAgB,mBAAA;AAC5C,EAAA,IAAI,CAAC,SAAA,IAAa,CAAC,MAAA,CAAO,MAAM,CAAA,IAAK,CAAC,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,CAAE,IAAA,CAAK,aAAa,CAAA,EAAG;AAC7E,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,EAAE,IAAA,EAAM,KAAA,GAAQ,EAAC,EAAG,GAAG,UAAS,GAAI,MAAA;AAC1C,EAAA,MAAM,UAA6B,CAAC,EAAE,IAAA,EAAK,EAAG,GAAG,KAAK,CAAA;AACtD,EAAA,OAAO,EAAE,GAAG,QAAA,EAAU,KAAA,EAAO,OAAA,EAAQ;AACvC;;"}
|
|
@@ -7,6 +7,7 @@ const pointerType = require('../ref-pointer/pointer-type.cjs');
|
|
|
7
7
|
const sharedTypes = require('../shared-types.cjs');
|
|
8
8
|
const compositionType = require('./composition-type.cjs');
|
|
9
9
|
const enumRule = require('./enum-rule.cjs');
|
|
10
|
+
const refSiblings = require('./ref-siblings.cjs');
|
|
10
11
|
|
|
11
12
|
class InvalidSchemaError extends errors.OpenAPITypesafeError {
|
|
12
13
|
constructor(schema, path) {
|
|
@@ -58,8 +59,9 @@ function transformSchemaShape(schema, location, context, isFromAdditionalPropert
|
|
|
58
59
|
return checked.type;
|
|
59
60
|
}
|
|
60
61
|
const current = request(location, context, isFromAdditionalProperties);
|
|
61
|
-
const
|
|
62
|
-
|
|
62
|
+
const shaped = refSiblings.refWithSiblingsAsAllOf(checked.schema, context.options) ?? checked.schema;
|
|
63
|
+
const rule = SHAPE_RULES.find((candidate) => candidate.matches(shaped));
|
|
64
|
+
return rule ? rule.transform(shaped, current) : compositionType.compositionType(shaped, current);
|
|
63
65
|
}
|
|
64
66
|
function transformSchema(schema, location, context, isFromAdditionalProperties = false) {
|
|
65
67
|
const type = transformSchemaShape(schema, location, context, isFromAdditionalProperties);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-transform.cjs","sources":["../../../../src/application/transform/schema/schema-transform.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { compositionType } from \"./composition-type.js\";\nimport { enumRule } from \"./enum-rule.js\";\nimport type { SchemaContext, SchemaLocation } from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nexport class InvalidSchemaError extends OpenAPITypesafeError {\n constructor(schema: unknown, path: string | undefined) {\n const received = Array.isArray(schema) ? \"Array\" : typeof schema;\n super({\n code: ERROR_CODES.SCHEMA_OBJECT_INVALID,\n message: `Expected SchemaObject, received ${received} at ${path}`,\n details: { path, received },\n });\n this.name = \"InvalidSchemaError\";\n }\n}\n\n/** Shape rules in the original precedence; composition handles everything they do not match. */\nconst SHAPE_RULES: readonly SchemaRule[] = [\n {\n name: \"$ref\",\n matches: (schema) => \"$ref\" in schema,\n transform: (schema, request) => schemaRefType((schema as { $ref: string }).$ref, request),\n },\n {\n name: \"const\",\n matches: (schema) => schema.const !== null && schema.const !== undefined,\n transform: (schema) => literalType(schema.const),\n },\n enumRule,\n];\n\n/** A schema checked for its input shape, or the type of a non-object schema. */\ntype CheckedSchema = { readonly type: IrType } | { readonly schema: SchemaObject };\n\n/** A missing schema is `never`; `true` allows anything; other non-objects are invalid. */\nfunction checkSchema(schema: unknown, path: string | undefined): CheckedSchema {\n if (!schema) {\n return { type: irKeyword(\"never\") };\n }\n if (schema === true) {\n return { type: UNKNOWN_TYPE };\n }\n if (Array.isArray(schema) || typeof schema !== \"object\") {\n throw new InvalidSchemaError(schema, path);\n }\n return { schema: schema as SchemaObject };\n}\n\nfunction request(\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties: boolean,\n): SchemaRequest {\n return {\n location,\n context,\n isFromAdditionalProperties,\n transformNested: (schema, nestedLocation, isNestedFromAdditionalProperties = false) =>\n transformSchema(schema, nestedLocation, context, isNestedFromAdditionalProperties),\n };\n}\n\n/**\n * Transform a schema without the `postTransform` callback (the original\n * `transformSchemaObjectWithComposition`). Nested schemas still get `postTransform`.\n */\nexport function transformSchemaShape(\n schema: Schema | null | undefined,\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties = false,\n): IrType {\n const checked = checkSchema(schema, location.path);\n if (\"type\" in checked) {\n return checked.type;\n }\n const current = request(location, context, isFromAdditionalProperties);\n const rule = SHAPE_RULES.find((candidate) => candidate.matches(
|
|
1
|
+
{"version":3,"file":"schema-transform.cjs","sources":["../../../../src/application/transform/schema/schema-transform.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { compositionType } from \"./composition-type.js\";\nimport { enumRule } from \"./enum-rule.js\";\nimport { refWithSiblingsAsAllOf } from \"./ref-siblings.js\";\nimport type { SchemaContext, SchemaLocation } from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nexport class InvalidSchemaError extends OpenAPITypesafeError {\n constructor(schema: unknown, path: string | undefined) {\n const received = Array.isArray(schema) ? \"Array\" : typeof schema;\n super({\n code: ERROR_CODES.SCHEMA_OBJECT_INVALID,\n message: `Expected SchemaObject, received ${received} at ${path}`,\n details: { path, received },\n });\n this.name = \"InvalidSchemaError\";\n }\n}\n\n/** Shape rules in the original precedence; composition handles everything they do not match. */\nconst SHAPE_RULES: readonly SchemaRule[] = [\n {\n name: \"$ref\",\n matches: (schema) => \"$ref\" in schema,\n transform: (schema, request) => schemaRefType((schema as { $ref: string }).$ref, request),\n },\n {\n name: \"const\",\n matches: (schema) => schema.const !== null && schema.const !== undefined,\n transform: (schema) => literalType(schema.const),\n },\n enumRule,\n];\n\n/** A schema checked for its input shape, or the type of a non-object schema. */\ntype CheckedSchema = { readonly type: IrType } | { readonly schema: SchemaObject };\n\n/** A missing schema is `never`; `true` allows anything; other non-objects are invalid. */\nfunction checkSchema(schema: unknown, path: string | undefined): CheckedSchema {\n if (!schema) {\n return { type: irKeyword(\"never\") };\n }\n if (schema === true) {\n return { type: UNKNOWN_TYPE };\n }\n if (Array.isArray(schema) || typeof schema !== \"object\") {\n throw new InvalidSchemaError(schema, path);\n }\n return { schema: schema as SchemaObject };\n}\n\nfunction request(\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties: boolean,\n): SchemaRequest {\n return {\n location,\n context,\n isFromAdditionalProperties,\n transformNested: (schema, nestedLocation, isNestedFromAdditionalProperties = false) =>\n transformSchema(schema, nestedLocation, context, isNestedFromAdditionalProperties),\n };\n}\n\n/**\n * Transform a schema without the `postTransform` callback (the original\n * `transformSchemaObjectWithComposition`). Nested schemas still get `postTransform`.\n */\nexport function transformSchemaShape(\n schema: Schema | null | undefined,\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties = false,\n): IrType {\n const checked = checkSchema(schema, location.path);\n if (\"type\" in checked) {\n return checked.type;\n }\n const current = request(location, context, isFromAdditionalProperties);\n const shaped = refWithSiblingsAsAllOf(checked.schema, context.options) ?? checked.schema;\n const rule = SHAPE_RULES.find((candidate) => candidate.matches(shaped));\n return rule ? rule.transform(shaped, current) : compositionType(shaped, current);\n}\n\n/** Transform a schema to IR, then apply `postTransform` (the original `transformSchemaObject`). */\nexport function transformSchema(\n schema: Schema | null | undefined,\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties = false,\n): IrType {\n const type = transformSchemaShape(schema, location, context, isFromAdditionalProperties);\n return context.callbacks.postTransform(type, location) ?? type;\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","request","schemaRefType","literalType","enumRule","irKeyword","UNKNOWN_TYPE","refWithSiblingsAsAllOf","compositionType"],"mappings":";;;;;;;;;;;AAaO,MAAM,2BAA2BA,2BAAA,CAAqB;AAAA,EAC3D,WAAA,CAAY,QAAiB,IAAA,EAA0B;AACrD,IAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAI,UAAU,OAAO,MAAA;AAC1D,IAAA,KAAA,CAAM;AAAA,MACJ,MAAMC,kBAAA,CAAY,qBAAA;AAAA,MAClB,OAAA,EAAS,CAAA,gCAAA,EAAmC,QAAQ,CAAA,IAAA,EAAO,IAAI,CAAA,CAAA;AAAA,MAC/D,OAAA,EAAS,EAAE,IAAA,EAAM,QAAA;AAAS,KAC3B,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AAAA,EACd;AACF;AAGA,MAAM,WAAA,GAAqC;AAAA,EACzC;AAAA,IACE,IAAA,EAAM,MAAA;AAAA,IACN,OAAA,EAAS,CAAC,MAAA,KAAW,MAAA,IAAU,MAAA;AAAA,IAC/B,WAAW,CAAC,MAAA,EAAQC,aAAYC,yBAAA,CAAe,MAAA,CAA4B,MAAMD,QAAO;AAAA,GAC1F;AAAA,EACA;AAAA,IACE,IAAA,EAAM,OAAA;AAAA,IACN,SAAS,CAAC,MAAA,KAAW,OAAO,KAAA,KAAU,IAAA,IAAQ,OAAO,KAAA,KAAU,MAAA;AAAA,IAC/D,SAAA,EAAW,CAAC,MAAA,KAAWE,uBAAA,CAAY,OAAO,KAAK;AAAA,GACjD;AAAA,EACAC;AACF,CAAA;AAMA,SAAS,WAAA,CAAY,QAAiB,IAAA,EAAyC;AAC7E,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,EAAE,IAAA,EAAMC,sBAAA,CAAU,OAAO,CAAA,EAAE;AAAA,EACpC;AACA,EAAA,IAAI,WAAW,IAAA,EAAM;AACnB,IA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6BAA6B,KAAA,EACrB;AACR,EAAA,MAAM,IAAA,GAAO,oBAAA,CAAqB,MAAA,EAAQ,QAAA,EAAU,SAAS,0BAA0B,CAAA;AACvF,EAAA,OAAO,OAAA,CAAQ,SAAA,CAAU,aAAA,CAAc,IAAA,EAAM,QAAQ,CAAA,IAAK,IAAA;AAC5D;;;;"}
|
|
@@ -5,6 +5,7 @@ import { schemaRefType } from '../ref-pointer/pointer-type.mjs';
|
|
|
5
5
|
import { UNKNOWN_TYPE } from '../shared-types.mjs';
|
|
6
6
|
import { compositionType } from './composition-type.mjs';
|
|
7
7
|
import { enumRule } from './enum-rule.mjs';
|
|
8
|
+
import { refWithSiblingsAsAllOf } from './ref-siblings.mjs';
|
|
8
9
|
|
|
9
10
|
class InvalidSchemaError extends OpenAPITypesafeError {
|
|
10
11
|
constructor(schema, path) {
|
|
@@ -56,8 +57,9 @@ function transformSchemaShape(schema, location, context, isFromAdditionalPropert
|
|
|
56
57
|
return checked.type;
|
|
57
58
|
}
|
|
58
59
|
const current = request(location, context, isFromAdditionalProperties);
|
|
59
|
-
const
|
|
60
|
-
|
|
60
|
+
const shaped = refWithSiblingsAsAllOf(checked.schema, context.options) ?? checked.schema;
|
|
61
|
+
const rule = SHAPE_RULES.find((candidate) => candidate.matches(shaped));
|
|
62
|
+
return rule ? rule.transform(shaped, current) : compositionType(shaped, current);
|
|
61
63
|
}
|
|
62
64
|
function transformSchema(schema, location, context, isFromAdditionalProperties = false) {
|
|
63
65
|
const type = transformSchemaShape(schema, location, context, isFromAdditionalProperties);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-transform.mjs","sources":["../../../../src/application/transform/schema/schema-transform.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { compositionType } from \"./composition-type.js\";\nimport { enumRule } from \"./enum-rule.js\";\nimport type { SchemaContext, SchemaLocation } from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nexport class InvalidSchemaError extends OpenAPITypesafeError {\n constructor(schema: unknown, path: string | undefined) {\n const received = Array.isArray(schema) ? \"Array\" : typeof schema;\n super({\n code: ERROR_CODES.SCHEMA_OBJECT_INVALID,\n message: `Expected SchemaObject, received ${received} at ${path}`,\n details: { path, received },\n });\n this.name = \"InvalidSchemaError\";\n }\n}\n\n/** Shape rules in the original precedence; composition handles everything they do not match. */\nconst SHAPE_RULES: readonly SchemaRule[] = [\n {\n name: \"$ref\",\n matches: (schema) => \"$ref\" in schema,\n transform: (schema, request) => schemaRefType((schema as { $ref: string }).$ref, request),\n },\n {\n name: \"const\",\n matches: (schema) => schema.const !== null && schema.const !== undefined,\n transform: (schema) => literalType(schema.const),\n },\n enumRule,\n];\n\n/** A schema checked for its input shape, or the type of a non-object schema. */\ntype CheckedSchema = { readonly type: IrType } | { readonly schema: SchemaObject };\n\n/** A missing schema is `never`; `true` allows anything; other non-objects are invalid. */\nfunction checkSchema(schema: unknown, path: string | undefined): CheckedSchema {\n if (!schema) {\n return { type: irKeyword(\"never\") };\n }\n if (schema === true) {\n return { type: UNKNOWN_TYPE };\n }\n if (Array.isArray(schema) || typeof schema !== \"object\") {\n throw new InvalidSchemaError(schema, path);\n }\n return { schema: schema as SchemaObject };\n}\n\nfunction request(\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties: boolean,\n): SchemaRequest {\n return {\n location,\n context,\n isFromAdditionalProperties,\n transformNested: (schema, nestedLocation, isNestedFromAdditionalProperties = false) =>\n transformSchema(schema, nestedLocation, context, isNestedFromAdditionalProperties),\n };\n}\n\n/**\n * Transform a schema without the `postTransform` callback (the original\n * `transformSchemaObjectWithComposition`). Nested schemas still get `postTransform`.\n */\nexport function transformSchemaShape(\n schema: Schema | null | undefined,\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties = false,\n): IrType {\n const checked = checkSchema(schema, location.path);\n if (\"type\" in checked) {\n return checked.type;\n }\n const current = request(location, context, isFromAdditionalProperties);\n const rule = SHAPE_RULES.find((candidate) => candidate.matches(
|
|
1
|
+
{"version":3,"file":"schema-transform.mjs","sources":["../../../../src/application/transform/schema/schema-transform.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { compositionType } from \"./composition-type.js\";\nimport { enumRule } from \"./enum-rule.js\";\nimport { refWithSiblingsAsAllOf } from \"./ref-siblings.js\";\nimport type { SchemaContext, SchemaLocation } from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\nexport class InvalidSchemaError extends OpenAPITypesafeError {\n constructor(schema: unknown, path: string | undefined) {\n const received = Array.isArray(schema) ? \"Array\" : typeof schema;\n super({\n code: ERROR_CODES.SCHEMA_OBJECT_INVALID,\n message: `Expected SchemaObject, received ${received} at ${path}`,\n details: { path, received },\n });\n this.name = \"InvalidSchemaError\";\n }\n}\n\n/** Shape rules in the original precedence; composition handles everything they do not match. */\nconst SHAPE_RULES: readonly SchemaRule[] = [\n {\n name: \"$ref\",\n matches: (schema) => \"$ref\" in schema,\n transform: (schema, request) => schemaRefType((schema as { $ref: string }).$ref, request),\n },\n {\n name: \"const\",\n matches: (schema) => schema.const !== null && schema.const !== undefined,\n transform: (schema) => literalType(schema.const),\n },\n enumRule,\n];\n\n/** A schema checked for its input shape, or the type of a non-object schema. */\ntype CheckedSchema = { readonly type: IrType } | { readonly schema: SchemaObject };\n\n/** A missing schema is `never`; `true` allows anything; other non-objects are invalid. */\nfunction checkSchema(schema: unknown, path: string | undefined): CheckedSchema {\n if (!schema) {\n return { type: irKeyword(\"never\") };\n }\n if (schema === true) {\n return { type: UNKNOWN_TYPE };\n }\n if (Array.isArray(schema) || typeof schema !== \"object\") {\n throw new InvalidSchemaError(schema, path);\n }\n return { schema: schema as SchemaObject };\n}\n\nfunction request(\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties: boolean,\n): SchemaRequest {\n return {\n location,\n context,\n isFromAdditionalProperties,\n transformNested: (schema, nestedLocation, isNestedFromAdditionalProperties = false) =>\n transformSchema(schema, nestedLocation, context, isNestedFromAdditionalProperties),\n };\n}\n\n/**\n * Transform a schema without the `postTransform` callback (the original\n * `transformSchemaObjectWithComposition`). Nested schemas still get `postTransform`.\n */\nexport function transformSchemaShape(\n schema: Schema | null | undefined,\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties = false,\n): IrType {\n const checked = checkSchema(schema, location.path);\n if (\"type\" in checked) {\n return checked.type;\n }\n const current = request(location, context, isFromAdditionalProperties);\n const shaped = refWithSiblingsAsAllOf(checked.schema, context.options) ?? checked.schema;\n const rule = SHAPE_RULES.find((candidate) => candidate.matches(shaped));\n return rule ? rule.transform(shaped, current) : compositionType(shaped, current);\n}\n\n/** Transform a schema to IR, then apply `postTransform` (the original `transformSchemaObject`). */\nexport function transformSchema(\n schema: Schema | null | undefined,\n location: SchemaLocation,\n context: SchemaContext,\n isFromAdditionalProperties = false,\n): IrType {\n const type = transformSchemaShape(schema, location, context, isFromAdditionalProperties);\n return context.callbacks.postTransform(type, location) ?? type;\n}\n"],"names":["request"],"mappings":";;;;;;;;;AAaO,MAAM,2BAA2B,oBAAA,CAAqB;AAAA,EAC3D,WAAA,CAAY,QAAiB,IAAA,EAA0B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