openapi-typesafe 1.0.0-rc.2 → 1.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1831 -0
- package/dist/adapters/node-deprecations/node-deprecations.cjs +14 -0
- package/dist/adapters/node-deprecations/node-deprecations.cjs.map +1 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs +12 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.cjs +105 -0
- package/dist/adapters/node-file-system/file-claims.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-claims.mjs +95 -0
- package/dist/adapters/node-file-system/file-claims.mjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.cjs +82 -0
- package/dist/adapters/node-file-system/file-identity.cjs.map +1 -0
- package/dist/adapters/node-file-system/file-identity.mjs +74 -0
- package/dist/adapters/node-file-system/file-identity.mjs.map +1 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +90 -14
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +90 -14
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +75 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +72 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs +2 -2
- package/dist/adapters/redocly-loader/bundled-ref-repair.mjs.map +1 -1
- package/dist/adapters/redocly-loader/loaded-documents.cjs +28 -0
- package/dist/adapters/redocly-loader/loaded-documents.cjs.map +1 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs +21 -0
- package/dist/adapters/redocly-loader/loaded-documents.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +14 -15
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +12 -13
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +31 -3
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.cjs +2 -2
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.mjs +3 -3
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-body-limit.cjs +50 -0
- package/dist/adapters/redocly-loader/remote-body-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs +48 -0
- package/dist/adapters/redocly-loader/remote-body-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +35 -6
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +47 -0
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +44 -0
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -0
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +32 -8
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +32 -9
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +11 -7
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +12 -8
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +3 -5
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/default-ports.cjs +19 -2
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +19 -3
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.mjs +2 -2
- package/dist/api/discriminator-conflict-warnings.mjs.map +1 -1
- package/dist/api/discriminator-enum-parent.cjs +2 -2
- package/dist/api/discriminator-enum-parent.cjs.map +1 -1
- package/dist/api/discriminator-enum-parent.mjs +3 -3
- package/dist/api/discriminator-enum-parent.mjs.map +1 -1
- package/dist/api/discriminator-other-owners.cjs +5 -3
- package/dist/api/discriminator-other-owners.cjs.map +1 -1
- package/dist/api/discriminator-other-owners.mjs +5 -3
- package/dist/api/discriminator-other-owners.mjs.map +1 -1
- package/dist/api/discriminator-patch.cjs +8 -4
- package/dist/api/discriminator-patch.cjs.map +1 -1
- package/dist/api/discriminator-patch.mjs +9 -5
- package/dist/api/discriminator-patch.mjs.map +1 -1
- package/dist/api/discriminator-scan.cjs +17 -10
- package/dist/api/discriminator-scan.cjs.map +1 -1
- package/dist/api/discriminator-scan.mjs +18 -11
- package/dist/api/discriminator-scan.mjs.map +1 -1
- package/dist/api/document-run.cjs +4 -3
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +4 -3
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-callback-warning.cjs +7 -4
- package/dist/api/legacy-callback-warning.cjs.map +1 -1
- package/dist/api/legacy-callback-warning.mjs +8 -5
- package/dist/api/legacy-callback-warning.mjs.map +1 -1
- package/dist/api/legacy-utils.cjs.map +1 -1
- package/dist/api/legacy-utils.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +9 -5
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +10 -7
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/schema-callbacks.cjs +36 -12
- package/dist/api/schema-callbacks.cjs.map +1 -1
- package/dist/api/schema-callbacks.mjs +36 -12
- package/dist/api/schema-callbacks.mjs.map +1 -1
- package/dist/api/string-to-ast.cjs +7 -9
- package/dist/api/string-to-ast.cjs.map +1 -1
- package/dist/api/string-to-ast.mjs +8 -9
- package/dist/api/string-to-ast.mjs.map +1 -1
- package/dist/api/transform-context.cjs +7 -3
- package/dist/api/transform-context.cjs.map +1 -1
- package/dist/api/transform-context.mjs +7 -3
- package/dist/api/transform-context.mjs.map +1 -1
- package/dist/api/transform-schema.cjs +42 -12
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +44 -14
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/print/text-writer.cjs +10 -3
- package/dist/application/print/text-writer.cjs.map +1 -1
- package/dist/application/print/text-writer.mjs +10 -3
- package/dist/application/print/text-writer.mjs.map +1 -1
- package/dist/application/stack-overflow.cjs +2 -1
- package/dist/application/stack-overflow.cjs.map +1 -1
- package/dist/application/stack-overflow.mjs +2 -1
- package/dist/application/stack-overflow.mjs.map +1 -1
- package/dist/application/transform/document/components.cjs +2 -2
- package/dist/application/transform/document/components.cjs.map +1 -1
- package/dist/application/transform/document/components.mjs +4 -4
- package/dist/application/transform/document/components.mjs.map +1 -1
- package/dist/application/transform/document/declared-type-names.cjs +23 -0
- package/dist/application/transform/document/declared-type-names.cjs.map +1 -0
- package/dist/application/transform/document/declared-type-names.mjs +20 -0
- package/dist/application/transform/document/declared-type-names.mjs.map +1 -0
- package/dist/application/transform/document/defs-root.cjs +1 -1
- package/dist/application/transform/document/defs-root.cjs.map +1 -1
- package/dist/application/transform/document/defs-root.mjs +2 -2
- package/dist/application/transform/document/defs-root.mjs.map +1 -1
- package/dist/application/transform/document/document.cjs +4 -1
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +3 -2
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/enum-names-given-back.cjs +62 -0
- package/dist/application/transform/document/enum-names-given-back.cjs.map +1 -0
- package/dist/application/transform/document/enum-names-given-back.mjs +58 -0
- package/dist/application/transform/document/enum-names-given-back.mjs.map +1 -0
- package/dist/application/transform/document/global-type-references.cjs +1 -0
- package/dist/application/transform/document/global-type-references.cjs.map +1 -1
- package/dist/application/transform/document/global-type-references.mjs +1 -1
- package/dist/application/transform/document/global-type-references.mjs.map +1 -1
- package/dist/application/transform/document/media-type.cjs +2 -2
- package/dist/application/transform/document/media-type.cjs.map +1 -1
- package/dist/application/transform/document/media-type.mjs +3 -3
- package/dist/application/transform/document/media-type.mjs.map +1 -1
- package/dist/application/transform/document/operation-keys-written.cjs +26 -0
- package/dist/application/transform/document/operation-keys-written.cjs.map +1 -0
- package/dist/application/transform/document/operation-keys-written.mjs +24 -0
- package/dist/application/transform/document/operation-keys-written.mjs.map +1 -0
- package/dist/application/transform/document/operation.cjs +1 -1
- package/dist/application/transform/document/operation.cjs.map +1 -1
- package/dist/application/transform/document/operation.mjs +2 -2
- package/dist/application/transform/document/operation.mjs.map +1 -1
- package/dist/application/transform/document/parameter-entries.cjs +34 -0
- package/dist/application/transform/document/parameter-entries.cjs.map +1 -0
- package/dist/application/transform/document/parameter-entries.mjs +30 -0
- package/dist/application/transform/document/parameter-entries.mjs.map +1 -0
- package/dist/application/transform/document/parameter.cjs +12 -4
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +13 -5
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +7 -30
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +8 -31
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +11 -14
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +12 -16
- package/dist/application/transform/document/path-item.mjs.map +1 -1
- package/dist/application/transform/document/paths-enum.cjs +1 -0
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +1 -1
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +6 -2
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +8 -4
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/referenced-parameter.cjs +80 -0
- package/dist/application/transform/document/referenced-parameter.cjs.map +1 -0
- package/dist/application/transform/document/referenced-parameter.mjs +78 -0
- package/dist/application/transform/document/referenced-parameter.mjs.map +1 -0
- package/dist/application/transform/document/request-body.cjs +1 -1
- package/dist/application/transform/document/request-body.cjs.map +1 -1
- package/dist/application/transform/document/request-body.mjs +2 -2
- package/dist/application/transform/document/request-body.mjs.map +1 -1
- package/dist/application/transform/document/response.cjs +2 -2
- package/dist/application/transform/document/response.cjs.map +1 -1
- package/dist/application/transform/document/response.mjs +3 -3
- package/dist/application/transform/document/response.mjs.map +1 -1
- package/dist/application/transform/document/responses.cjs +1 -1
- package/dist/application/transform/document/responses.cjs.map +1 -1
- package/dist/application/transform/document/responses.mjs +2 -2
- package/dist/application/transform/document/responses.mjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.cjs +8 -23
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.mjs +8 -24
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
- package/dist/application/transform/document/type-resolution.cjs +3 -1
- package/dist/application/transform/document/type-resolution.cjs.map +1 -1
- package/dist/application/transform/document/type-resolution.mjs +3 -1
- package/dist/application/transform/document/type-resolution.mjs.map +1 -1
- package/dist/application/transform/document/webhooks.cjs +1 -1
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +2 -2
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +10 -2
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +10 -2
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/footer/enum-name-claims.cjs +48 -0
- package/dist/application/transform/footer/enum-name-claims.cjs.map +1 -0
- package/dist/application/transform/footer/enum-name-claims.mjs +46 -0
- package/dist/application/transform/footer/enum-name-claims.mjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.cjs +23 -0
- package/dist/application/transform/footer/operation-keys.cjs.map +1 -0
- package/dist/application/transform/footer/operation-keys.mjs +21 -0
- package/dist/application/transform/footer/operation-keys.mjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.cjs +4 -4
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
- package/dist/application/transform/footer/type-evaluation.mjs +4 -4
- package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
- package/dist/application/transform/helper-types.cjs +1 -1
- package/dist/application/transform/helper-types.cjs.map +1 -1
- package/dist/application/transform/helper-types.mjs +1 -1
- package/dist/application/transform/helper-types.mjs.map +1 -1
- package/dist/application/transform/numbered-names.cjs +9 -0
- package/dist/application/transform/numbered-names.cjs.map +1 -1
- package/dist/application/transform/numbered-names.mjs +9 -1
- package/dist/application/transform/numbered-names.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +2 -2
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs +2 -2
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
- package/dist/application/transform/ref-type.cjs +2 -1
- package/dist/application/transform/ref-type.cjs.map +1 -1
- package/dist/application/transform/ref-type.mjs +2 -1
- package/dist/application/transform/ref-type.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs +2 -2
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/array-type.cjs +2 -2
- package/dist/application/transform/schema/array-type.cjs.map +1 -1
- package/dist/application/transform/schema/array-type.mjs +3 -3
- package/dist/application/transform/schema/array-type.mjs.map +1 -1
- package/dist/application/transform/schema/composition-type.cjs +4 -4
- package/dist/application/transform/schema/composition-type.cjs.map +1 -1
- package/dist/application/transform/schema/composition-type.mjs +6 -6
- package/dist/application/transform/schema/composition-type.mjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.cjs +4 -6
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.mjs +6 -8
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
- package/dist/application/transform/schema/object-type.cjs +3 -3
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +4 -4
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/presence-members.cjs +1 -1
- package/dist/application/transform/schema/presence-members.cjs.map +1 -1
- package/dist/application/transform/schema/presence-members.mjs +2 -2
- package/dist/application/transform/schema/presence-members.mjs.map +1 -1
- package/dist/application/transform/schema/ref-siblings.cjs +47 -0
- package/dist/application/transform/schema/ref-siblings.cjs.map +1 -0
- package/dist/application/transform/schema/ref-siblings.mjs +45 -0
- package/dist/application/transform/schema/ref-siblings.mjs.map +1 -0
- package/dist/application/transform/schema/required-variants.cjs +2 -2
- package/dist/application/transform/schema/required-variants.cjs.map +1 -1
- package/dist/application/transform/schema/required-variants.mjs +3 -3
- package/dist/application/transform/schema/required-variants.mjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.cjs +4 -2
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +4 -2
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.mjs +2 -2
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
- package/dist/application/transform/schema-comment.cjs +6 -2
- package/dist/application/transform/schema-comment.cjs.map +1 -1
- package/dist/application/transform/schema-comment.mjs +7 -3
- package/dist/application/transform/schema-comment.mjs.map +1 -1
- package/dist/cli/api-settings.cjs +62 -6
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +60 -7
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +72 -0
- package/dist/cli/api-writes.cjs.map +1 -0
- package/dist/cli/api-writes.mjs +69 -0
- package/dist/cli/api-writes.mjs.map +1 -0
- package/dist/cli/cli-errors.cjs +12 -1
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +12 -1
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +106 -1
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +99 -2
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +5 -1
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +6 -2
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +82 -36
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +85 -39
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +13 -7
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +14 -8
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/append-all.cjs +10 -0
- package/dist/domain/append-all.cjs.map +1 -0
- package/dist/domain/append-all.mjs +8 -0
- package/dist/domain/append-all.mjs.map +1 -0
- package/dist/domain/cause-secrets.cjs +37 -0
- package/dist/domain/cause-secrets.cjs.map +1 -0
- package/dist/domain/cause-secrets.mjs +35 -0
- package/dist/domain/cause-secrets.mjs.map +1 -0
- package/dist/domain/deprecations.cjs +11 -0
- package/dist/domain/deprecations.cjs.map +1 -0
- package/dist/domain/deprecations.mjs +9 -0
- package/dist/domain/deprecations.mjs.map +1 -0
- package/dist/domain/errors.cjs +9 -3
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +9 -3
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/identifier-text.cjs.map +1 -1
- package/dist/domain/ir/identifier-text.mjs +1 -1
- package/dist/domain/ir/identifier-text.mjs.map +1 -1
- package/dist/domain/ir/ir-shape.cjs +187 -0
- package/dist/domain/ir/ir-shape.cjs.map +1 -0
- package/dist/domain/ir/ir-shape.mjs +184 -0
- package/dist/domain/ir/ir-shape.mjs.map +1 -0
- package/dist/domain/ir/newer-identifier-ranges.cjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.cjs.map +1 -1
- package/dist/domain/ir/newer-identifier-ranges.mjs +182 -29
- package/dist/domain/ir/newer-identifier-ranges.mjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.cjs +3 -1
- package/dist/domain/openapi/alias-expansion.cjs.map +1 -1
- package/dist/domain/openapi/alias-expansion.mjs +3 -1
- package/dist/domain/openapi/alias-expansion.mjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.cjs +3 -3
- package/dist/domain/openapi/discriminated-union.cjs.map +1 -1
- package/dist/domain/openapi/discriminated-union.mjs +4 -4
- package/dist/domain/openapi/discriminated-union.mjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.cjs +10 -6
- package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -1
- package/dist/domain/openapi/discriminator-conflicts.mjs +11 -7
- package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -1
- package/dist/domain/openapi/json-pointer.cjs +43 -1
- package/dist/domain/openapi/json-pointer.cjs.map +1 -1
- package/dist/domain/openapi/json-pointer.mjs +40 -2
- package/dist/domain/openapi/json-pointer.mjs.map +1 -1
- package/dist/domain/openapi/schema-dialect.cjs +15 -0
- package/dist/domain/openapi/schema-dialect.cjs.map +1 -0
- package/dist/domain/openapi/schema-dialect.mjs +12 -0
- package/dist/domain/openapi/schema-dialect.mjs.map +1 -0
- package/dist/domain/openapi/unsupported-features.cjs +1 -1
- package/dist/domain/openapi/unsupported-features.cjs.map +1 -1
- package/dist/domain/openapi/unsupported-features.mjs +2 -2
- package/dist/domain/openapi/unsupported-features.mjs.map +1 -1
- package/dist/domain/output-fixes.cjs +25 -14
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +25 -13
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/url-secrets.cjs +48 -0
- package/dist/domain/url-secrets.cjs.map +1 -0
- package/dist/domain/url-secrets.mjs +45 -0
- package/dist/domain/url-secrets.mjs.map +1 -0
- package/dist/domain/warnings.cjs +0 -1
- package/dist/domain/warnings.cjs.map +1 -1
- package/dist/domain/warnings.mjs +0 -1
- package/dist/domain/warnings.mjs.map +1 -1
- package/dist/index.cjs +2 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -20
- package/dist/index.d.mts +57 -20
- package/dist/index.d.ts +57 -20
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -6
- package/src/adapters/node-deprecations/node-deprecations.ts +14 -0
- package/src/adapters/node-file-system/file-claims.ts +138 -0
- package/src/adapters/node-file-system/file-identity.ts +137 -0
- package/src/adapters/node-file-system/node-file-system.ts +145 -18
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +95 -0
- package/src/adapters/redocly-loader/bundled-ref-repair.ts +2 -2
- package/src/adapters/redocly-loader/loaded-documents.ts +46 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +18 -24
- package/src/adapters/redocly-loader/ref-access.ts +37 -3
- package/src/adapters/redocly-loader/ref-holders.ts +3 -3
- package/src/adapters/redocly-loader/remote-body-limit.ts +66 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +74 -11
- package/src/adapters/redocly-loader/remote-node-limit.ts +62 -0
- package/src/adapters/redocly-loader/schema-load-errors.ts +52 -13
- package/src/adapters/redocly-loader/schema-source.ts +20 -8
- package/src/adapters/redocly-loader/unsupported-keys.ts +3 -7
- package/src/adapters/terminal-logger/terminal-logger.ts +10 -5
- package/src/api/default-ports.ts +40 -4
- package/src/api/discriminator-conflict-warnings.ts +2 -2
- package/src/api/discriminator-enum-parent.ts +3 -3
- package/src/api/discriminator-other-owners.ts +5 -3
- package/src/api/discriminator-patch.ts +9 -6
- package/src/api/discriminator-scan.ts +19 -11
- package/src/api/document-run.ts +9 -3
- package/src/api/legacy-callback-warning.ts +13 -6
- package/src/api/legacy-utils.ts +5 -1
- package/src/api/openapi-ts.ts +26 -7
- package/src/api/run-context.ts +6 -0
- package/src/api/schema-callbacks.ts +60 -17
- package/src/api/string-to-ast.ts +11 -15
- package/src/api/transform-context.ts +7 -3
- package/src/api/transform-schema.ts +67 -15
- package/src/application/ports/deprecation-reporter.ts +9 -0
- package/src/application/ports/file-system.ts +39 -0
- package/src/application/ports/schema-loader.ts +11 -1
- package/src/application/print/text-writer.ts +10 -3
- package/src/application/stack-overflow.ts +9 -5
- package/src/application/transform/document/components.ts +4 -4
- package/src/application/transform/document/declared-type-names.ts +36 -0
- package/src/application/transform/document/defs-root.ts +2 -2
- package/src/application/transform/document/document.ts +4 -3
- package/src/application/transform/document/enum-names-given-back.ts +91 -0
- package/src/application/transform/document/global-type-references.ts +1 -1
- package/src/application/transform/document/media-type.ts +4 -3
- package/src/application/transform/document/operation-keys-written.ts +27 -0
- package/src/application/transform/document/operation.ts +2 -2
- package/src/application/transform/document/parameter-entries.ts +70 -0
- package/src/application/transform/document/parameter.ts +21 -9
- package/src/application/transform/document/parameters.ts +13 -58
- package/src/application/transform/document/path-item.ts +13 -31
- package/src/application/transform/document/paths-enum.ts +1 -1
- package/src/application/transform/document/paths.ts +8 -4
- package/src/application/transform/document/referenced-parameter.ts +146 -0
- package/src/application/transform/document/request-body.ts +2 -2
- package/src/application/transform/document/response.ts +3 -3
- package/src/application/transform/document/responses.ts +2 -2
- package/src/application/transform/document/root-type-aliases.ts +17 -38
- package/src/application/transform/document/type-resolution.ts +2 -1
- package/src/application/transform/document/webhooks.ts +2 -2
- package/src/application/transform/footer/document-footer.ts +18 -1
- package/src/application/transform/footer/enum-name-claims.ts +62 -0
- package/src/application/transform/footer/operation-keys.ts +28 -0
- package/src/application/transform/footer/type-evaluation.ts +4 -4
- package/src/application/transform/helper-types.ts +6 -5
- package/src/application/transform/numbered-names.ts +15 -0
- package/src/application/transform/ref-pointer/generated-location.ts +2 -2
- package/src/application/transform/ref-pointer/pointer-type.ts +2 -4
- package/src/application/transform/ref-type.ts +2 -1
- package/src/application/transform/schema/access-flags.ts +2 -2
- package/src/application/transform/schema/array-type.ts +3 -5
- package/src/application/transform/schema/composition-type.ts +6 -6
- package/src/application/transform/schema/enum-rule.ts +10 -8
- package/src/application/transform/schema/object-type.ts +4 -4
- package/src/application/transform/schema/presence-members.ts +2 -2
- package/src/application/transform/schema/ref-siblings.ts +76 -0
- package/src/application/transform/schema/required-variants.ts +3 -3
- package/src/application/transform/schema/schema-context.ts +3 -0
- package/src/application/transform/schema/schema-transform.ts +4 -2
- package/src/application/transform/schema/unevaluated-properties.ts +2 -2
- package/src/application/transform/schema-comment.ts +7 -3
- package/src/application/transform/transform-context.ts +5 -0
- package/src/cli/api-settings.ts +82 -7
- package/src/cli/api-writes.ts +117 -0
- package/src/cli/cli-dependencies.ts +21 -4
- package/src/cli/cli-errors.ts +20 -1
- package/src/cli/cli-output.ts +186 -7
- package/src/cli/main.ts +6 -3
- package/src/cli/redocly-apis.ts +153 -48
- package/src/cli/run-cli.ts +37 -8
- package/src/domain/append-all.ts +10 -0
- package/src/domain/cause-secrets.ts +52 -0
- package/src/domain/deprecations.ts +15 -0
- package/src/domain/errors.ts +22 -7
- package/src/domain/ir/identifier-text.ts +6 -5
- package/src/domain/ir/ir-shape.ts +299 -0
- package/src/domain/ir/newer-identifier-ranges.ts +183 -30
- package/src/domain/openapi/alias-expansion.ts +4 -1
- package/src/domain/openapi/discriminated-union.ts +6 -4
- package/src/domain/openapi/discriminator-conflicts.ts +21 -7
- package/src/domain/openapi/document-object.ts +2 -0
- package/src/domain/openapi/json-pointer.ts +96 -7
- package/src/domain/openapi/schema-dialect.ts +22 -0
- package/src/domain/openapi/unsupported-features.ts +2 -2
- package/src/domain/output-fixes.ts +37 -18
- package/src/domain/url-secrets.ts +72 -0
- package/src/domain/warnings.ts +0 -1
- package/src/index.ts +2 -6
- package/src/types/generator-options.ts +1 -1
- package/dist/cli/main.d.cts +0 -2
- package/dist/cli/main.d.mts +0 -2
- package/dist/cli/main.d.ts +0 -2
- package/dist/domain/url-credentials.cjs +0 -10
- package/dist/domain/url-credentials.cjs.map +0 -1
- package/dist/domain/url-credentials.mjs +0 -8
- package/dist/domain/url-credentials.mjs.map +0 -1
- package/src/domain/url-credentials.ts +0 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminator-conflicts.cjs","sources":["../../../src/domain/openapi/discriminator-conflicts.ts"],"sourcesContent":["import { admittedPropertyValues, resolveLocalRef } from \"./admitted-values.js\";\nimport { isUnionMember, unionAt } from \"./discriminated-union.js\";\nimport { createRef, escapePointerSegment, parseRefPointer } from \"./json-pointer.js\";\n\n/**\n * Discriminator members whose discriminator value their own property does not allow. By the\n * Discriminator Object rule, a member that no `mapping` entry names has its schema name as the\n * value, so with a property `enum` (or `const`) that does not list it no value of the member\n * matches, and where the generator adds the value to the member the property type is `never`.\n * Each one gets a warning (CODING_PRINCIPLES §8.7).\n */\n\nexport interface DiscriminatorValueConflict {\n /** The member schema, such as `#/components/schemas/EpisodeObject`. */\n readonly member: string;\n /** The schema that has the Discriminator Object. */\n readonly owner: string;\n readonly propertyName: string;\n /** The values the discriminator gives the member: its mapping keys, or its name. */\n readonly values: readonly string[];\n /** The values the member's property allows. */\n readonly allowed: readonly (string | number | boolean | null)[];\n /** Whether no mapping entry names the member, so its value is its schema name. */\n readonly isImplicit: boolean;\n}\n\ntype JsonObject = Readonly<Record<string, unknown>>;\n\nconst COMPONENT_SCHEMAS = \"#/components/schemas/\";\n\nfunction isObject(value: unknown): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\ninterface Owner {\n readonly pointer: string;\n readonly propertyName: string;\n readonly mapping: Readonly<Record<string, string>>;\n readonly memberRefs: readonly string[];\n}\n\nfunction refsOf(list: unknown): string[] {\n return (Array.isArray(list) ? list : []).flatMap((item) =>\n isObject(item) && typeof item.$ref === \"string\" ? [item.$ref] : [],\n );\n}\n\nfunction mappingTarget(target: string): string {\n return target.startsWith(\"#\") ? target : `${COMPONENT_SCHEMAS}${escapePointerSegment(target)}`;\n}\n\nfunction ownerAt(node: JsonObject, pointer: () => string): Owner | null {\n const discriminator = node.discriminator;\n if (!isObject(discriminator) || typeof discriminator.propertyName !== \"string\") {\n return null;\n }\n const mapping = isObject(discriminator.mapping)\n ? (discriminator.mapping as Readonly<Record<string, string>>)\n : {};\n const mapped = Object.values(mapping)\n .filter((t) => typeof t === \"string\")\n .map(mappingTarget);\n const memberRefs = [...refsOf(node.oneOf), ...refsOf(node.anyOf), ...mapped];\n return { pointer: pointer(), propertyName: discriminator.propertyName, mapping, memberRefs };\n}\n\n/** A node of the document walk; the pointer is built only for the nodes that need it. */\ninterface Visit {\n readonly node: unknown;\n readonly key: string | null;\n readonly parent: Visit | null;\n}\n\nfunction pointerOf(visit: Visit): string {\n const segments: string[] = [];\n for (let current: Visit | null = visit; current?.key != null; current = current.parent) {\n segments.unshift(current.key);\n }\n return createRef(segments);\n}\n\nfunction childrenOf(visit: Visit): Visit[] {\n const { node } = visit;\n const entries: [string, unknown][] = Array.isArray(node)\n ? node.map((item, index) => [String(index), item])\n : isObject(node)\n ? Object.entries(node)\n : [];\n return entries.map(([key, child]) => ({ node: child, key, parent: visit }));\n}\n\n/**\n * Every Discriminator Object of the document, depth first, with its pointer. The walk keeps its\n * own stack, so a document nested past the call stack fails in the transform, as it did before.\n */\nfunction ownersIn(document: unknown): Owner[] {\n const found: Owner[] = [];\n const stack: Visit[] = [{ node: document, key: null, parent: null }];\n for (let visit = stack.pop(); visit !== undefined; visit = stack.pop()) {\n const owner = isObject(visit.node) ? ownerAt(visit.node, () => pointerOf(visit)) : null;\n if (owner !== null) {\n found.push(owner);\n }\n stack.push(...childrenOf(visit).reverse());\n }\n return found;\n}\n\n/** A member and the `$ref`s whose properties its type leaves out (`Omit` of its parents). */\ninterface Member {\n readonly ref: string;\n readonly skipped: ReadonlySet<string>;\n}\n\ninterface Child {\n readonly ref: string;\n readonly schema: JsonObject;\n}\n\n/** How the run types an `allOf` of a discriminated union. */\nexport interface ConflictOptions {\n /**\n * `allof-discriminated-union`: a schema that `allOf`s a union which does not contain it reuses\n * the union and gets no value, so neither it nor the schemas below it are members.\n */\n readonly isUnionReused: boolean;\n}\n\n/** What the search for conflicts reads: the document and its `allOf` children by parent. */\ninterface ConflictSearch extends ConflictOptions {\n readonly document: unknown;\n readonly children: ReadonlyMap<string, readonly Child[]>;\n}\n\n/** The `allOf` children of the owner that inherit its discriminator. */\nfunction inheritingChildren(owner: Owner, search: ConflictSearch): readonly Child[] {\n const children = search.children.get(owner.pointer) ?? [];\n const resolve = (ref: string) => resolveLocalRef(search.document, ref);\n const union = search.isUnionReused ? unionAt(owner.pointer, resolve) : undefined;\n return union === undefined\n ? children\n : children.filter((child) => isUnionMember(union, child.ref, resolve));\n}\n\n/** The component schemas whose `allOf` holds a `$ref`, by that `$ref`, in document order. */\nfunction allOfChildren(document: unknown): Map<string, Child[]> {\n const schemas = resolveLocalRef(document, \"#/components/schemas\");\n const children = new Map<string, Child[]>();\n for (const [name, schema] of Object.entries(isObject(schemas) ? schemas : {})) {\n if (!isObject(schema)) {\n continue;\n }\n const child = { ref: `${COMPONENT_SCHEMAS}${escapePointerSegment(name)}`, schema };\n for (const parent of new Set(refsOf(schema.allOf))) {\n const siblings = children.get(parent) ?? [];\n siblings.push(child);\n children.set(parent, siblings);\n }\n }\n return children;\n}\n\n/** Whether a schema defines a discriminator of the property itself: it is the owner below. */\nfunction ownsProperty(schema: JsonObject, propertyName: string): boolean {\n const discriminator = schema.discriminator;\n return isObject(discriminator) && discriminator.propertyName === propertyName;\n}\n\n/**\n * Component schemas that inherit the owner through `allOf`, also through a chain\n * (`Lion: { allOf: [Cat] }`, `Cat: { allOf: [Pet] }`). Each parent on the way is left out of the\n * member's values, as its type omits the property. A schema with its own discriminator of the\n * property is a member, but the schemas below it are its own members.\n */\nfunction inheritingMembers(owner: Owner, search: ConflictSearch): Member[] {\n const found: Member[] = [];\n const visited = new Set([owner.pointer]);\n const parents: Member[] = [{ ref: owner.pointer, skipped: new Set([owner.pointer]) }];\n for (let parent = parents.shift(); parent !== undefined; parent = parents.shift()) {\n const children =\n parent.ref === owner.pointer\n ? inheritingChildren(owner, search)\n : (search.children.get(parent.ref) ?? []);\n for (const child of children) {\n if (visited.has(child.ref)) {\n continue;\n }\n visited.add(child.ref);\n found.push({ ref: child.ref, skipped: parent.skipped });\n if (!ownsProperty(child.schema, owner.propertyName)) {\n parents.push({ ref: child.ref, skipped: new Set([...parent.skipped, child.ref]) });\n }\n }\n }\n return found;\n}\n\n/** The members of an owner, each once: the listed and mapped ones, then the inheriting ones. */\nfunction membersOf(owner: Owner, search: ConflictSearch): Member[] {\n const listed = owner.memberRefs.map((ref) => ({ ref, skipped: new Set([owner.pointer]) }));\n const members = new Map<string, Member>();\n for (const member of [...listed, ...inheritingMembers(owner, search)]) {\n if (!members.has(member.ref)) {\n members.set(member.ref, member);\n }\n }\n return [...members.values()];\n}\n\nfunction memberValues(owner: Owner, member: string): { values: string[]; isImplicit: boolean } {\n const values = Object.entries(owner.mapping)\n .filter(([, target]) => typeof target === \"string\" && mappingTarget(target) === member)\n .map(([key]) => key);\n const name = parseRefPointer(member).pop() ?? \"\";\n return values.length > 0 ? { values, isImplicit: false } : { values: [name], isImplicit: true };\n}\n\nfunction conflictOf(owner: Owner, { ref: member, skipped }: Member, document: unknown) {\n // The owner's own property is left out of an inheriting member's type (`Omit`).\n const allowed = admittedPropertyValues(\n resolveLocalRef(document, member),\n owner.propertyName,\n document,\n skipped,\n );\n const { values, isImplicit } = memberValues(owner, member);\n if (allowed === null || values.some((value) => allowed.has(value))) {\n return null;\n }\n const { pointer, propertyName } = owner;\n return { member, owner: pointer, propertyName, values, allowed: [...allowed], isImplicit };\n}\n\n/** The conflicts of the document, one per member and value list, in document order. */\nexport function findDiscriminatorValueConflicts(\n document: unknown,\n options: ConflictOptions = { isUnionReused: false },\n): readonly DiscriminatorValueConflict[] {\n const conflicts = new Map<string, DiscriminatorValueConflict>();\n const search = { ...options, document, children: allOfChildren(document) };\n for (const owner of ownersIn(document)) {\n for (const member of membersOf(owner, search)) {\n const conflict = conflictOf(owner, member, document);\n const key = JSON.stringify([member.ref, conflict?.propertyName, conflict?.values]);\n if (conflict !== null && !conflicts.has(key)) {\n conflicts.set(key, conflict);\n }\n }\n }\n return [...conflicts.values()];\n}\n"],"names":["escapePointerSegment","createRef","resolveLocalRef","unionAt","isUnionMember","parseRefPointer","admittedPropertyValues"],"mappings":";;;;;;AA4BA,MAAM,iBAAA,GAAoB,uBAAA;AAE1B,SAAS,SAAS,KAAA,EAAqC;AACrD,EAAA,OAAO,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,QAAQ,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC5E;AASA,SAAS,OAAO,IAAA,EAAyB;AACvC,EAAA,OAAA,CAAQ,MAAM,OAAA,CAAQ,IAAI,CAAA,GAAI,IAAA,GAAO,EAAC,EAAG,OAAA;AAAA,IAAQ,CAAC,IAAA,KAChD,QAAA,CAAS,IAAI,CAAA,IAAK,OAAO,IAAA,CAAK,IAAA,KAAS,QAAA,GAAW,CAAC,IAAA,CAAK,IAAI,IAAI;AAAC,GACnE;AACF;AAEA,SAAS,cAAc,MAAA,EAAwB;AAC7C,EAAA,OAAO,MAAA,CAAO,UAAA,CAAW,GAAG,CAAA,GAAI,MAAA,GAAS,GAAG,iBAAiB,CAAA,EAAGA,gCAAA,CAAqB,MAAM,CAAC,CAAA,CAAA;AAC9F;AAEA,SAAS,OAAA,CAAQ,MAAkB,OAAA,EAAqC;AACtE,EAAA,MAAM,gBAAgB,IAAA,CAAK,aAAA;AAC3B,EAAA,IAAI,CAAC,QAAA,CAAS,aAAa,KAAK,OAAO,aAAA,CAAc,iBAAiB,QAAA,EAAU;AAC9E,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,UAAU,QAAA,CAAS,aAAA,CAAc,OAAO,CAAA,GACzC,aAAA,CAAc,UACf,EAAC;AACL,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA,CACjC,MAAA,CAAO,CAAC,CAAA,KAAM,OAAO,CAAA,KAAM,QAAQ,CAAA,CACnC,IAAI,aAAa,CAAA;AACpB,EAAA,MAAM,UAA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,EAAS,YAAA,EAAc,MAAA,EAAQ,OAAA,EAAS,CAAC,GAAG,OAAO,CAAA,EAAG,UAAA,EAAW;AAC3F;AAGO,SAAS,gCACd,QAAA,EACA,OAAA,GAA2B,EAAE,aAAA,EAAe,OAAM,EACX;AACvC,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAwC;AAC9D,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,OAAA,EAAS,UAAU,QAAA,EAAU,aAAA,CAAc,QAAQ,CAAA,EAAE;AACzE,EAAA,KAAA,MAAW,KAAA,IAAS,QAAA,CAAS,QAAQ,CAAA,EAAG;AACtC,IAAA,KAAA,MAAW,MAAA,IAAU,SAAA,CAAU,KAAA,EAAO,MAAM,CAAA,EAAG;AAC7C,MAAA,MAAM,QAAA,GAAW,UAAA,CAAW,KAAA,EAAO,MAAA,EAAQ,QAAQ,CAAA;AACnD,MAAA,MAAM,GAAA,GAAM,IAAA,CAAK,SAAA,CAAU,CAAC,MAAA,CAAO,KAAK,QAAA,EAAU,YAAA,EAAc,QAAA,EAAU,MAAM,CAAC,CAAA;AACjF,MAAA,IAAI,aAAa,IAAA,IAAQ,CAAC,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA,EAAG;AAC5C,QAAA,SAAA,CAAU,GAAA,CAAI,KAAK,QAAQ,CAAA;AAAA,MAC7B;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,CAAC,GAAG,SAAA,CAAU,MAAA,EAAQ,CAAA;AAC/B;;"}
|
|
1
|
+
{"version":3,"file":"discriminator-conflicts.cjs","sources":["../../../src/domain/openapi/discriminator-conflicts.ts"],"sourcesContent":["import { appendAll } from \"../append-all.js\";\nimport { admittedPropertyValues, resolveLocalRef } from \"./admitted-values.js\";\nimport { isUnionMember, unionAt } from \"./discriminated-union.js\";\nimport {\n appendPointer,\n canonicalRef,\n escapePointerSegment,\n parseRefPointer,\n ROOT_POINTER,\n} from \"./json-pointer.js\";\n\n/**\n * Discriminator members whose discriminator value their own property does not allow. By the\n * Discriminator Object rule, a member that no `mapping` entry names has its schema name as the\n * value, so with a property `enum` (or `const`) that does not list it no value of the member\n * matches, and where the generator adds the value to the member the property type is `never`.\n * Each one gets a warning (CODING_PRINCIPLES §8.7).\n */\n\nexport interface DiscriminatorValueConflict {\n /** The member schema, such as `#/components/schemas/EpisodeObject`. */\n readonly member: string;\n /** The schema that has the Discriminator Object. */\n readonly owner: string;\n readonly propertyName: string;\n /** The values the discriminator gives the member: its mapping keys, or its name. */\n readonly values: readonly string[];\n /** The values the member's property allows. */\n readonly allowed: readonly (string | number | boolean | null)[];\n /** Whether no mapping entry names the member, so its value is its schema name. */\n readonly isImplicit: boolean;\n}\n\ntype JsonObject = Readonly<Record<string, unknown>>;\n\nconst COMPONENT_SCHEMAS = \"#/components/schemas/\";\n\nfunction isObject(value: unknown): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\ninterface Owner {\n readonly pointer: string;\n readonly propertyName: string;\n readonly mapping: Readonly<Record<string, string>>;\n readonly memberRefs: readonly string[];\n}\n\nfunction refsOf(list: unknown): string[] {\n return (Array.isArray(list) ? list : []).flatMap((item) =>\n isObject(item) && typeof item.$ref === \"string\" ? [item.$ref] : [],\n );\n}\n\n/** A mapping value as a canonical `$ref`: Redocly writes it percent-decoded (`canonicalRef`). */\nfunction mappingTarget(target: string): string {\n return target.startsWith(\"#\")\n ? canonicalRef(target)\n : `${COMPONENT_SCHEMAS}${escapePointerSegment(target)}`;\n}\n\nfunction ownerAt(node: JsonObject, pointer: () => string): Owner | null {\n const discriminator = node.discriminator;\n if (!isObject(discriminator) || typeof discriminator.propertyName !== \"string\") {\n return null;\n }\n const mapping = isObject(discriminator.mapping)\n ? (discriminator.mapping as Readonly<Record<string, string>>)\n : {};\n const mapped = Object.values(mapping)\n .filter((t) => typeof t === \"string\")\n .map(mappingTarget);\n const memberRefs = [...refsOf(node.oneOf), ...refsOf(node.anyOf), ...mapped];\n return { pointer: pointer(), propertyName: discriminator.propertyName, mapping, memberRefs };\n}\n\n/** A node of the document walk; the pointer is built only for the nodes that need it. */\ninterface Visit {\n readonly node: unknown;\n readonly key: string | null;\n readonly parent: Visit | null;\n}\n\nfunction pointerOf(visit: Visit): string {\n const segments: string[] = [];\n for (let current: Visit | null = visit; current?.key != null; current = current.parent) {\n segments.unshift(current.key);\n }\n return appendPointer(ROOT_POINTER, segments);\n}\n\nfunction childrenOf(visit: Visit): Visit[] {\n const { node } = visit;\n const entries: [string, unknown][] = Array.isArray(node)\n ? node.map((item, index) => [String(index), item])\n : isObject(node)\n ? Object.entries(node)\n : [];\n return entries.map(([key, child]) => ({ node: child, key, parent: visit }));\n}\n\n/**\n * Every Discriminator Object of the document, depth first, with its pointer. The walk keeps its\n * own stack, so a document nested past the call stack fails in the transform, as it did before.\n */\nfunction ownersIn(document: unknown): Owner[] {\n const found: Owner[] = [];\n const stack: Visit[] = [{ node: document, key: null, parent: null }];\n for (let visit = stack.pop(); visit !== undefined; visit = stack.pop()) {\n const owner = isObject(visit.node) ? ownerAt(visit.node, () => pointerOf(visit)) : null;\n if (owner !== null) {\n found.push(owner);\n }\n appendAll(stack, childrenOf(visit).reverse());\n }\n return found;\n}\n\n/** A member and the `$ref`s whose properties its type leaves out (`Omit` of its parents). */\ninterface Member {\n readonly ref: string;\n readonly skipped: ReadonlySet<string>;\n}\n\ninterface Child {\n readonly ref: string;\n readonly schema: JsonObject;\n}\n\n/** How the run types an `allOf` of a discriminated union. */\nexport interface ConflictOptions {\n /**\n * `allof-discriminated-union`: a schema that `allOf`s a union which does not contain it reuses\n * the union and gets no value, so neither it nor the schemas below it are members.\n */\n readonly isUnionReused: boolean;\n}\n\n/** What the search for conflicts reads: the document and its `allOf` children by parent. */\ninterface ConflictSearch extends ConflictOptions {\n readonly document: unknown;\n readonly children: ReadonlyMap<string, readonly Child[]>;\n}\n\n/** The `allOf` children of the owner that inherit its discriminator. */\nfunction inheritingChildren(owner: Owner, search: ConflictSearch): readonly Child[] {\n const children = search.children.get(owner.pointer) ?? [];\n const resolve = (ref: string) => resolveLocalRef(search.document, ref);\n const union = search.isUnionReused ? unionAt(owner.pointer, resolve) : undefined;\n return union === undefined\n ? children\n : children.filter((child) => isUnionMember(union, child.ref, resolve));\n}\n\n/** The component schemas whose `allOf` holds a `$ref`, by that `$ref`, in document order. */\nfunction allOfChildren(document: unknown): Map<string, Child[]> {\n const schemas = resolveLocalRef(document, \"#/components/schemas\");\n const children = new Map<string, Child[]>();\n for (const [name, schema] of Object.entries(isObject(schemas) ? schemas : {})) {\n if (!isObject(schema)) {\n continue;\n }\n const child = { ref: `${COMPONENT_SCHEMAS}${escapePointerSegment(name)}`, schema };\n for (const parent of new Set(refsOf(schema.allOf))) {\n const siblings = children.get(parent) ?? [];\n siblings.push(child);\n children.set(parent, siblings);\n }\n }\n return children;\n}\n\n/** Whether a schema defines a discriminator of the property itself: it is the owner below. */\nfunction ownsProperty(schema: JsonObject, propertyName: string): boolean {\n const discriminator = schema.discriminator;\n return isObject(discriminator) && discriminator.propertyName === propertyName;\n}\n\n/**\n * Component schemas that inherit the owner through `allOf`, also through a chain\n * (`Lion: { allOf: [Cat] }`, `Cat: { allOf: [Pet] }`). Each parent on the way is left out of the\n * member's values, as its type omits the property. A schema with its own discriminator of the\n * property is a member, but the schemas below it are its own members.\n */\nfunction inheritingMembers(owner: Owner, search: ConflictSearch): Member[] {\n const found: Member[] = [];\n const visited = new Set([owner.pointer]);\n const parents: Member[] = [{ ref: owner.pointer, skipped: new Set([owner.pointer]) }];\n for (let parent = parents.shift(); parent !== undefined; parent = parents.shift()) {\n const children =\n parent.ref === owner.pointer\n ? inheritingChildren(owner, search)\n : (search.children.get(parent.ref) ?? []);\n for (const child of children) {\n if (visited.has(child.ref)) {\n continue;\n }\n visited.add(child.ref);\n found.push({ ref: child.ref, skipped: parent.skipped });\n if (!ownsProperty(child.schema, owner.propertyName)) {\n parents.push({ ref: child.ref, skipped: new Set([...parent.skipped, child.ref]) });\n }\n }\n }\n return found;\n}\n\n/** The members of an owner, each once: the listed and mapped ones, then the inheriting ones. */\nfunction membersOf(owner: Owner, search: ConflictSearch): Member[] {\n const listed = owner.memberRefs.map((ref) => ({ ref, skipped: new Set([owner.pointer]) }));\n const members = new Map<string, Member>();\n for (const member of [...listed, ...inheritingMembers(owner, search)]) {\n // A member may be listed by a `$ref` and found by its pointer: both name it canonically.\n const key = canonicalRef(member.ref);\n if (!members.has(key)) {\n members.set(key, member);\n }\n }\n return [...members.values()];\n}\n\nfunction memberValues(owner: Owner, member: string): { values: string[]; isImplicit: boolean } {\n const values = Object.entries(owner.mapping)\n .filter(\n ([, target]) => typeof target === \"string\" && mappingTarget(target) === canonicalRef(member),\n )\n .map(([key]) => key);\n const name = parseRefPointer(member).pop() ?? \"\";\n return values.length > 0 ? { values, isImplicit: false } : { values: [name], isImplicit: true };\n}\n\nfunction conflictOf(owner: Owner, { ref: member, skipped }: Member, document: unknown) {\n // The owner's own property is left out of an inheriting member's type (`Omit`).\n const allowed = admittedPropertyValues(\n resolveLocalRef(document, member),\n owner.propertyName,\n document,\n skipped,\n );\n const { values, isImplicit } = memberValues(owner, member);\n if (allowed === null || values.some((value) => allowed.has(value))) {\n return null;\n }\n const { pointer, propertyName } = owner;\n return { member, owner: pointer, propertyName, values, allowed: [...allowed], isImplicit };\n}\n\n/** The conflicts of the document, one per member and value list, in document order. */\nexport function findDiscriminatorValueConflicts(\n document: unknown,\n options: ConflictOptions = { isUnionReused: false },\n): readonly DiscriminatorValueConflict[] {\n const conflicts = new Map<string, DiscriminatorValueConflict>();\n const search = { ...options, document, children: allOfChildren(document) };\n for (const owner of ownersIn(document)) {\n for (const member of membersOf(owner, search)) {\n const conflict = conflictOf(owner, member, document);\n const key = JSON.stringify([member.ref, conflict?.propertyName, conflict?.values]);\n if (conflict !== null && !conflicts.has(key)) {\n conflicts.set(key, conflict);\n }\n }\n }\n return [...conflicts.values()];\n}\n"],"names":["canonicalRef","escapePointerSegment","appendPointer","ROOT_POINTER","appendA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AO,EAAE,MAAA,EAAQ,KAAA,EAAO,OAAA,EAAS,YAAA,EAAc,MAAA,EAAQ,OAAA,EAAS,CAAC,GAAG,OAAO,CAAA,EAAG,UAAA,EAAW;AAC3F;AAGO,SAAS,gCACd,QAAA,EACA,OAAA,GAA2B,EAAE,aAAA,EAAe,OAAM,EACX;AACvC,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAwC;AAC9D,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,OAAA,EAAS,UAAU,QAAA,EAAU,aAAA,CAAc,QAAQ,CAAA,EAAE;AACzE,EAAA,KAAA,MAAW,KAAA,IAAS,QAAA,CAAS,QAAQ,CAAA,EAAG;AACtC,IAAA,KAAA,MAAW,MAAA,IAAU,SAAA,CAAU,KAAA,EAAO,MAAM,CAAA,EAAG;AAC7C,MAAA,MAAM,QAAA,GAAW,UAAA,CAAW,KAAA,EAAO,MAAA,EAAQ,QAAQ,CAAA;AACnD,MAAA,MAAM,GAAA,GAAM,IAAA,CAAK,SAAA,CAAU,CAAC,MAAA,CAAO,KAAK,QAAA,EAAU,YAAA,EAAc,QAAA,EAAU,MAAM,CAAC,CAAA;AACjF,MAAA,IAAI,aAAa,IAAA,IAAQ,CAAC,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA,EAAG;AAC5C,QAAA,SAAA,CAAU,GAAA,CAAI,KAAK,QAAQ,CAAA;AAAA,MAC7B;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,CAAC,GAAG,SAAA,CAAU,MAAA,EAAQ,CAAA;AAC/B;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { appendAll } from '../append-all.mjs';
|
|
1
2
|
import { resolveLocalRef, admittedPropertyValues } from './admitted-values.mjs';
|
|
2
3
|
import { unionAt, isUnionMember } from './discriminated-union.mjs';
|
|
3
|
-
import { escapePointerSegment, parseRefPointer,
|
|
4
|
+
import { escapePointerSegment, canonicalRef, parseRefPointer, appendPointer, ROOT_POINTER } from './json-pointer.mjs';
|
|
4
5
|
|
|
5
6
|
const COMPONENT_SCHEMAS = "#/components/schemas/";
|
|
6
7
|
function isObject(value) {
|
|
@@ -12,7 +13,7 @@ function refsOf(list) {
|
|
|
12
13
|
);
|
|
13
14
|
}
|
|
14
15
|
function mappingTarget(target) {
|
|
15
|
-
return target.startsWith("#") ? target : `${COMPONENT_SCHEMAS}${escapePointerSegment(target)}`;
|
|
16
|
+
return target.startsWith("#") ? canonicalRef(target) : `${COMPONENT_SCHEMAS}${escapePointerSegment(target)}`;
|
|
16
17
|
}
|
|
17
18
|
function ownerAt(node, pointer) {
|
|
18
19
|
const discriminator = node.discriminator;
|
|
@@ -29,7 +30,7 @@ function pointerOf(visit) {
|
|
|
29
30
|
for (let current = visit; current?.key != null; current = current.parent) {
|
|
30
31
|
segments.unshift(current.key);
|
|
31
32
|
}
|
|
32
|
-
return
|
|
33
|
+
return appendPointer(ROOT_POINTER, segments);
|
|
33
34
|
}
|
|
34
35
|
function childrenOf(visit) {
|
|
35
36
|
const { node } = visit;
|
|
@@ -44,7 +45,7 @@ function ownersIn(document) {
|
|
|
44
45
|
if (owner !== null) {
|
|
45
46
|
found.push(owner);
|
|
46
47
|
}
|
|
47
|
-
stack
|
|
48
|
+
appendAll(stack, childrenOf(visit).reverse());
|
|
48
49
|
}
|
|
49
50
|
return found;
|
|
50
51
|
}
|
|
@@ -97,14 +98,17 @@ function membersOf(owner, search) {
|
|
|
97
98
|
const listed = owner.memberRefs.map((ref) => ({ ref, skipped: /* @__PURE__ */ new Set([owner.pointer]) }));
|
|
98
99
|
const members = /* @__PURE__ */ new Map();
|
|
99
100
|
for (const member of [...listed, ...inheritingMembers(owner, search)]) {
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
const key = canonicalRef(member.ref);
|
|
102
|
+
if (!members.has(key)) {
|
|
103
|
+
members.set(key, member);
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
return [...members.values()];
|
|
105
107
|
}
|
|
106
108
|
function memberValues(owner, member) {
|
|
107
|
-
const values = Object.entries(owner.mapping).filter(
|
|
109
|
+
const values = Object.entries(owner.mapping).filter(
|
|
110
|
+
([, target]) => typeof target === "string" && mappingTarget(target) === canonicalRef(member)
|
|
111
|
+
).map(([key]) => key);
|
|
108
112
|
const name = parseRefPointer(member).pop() ?? "";
|
|
109
113
|
return values.length > 0 ? { values, isImplicit: false } : { values: [name], isImplicit: true };
|
|
110
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminator-conflicts.mjs","sources":["../../../src/domain/openapi/discriminator-conflicts.ts"],"sourcesContent":["import { admittedPropertyValues, resolveLocalRef } from \"./admitted-values.js\";\nimport { isUnionMember, unionAt } from \"./discriminated-union.js\";\nimport { createRef, escapePointerSegment, parseRefPointer } from \"./json-pointer.js\";\n\n/**\n * Discriminator members whose discriminator value their own property does not allow. By the\n * Discriminator Object rule, a member that no `mapping` entry names has its schema name as the\n * value, so with a property `enum` (or `const`) that does not list it no value of the member\n * matches, and where the generator adds the value to the member the property type is `never`.\n * Each one gets a warning (CODING_PRINCIPLES §8.7).\n */\n\nexport interface DiscriminatorValueConflict {\n /** The member schema, such as `#/components/schemas/EpisodeObject`. */\n readonly member: string;\n /** The schema that has the Discriminator Object. */\n readonly owner: string;\n readonly propertyName: string;\n /** The values the discriminator gives the member: its mapping keys, or its name. */\n readonly values: readonly string[];\n /** The values the member's property allows. */\n readonly allowed: readonly (string | number | boolean | null)[];\n /** Whether no mapping entry names the member, so its value is its schema name. */\n readonly isImplicit: boolean;\n}\n\ntype JsonObject = Readonly<Record<string, unknown>>;\n\nconst COMPONENT_SCHEMAS = \"#/components/schemas/\";\n\nfunction isObject(value: unknown): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\ninterface Owner {\n readonly pointer: string;\n readonly propertyName: string;\n readonly mapping: Readonly<Record<string, string>>;\n readonly memberRefs: readonly string[];\n}\n\nfunction refsOf(list: unknown): string[] {\n return (Array.isArray(list) ? list : []).flatMap((item) =>\n isObject(item) && typeof item.$ref === \"string\" ? [item.$ref] : [],\n );\n}\n\nfunction mappingTarget(target: string): string {\n return target.startsWith(\"#\") ? target : `${COMPONENT_SCHEMAS}${escapePointerSegment(target)}`;\n}\n\nfunction ownerAt(node: JsonObject, pointer: () => string): Owner | null {\n const discriminator = node.discriminator;\n if (!isObject(discriminator) || typeof discriminator.propertyName !== \"string\") {\n return null;\n }\n const mapping = isObject(discriminator.mapping)\n ? (discriminator.mapping as Readonly<Record<string, string>>)\n : {};\n const mapped = Object.values(mapping)\n .filter((t) => typeof t === \"string\")\n .map(mappingTarget);\n const memberRefs = [...refsOf(node.oneOf), ...refsOf(node.anyOf), ...mapped];\n return { pointer: pointer(), propertyName: discriminator.propertyName, mapping, memberRefs };\n}\n\n/** A node of the document walk; the pointer is built only for the nodes that need it. */\ninterface Visit {\n readonly node: unknown;\n readonly key: string | null;\n readonly parent: Visit | null;\n}\n\nfunction pointerOf(visit: Visit): string {\n const segments: string[] = [];\n for (let current: Visit | null = visit; current?.key != null; current = current.parent) {\n segments.unshift(current.key);\n }\n return createRef(segments);\n}\n\nfunction childrenOf(visit: Visit): Visit[] {\n const { node } = visit;\n const entries: [string, unknown][] = Array.isArray(node)\n ? node.map((item, index) => [String(index), item])\n : isObject(node)\n ? Object.entries(node)\n : [];\n return entries.map(([key, child]) => ({ node: child, key, parent: visit }));\n}\n\n/**\n * Every Discriminator Object of the document, depth first, with its pointer. The walk keeps its\n * own stack, so a document nested past the call stack fails in the transform, as it did before.\n */\nfunction ownersIn(document: unknown): Owner[] {\n const found: Owner[] = [];\n const stack: Visit[] = [{ node: document, key: null, parent: null }];\n for (let visit = stack.pop(); visit !== undefined; visit = stack.pop()) {\n const owner = isObject(visit.node) ? ownerAt(visit.node, () => pointerOf(visit)) : null;\n if (owner !== null) {\n found.push(owner);\n }\n stack.push(...childrenOf(visit).reverse());\n }\n return found;\n}\n\n/** A member and the `$ref`s whose properties its type leaves out (`Omit` of its parents). */\ninterface Member {\n readonly ref: string;\n readonly skipped: ReadonlySet<string>;\n}\n\ninterface Child {\n readonly ref: string;\n readonly schema: JsonObject;\n}\n\n/** How the run types an `allOf` of a discriminated union. */\nexport interface ConflictOptions {\n /**\n * `allof-discriminated-union`: a schema that `allOf`s a union which does not contain it reuses\n * the union and gets no value, so neither it nor the schemas below it are members.\n */\n readonly isUnionReused: boolean;\n}\n\n/** What the search for conflicts reads: the document and its `allOf` children by parent. */\ninterface ConflictSearch extends ConflictOptions {\n readonly document: unknown;\n readonly children: ReadonlyMap<string, readonly Child[]>;\n}\n\n/** The `allOf` children of the owner that inherit its discriminator. */\nfunction inheritingChildren(owner: Owner, search: ConflictSearch): readonly Child[] {\n const children = search.children.get(owner.pointer) ?? [];\n const resolve = (ref: string) => resolveLocalRef(search.document, ref);\n const union = search.isUnionReused ? unionAt(owner.pointer, resolve) : undefined;\n return union === undefined\n ? children\n : children.filter((child) => isUnionMember(union, child.ref, resolve));\n}\n\n/** The component schemas whose `allOf` holds a `$ref`, by that `$ref`, in document order. */\nfunction allOfChildren(document: unknown): Map<string, Child[]> {\n const schemas = resolveLocalRef(document, \"#/components/schemas\");\n const children = new Map<string, Child[]>();\n for (const [name, schema] of Object.entries(isObject(schemas) ? schemas : {})) {\n if (!isObject(schema)) {\n continue;\n }\n const child = { ref: `${COMPONENT_SCHEMAS}${escapePointerSegment(name)}`, schema };\n for (const parent of new Set(refsOf(schema.allOf))) {\n const siblings = children.get(parent) ?? [];\n siblings.push(child);\n children.set(parent, siblings);\n }\n }\n return children;\n}\n\n/** Whether a schema defines a discriminator of the property itself: it is the owner below. */\nfunction ownsProperty(schema: JsonObject, propertyName: string): boolean {\n const discriminator = schema.discriminator;\n return isObject(discriminator) && discriminator.propertyName === propertyName;\n}\n\n/**\n * Component schemas that inherit the owner through `allOf`, also through a chain\n * (`Lion: { allOf: [Cat] }`, `Cat: { allOf: [Pet] }`). Each parent on the way is left out of the\n * member's values, as its type omits the property. A schema with its own discriminator of the\n * property is a member, but the schemas below it are its own members.\n */\nfunction inheritingMembers(owner: Owner, search: ConflictSearch): Member[] {\n const found: Member[] = [];\n const visited = new Set([owner.pointer]);\n const parents: Member[] = [{ ref: owner.pointer, skipped: new Set([owner.pointer]) }];\n for (let parent = parents.shift(); parent !== undefined; parent = parents.shift()) {\n const children =\n parent.ref === owner.pointer\n ? inheritingChildren(owner, search)\n : (search.children.get(parent.ref) ?? []);\n for (const child of children) {\n if (visited.has(child.ref)) {\n continue;\n }\n visited.add(child.ref);\n found.push({ ref: child.ref, skipped: parent.skipped });\n if (!ownsProperty(child.schema, owner.propertyName)) {\n parents.push({ ref: child.ref, skipped: new Set([...parent.skipped, child.ref]) });\n }\n }\n }\n return found;\n}\n\n/** The members of an owner, each once: the listed and mapped ones, then the inheriting ones. */\nfunction membersOf(owner: Owner, search: ConflictSearch): Member[] {\n const listed = owner.memberRefs.map((ref) => ({ ref, skipped: new Set([owner.pointer]) }));\n const members = new Map<string, Member>();\n for (const member of [...listed, ...inheritingMembers(owner, search)]) {\n if (!members.has(member.ref)) {\n members.set(member.ref, member);\n }\n }\n return [...members.values()];\n}\n\nfunction memberValues(owner: Owner, member: string): { values: string[]; isImplicit: boolean } {\n const values = Object.entries(owner.mapping)\n .filter(([, target]) => typeof target === \"string\" && mappingTarget(target) === member)\n .map(([key]) => key);\n const name = parseRefPointer(member).pop() ?? \"\";\n return values.length > 0 ? { values, isImplicit: false } : { values: [name], isImplicit: true };\n}\n\nfunction conflictOf(owner: Owner, { ref: member, skipped }: Member, document: unknown) {\n // The owner's own property is left out of an inheriting member's type (`Omit`).\n const allowed = admittedPropertyValues(\n resolveLocalRef(document, member),\n owner.propertyName,\n document,\n skipped,\n );\n const { values, isImplicit } = memberValues(owner, member);\n if (allowed === null || values.some((value) => allowed.has(value))) {\n return null;\n }\n const { pointer, propertyName } = owner;\n return { member, owner: pointer, propertyName, values, allowed: [...allowed], isImplicit };\n}\n\n/** The conflicts of the document, one per member and value list, in document order. */\nexport function findDiscriminatorValueConflicts(\n document: unknown,\n options: ConflictOptions = { isUnionReused: false },\n): readonly DiscriminatorValueConflict[] {\n const conflicts = new Map<string, DiscriminatorValueConflict>();\n const search = { ...options, document, children: allOfChildren(document) };\n for (const owner of ownersIn(document)) {\n for (const member of membersOf(owner, search)) {\n const conflict = conflictOf(owner, member, document);\n const key = JSON.stringify([member.ref, conflict?.propertyName, conflict?.values]);\n if (conflict !== null && !conflicts.has(key)) {\n conflicts.set(key, conflict);\n }\n }\n }\n return [...conflicts.values()];\n}\n"],"names":[],"mappings":";;;;AA4BA,MAAM,iBAAA,GAAoB,uBAAA;AAE1B,SAAS,SAAS,KAAA,EAAqC;AACrD,EAAA,OAAO,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,QAAQ,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC5E;AASA,SAAS,OAAO,IAAA,EAAyB;AACvC,EAAA,OAAA,CAAQ,MAAM,OAAA,CAAQ,IAAI,CAAA,GAAI,IAAA,GAAO,EAAC,EAAG,OAAA;AAAA,IAAQ,CAAC,IAAA,KAChD,QAAA,CAAS,IAAI,CAAA,IAAK,OAAO,IAAA,CAAK,IAAA,KAAS,QAAA,GAAW,CAAC,IAAA,CAAK,IAAI,IAAI;AAAC,GACnE;AACF;AAEA,SAAS,cAAc,MAAA,EAAwB;AAC7C,EAAA,OAAO,MAAA,CAAO,UAAA,CAAW,GAAG,CAAA,GAAI,MAAA,GAAS,GAAG,iBAAiB,CAAA,EAAG,oBAAA,CAAqB,MAAM,CAAC,CAAA,CAAA;AAC9F;AAEA,SAAS,OAAA,CAAQ,MAAkB,OAAA,EAAqC;AACtE,EAAA,MAAM,gBAAgB,IAAA,CAAK,aAAA;AAC3B,EAAA,IAAI,CAAC,QAAA,CAAS,aAAa,KAAK,OAAO,aAAA,CAAc,iBAAiB,QAAA,EAAU;AAC9E,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,UAAU,QAAA,CAAS,aAAA,C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UAAU,OAAA,CAAQ,GAAA,CAAI,KAAK,CAAC,CAAA,EAAG;AAClE,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,EAAE,OAAA,EAAS,YAAA,EAAa,GAAI,KAAA;AAClC,EAAA,OAAO,EAAE,MAAA,EAAQ,KAAA,EAAO,OAAA,EAAS,YAAA,EAAc,MAAA,EAAQ,OAAA,EAAS,CAAC,GAAG,OAAO,CAAA,EAAG,UAAA,EAAW;AAC3F;AAGO,SAAS,gCACd,QAAA,EACA,OAAA,GAA2B,EAAE,aAAA,EAAe,OAAM,EACX;AACvC,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAwC;AAC9D,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,OAAA,EAAS,UAAU,QAAA,EAAU,aAAA,CAAc,QAAQ,CAAA,EAAE;AACzE,EAAA,KAAA,MAAW,KAAA,IAAS,QAAA,CAAS,QAAQ,CAAA,EAAG;AACtC,IAAA,KAAA,MAAW,MAAA,IAAU,SAAA,CAAU,KAAA,EAAO,MAAM,CAAA,EAAG;AAC7C,MAAA,MAAM,QAAA,GAAW,UAAA,CAAW,KAAA,EAAO,MAAA,EAAQ,QAAQ,CAAA;AACnD,MAAA,MAAM,GAAA,GAAM,IAAA,CAAK,SAAA,CAAU,CAAC,MAAA,CAAO,KAAK,QAAA,EAAU,YAAA,EAAc,QAAA,EAAU,MAAM,CAAC,CAAA;AACjF,MAAA,IAAI,aAAa,IAAA,IAAQ,CAAC,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA,EAAG;AAC5C,QAAA,SAAA,CAAU,GAAA,CAAI,KAAK,QAAQ,CAAA;AAAA,MAC7B;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,CAAC,GAAG,SAAA,CAAU,MAAA,EAAQ,CAAA;AAC/B;;"}
|
|
1
|
+
{"version":3,"file":"discriminator-conflicts.mjs","sources":["../../../src/domain/openapi/discriminator-conflicts.ts"],"sourcesContent":["import { appendAll } from \"../append-all.js\";\nimport { admittedPropertyValues, resolveLocalRef } from \"./admitted-values.js\";\nimport { isUnionMember, unionAt } from \"./discriminated-union.js\";\nimport {\n appendPointer,\n canonicalRef,\n escapePointerSegment,\n parseRefPointer,\n ROOT_POINTER,\n} from \"./json-pointer.js\";\n\n/**\n * Discriminator members whose discriminator value their own property does not allow. By the\n * Discriminator Object rule, a member that no `mapping` entry names has its schema name as the\n * value, so with a property `enum` (or `const`) that does not list it no value of the member\n * matches, and where the generator adds the value to the member the property type is `never`.\n * Each one gets a warning (CODING_PRINCIPLES §8.7).\n */\n\nexport interface DiscriminatorValueConflict {\n /** The member schema, such as `#/components/schemas/EpisodeObject`. */\n readonly member: string;\n /** The schema that has the Discriminator Object. */\n readonly owner: string;\n readonly propertyName: string;\n /** The values the discriminator gives the member: its mapping keys, or its name. */\n readonly values: readonly string[];\n /** The values the member's property allows. */\n readonly allowed: readonly (string | number | boolean | null)[];\n /** Whether no mapping entry names the member, so its value is its schema name. */\n readonly isImplicit: boolean;\n}\n\ntype JsonObject = Readonly<Record<string, unknown>>;\n\nconst COMPONENT_SCHEMAS = \"#/components/schemas/\";\n\nfunction isObject(value: unknown): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\ninterface Owner {\n readonly pointer: string;\n readonly propertyName: string;\n readonly mapping: Readonly<Record<string, string>>;\n readonly memberRefs: readonly string[];\n}\n\nfunction refsOf(list: unknown): string[] {\n return (Array.isArray(list) ? list : []).flatMap((item) =>\n isObject(item) && typeof item.$ref === \"string\" ? [item.$ref] : [],\n );\n}\n\n/** A mapping value as a canonical `$ref`: Redocly writes it percent-decoded (`canonicalRef`). */\nfunction mappingTarget(target: string): string {\n return target.startsWith(\"#\")\n ? canonicalRef(target)\n : `${COMPONENT_SCHEMAS}${escapePointerSegment(target)}`;\n}\n\nfunction ownerAt(node: JsonObject, pointer: () => string): Owner | null {\n const discriminator = node.discriminator;\n if (!isObject(discriminator) || typeof discriminator.propertyName !== \"string\") {\n return null;\n }\n const mapping = isObject(discriminator.mapping)\n ? (discriminator.mapping as Readonly<Record<string, string>>)\n : {};\n const mapped = Object.values(mapping)\n .filter((t) => typeof t === \"string\")\n .map(mappingTarget);\n const memberRefs = [...refsOf(node.oneOf), ...refsOf(node.anyOf), ...mapped];\n return { pointer: pointer(), propertyName: discriminator.propertyName, mapping, memberRefs };\n}\n\n/** A node of the document walk; the pointer is built only for the nodes that need it. */\ninterface Visit {\n readonly node: unknown;\n readonly key: string | null;\n readonly parent: Visit | null;\n}\n\nfunction pointerOf(visit: Visit): string {\n const segments: string[] = [];\n for (let current: Visit | null = visit; current?.key != null; current = current.parent) {\n segments.unshift(current.key);\n }\n return appendPointer(ROOT_POINTER, segments);\n}\n\nfunction childrenOf(visit: Visit): Visit[] {\n const { node } = visit;\n const entries: [string, unknown][] = Array.isArray(node)\n ? node.map((item, index) => [String(index), item])\n : isObject(node)\n ? Object.entries(node)\n : [];\n return entries.map(([key, child]) => ({ node: child, key, parent: visit }));\n}\n\n/**\n * Every Discriminator Object of the document, depth first, with its pointer. The walk keeps its\n * own stack, so a document nested past the call stack fails in the transform, as it did before.\n */\nfunction ownersIn(document: unknown): Owner[] {\n const found: Owner[] = [];\n const stack: Visit[] = [{ node: document, key: null, parent: null }];\n for (let visit = stack.pop(); visit !== undefined; visit = stack.pop()) {\n const owner = isObject(visit.node) ? ownerAt(visit.node, () => pointerOf(visit)) : null;\n if (owner !== null) {\n found.push(owner);\n }\n appendAll(stack, childrenOf(visit).reverse());\n }\n return found;\n}\n\n/** A member and the `$ref`s whose properties its type leaves out (`Omit` of its parents). */\ninterface Member {\n readonly ref: string;\n readonly skipped: ReadonlySet<string>;\n}\n\ninterface Child {\n readonly ref: string;\n readonly schema: JsonObject;\n}\n\n/** How the run types an `allOf` of a discriminated union. */\nexport interface ConflictOptions {\n /**\n * `allof-discriminated-union`: a schema that `allOf`s a union which does not contain it reuses\n * the union and gets no value, so neither it nor the schemas below it are members.\n */\n readonly isUnionReused: boolean;\n}\n\n/** What the search for conflicts reads: the document and its `allOf` children by parent. */\ninterface ConflictSearch extends ConflictOptions {\n readonly document: unknown;\n readonly children: ReadonlyMap<string, readonly Child[]>;\n}\n\n/** The `allOf` children of the owner that inherit its discriminator. */\nfunction inheritingChildren(owner: Owner, search: ConflictSearch): readonly Child[] {\n const children = search.children.get(owner.pointer) ?? [];\n const resolve = (ref: string) => resolveLocalRef(search.document, ref);\n const union = search.isUnionReused ? unionAt(owner.pointer, resolve) : undefined;\n return union === undefined\n ? children\n : children.filter((child) => isUnionMember(union, child.ref, resolve));\n}\n\n/** The component schemas whose `allOf` holds a `$ref`, by that `$ref`, in document order. */\nfunction allOfChildren(document: unknown): Map<string, Child[]> {\n const schemas = resolveLocalRef(document, \"#/components/schemas\");\n const children = new Map<string, Child[]>();\n for (const [name, schema] of Object.entries(isObject(schemas) ? schemas : {})) {\n if (!isObject(schema)) {\n continue;\n }\n const child = { ref: `${COMPONENT_SCHEMAS}${escapePointerSegment(name)}`, schema };\n for (const parent of new Set(refsOf(schema.allOf))) {\n const siblings = children.get(parent) ?? [];\n siblings.push(child);\n children.set(parent, siblings);\n }\n }\n return children;\n}\n\n/** Whether a schema defines a discriminator of the property itself: it is the owner below. */\nfunction ownsProperty(schema: JsonObject, propertyName: string): boolean {\n const discriminator = schema.discriminator;\n return isObject(discriminator) && discriminator.propertyName === propertyName;\n}\n\n/**\n * Component schemas that inherit the owner through `allOf`, also through a chain\n * (`Lion: { allOf: [Cat] }`, `Cat: { allOf: [Pet] }`). Each parent on the way is left out of the\n * member's values, as its type omits the property. A schema with its own discriminator of the\n * property is a member, but the schemas below it are its own members.\n */\nfunction inheritingMembers(owner: Owner, search: ConflictSearch): Member[] {\n const found: Member[] = [];\n const visited = new Set([owner.pointer]);\n const parents: Member[] = [{ ref: owner.pointer, skipped: new Set([owner.pointer]) }];\n for (let parent = parents.shift(); parent !== undefined; parent = parents.shift()) {\n const children =\n parent.ref === owner.pointer\n ? inheritingChildren(owner, search)\n : (search.children.get(parent.ref) ?? []);\n for (const child of children) {\n if (visited.has(child.ref)) {\n continue;\n }\n visited.add(child.ref);\n found.push({ ref: child.ref, skipped: parent.skipped });\n if (!ownsProperty(child.schema, owner.propertyName)) {\n parents.push({ ref: child.ref, skipped: new Set([...parent.skipped, child.ref]) });\n }\n }\n }\n return found;\n}\n\n/** The members of an owner, each once: the listed and mapped ones, then the inheriting ones. */\nfunction membersOf(owner: Owner, search: ConflictSearch): Member[] {\n const listed = owner.memberRefs.map((ref) => ({ ref, skipped: new Set([owner.pointer]) }));\n const members = new Map<string, Member>();\n for (const member of [...listed, ...inheritingMembers(owner, search)]) {\n // A member may be listed by a `$ref` and found by its pointer: both name it canonically.\n const key = canonicalRef(member.ref);\n if (!members.has(key)) {\n members.set(key, member);\n }\n }\n return [...members.values()];\n}\n\nfunction memberValues(owner: Owner, member: string): { values: string[]; isImplicit: boolean } {\n const values = Object.entries(owner.mapping)\n .filter(\n ([, target]) => typeof target === \"string\" && mappingTarget(target) === canonicalRef(member),\n )\n .map(([key]) => key);\n const name = parseRefPointer(member).pop() ?? \"\";\n return values.length > 0 ? { values, isImplicit: false } : { values: [name], isImplicit: true };\n}\n\nfunction conflictOf(owner: Owner, { ref: member, skipped }: Member, document: unknown) {\n // The owner's own property is left out of an inheriting member's type (`Omit`).\n const allowed = admittedPropertyValues(\n resolveLocalRef(document, member),\n owner.propertyName,\n document,\n skipped,\n );\n const { values, isImplicit } = memberValues(owner, member);\n if (allowed === null || values.some((value) => allowed.has(value))) {\n return null;\n }\n const { pointer, propertyName } = owner;\n return { member, owner: pointer, propertyName, values, allowed: [...allowed], isImplicit };\n}\n\n/** The conflicts of the document, one per member and value list, in document order. */\nexport function findDiscriminatorValueConflicts(\n document: unknown,\n options: ConflictOptions = { isUnionReused: false },\n): readonly DiscriminatorValueConflict[] {\n const conflicts = new Map<string, DiscriminatorValueConflict>();\n const search = { ...options, document, children: allOfChildren(document) };\n for (const owner of ownersIn(document)) {\n for (const member of membersOf(owner, search)) {\n const conflict = conflictOf(owner, member, document);\n const key = JSON.stringify([member.ref, conflict?.propertyName, conflict?.values]);\n if (conflict !== null && !conflicts.has(key)) {\n conflicts.set(key, conflict);\n }\n }\n }\n return [...conflicts.values()];\n}\n"],"names":[],"mappings":";;;;;AAmCA,MAAM,iBAAA,GAAoB,uBAAA;AAE1B,SAAS,SAAS,KAAA,EAAqC;AACrD,EAAA,OAAO,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,QAAQ,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC5E;AASA,SAAS,OAAO,IAAA,EAAyB;AACvC,EAAA,OAAA,CAAQ,MAAM,OAAA,CAAQ,IAAI,CAAA,GAAI,IAAA,GAAO,EAAC,EAAG,OAAA;AAAA,IAAQ,CAAC,IAAA,KAChD,QAAA,CAAS,IAAI,CAAA,IAAK,OAAO,IAAA,CAAK,IAAA,KAAS,QAAA,GAAW,CAAC,IAAA,CAAK,IAAI,IAAI;AAAC,GACnE;AACF;AAGA,SAAS,cAAc,MAAA,EAAwB;AAC7C,EAAA,OAAO,MAAA,CAAO,UAAA,CAAW,GAAG,CAAA,GACxB,YAAA,CAAa,MAAM,CAAA,GACnB,CAAA,EAAG,iBAAiB,CAAA,EAAG,oBAAA,CAAqB,MAAM,CAAC,CAAA,CAAA;AACzD;AAEA,SAAS,OAAA,CAAQ,MAAkB,OAAA,EAAqC;AACtE,EAAA,MAAM,gBAAgB,IAAA,CAAK,aAAA;AAC3B,EAAA,IAAI,CAAC,QAAA,CAAS,aAAa,KAAK,OAAO,aAAA,CAAc,iBAAiB,QAAA,EAAU;AAC9E,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,UAAU,QAAA,CAAS,aAAA,CAAc,OAAO,CAAA,GACzC,aAAA,CAAc,UACf,EAAC;AACL,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA,CACjC,MAAA,CAAO,CAAC,CAAA,KAAM,OAAO,CA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AACA,EAAA,MAAM,EAAE,OAAA,EAAS,YAAA,EAAa,GAAI,KAAA;AAClC,EAAA,OAAO,EAAE,MAAA,EAAQ,KAAA,EAAO,OAAA,EAAS,YAAA,EAAc,MAAA,EAAQ,OAAA,EAAS,CAAC,GAAG,OAAO,CAAA,EAAG,UAAA,EAAW;AAC3F;AAGO,SAAS,gCACd,QAAA,EACA,OAAA,GAA2B,EAAE,aAAA,EAAe,OAAM,EACX;AACvC,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAwC;AAC9D,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,OAAA,EAAS,UAAU,QAAA,EAAU,aAAA,CAAc,QAAQ,CAAA,EAAE;AACzE,EAAA,KAAA,MAAW,KAAA,IAAS,QAAA,CAAS,QAAQ,CAAA,EAAG;AACtC,IAAA,KAAA,MAAW,MAAA,IAAU,SAAA,CAAU,KAAA,EAAO,MAAM,CAAA,EAAG;AAC7C,MAAA,MAAM,QAAA,GAAW,UAAA,CAAW,KAAA,EAAO,MAAA,EAAQ,QAAQ,CAAA;AACnD,MAAA,MAAM,GAAA,GAAM,IAAA,CAAK,SAAA,CAAU,CAAC,MAAA,CAAO,KAAK,QAAA,EAAU,YAAA,EAAc,QAAA,EAAU,MAAM,CAAC,CAAA;AACjF,MAAA,IAAI,aAAa,IAAA,IAAQ,CAAC,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA,EAAG;AAC5C,QAAA,SAAA,CAAU,GAAA,CAAI,KAAK,QAAQ,CAAA;AAAA,MAC7B;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,CAAC,GAAG,SAAA,CAAU,MAAA,EAAQ,CAAA;AAC/B;;"}
|
|
@@ -8,7 +8,45 @@ function unescapePointerSegment(segment) {
|
|
|
8
8
|
return decodeURIComponent(segment.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
9
9
|
}
|
|
10
10
|
function escapePointerSegment(segment) {
|
|
11
|
-
return segment.replaceAll("~", "~0").replaceAll("/", "~1").replaceAll("%", "%25");
|
|
11
|
+
return segment.replaceAll("~", "~0").replaceAll("/", "~1").replaceAll("%", "%25").replaceAll("#", "%23");
|
|
12
|
+
}
|
|
13
|
+
const ROOT_POINTER = "#";
|
|
14
|
+
function appendPointer(base, segments) {
|
|
15
|
+
let pointer = pointerBase(base);
|
|
16
|
+
for (const segment of segments) {
|
|
17
|
+
if (segment !== void 0 && segment !== null && segment !== "") {
|
|
18
|
+
pointer = childPointer(pointer, String(segment));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return pointer;
|
|
22
|
+
}
|
|
23
|
+
function childPointer(pointer, key) {
|
|
24
|
+
return `${pointer}/${escapePointerSegment(key)}`;
|
|
25
|
+
}
|
|
26
|
+
function canonicalRef(ref) {
|
|
27
|
+
if (!ref.startsWith(`${ROOT_POINTER}/`)) {
|
|
28
|
+
return ref;
|
|
29
|
+
}
|
|
30
|
+
return appendPointer(ROOT_POINTER, refSegments(ref));
|
|
31
|
+
}
|
|
32
|
+
function refSegments(ref) {
|
|
33
|
+
try {
|
|
34
|
+
return parseRefPointer(ref);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (!(error instanceof URIError)) {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
return writtenSegments(ref);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function writtenSegments(ref) {
|
|
43
|
+
return ref.slice(ROOT_POINTER.length + 1).split("/").filter((segment) => segment.length > 0).map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
44
|
+
}
|
|
45
|
+
function pointerBase(base) {
|
|
46
|
+
if (base === void 0 || base === "") {
|
|
47
|
+
return ROOT_POINTER;
|
|
48
|
+
}
|
|
49
|
+
return base === ROOT_POINTER || base.startsWith(`${ROOT_POINTER}/`) ? base : createRef([base]);
|
|
12
50
|
}
|
|
13
51
|
function createRef(parts) {
|
|
14
52
|
let ref = "#";
|
|
@@ -25,6 +63,10 @@ function createRef(parts) {
|
|
|
25
63
|
return ref;
|
|
26
64
|
}
|
|
27
65
|
|
|
66
|
+
exports.ROOT_POINTER = ROOT_POINTER;
|
|
67
|
+
exports.appendPointer = appendPointer;
|
|
68
|
+
exports.canonicalRef = canonicalRef;
|
|
69
|
+
exports.childPointer = childPointer;
|
|
28
70
|
exports.createRef = createRef;
|
|
29
71
|
exports.escapePointerSegment = escapePointerSegment;
|
|
30
72
|
exports.parseRefPointer = parseRefPointer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-pointer.cjs","sources":["../../../src/domain/openapi/json-pointer.ts"],"sourcesContent":["/**\n * The JSON Pointer of a `$ref` as path segments, with the semantics of Redocly's `parseRef`, which\n * the original generator used: the part after the first `#/`, split at `/`, each segment unescaped\n * (`~1` → `/`, `~0` → `~`, then percent-decoding), and empty segments dropped.\n *\n * Throws URIError for a malformed percent escape, as the original does.\n */\nexport function parseRefPointer(ref: string): string[] {\n const [, pointer = \"\"] = ref.split(\"#/\");\n return pointer\n .split(\"/\")\n .map(unescapePointerSegment)\n .filter((segment) => segment.length > 0);\n}\n\nfunction unescapePointerSegment(segment: string): string {\n return decodeURIComponent(segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"));\n}\n\n/**\n * Escape one segment for a JSON Pointer in a `$ref` fragment: `~` → `~0
|
|
1
|
+
{"version":3,"file":"json-pointer.cjs","sources":["../../../src/domain/openapi/json-pointer.ts"],"sourcesContent":["/**\n * The JSON Pointer of a `$ref` as path segments, with the semantics of Redocly's `parseRef`, which\n * the original generator used: the part after the first `#/`, split at `/`, each segment unescaped\n * (`~1` → `/`, `~0` → `~`, then percent-decoding), and empty segments dropped.\n *\n * Throws URIError for a malformed percent escape, as the original does.\n */\nexport function parseRefPointer(ref: string): string[] {\n const [, pointer = \"\"] = ref.split(\"#/\");\n return pointer\n .split(\"/\")\n .map(unescapePointerSegment)\n .filter((segment) => segment.length > 0);\n}\n\nfunction unescapePointerSegment(segment: string): string {\n return decodeURIComponent(segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"));\n}\n\n/**\n * Escape one segment for a JSON Pointer in a `$ref` fragment: `~` → `~0` and `/` → `~1` (RFC 6901),\n * then `%` → `%25` and `#` → `%23`, the two characters of a key that a URI fragment cannot hold as\n * written (RFC 6901 §6, RFC 3986). Reading a pointer back percent-decodes it, so the original's\n * unescaped `%` threw URIError for `50%` and read `a%2Fb` as `a/b` (upstream #2251, #2828), and\n * reading starts at the first `#/`, so an unescaped key `a#` cut the pointer short.\n */\nexport function escapePointerSegment(segment: string): string {\n return segment\n .replaceAll(\"~\", \"~0\")\n .replaceAll(\"/\", \"~1\")\n .replaceAll(\"%\", \"%25\")\n .replaceAll(\"#\", \"%23\");\n}\n\n/** The pointer of the document root. */\nexport const ROOT_POINTER = \"#\";\n\n/** A raw pointer segment; a missing one (`undefined`, `null` or empty) is skipped. */\nexport type PointerSegment = string | number | null | undefined;\n\n/**\n * Extend the pointer `base` with raw segments: document keys, such as a path, a property name or a\n * media type, and array indexes. Each segment is escaped and never read as a `$ref`, so a key like\n * `#/%41` stays one segment and reads back unchanged with {@link parseRefPointer}. A missing\n * segment, such as the absent `name` of a parameter, is skipped, as the original `createRef` did,\n * and an empty one too, because `parseRefPointer` drops it.\n */\nexport function appendPointer(\n base: string | undefined,\n segments: readonly PointerSegment[],\n): string {\n let pointer = pointerBase(base);\n for (const segment of segments) {\n if (segment !== undefined && segment !== null && segment !== \"\") {\n pointer = childPointer(pointer, String(segment));\n }\n }\n return pointer;\n}\n\n/**\n * The pointer of the child `key` of the node at `pointer`, with `key` escaped. Unlike\n * {@link appendPointer}, an empty key is a child too: a document walk names every key it visits.\n */\nexport function childPointer(pointer: string, key: string): string {\n return `${pointer}/${escapePointerSegment(key)}`;\n}\n\n/**\n * A local `$ref` or `mapping` value in the form {@link appendPointer} builds, so that pointers\n * compare as text whatever escapes the document chose: `.../a#b` and `.../a%23b` are both\n * `.../a%23b`. Redocly writes a bundled `mapping` value percent-decoded, which is no pointer for a\n * key with `%` (`.../50%`), so such a text is read as written. Any other text, such as an\n * external `$ref` or a bare schema name, is returned unchanged.\n */\nexport function canonicalRef(ref: string): string {\n if (!ref.startsWith(`${ROOT_POINTER}/`)) {\n return ref;\n }\n return appendPointer(ROOT_POINTER, refSegments(ref));\n}\n\nfunction refSegments(ref: string): string[] {\n try {\n return parseRefPointer(ref);\n } catch (error) {\n if (!(error instanceof URIError)) {\n throw error;\n }\n return writtenSegments(ref);\n }\n}\n\n/** The segments of a pointer that is not percent-encoded: only `~1` and `~0` are escapes. */\nfunction writtenSegments(ref: string): string[] {\n return ref\n .slice(ROOT_POINTER.length + 1)\n .split(\"/\")\n .filter((segment) => segment.length > 0)\n .map((segment) => segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"));\n}\n\n/**\n * A pointer (`#` or `#/...`) is kept as written; a missing base is the root. Any other text is a\n * `path` given to the exported transformers, such as `/items/{id}` or `other.yaml#/a`, which the\n * original read as a `createRef` part, so it is read the same way here.\n */\nfunction pointerBase(base: string | undefined): string {\n if (base === undefined || base === \"\") {\n return ROOT_POINTER;\n }\n return base === ROOT_POINTER || base.startsWith(`${ROOT_POINTER}/`) ? base : createRef([base]);\n}\n\n/**\n * Join parts into a local `$ref` (the original `createRef`, exported for 1.x by ADR-034). Empty\n * parts are skipped. A part that contains `#/` is parsed as a `$ref` and contributes its decoded\n * segments, so it throws URIError for a malformed percent escape; any other part is one segment.\n * Because of that parsing, the generator does not pass document keys here: it builds pointers\n * with {@link appendPointer}, which never parses a segment.\n */\nexport function createRef(parts: readonly PointerSegment[]): string {\n let ref = \"#\";\n for (const part of parts) {\n if (part === undefined || part === null || part === \"\") {\n continue;\n }\n const text = String(part);\n const segments = parseRefPointer(text);\n for (const segment of segments.length > 0 ? segments : [text]) {\n ref += `/${escapePointerSegment(segment)}`;\n }\n }\n return ref;\n}\n"],"names":[],"mappings":";;AAOO,SAAS,gBAAgB,GAAA,EAAuB;AACrD,EAAA,MAAM,GA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ACtD,MAAA;AAAA,IACF;AACA,IAAA,MAAM,IAAA,GAAO,OAAO,IAAI,CAAA;AACxB,IAAA,MAAM,QAAA,GAAW,gBAAgB,IAAI,CAAA;AACrC,IAAA,KAAA,MAAW,WAAW,QAAA,CAAS,MAAA,GAAS,IAAI,QAAA,GAAW,CAAC,IAAI,CAAA,EAAG;AAC7D,MAAA,GAAA,IAAO,CAAA,CAAA,EAAI,oBAAA,CAAqB,OAAO,CAAC,CAAA,CAAA;AAAA,IAC1C;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT;;;;;;;;"}
|
|
@@ -6,7 +6,45 @@ function unescapePointerSegment(segment) {
|
|
|
6
6
|
return decodeURIComponent(segment.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
7
7
|
}
|
|
8
8
|
function escapePointerSegment(segment) {
|
|
9
|
-
return segment.replaceAll("~", "~0").replaceAll("/", "~1").replaceAll("%", "%25");
|
|
9
|
+
return segment.replaceAll("~", "~0").replaceAll("/", "~1").replaceAll("%", "%25").replaceAll("#", "%23");
|
|
10
|
+
}
|
|
11
|
+
const ROOT_POINTER = "#";
|
|
12
|
+
function appendPointer(base, segments) {
|
|
13
|
+
let pointer = pointerBase(base);
|
|
14
|
+
for (const segment of segments) {
|
|
15
|
+
if (segment !== void 0 && segment !== null && segment !== "") {
|
|
16
|
+
pointer = childPointer(pointer, String(segment));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return pointer;
|
|
20
|
+
}
|
|
21
|
+
function childPointer(pointer, key) {
|
|
22
|
+
return `${pointer}/${escapePointerSegment(key)}`;
|
|
23
|
+
}
|
|
24
|
+
function canonicalRef(ref) {
|
|
25
|
+
if (!ref.startsWith(`${ROOT_POINTER}/`)) {
|
|
26
|
+
return ref;
|
|
27
|
+
}
|
|
28
|
+
return appendPointer(ROOT_POINTER, refSegments(ref));
|
|
29
|
+
}
|
|
30
|
+
function refSegments(ref) {
|
|
31
|
+
try {
|
|
32
|
+
return parseRefPointer(ref);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (!(error instanceof URIError)) {
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
return writtenSegments(ref);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function writtenSegments(ref) {
|
|
41
|
+
return ref.slice(ROOT_POINTER.length + 1).split("/").filter((segment) => segment.length > 0).map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
42
|
+
}
|
|
43
|
+
function pointerBase(base) {
|
|
44
|
+
if (base === void 0 || base === "") {
|
|
45
|
+
return ROOT_POINTER;
|
|
46
|
+
}
|
|
47
|
+
return base === ROOT_POINTER || base.startsWith(`${ROOT_POINTER}/`) ? base : createRef([base]);
|
|
10
48
|
}
|
|
11
49
|
function createRef(parts) {
|
|
12
50
|
let ref = "#";
|
|
@@ -23,5 +61,5 @@ function createRef(parts) {
|
|
|
23
61
|
return ref;
|
|
24
62
|
}
|
|
25
63
|
|
|
26
|
-
export { createRef, escapePointerSegment, parseRefPointer };
|
|
64
|
+
export { ROOT_POINTER, appendPointer, canonicalRef, childPointer, createRef, escapePointerSegment, parseRefPointer };
|
|
27
65
|
//# sourceMappingURL=json-pointer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-pointer.mjs","sources":["../../../src/domain/openapi/json-pointer.ts"],"sourcesContent":["/**\n * The JSON Pointer of a `$ref` as path segments, with the semantics of Redocly's `parseRef`, which\n * the original generator used: the part after the first `#/`, split at `/`, each segment unescaped\n * (`~1` → `/`, `~0` → `~`, then percent-decoding), and empty segments dropped.\n *\n * Throws URIError for a malformed percent escape, as the original does.\n */\nexport function parseRefPointer(ref: string): string[] {\n const [, pointer = \"\"] = ref.split(\"#/\");\n return pointer\n .split(\"/\")\n .map(unescapePointerSegment)\n .filter((segment) => segment.length > 0);\n}\n\nfunction unescapePointerSegment(segment: string): string {\n return decodeURIComponent(segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"));\n}\n\n/**\n * Escape one segment for a JSON Pointer in a `$ref` fragment: `~` → `~0
|
|
1
|
+
{"version":3,"file":"json-pointer.mjs","sources":["../../../src/domain/openapi/json-pointer.ts"],"sourcesContent":["/**\n * The JSON Pointer of a `$ref` as path segments, with the semantics of Redocly's `parseRef`, which\n * the original generator used: the part after the first `#/`, split at `/`, each segment unescaped\n * (`~1` → `/`, `~0` → `~`, then percent-decoding), and empty segments dropped.\n *\n * Throws URIError for a malformed percent escape, as the original does.\n */\nexport function parseRefPointer(ref: string): string[] {\n const [, pointer = \"\"] = ref.split(\"#/\");\n return pointer\n .split(\"/\")\n .map(unescapePointerSegment)\n .filter((segment) => segment.length > 0);\n}\n\nfunction unescapePointerSegment(segment: string): string {\n return decodeURIComponent(segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"));\n}\n\n/**\n * Escape one segment for a JSON Pointer in a `$ref` fragment: `~` → `~0` and `/` → `~1` (RFC 6901),\n * then `%` → `%25` and `#` → `%23`, the two characters of a key that a URI fragment cannot hold as\n * written (RFC 6901 §6, RFC 3986). Reading a pointer back percent-decodes it, so the original's\n * unescaped `%` threw URIError for `50%` and read `a%2Fb` as `a/b` (upstream #2251, #2828), and\n * reading starts at the first `#/`, so an unescaped key `a#` cut the pointer short.\n */\nexport function escapePointerSegment(segment: string): string {\n return segment\n .replaceAll(\"~\", \"~0\")\n .replaceAll(\"/\", \"~1\")\n .replaceAll(\"%\", \"%25\")\n .replaceAll(\"#\", \"%23\");\n}\n\n/** The pointer of the document root. */\nexport const ROOT_POINTER = \"#\";\n\n/** A raw pointer segment; a missing one (`undefined`, `null` or empty) is skipped. */\nexport type PointerSegment = string | number | null | undefined;\n\n/**\n * Extend the pointer `base` with raw segments: document keys, such as a path, a property name or a\n * media type, and array indexes. Each segment is escaped and never read as a `$ref`, so a key like\n * `#/%41` stays one segment and reads back unchanged with {@link parseRefPointer}. A missing\n * segment, such as the absent `name` of a parameter, is skipped, as the original `createRef` did,\n * and an empty one too, because `parseRefPointer` drops it.\n */\nexport function appendPointer(\n base: string | undefined,\n segments: readonly PointerSegment[],\n): string {\n let pointer = pointerBase(base);\n for (const segment of segments) {\n if (segment !== undefined && segment !== null && segment !== \"\") {\n pointer = childPointer(pointer, String(segment));\n }\n }\n return pointer;\n}\n\n/**\n * The pointer of the child `key` of the node at `pointer`, with `key` escaped. Unlike\n * {@link appendPointer}, an empty key is a child too: a document walk names every key it visits.\n */\nexport function childPointer(pointer: string, key: string): string {\n return `${pointer}/${escapePointerSegment(key)}`;\n}\n\n/**\n * A local `$ref` or `mapping` value in the form {@link appendPointer} builds, so that pointers\n * compare as text whatever escapes the document chose: `.../a#b` and `.../a%23b` are both\n * `.../a%23b`. Redocly writes a bundled `mapping` value percent-decoded, which is no pointer for a\n * key with `%` (`.../50%`), so such a text is read as written. Any other text, such as an\n * external `$ref` or a bare schema name, is returned unchanged.\n */\nexport function canonicalRef(ref: string): string {\n if (!ref.startsWith(`${ROOT_POINTER}/`)) {\n return ref;\n }\n return appendPointer(ROOT_POINTER, refSegments(ref));\n}\n\nfunction refSegments(ref: string): string[] {\n try {\n return parseRefPointer(ref);\n } catch (error) {\n if (!(error instanceof URIError)) {\n throw error;\n }\n return writtenSegments(ref);\n }\n}\n\n/** The segments of a pointer that is not percent-encoded: only `~1` and `~0` are escapes. */\nfunction writtenSegments(ref: string): string[] {\n return ref\n .slice(ROOT_POINTER.length + 1)\n .split(\"/\")\n .filter((segment) => segment.length > 0)\n .map((segment) => segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"));\n}\n\n/**\n * A pointer (`#` or `#/...`) is kept as written; a missing base is the root. Any other text is a\n * `path` given to the exported transformers, such as `/items/{id}` or `other.yaml#/a`, which the\n * original read as a `createRef` part, so it is read the same way here.\n */\nfunction pointerBase(base: string | undefined): string {\n if (base === undefined || base === \"\") {\n return ROOT_POINTER;\n }\n return base === ROOT_POINTER || base.startsWith(`${ROOT_POINTER}/`) ? base : createRef([base]);\n}\n\n/**\n * Join parts into a local `$ref` (the original `createRef`, exported for 1.x by ADR-034). Empty\n * parts are skipped. A part that contains `#/` is parsed as a `$ref` and contributes its decoded\n * segments, so it throws URIError for a malformed percent escape; any other part is one segment.\n * Because of that parsing, the generator does not pass document keys here: it builds pointers\n * with {@link appendPointer}, which never parses a segment.\n */\nexport function createRef(parts: readonly PointerSegment[]): string {\n let ref = \"#\";\n for (const part of parts) {\n if (part === undefined || part === null || part === \"\") {\n continue;\n }\n const text = String(part);\n const segments = parseRefPointer(text);\n for (const segment of segments.length > 0 ? segments : [text]) {\n ref += `/${escapePointerSegment(segment)}`;\n }\n }\n return ref;\n}\n"],"names":[],"mappings":"AAOO,SAAS,gBAAgB,GAAA,EAAuB;AACrD,EAAA,MAAM,GAAG,OAAA,GAAU,EAAE,CAAA,GAAI,GAAA,CAAI,MAAM,IAAI,CAAA;AACvC,EAAA,OAAO,OAAA,CACJ,KAAA,CAAM,GAAG,CAAA,CACT,GAAA,CAAI,sBAAsB,CAAA,CAC1B,MAAA,CAAO,CAAC,OAAA,KAAY,OAAA,CAAQ,MAAA,GAAS,CAAC,CAAA;AAC3C;AAEA,SAAS,uBAAuB,OAAA,EAAyB;AACvD,EAAA,OAAO,kBAAA,CAAmB,QAAQ,UAAA,CAAW,IAAA,EAAM,GAAG,CAAA,CAAE,UAAA,CAAW,IAAA,EAAM,GAAG,CAAC,CAAA;AAC/E;AASO,SAAS,qBAAqB,OAAA,EAAyB;AAC5D,EAAA,OAAO,OAAA,CACJ,UAAA,CAAW,GAAA,EAAK,IAAI,EACpB,UAAA,CAAW,GAAA,EAAK,IAAI,CAAA,CACpB,WAAW,GAAA,EAAK,KAAK,CAAA,CACrB,UAAA,CAAW,KAAK,KAAK,CAAA;AAC1B;AAGO,MAAM,YAAA,GAAe;AAYrB,SAAS,aAAA,CACd,MACA,QAAA,EACQ;AACR,EAAA,IAAI,OAAA,GAAU,YAAY,IAAI,CAAA;AAC9B,EAAA,KAAA,MAAW,WAAW,QAA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,EAAkC;AACrD,EAAA,IAAI,IAAA,KAAS,MAAA,IAAa,IAAA,KAAS,EAAA,EAAI;AACrC,IAAA,OAAO,YAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAA,KAAS,YAAA,IAAgB,IAAA,CAAK,UAAA,CAAW,CAAA,EAAG,YAAY,CAAA,CAAA,CAAG,CAAA,GAAI,IAAA,GAAO,SAAA,CAAU,CAAC,IAAI,CAAC,CAAA;AAC/F;AASO,SAAS,UAAU,KAAA,EAA0C;AAClE,EAAA,IAAI,GAAA,GAAM,GAAA;AACV,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,IAAI,IAAA,KAAS,MAAA,IAAa,IAAA,KAAS,IAAA,IAAQ,SAAS,EAAA,EAAI;AACtD,MAAA;AAAA,IACF;AACA,IAAA,MAAM,IAAA,GAAO,OAAO,IAAI,CAAA;AACxB,IAAA,MAAM,QAAA,GAAW,gBAAgB,IAAI,CAAA;AACrC,IAAA,KAAA,MAAW,WAAW,QAAA,CAAS,MAAA,GAAS,IAAI,QAAA,GAAW,CAAC,IAAI,CAAA,EAAG;AAC7D,MAAA,GAAA,IAAO,CAAA,CAAA,EAAI,oBAAA,CAAqB,OAAO,CAAC,CAAA,CAAA;AAAA,IAC1C;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const SCHEMA_DIALECTS = {
|
|
4
|
+
OPENAPI_3_0: "openapi-3.0",
|
|
5
|
+
JSON_SCHEMA_2020_12: "json-schema-2020-12"
|
|
6
|
+
};
|
|
7
|
+
const OPENAPI_3_0_RE = /^3\.0(?:\.|$)/;
|
|
8
|
+
function schemaDialectOf(openapiVersion) {
|
|
9
|
+
const isOpenApi30 = typeof openapiVersion !== "string" || OPENAPI_3_0_RE.test(openapiVersion);
|
|
10
|
+
return isOpenApi30 ? SCHEMA_DIALECTS.OPENAPI_3_0 : SCHEMA_DIALECTS.JSON_SCHEMA_2020_12;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.SCHEMA_DIALECTS = SCHEMA_DIALECTS;
|
|
14
|
+
exports.schemaDialectOf = schemaDialectOf;
|
|
15
|
+
//# sourceMappingURL=schema-dialect.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-dialect.cjs","sources":["../../../src/domain/openapi/schema-dialect.ts"],"sourcesContent":["/**\n * The schema dialect of a document. OpenAPI 3.0 Schema Objects ignore every keyword next to a\n * `$ref` (OpenAPI 3.0.3, Reference Object). OpenAPI 3.1 and 3.2 use JSON Schema 2020-12, where a\n * `$ref` is one keyword among the others, and all of them apply (JSON Schema Core §8.2.3.1).\n */\nexport const SCHEMA_DIALECTS = {\n OPENAPI_3_0: \"openapi-3.0\",\n JSON_SCHEMA_2020_12: \"json-schema-2020-12\",\n} as const;\n\nexport type SchemaDialect = (typeof SCHEMA_DIALECTS)[keyof typeof SCHEMA_DIALECTS];\n\nconst OPENAPI_3_0_RE = /^3\\.0(?:\\.|$)/;\n\n/**\n * The dialect of a document's `openapi` version. Without a version (a schema passed to a\n * transformer on its own) it is OpenAPI 3.0, which keeps the output the original gives.\n */\nexport function schemaDialectOf(openapiVersion: unknown): SchemaDialect {\n const isOpenApi30 = typeof openapiVersion !== \"string\" || OPENAPI_3_0_RE.test(openapiVersion);\n return isOpenApi30 ? SCHEMA_DIALECTS.OPENAPI_3_0 : SCHEMA_DIALECTS.JSON_SCHEMA_2020_12;\n}\n"],"names":[],"mappings":";;AAKO,MAAM,eAAA,GAAkB;AAAA,EAC7B,WAAA,EAAa,aAAA;AAAA,EACb,mBAAA,EAAqB;AACvB;AAIA,MAAM,cAAA,GAAiB,eAAA;AAMhB,SAAS,gBAAgB,cAAA,EAAwC;AACtE,EAAA,MAAM,cAAc,OAAO,cAAA,KAAmB,QAAA,IAAY,cAAA,CAAe,KAAK,cAAc,CAAA;AAC5F,EAAA,OAAO,WAAA,GAAc,eAAA,CAAgB,WAAA,GAAc,eAAA,CAAgB,mBAAA;AACrE;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const SCHEMA_DIALECTS = {
|
|
2
|
+
OPENAPI_3_0: "openapi-3.0",
|
|
3
|
+
JSON_SCHEMA_2020_12: "json-schema-2020-12"
|
|
4
|
+
};
|
|
5
|
+
const OPENAPI_3_0_RE = /^3\.0(?:\.|$)/;
|
|
6
|
+
function schemaDialectOf(openapiVersion) {
|
|
7
|
+
const isOpenApi30 = typeof openapiVersion !== "string" || OPENAPI_3_0_RE.test(openapiVersion);
|
|
8
|
+
return isOpenApi30 ? SCHEMA_DIALECTS.OPENAPI_3_0 : SCHEMA_DIALECTS.JSON_SCHEMA_2020_12;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { SCHEMA_DIALECTS, schemaDialectOf };
|
|
12
|
+
//# sourceMappingURL=schema-dialect.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-dialect.mjs","sources":["../../../src/domain/openapi/schema-dialect.ts"],"sourcesContent":["/**\n * The schema dialect of a document. OpenAPI 3.0 Schema Objects ignore every keyword next to a\n * `$ref` (OpenAPI 3.0.3, Reference Object). OpenAPI 3.1 and 3.2 use JSON Schema 2020-12, where a\n * `$ref` is one keyword among the others, and all of them apply (JSON Schema Core §8.2.3.1).\n */\nexport const SCHEMA_DIALECTS = {\n OPENAPI_3_0: \"openapi-3.0\",\n JSON_SCHEMA_2020_12: \"json-schema-2020-12\",\n} as const;\n\nexport type SchemaDialect = (typeof SCHEMA_DIALECTS)[keyof typeof SCHEMA_DIALECTS];\n\nconst OPENAPI_3_0_RE = /^3\\.0(?:\\.|$)/;\n\n/**\n * The dialect of a document's `openapi` version. Without a version (a schema passed to a\n * transformer on its own) it is OpenAPI 3.0, which keeps the output the original gives.\n */\nexport function schemaDialectOf(openapiVersion: unknown): SchemaDialect {\n const isOpenApi30 = typeof openapiVersion !== \"string\" || OPENAPI_3_0_RE.test(openapiVersion);\n return isOpenApi30 ? SCHEMA_DIALECTS.OPENAPI_3_0 : SCHEMA_DIALECTS.JSON_SCHEMA_2020_12;\n}\n"],"names":[],"mappings":"AAKO,MAAM,eAAA,GAAkB;AAAA,EAC7B,WAAA,EAAa,aAAA;AAAA,EACb,mBAAA,EAAqB;AACvB;AAIA,MAAM,cAAA,GAAiB,eAAA;AAMhB,SAAS,gBAAgB,cAAA,EAAwC;AACtE,EAAA,MAAM,cAAc,OAAO,cAAA,KAAmB,QAAA,IAAY,cAAA,CAAe,KAAK,cAAc,CAAA;AAC5F,EAAA,OAAO,WAAA,GAAc,eAAA,CAAgB,WAAA,GAAc,eAAA,CAAgB,mBAAA;AACrE;;"}
|
|
@@ -31,7 +31,7 @@ function locatedParameters(document, parameters, segments) {
|
|
|
31
31
|
}
|
|
32
32
|
return parameters.flatMap((entry, index) => {
|
|
33
33
|
const parameter = resolveLocal(document, entry);
|
|
34
|
-
const pointer = jsonPointer.
|
|
34
|
+
const pointer = jsonPointer.appendPointer(jsonPointer.ROOT_POINTER, [...segments, index]);
|
|
35
35
|
return isObject(parameter) ? [{ pointer, parameter }] : [];
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unsupported-features.cjs","sources":["../../../src/domain/openapi/unsupported-features.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"unsupported-features.cjs","sources":["../../../src/domain/openapi/unsupported-features.ts"],"sourcesContent":["import { appendPointer, parseRefPointer, ROOT_POINTER } from \"./json-pointer.js\";\nimport { QUERYSTRING_LOCATION } from \"./parameter-object.js\";\nimport { type PathItemObject, pathItemOperations } from \"./path-item-object.js\";\n\n/**\n * OpenAPI 3.2 uses that the generated types leave out, so each one gets a warning. The 3.2\n * features are typed (ADR-020); what is left is an `in: querystring` parameter next to\n * `in: query` parameters of the same operation, which 3.2 does not allow: the `query`\n * parameters keep their types and the `querystring` parameter is not in the output.\n */\nexport const UnsupportedFeature = {\n QUERYSTRING_NEXT_TO_QUERY: \"querystring\",\n} as const;\nexport type UnsupportedFeature = (typeof UnsupportedFeature)[keyof typeof UnsupportedFeature];\n\n/** One place in the document that uses a feature the output leaves out. */\nexport interface UnsupportedFeatureUse {\n readonly feature: UnsupportedFeature;\n /** A JSON Pointer to the object that has the feature's key, such as `#/paths/~1items`. */\n readonly pointer: string;\n}\n\nconst QUERY_LOCATION = \"query\";\nconst LOCAL_REF_PREFIX = \"#/\";\n\ntype JsonObject = Readonly<Record<string, unknown>>;\n\nfunction isObject(value: unknown): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The value at a local `$ref` (`#/...`) of the document; null for other or broken `$ref`s. */\nfunction resolveLocal(document: JsonObject, value: unknown): unknown {\n if (!isObject(value) || typeof value.$ref !== \"string\") {\n return value;\n }\n if (!value.$ref.startsWith(LOCAL_REF_PREFIX)) {\n return null;\n }\n let node: unknown = document;\n for (const segment of parseRefPointer(value.$ref)) {\n node = isObject(node) || Array.isArray(node) ? (node as JsonObject)[segment] : undefined;\n }\n return node ?? null;\n}\n\n/** A parameter where it is written, with the object its `$ref` points to. */\ninterface LocatedParameter {\n readonly pointer: string;\n readonly parameter: JsonObject;\n}\n\nfunction locatedParameters(\n document: JsonObject,\n parameters: unknown,\n segments: readonly string[],\n): LocatedParameter[] {\n if (!Array.isArray(parameters)) {\n return [];\n }\n return parameters.flatMap((entry, index) => {\n const parameter = resolveLocal(document, entry);\n const pointer = appendPointer(ROOT_POINTER, [...segments, index]);\n return isObject(parameter) ? [{ pointer, parameter }] : [];\n });\n}\n\n/** Path item parameters, then the operation's, which replace those of the same `in` and name. */\nfunction mergedParameters(\n shared: readonly LocatedParameter[],\n own: readonly LocatedParameter[],\n): LocatedParameter[] {\n const byKey = new Map<string, LocatedParameter>();\n for (const located of [...shared, ...own]) {\n byKey.set(`${String(located.parameter.in)}-${String(located.parameter.name)}`, located);\n }\n return [...byKey.values()];\n}\n\n/** The `querystring` parameters of one operation that has `in: query` parameters as well. */\nfunction querystringPointers(parameters: readonly LocatedParameter[]): string[] {\n const hasQuery = parameters.some(({ parameter }) => parameter.in === QUERY_LOCATION);\n return hasQuery\n ? parameters\n .filter(({ parameter }) => parameter.in === QUERYSTRING_LOCATION)\n .map(({ pointer }) => pointer)\n : [];\n}\n\n/** Pointers of `querystring` parameters next to `query` ones in the operations of a path item. */\nfunction pathItemPointers(\n document: JsonObject,\n pathItem: JsonObject,\n segments: readonly string[],\n): string[] {\n const shared = locatedParameters(document, pathItem.parameters, [...segments, \"parameters\"]);\n return pathItemOperations(pathItem as PathItemObject).flatMap((entry) => {\n const operation = resolveLocal(document, entry.operation);\n if (!isObject(operation)) {\n return [];\n }\n const operationSegments = [...segments, ...entry.segments, \"parameters\"];\n const own = locatedParameters(document, operation.parameters, operationSegments);\n return querystringPointers(mergedParameters(shared, own));\n });\n}\n\nfunction pathItemsPointers(\n document: JsonObject,\n pathItems: unknown,\n root: readonly string[],\n): string[] {\n if (!isObject(pathItems)) {\n return [];\n }\n return Object.entries(pathItems).flatMap(([key, pathItem]) =>\n isObject(pathItem) ? pathItemPointers(document, pathItem, [...root, key]) : [],\n );\n}\n\n/**\n * Every use of a feature in `UnsupportedFeature`, once per pointer, in document order: `paths`,\n * then `webhooks`, then `components.pathItems`.\n */\nexport function findUnsupportedFeatures(document: unknown): UnsupportedFeatureUse[] {\n if (!isObject(document)) {\n return [];\n }\n const components = isObject(document.components) ? document.components : {};\n const pointers = [\n ...pathItemsPointers(document, document.paths, [\"paths\"]),\n ...pathItemsPointers(document, document.webhooks, [\"webhooks\"]),\n ...pathItemsPointers(document, components.pathItems, [\"components\", \"pathItems\"]),\n ];\n return [...new Set(pointers)].map((pointer) => ({\n feature: UnsupportedFeature.QUERYSTRING_NEXT_TO_QUERY,\n pointer,\n }));\n}\n"],"names":["parseRefPointer","appendPointer","ROOT_POINTER","QUERYSTRING_LOCATION","pathItemOperations"],"m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AW,CAAC;AAAA,GAClF;AACA,EAAA,OAAO,CAAC,GAAG,IAAI,GAAA,CAAI,QAAQ,CAAC,CAAA,CAAE,GAAA,CAAI,CAAC,OAAA,MAAa;AAAA,IAC9C,SAAS,kBAAA,CAAmB,yBAAA;AAAA,IAC5B;AAAA,GACF,CAAE,CAAA;AACJ;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { appendPointer, ROOT_POINTER, parseRefPointer } from './json-pointer.mjs';
|
|
2
2
|
import { QUERYSTRING_LOCATION } from './parameter-object.mjs';
|
|
3
3
|
import { pathItemOperations } from './path-item-object.mjs';
|
|
4
4
|
|
|
@@ -29,7 +29,7 @@ function locatedParameters(document, parameters, segments) {
|
|
|
29
29
|
}
|
|
30
30
|
return parameters.flatMap((entry, index) => {
|
|
31
31
|
const parameter = resolveLocal(document, entry);
|
|
32
|
-
const pointer =
|
|
32
|
+
const pointer = appendPointer(ROOT_POINTER, [...segments, index]);
|
|
33
33
|
return isObject(parameter) ? [{ pointer, parameter }] : [];
|
|
34
34
|
});
|
|
35
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unsupported-features.mjs","sources":["../../../src/domain/openapi/unsupported-features.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"unsupported-features.mjs","sources":["../../../src/domain/openapi/unsupported-features.ts"],"sourcesContent":["import { appendPointer, parseRefPointer, ROOT_POINTER } from \"./json-pointer.js\";\nimport { QUERYSTRING_LOCATION } from \"./parameter-object.js\";\nimport { type PathItemObject, pathItemOperations } from \"./path-item-object.js\";\n\n/**\n * OpenAPI 3.2 uses that the generated types leave out, so each one gets a warning. The 3.2\n * features are typed (ADR-020); what is left is an `in: querystring` parameter next to\n * `in: query` parameters of the same operation, which 3.2 does not allow: the `query`\n * parameters keep their types and the `querystring` parameter is not in the output.\n */\nexport const UnsupportedFeature = {\n QUERYSTRING_NEXT_TO_QUERY: \"querystring\",\n} as const;\nexport type UnsupportedFeature = (typeof UnsupportedFeature)[keyof typeof UnsupportedFeature];\n\n/** One place in the document that uses a feature the output leaves out. */\nexport interface UnsupportedFeatureUse {\n readonly feature: UnsupportedFeature;\n /** A JSON Pointer to the object that has the feature's key, such as `#/paths/~1items`. */\n readonly pointer: string;\n}\n\nconst QUERY_LOCATION = \"query\";\nconst LOCAL_REF_PREFIX = \"#/\";\n\ntype JsonObject = Readonly<Record<string, unknown>>;\n\nfunction isObject(value: unknown): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The value at a local `$ref` (`#/...`) of the document; null for other or broken `$ref`s. */\nfunction resolveLocal(document: JsonObject, value: unknown): unknown {\n if (!isObject(value) || typeof value.$ref !== \"string\") {\n return value;\n }\n if (!value.$ref.startsWith(LOCAL_REF_PREFIX)) {\n return null;\n }\n let node: unknown = document;\n for (const segment of parseRefPointer(value.$ref)) {\n node = isObject(node) || Array.isArray(node) ? (node as JsonObject)[segment] : undefined;\n }\n return node ?? null;\n}\n\n/** A parameter where it is written, with the object its `$ref` points to. */\ninterface LocatedParameter {\n readonly pointer: string;\n readonly parameter: JsonObject;\n}\n\nfunction locatedParameters(\n document: JsonObject,\n parameters: unknown,\n segments: readonly string[],\n): LocatedParameter[] {\n if (!Array.isArray(parameters)) {\n return [];\n }\n return parameters.flatMap((entry, index) => {\n const parameter = resolveLocal(document, entry);\n const pointer = appendPointer(ROOT_POINTER, [...segments, index]);\n return isObject(parameter) ? [{ pointer, parameter }] : [];\n });\n}\n\n/** Path item parameters, then the operation's, which replace those of the same `in` and name. */\nfunction mergedParameters(\n shared: readonly LocatedParameter[],\n own: readonly LocatedParameter[],\n): LocatedParameter[] {\n const byKey = new Map<string, LocatedParameter>();\n for (const located of [...shared, ...own]) {\n byKey.set(`${String(located.parameter.in)}-${String(located.parameter.name)}`, located);\n }\n return [...byKey.values()];\n}\n\n/** The `querystring` parameters of one operation that has `in: query` parameters as well. */\nfunction querystringPointers(parameters: readonly LocatedParameter[]): string[] {\n const hasQuery = parameters.some(({ parameter }) => parameter.in === QUERY_LOCATION);\n return hasQuery\n ? parameters\n .filter(({ parameter }) => parameter.in === QUERYSTRING_LOCATION)\n .map(({ pointer }) => pointer)\n : [];\n}\n\n/** Pointers of `querystring` parameters next to `query` ones in the operations of a path item. */\nfunction pathItemPointers(\n document: JsonObject,\n pathItem: JsonObject,\n segments: readonly string[],\n): string[] {\n const shared = locatedParameters(document, pathItem.parameters, [...segments, \"parameters\"]);\n return pathItemOperations(pathItem as PathItemObject).flatMap((entry) => {\n const operation = resolveLocal(document, entry.operation);\n if (!isObject(operation)) {\n return [];\n }\n const operationSegments = [...segments, ...entry.segments, \"parameters\"];\n const own = locatedParameters(document, operation.parameters, operationSegments);\n return querystringPointers(mergedParameters(shared, own));\n });\n}\n\nfunction pathItemsPointers(\n document: JsonObject,\n pathItems: unknown,\n root: readonly string[],\n): string[] {\n if (!isObject(pathItems)) {\n return [];\n }\n return Object.entries(pathItems).flatMap(([key, pathItem]) =>\n isObject(pathItem) ? pathItemPointers(document, pathItem, [...root, key]) : [],\n );\n}\n\n/**\n * Every use of a feature in `UnsupportedFeature`, once per pointer, in document order: `paths`,\n * then `webhooks`, then `components.pathItems`.\n */\nexport function findUnsupportedFeatures(document: unknown): UnsupportedFeatureUse[] {\n if (!isObject(document)) {\n return [];\n }\n const components = isObject(document.components) ? document.components : {};\n const pointers = [\n ...pathItemsPointers(document, document.paths, [\"paths\"]),\n ...pathItemsPointers(document, document.webhooks, [\"webhooks\"]),\n ...pathItemsPointers(document, components.pathItems, [\"components\", \"pathItems\"]),\n ];\n return [...new Set(pointers)].map((pointer) => ({\n feature: UnsupportedFeature.QUERYSTRING_NEXT_TO_QUERY,\n pointer,\n }));\n}\n"],"names":[],"mappings":";;;;AAUO,MAAM,kBAAA,GAAqB;AAAA,EAChC,yBAAA,EAA2B;AAC7B;AAUA,MAAM,cAAA,GAAiB,OAAA;AACvB,MAAM,gBAAA,GAAmB,IAAA;AA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