openapi-typesafe 1.0.0-rc.0 → 1.0.0-rc.2
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/README.md +12 -5
- package/dist/adapters/redocly-loader/configured-headers.cjs +32 -0
- package/dist/adapters/redocly-loader/configured-headers.cjs.map +1 -0
- package/dist/adapters/redocly-loader/configured-headers.mjs +30 -0
- package/dist/adapters/redocly-loader/configured-headers.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-config-source.cjs +21 -2
- package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-config-source.mjs +22 -3
- package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +34 -11
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +33 -10
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +37 -4
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +37 -4
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-resolution-check.cjs +191 -0
- package/dist/adapters/redocly-loader/ref-resolution-check.cjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-resolution-check.mjs +189 -0
- package/dist/adapters/redocly-loader/ref-resolution-check.mjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-resolution-steps.cjs +73 -0
- package/dist/adapters/redocly-loader/ref-resolution-steps.cjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-resolution-steps.mjs +60 -0
- package/dist/adapters/redocly-loader/ref-resolution-steps.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +41 -14
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -14
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +23 -5
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +23 -5
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +9 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +9 -1
- 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/adapters/type-ast-bridge/ir-to-typescript.cjs +5 -1
- package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -1
- package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +5 -1
- package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs.map +1 -1
- package/dist/adapters/type-ast-bridge/print-typescript.cjs.map +1 -1
- package/dist/adapters/type-ast-bridge/print-typescript.mjs.map +1 -1
- package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs +15 -9
- package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs.map +1 -1
- package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs +15 -9
- package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs.map +1 -1
- package/dist/api/default-ports.cjs +9 -0
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +8 -1
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs +25 -0
- package/dist/api/discriminator-conflict-warnings.cjs.map +1 -0
- package/dist/api/discriminator-conflict-warnings.mjs +23 -0
- package/dist/api/discriminator-conflict-warnings.mjs.map +1 -0
- package/dist/api/discriminator-enum-names.cjs +19 -0
- package/dist/api/discriminator-enum-names.cjs.map +1 -0
- package/dist/api/discriminator-enum-names.mjs +17 -0
- package/dist/api/discriminator-enum-names.mjs.map +1 -0
- package/dist/api/discriminator-enum-parent.cjs +59 -0
- package/dist/api/discriminator-enum-parent.cjs.map +1 -0
- package/dist/api/discriminator-enum-parent.mjs +57 -0
- package/dist/api/discriminator-enum-parent.mjs.map +1 -0
- package/dist/api/discriminator-enum.cjs +25 -0
- package/dist/api/discriminator-enum.cjs.map +1 -1
- package/dist/api/discriminator-enum.mjs +25 -1
- package/dist/api/discriminator-enum.mjs.map +1 -1
- package/dist/api/discriminator-other-owners.cjs +67 -0
- package/dist/api/discriminator-other-owners.cjs.map +1 -0
- package/dist/api/discriminator-other-owners.mjs +64 -0
- package/dist/api/discriminator-other-owners.mjs.map +1 -0
- package/dist/api/discriminator-patch.cjs +92 -0
- package/dist/api/discriminator-patch.cjs.map +1 -0
- package/dist/api/discriminator-patch.mjs +86 -0
- package/dist/api/discriminator-patch.mjs.map +1 -0
- package/dist/api/discriminator-scan.cjs +50 -65
- package/dist/api/discriminator-scan.cjs.map +1 -1
- package/dist/api/discriminator-scan.mjs +44 -59
- package/dist/api/discriminator-scan.mjs.map +1 -1
- package/dist/api/document-refs.cjs +15 -12
- package/dist/api/document-refs.cjs.map +1 -1
- package/dist/api/document-refs.mjs +15 -12
- package/dist/api/document-refs.mjs.map +1 -1
- package/dist/api/document-run.cjs +21 -4
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +22 -5
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/enum-values-warnings.cjs +16 -0
- package/dist/api/enum-values-warnings.cjs.map +1 -0
- package/dist/api/enum-values-warnings.mjs +14 -0
- package/dist/api/enum-values-warnings.mjs.map +1 -0
- package/dist/api/footer-sink.cjs +25 -2
- package/dist/api/footer-sink.cjs.map +1 -1
- package/dist/api/footer-sink.mjs +25 -2
- package/dist/api/footer-sink.mjs.map +1 -1
- package/dist/api/legacy-callback-warning.cjs +4 -1
- package/dist/api/legacy-callback-warning.cjs.map +1 -1
- package/dist/api/legacy-callback-warning.mjs +4 -1
- package/dist/api/legacy-callback-warning.mjs.map +1 -1
- package/dist/api/legacy-ts-helpers.cjs.map +1 -1
- package/dist/api/legacy-ts-helpers.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 +2 -1
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +3 -2
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/path-template-warnings.cjs +21 -0
- package/dist/api/path-template-warnings.cjs.map +1 -0
- package/dist/api/path-template-warnings.mjs +19 -0
- package/dist/api/path-template-warnings.mjs.map +1 -0
- package/dist/api/transform-context.cjs +4 -2
- package/dist/api/transform-context.cjs.map +1 -1
- package/dist/api/transform-context.mjs +4 -2
- package/dist/api/transform-context.mjs.map +1 -1
- package/dist/api/transform-schema.cjs +52 -3
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +53 -4
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/api/unsupported-feature-warnings.cjs +6 -1
- package/dist/api/unsupported-feature-warnings.cjs.map +1 -1
- package/dist/api/unsupported-feature-warnings.mjs +6 -1
- package/dist/api/unsupported-feature-warnings.mjs.map +1 -1
- package/dist/application/print/type-printer.cjs +7 -1
- package/dist/application/print/type-printer.cjs.map +1 -1
- package/dist/application/print/type-printer.mjs +7 -1
- package/dist/application/print/type-printer.mjs.map +1 -1
- package/dist/application/transform/document/assignability.cjs +144 -0
- package/dist/application/transform/document/assignability.cjs.map +1 -0
- package/dist/application/transform/document/assignability.mjs +138 -0
- package/dist/application/transform/document/assignability.mjs.map +1 -0
- 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-types.cjs +66 -0
- package/dist/application/transform/document/declared-types.cjs.map +1 -0
- package/dist/application/transform/document/declared-types.mjs +63 -0
- package/dist/application/transform/document/declared-types.mjs.map +1 -0
- package/dist/application/transform/document/document.cjs +32 -9
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +34 -11
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/exploded-query.cjs +46 -0
- package/dist/application/transform/document/exploded-query.cjs.map +1 -0
- package/dist/application/transform/document/exploded-query.mjs +43 -0
- package/dist/application/transform/document/exploded-query.mjs.map +1 -0
- package/dist/application/transform/document/global-type-references.cjs +63 -0
- package/dist/application/transform/document/global-type-references.cjs.map +1 -0
- package/dist/application/transform/document/global-type-references.mjs +61 -0
- package/dist/application/transform/document/global-type-references.mjs.map +1 -0
- package/dist/application/transform/document/list-assignability.cjs +54 -0
- package/dist/application/transform/document/list-assignability.cjs.map +1 -0
- package/dist/application/transform/document/list-assignability.mjs +52 -0
- package/dist/application/transform/document/list-assignability.mjs.map +1 -0
- package/dist/application/transform/document/parameters.cjs +41 -9
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +42 -10
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-key-overlaps.cjs +83 -33
- package/dist/application/transform/document/path-key-overlaps.cjs.map +1 -1
- package/dist/application/transform/document/path-key-overlaps.mjs +83 -33
- package/dist/application/transform/document/path-key-overlaps.mjs.map +1 -1
- package/dist/application/transform/document/path-template-replace.cjs +48 -0
- package/dist/application/transform/document/path-template-replace.cjs.map +1 -0
- package/dist/application/transform/document/path-template-replace.mjs +45 -0
- package/dist/application/transform/document/path-template-replace.mjs.map +1 -0
- package/dist/application/transform/document/paths.cjs +55 -29
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +54 -30
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.cjs +15 -14
- package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
- package/dist/application/transform/document/root-type-aliases.mjs +15 -13
- package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
- package/dist/application/transform/document/template-key-match.cjs +128 -0
- package/dist/application/transform/document/template-key-match.cjs.map +1 -0
- package/dist/application/transform/document/template-key-match.mjs +125 -0
- package/dist/application/transform/document/template-key-match.mjs.map +1 -0
- package/dist/application/transform/document/type-assignability.cjs +192 -0
- package/dist/application/transform/document/type-assignability.cjs.map +1 -0
- package/dist/application/transform/document/type-assignability.mjs +190 -0
- package/dist/application/transform/document/type-assignability.mjs.map +1 -0
- package/dist/application/transform/document/type-key.cjs +70 -0
- package/dist/application/transform/document/type-key.cjs.map +1 -0
- package/dist/application/transform/document/type-key.mjs +68 -0
- package/dist/application/transform/document/type-key.mjs.map +1 -0
- package/dist/application/transform/document/type-resolution.cjs +131 -0
- package/dist/application/transform/document/type-resolution.cjs.map +1 -0
- package/dist/application/transform/document/type-resolution.mjs +125 -0
- package/dist/application/transform/document/type-resolution.mjs.map +1 -0
- package/dist/application/transform/footer/document-footer.cjs +66 -4
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +67 -5
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/footer/enum-naming.cjs +17 -0
- package/dist/application/transform/footer/enum-naming.cjs.map +1 -1
- package/dist/application/transform/footer/enum-naming.mjs +17 -1
- package/dist/application/transform/footer/enum-naming.mjs.map +1 -1
- package/dist/application/transform/footer/enum-values-check.cjs +129 -0
- package/dist/application/transform/footer/enum-values-check.cjs.map +1 -0
- package/dist/application/transform/footer/enum-values-check.mjs +127 -0
- package/dist/application/transform/footer/enum-values-check.mjs.map +1 -0
- package/dist/application/transform/footer/evaluation.cjs +42 -0
- package/dist/application/transform/footer/evaluation.cjs.map +1 -0
- package/dist/application/transform/footer/evaluation.mjs +33 -0
- package/dist/application/transform/footer/evaluation.mjs.map +1 -0
- package/dist/application/transform/footer/shared-enum-names.cjs +60 -0
- package/dist/application/transform/footer/shared-enum-names.cjs.map +1 -0
- package/dist/application/transform/footer/shared-enum-names.mjs +57 -0
- package/dist/application/transform/footer/shared-enum-names.mjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.cjs +138 -0
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.mjs +136 -0
- package/dist/application/transform/footer/type-evaluation.mjs.map +1 -0
- package/dist/application/transform/footer/type-indexing.cjs +107 -0
- package/dist/application/transform/footer/type-indexing.cjs.map +1 -0
- package/dist/application/transform/footer/type-indexing.mjs +105 -0
- package/dist/application/transform/footer/type-indexing.mjs.map +1 -0
- package/dist/application/transform/footer/type-rules.cjs +172 -0
- package/dist/application/transform/footer/type-rules.cjs.map +1 -0
- package/dist/application/transform/footer/type-rules.mjs +166 -0
- package/dist/application/transform/footer/type-rules.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/generated-location.cjs +138 -0
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/generated-location.mjs +136 -0
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/generated-shape.cjs +171 -0
- package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/generated-shape.mjs +162 -0
- package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/inline-cycles.cjs +44 -0
- package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/inline-cycles.mjs +42 -0
- package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/original-index.cjs +62 -0
- package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/original-index.mjs +60 -0
- package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/pointer-type.cjs +60 -0
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/pointer-type.mjs +57 -0
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/pointer-walk.cjs +66 -0
- package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/pointer-walk.mjs +56 -0
- package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/typed-walk.cjs +124 -0
- package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/typed-walk.mjs +122 -0
- package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -0
- package/dist/application/transform/ref-type.cjs +7 -2
- package/dist/application/transform/ref-type.cjs.map +1 -1
- package/dist/application/transform/ref-type.mjs +3 -2
- package/dist/application/transform/ref-type.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs +38 -0
- package/dist/application/transform/schema/access-flags.cjs.map +1 -0
- package/dist/application/transform/schema/access-flags.mjs +36 -0
- package/dist/application/transform/schema/access-flags.mjs.map +1 -0
- package/dist/application/transform/schema/array-type.cjs +32 -1
- package/dist/application/transform/schema/array-type.cjs.map +1 -1
- package/dist/application/transform/schema/array-type.mjs +33 -2
- package/dist/application/transform/schema/array-type.mjs.map +1 -1
- package/dist/application/transform/schema/composition-type.cjs +50 -15
- package/dist/application/transform/schema/composition-type.cjs.map +1 -1
- package/dist/application/transform/schema/composition-type.mjs +50 -15
- package/dist/application/transform/schema/composition-type.mjs.map +1 -1
- package/dist/application/transform/schema/core-type.cjs +3 -1
- package/dist/application/transform/schema/core-type.cjs.map +1 -1
- package/dist/application/transform/schema/core-type.mjs +3 -1
- package/dist/application/transform/schema/core-type.mjs.map +1 -1
- package/dist/application/transform/schema/discriminated-union.cjs +30 -0
- package/dist/application/transform/schema/discriminated-union.cjs.map +1 -0
- package/dist/application/transform/schema/discriminated-union.mjs +27 -0
- package/dist/application/transform/schema/discriminated-union.mjs.map +1 -0
- package/dist/application/transform/schema/discriminator-property.cjs +3 -2
- package/dist/application/transform/schema/discriminator-property.cjs.map +1 -1
- package/dist/application/transform/schema/discriminator-property.mjs +3 -2
- package/dist/application/transform/schema/discriminator-property.mjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.cjs +66 -10
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.mjs +67 -12
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
- package/dist/application/transform/schema/inherited-discriminator.cjs +29 -0
- package/dist/application/transform/schema/inherited-discriminator.cjs.map +1 -0
- package/dist/application/transform/schema/inherited-discriminator.mjs +26 -0
- package/dist/application/transform/schema/inherited-discriminator.mjs.map +1 -0
- package/dist/application/transform/schema/object-type.cjs +38 -25
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +39 -27
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/required-variants.cjs +45 -0
- package/dist/application/transform/schema/required-variants.cjs.map +1 -0
- package/dist/application/transform/schema/required-variants.mjs +42 -0
- package/dist/application/transform/schema/required-variants.mjs.map +1 -0
- package/dist/application/transform/schema/schema-transform.cjs +2 -2
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +2 -2
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema-comment.cjs +51 -5
- package/dist/application/transform/schema-comment.cjs.map +1 -1
- package/dist/application/transform/schema-comment.mjs +50 -6
- package/dist/application/transform/schema-comment.mjs.map +1 -1
- package/dist/application/transform/type-combinators.mjs +1 -1
- package/dist/cli/api-settings.cjs +78 -0
- package/dist/cli/api-settings.cjs.map +1 -0
- package/dist/cli/api-settings.mjs +73 -0
- package/dist/cli/api-settings.mjs.map +1 -0
- package/dist/cli/cli-arguments.cjs +12 -3
- package/dist/cli/cli-arguments.cjs.map +1 -1
- package/dist/cli/cli-arguments.mjs +12 -4
- package/dist/cli/cli-arguments.mjs.map +1 -1
- package/dist/cli/cli-errors.cjs +3 -2
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +3 -2
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +8 -3
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +9 -4
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/help-text.cjs +3 -3
- package/dist/cli/help-text.cjs.map +1 -1
- package/dist/cli/help-text.mjs +3 -3
- package/dist/cli/help-text.mjs.map +1 -1
- package/dist/cli/main.cjs +5 -0
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +5 -0
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +15 -7
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +15 -7
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/ref-limits.cjs +1 -1
- package/dist/cli/ref-limits.cjs.map +1 -1
- package/dist/cli/ref-limits.mjs +2 -2
- package/dist/cli/ref-limits.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +20 -3
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +21 -4
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/errors.cjs +6 -1
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +6 -1
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/constructors.cjs +7 -1
- package/dist/domain/ir/constructors.cjs.map +1 -1
- package/dist/domain/ir/constructors.mjs +6 -2
- package/dist/domain/ir/constructors.mjs.map +1 -1
- package/dist/domain/openapi/admitted-values.cjs +75 -0
- package/dist/domain/openapi/admitted-values.cjs.map +1 -0
- package/dist/domain/openapi/admitted-values.mjs +72 -0
- package/dist/domain/openapi/admitted-values.mjs.map +1 -0
- package/dist/domain/openapi/discriminated-union.cjs +68 -0
- package/dist/domain/openapi/discriminated-union.cjs.map +1 -0
- package/dist/domain/openapi/discriminated-union.mjs +62 -0
- package/dist/domain/openapi/discriminated-union.mjs.map +1 -0
- package/dist/domain/openapi/discriminator-conflicts.cjs +143 -0
- package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -0
- package/dist/domain/openapi/discriminator-conflicts.mjs +141 -0
- package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -0
- package/dist/domain/openapi/parameter-object.cjs.map +1 -1
- package/dist/domain/openapi/parameter-object.mjs.map +1 -1
- package/dist/domain/openapi/path-templates.cjs +23 -0
- package/dist/domain/openapi/path-templates.cjs.map +1 -0
- package/dist/domain/openapi/path-templates.mjs +21 -0
- package/dist/domain/openapi/path-templates.mjs.map +1 -0
- package/dist/domain/output-fixes.cjs +36 -1
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +36 -1
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/url-credentials.cjs +10 -0
- package/dist/domain/url-credentials.cjs.map +1 -0
- package/dist/domain/url-credentials.mjs +8 -0
- package/dist/domain/url-credentials.mjs.map +1 -0
- package/dist/domain/warnings.cjs +23 -0
- package/dist/domain/warnings.cjs.map +1 -0
- package/dist/domain/warnings.mjs +20 -0
- package/dist/domain/warnings.mjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1182 -46
- package/dist/index.d.mts +1182 -46
- package/dist/index.d.ts +1182 -46
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/transform/components-object.cjs +2 -1
- package/dist/transform/components-object.cjs.map +1 -1
- package/dist/transform/components-object.mjs +2 -1
- package/dist/transform/components-object.mjs.map +1 -1
- package/dist/transform/path-item-object.cjs.map +1 -1
- package/dist/transform/path-item-object.mjs.map +1 -1
- package/package.json +6 -5
- package/src/adapters/redocly-loader/configured-headers.ts +65 -0
- package/src/adapters/redocly-loader/redocly-config-source.ts +41 -6
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +44 -13
- package/src/adapters/redocly-loader/ref-access.ts +60 -5
- package/src/adapters/redocly-loader/ref-resolution-check.ts +257 -0
- package/src/adapters/redocly-loader/ref-resolution-steps.ts +113 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +77 -21
- package/src/adapters/redocly-loader/schema-load-errors.ts +33 -11
- package/src/adapters/redocly-loader/unsupported-keys.ts +17 -2
- package/src/adapters/terminal-logger/terminal-logger.ts +9 -5
- package/src/adapters/type-ast-bridge/ir-to-typescript.ts +5 -1
- package/src/adapters/type-ast-bridge/print-typescript.ts +3 -1
- package/src/adapters/type-ast-bridge/typescript-to-ir.ts +26 -12
- package/src/adapters/type-ast-bridge/typescript-types.ts +57 -5
- package/src/api/default-ports.ts +16 -0
- package/src/api/discriminator-conflict-warnings.ts +43 -0
- package/src/api/discriminator-enum-names.ts +26 -0
- package/src/api/discriminator-enum-parent.ts +129 -0
- package/src/api/discriminator-enum.ts +39 -0
- package/src/api/discriminator-other-owners.ts +97 -0
- package/src/api/discriminator-patch.ts +152 -0
- package/src/api/discriminator-scan.ts +78 -90
- package/src/api/document-refs.ts +19 -15
- package/src/api/document-run.ts +32 -11
- package/src/api/enum-values-warnings.ts +21 -0
- package/src/api/footer-sink.ts +34 -2
- package/src/api/legacy-callback-warning.ts +7 -3
- package/src/api/legacy-ts-helpers.ts +7 -5
- package/src/api/legacy-utils.ts +1 -1
- package/src/api/openapi-ts.ts +2 -0
- package/src/api/path-template-warnings.ts +27 -0
- package/src/api/run-context.ts +34 -0
- package/src/api/transform-context.ts +17 -9
- package/src/api/transform-schema.ts +90 -5
- package/src/api/unsupported-feature-warnings.ts +8 -1
- package/src/application/ports/redocly-config-source.ts +5 -1
- package/src/application/print/type-printer.ts +8 -1
- package/src/application/transform/document/assignability.ts +203 -0
- package/src/application/transform/document/components.ts +6 -6
- package/src/application/transform/document/declared-types.ts +93 -0
- package/src/application/transform/document/document.ts +71 -13
- package/src/application/transform/document/exploded-query.ts +91 -0
- package/src/application/transform/document/global-type-references.ts +78 -0
- package/src/application/transform/document/list-assignability.ts +87 -0
- package/src/application/transform/document/parameters.ts +78 -12
- package/src/application/transform/document/path-key-overlaps.ts +148 -59
- package/src/application/transform/document/path-template-replace.ts +90 -0
- package/src/application/transform/document/paths.ts +101 -38
- package/src/application/transform/document/root-type-aliases.ts +29 -28
- package/src/application/transform/document/template-key-match.ts +183 -0
- package/src/application/transform/document/type-assignability.ts +268 -0
- package/src/application/transform/document/type-key.ts +80 -0
- package/src/application/transform/document/type-resolution.ts +163 -0
- package/src/application/transform/footer/document-footer.ts +91 -6
- package/src/application/transform/footer/enum-naming.ts +29 -0
- package/src/application/transform/footer/enum-values-check.ts +171 -0
- package/src/application/transform/footer/evaluation.ts +57 -0
- package/src/application/transform/footer/shared-enum-names.ts +86 -0
- package/src/application/transform/footer/type-evaluation.ts +167 -0
- package/src/application/transform/footer/type-indexing.ts +152 -0
- package/src/application/transform/footer/type-rules.ts +269 -0
- package/src/application/transform/ref-pointer/generated-location.ts +211 -0
- package/src/application/transform/ref-pointer/generated-shape.ts +275 -0
- package/src/application/transform/ref-pointer/inline-cycles.ts +56 -0
- package/src/application/transform/ref-pointer/original-index.ts +95 -0
- package/src/application/transform/ref-pointer/pointer-type.ts +92 -0
- package/src/application/transform/ref-pointer/pointer-walk.ts +96 -0
- package/src/application/transform/ref-pointer/typed-walk.ts +192 -0
- package/src/application/transform/ref-type.ts +11 -6
- package/src/application/transform/schema/access-flags.ts +63 -0
- package/src/application/transform/schema/array-type.ts +66 -5
- package/src/application/transform/schema/composition-type.ts +96 -24
- package/src/application/transform/schema/core-type.ts +8 -4
- package/src/application/transform/schema/discriminated-union.ts +58 -0
- package/src/application/transform/schema/discriminator-property.ts +8 -3
- package/src/application/transform/schema/enum-rule.ts +136 -13
- package/src/application/transform/schema/inherited-discriminator.ts +54 -0
- package/src/application/transform/schema/object-type.ts +51 -33
- package/src/application/transform/schema/required-variants.ts +88 -0
- package/src/application/transform/schema/schema-context.ts +26 -0
- package/src/application/transform/schema/schema-transform.ts +2 -2
- package/src/application/transform/schema-comment.ts +84 -4
- package/src/cli/api-settings.ts +109 -0
- package/src/cli/cli-arguments.ts +18 -5
- package/src/cli/cli-dependencies.ts +5 -0
- package/src/cli/cli-errors.ts +4 -2
- package/src/cli/cli-output.ts +18 -4
- package/src/cli/help-text.ts +4 -4
- package/src/cli/main.ts +6 -0
- package/src/cli/redocly-apis.ts +21 -11
- package/src/cli/ref-limits.ts +2 -2
- package/src/cli/run-cli.ts +25 -4
- package/src/domain/errors.ts +10 -2
- package/src/domain/ir/constructors.ts +9 -1
- package/src/domain/ir/nodes.ts +11 -7
- package/src/domain/openapi/admitted-values.ts +113 -0
- package/src/domain/openapi/discriminated-union.ts +109 -0
- package/src/domain/openapi/discriminator-conflicts.ts +251 -0
- package/src/domain/openapi/parameter-object.ts +4 -0
- package/src/domain/openapi/path-templates.ts +32 -0
- package/src/domain/openapi/schema-object.ts +2 -0
- package/src/domain/output-fixes.ts +43 -2
- package/src/domain/url-credentials.ts +18 -0
- package/src/domain/warnings.ts +28 -0
- package/src/index.ts +1 -0
- package/src/transform/components-object.ts +3 -1
- package/src/transform/path-item-object.ts +6 -2
- package/src/types/generator-options.ts +12 -21
- package/src/types/openapi-common.ts +1 -0
- package/src/types/openapi-request.ts +3 -0
- package/src/types/openapi-schema.ts +2 -0
- package/src/types/openapi-security.ts +1 -0
- package/dist/application/transform/document/path-item-conflicts.cjs +0 -51
- package/dist/application/transform/document/path-item-conflicts.cjs.map +0 -1
- package/dist/application/transform/document/path-item-conflicts.mjs +0 -49
- package/dist/application/transform/document/path-item-conflicts.mjs.map +0 -1
- package/src/application/transform/document/path-item-conflicts.ts +0 -79
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { findDiscriminatorValueConflicts } from '../domain/openapi/discriminator-conflicts.mjs';
|
|
2
|
+
import { OutputFix } from '../domain/output-fixes.mjs';
|
|
3
|
+
import { warningText, WARNING_CODES } from '../domain/warnings.mjs';
|
|
4
|
+
|
|
5
|
+
const DOCS_BASE_URL = "https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs";
|
|
6
|
+
const DOCS_URL = `${DOCS_BASE_URL}/advanced.md#discriminator-values`;
|
|
7
|
+
function listed(values) {
|
|
8
|
+
return values.map((value) => JSON.stringify(value)).join(", ");
|
|
9
|
+
}
|
|
10
|
+
function warningOf(conflict) {
|
|
11
|
+
const { member, owner, propertyName, values, allowed, isImplicit } = conflict;
|
|
12
|
+
const rule = isImplicit ? `A Discriminator Object without a mapping entry for a schema gives it its schema name as the value; add a mapping entry such as ${JSON.stringify(allowed[0])}: "${member}".` : "The Discriminator Object maps these values to the schema; map the values it allows.";
|
|
13
|
+
return `${member}: the discriminator "${propertyName}" of ${owner} gives this schema the value ${listed(values)}, which its "${propertyName}" property does not allow (${listed(allowed)}), so no value of the schema matches the discriminator. ${rule} See ${DOCS_URL}`;
|
|
14
|
+
}
|
|
15
|
+
function warnDiscriminatorValueConflicts(document, fixes, logger) {
|
|
16
|
+
const isUnionReused = fixes.includes(OutputFix.ALLOF_DISCRIMINATED_UNION);
|
|
17
|
+
for (const conflict of findDiscriminatorValueConflicts(document, { isUnionReused })) {
|
|
18
|
+
logger.warn(warningText(warningOf(conflict), WARNING_CODES.DISCRIMINATOR_VALUE_NOT_ALLOWED));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { warnDiscriminatorValueConflicts };
|
|
23
|
+
//# sourceMappingURL=discriminator-conflict-warnings.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-conflict-warnings.mjs","sources":["../../src/api/discriminator-conflict-warnings.ts"],"sourcesContent":["import type { Logger } from \"../application/ports/logger.js\";\nimport {\n type DiscriminatorValueConflict,\n findDiscriminatorValueConflicts,\n} from \"../domain/openapi/discriminator-conflicts.js\";\nimport { OutputFix } from \"../domain/output-fixes.js\";\nimport { WARNING_CODES, warningText } from \"../domain/warnings.js\";\n\nconst DOCS_BASE_URL = \"https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs\";\nconst DOCS_URL = `${DOCS_BASE_URL}/advanced.md#discriminator-values`;\n\nfunction listed(values: readonly unknown[]): string {\n return values.map((value) => JSON.stringify(value)).join(\", \");\n}\n\nfunction warningOf(conflict: DiscriminatorValueConflict): string {\n const { member, owner, propertyName, values, allowed, isImplicit } = conflict;\n const rule = isImplicit\n ? \"A Discriminator Object without a mapping entry for a schema gives it its schema name as \" +\n `the value; add a mapping entry such as ${JSON.stringify(allowed[0])}: \"${member}\".`\n : \"The Discriminator Object maps these values to the schema; map the values it allows.\";\n return (\n `${member}: the discriminator \"${propertyName}\" of ${owner} gives this schema the value ` +\n `${listed(values)}, which its \"${propertyName}\" property does not allow ` +\n `(${listed(allowed)}), so no value of the schema matches the discriminator. ${rule} ` +\n `See ${DOCS_URL}`\n );\n}\n\n/**\n * Warn once per discriminator member whose value its own property does not allow. The members\n * depend on the run's fixes (`allof-discriminated-union`).\n */\nexport function warnDiscriminatorValueConflicts(\n document: unknown,\n fixes: readonly OutputFix[],\n logger: Logger,\n): void {\n const isUnionReused = fixes.includes(OutputFix.ALLOF_DISCRIMINATED_UNION);\n for (const conflict of findDiscriminatorValueConflicts(document, { isUnionReused })) {\n logger.warn(warningText(warningOf(conflict), WARNING_CODES.DISCRIMINATOR_VALUE_NOT_ALLOWED));\n }\n}\n"],"names":[],"mappings":";;;;AAQA,MAAM,aAAA,GAAgB,qEAAA;AACtB,MAAM,QAAA,GAAW,GAAG,aAAa,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if (!request.isOwnerReference && !this.names.has(key)) {
|
|
7
|
+
this.names.set(key, name);
|
|
8
|
+
}
|
|
9
|
+
return name;
|
|
10
|
+
}
|
|
11
|
+
/** The recorded name of each shared enum, for the second pass. */
|
|
12
|
+
chosenNames() {
|
|
13
|
+
const chosen = new Map(this.names);
|
|
14
|
+
return { nameOf: (key, name) => chosen.get(key) ?? name };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.FirstSchemaNameRecorder = FirstSchemaNameRecorder;
|
|
19
|
+
//# sourceMappingURL=discriminator-enum-names.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-enum-names.cjs","sources":["../../src/api/discriminator-enum-names.ts"],"sourcesContent":["import type { SharedEnumNames } from \"../application/transform/footer/shared-enum-names.js\";\nimport type { EnumDeclarationRequest } from \"../application/transform/schema/schema-context.js\";\n\n/**\n * `--dedupe-enums` names a shared enum after the first schema that declares it. With\n * `discriminator-values` and `--enum`, a member's value refers to the owner's enum, which is then\n * declared when the member is typed, maybe before that first schema; the shared enum would take\n * the owner's name. A first pass records the names of the declaring schemas only, so the second\n * pass names each shared enum as the document order does (`OtherKind`, not `PetPetType`).\n */\nexport class FirstSchemaNameRecorder implements SharedEnumNames {\n private readonly names = new Map<string, string>();\n\n nameOf(key: string, name: string, request: EnumDeclarationRequest): string {\n if (!request.isOwnerReference && !this.names.has(key)) {\n this.names.set(key, name);\n }\n return name;\n }\n\n /** The recorded name of each shared enum, for the second pass. */\n chosenNames(): SharedEnumNames {\n const chosen = new Map(this.names);\n return { nameOf: (key, name) => chosen.get(key) ?? name };\n }\n}\n"],"names":[],"mappings":";;AAUO,MAAM,uBAAA,CAAmD;AAAA,EAC7C,KAAA,uBAAY,GAAA,EAAoB;AAAA,EAEjD,MAAA,CAAO,GAAA,EAAa,IAAA,EAAc,OAAA,EAAyC;AACzE,IAAA,IAAI,CAAC,QAAQ,gBAAA,IAAoB,CAAC,KAAK,KAAA,CAAM,GAAA,CAAI,GAAG,CAAA,EAAG;AACrD,MAAA,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,GAAA,EAAK,IAAI,CAAA;AAAA,IAC1B;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA,EAGA,WAAA,GAA+B;AAC7B,IAAA,MAAM,MAAA,GAAS,IAAI,GAAA,CAAI,IAAA,CAAK,KAAK,CAAA;AACjC,IAAA,OAAO,EAAE,QAAQ,CAAC,GAAA,EAAK,SAAS,MAAA,CAAO,GAAA,CAAI,GAAG,CAAA,IAAK,IAAA,EAAK;AAAA,EAC1D;AACF;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class FirstSchemaNameRecorder {
|
|
2
|
+
names = /* @__PURE__ */ new Map();
|
|
3
|
+
nameOf(key, name, request) {
|
|
4
|
+
if (!request.isOwnerReference && !this.names.has(key)) {
|
|
5
|
+
this.names.set(key, name);
|
|
6
|
+
}
|
|
7
|
+
return name;
|
|
8
|
+
}
|
|
9
|
+
/** The recorded name of each shared enum, for the second pass. */
|
|
10
|
+
chosenNames() {
|
|
11
|
+
const chosen = new Map(this.names);
|
|
12
|
+
return { nameOf: (key, name) => chosen.get(key) ?? name };
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { FirstSchemaNameRecorder };
|
|
17
|
+
//# sourceMappingURL=discriminator-enum-names.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-enum-names.mjs","sources":["../../src/api/discriminator-enum-names.ts"],"sourcesContent":["import type { SharedEnumNames } from \"../application/transform/footer/shared-enum-names.js\";\nimport type { EnumDeclarationRequest } from \"../application/transform/schema/schema-context.js\";\n\n/**\n * `--dedupe-enums` names a shared enum after the first schema that declares it. With\n * `discriminator-values` and `--enum`, a member's value refers to the owner's enum, which is then\n * declared when the member is typed, maybe before that first schema; the shared enum would take\n * the owner's name. A first pass records the names of the declaring schemas only, so the second\n * pass names each shared enum as the document order does (`OtherKind`, not `PetPetType`).\n */\nexport class FirstSchemaNameRecorder implements SharedEnumNames {\n private readonly names = new Map<string, string>();\n\n nameOf(key: string, name: string, request: EnumDeclarationRequest): string {\n if (!request.isOwnerReference && !this.names.has(key)) {\n this.names.set(key, name);\n }\n return name;\n }\n\n /** The recorded name of each shared enum, for the second pass. */\n chosenNames(): SharedEnumNames {\n const chosen = new Map(this.names);\n return { nameOf: (key, name) => chosen.get(key) ?? name };\n }\n}\n"],"names":[],"mappings":"AAUO,MAAM,uBAAA,CAAmD;AAAA,EAC7C,KAAA,uBAAY,GAAA,EAAoB;AAAA,EAEjD,MAAA,CAAO,GAAA,EAAa,IAAA,EAAc,OAAA,EAAyC;AACzE,IAAA,IAAI,CAAC,QAAQ,gBAAA,IAAoB,CAAC,KAAK,KAAA,CAAM,GAAA,CAAI,GAAG,CAAA,EAAG;AACrD,MAAA,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,GAAA,EAAK,IAAI,CAAA;AAAA,IAC1B;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA,EAGA,WAAA,GAA+B;AAC7B,IAAA,MAAM,MAAA,GAAS,IAAI,GAAA,CAAI,IAAA,CAAK,KAAK,CAAA;AACjC,IAAA,OAAO,EAAE,QAAQ,CAAC,GAAA,EAAK,SAAS,MAAA,CAAO,GAAA,CAAI,GAAG,CAAA,IAAK,IAAA,EAAK;AAAA,EAC1D;AACF;;"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsonPointer = require('../domain/openapi/json-pointer.cjs');
|
|
4
|
+
|
|
5
|
+
const PROPERTIES_KEYWORD = "properties";
|
|
6
|
+
const ROOT_SEGMENTS = 3;
|
|
7
|
+
function typedAt(ref) {
|
|
8
|
+
const segments = jsonPointer.parseRefPointer(ref);
|
|
9
|
+
const nested = segments.slice(ROOT_SEGMENTS).filter((segment) => segment !== PROPERTIES_KEYWORD);
|
|
10
|
+
return jsonPointer.createRef([...segments.slice(0, ROOT_SEGMENTS), ...nested]);
|
|
11
|
+
}
|
|
12
|
+
function isSchemaObject(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function ownProperty(item, ref, name) {
|
|
16
|
+
const property = ("properties" in item ? item.properties : void 0)?.[name];
|
|
17
|
+
return property === void 0 ? void 0 : { property, path: jsonPointer.createRef([ref, name]) };
|
|
18
|
+
}
|
|
19
|
+
function declaredProperty(ref, name, resolve, visited) {
|
|
20
|
+
const schema = resolve(ref);
|
|
21
|
+
if (visited.has(ref) || !isSchemaObject(schema)) {
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
visited.add(ref);
|
|
25
|
+
for (const item of [schema, ...schema.allOf ?? []]) {
|
|
26
|
+
if (!isSchemaObject(item)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const found = "$ref" in item ? declaredProperty(item.$ref, name, resolve, visited) : ownProperty(item, ref, name);
|
|
30
|
+
if (found !== void 0) {
|
|
31
|
+
return found;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
function inheritedProperty(ref, name, resolve) {
|
|
37
|
+
const schema = resolve(ref);
|
|
38
|
+
const visited = /* @__PURE__ */ new Set([ref]);
|
|
39
|
+
for (const item of isSchemaObject(schema) ? schema.allOf ?? [] : []) {
|
|
40
|
+
const found = isSchemaObject(item) && "$ref" in item ? declaredProperty(item.$ref, name, resolve, visited) : void 0;
|
|
41
|
+
if (found !== void 0) {
|
|
42
|
+
return found;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
function enumParentOf(patch, resolve) {
|
|
48
|
+
const name = patch.discriminator.propertyName;
|
|
49
|
+
const declared = declaredProperty(patch.discriminatorRef, name, resolve, /* @__PURE__ */ new Set()) ?? (patch.ref === void 0 ? void 0 : inheritedProperty(patch.ref, name, resolve));
|
|
50
|
+
if (declared === void 0 || !isSchemaObject(declared.property)) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
const ref = declared.property.$ref;
|
|
54
|
+
const parent = typeof ref === "string" ? { schema: resolve(ref), path: typedAt(ref) } : { schema: declared.property, path: declared.path };
|
|
55
|
+
return isSchemaObject(parent.schema) && Array.isArray(parent.schema.enum) ? { schema: parent.schema, path: parent.path } : void 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.enumParentOf = enumParentOf;
|
|
59
|
+
//# sourceMappingURL=discriminator-enum-parent.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-enum-parent.cjs","sources":["../../src/api/discriminator-enum-parent.ts"],"sourcesContent":["import { createRef, parseRefPointer } from \"../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../types.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\n\n/**\n * The `discriminator-values` fix (#1700). With `--enum`, the enum the scan adds to a member\n * (`petType: \"Cat\"`) is declared as an enum of its own (`CatPetType`), which is not assignable to\n * the parent's enum (`PetType`). The parent's enum is found here, so the member's property can be\n * typed with its members (`PetType.Cat`).\n */\n\n/** The parent's enum schema and the location it is typed at, which gives the enum its name. */\nexport interface EnumParent {\n readonly schema: SchemaObject;\n readonly path: string;\n}\n\ntype ResolveSchemaRef = (ref: string) => unknown;\n\n/** A declared property schema and the location the transformer types it at. */\ninterface DeclaredProperty {\n readonly property: unknown;\n readonly path: string;\n}\n\nconst PROPERTIES_KEYWORD = \"properties\";\n/** `components`, `schemas` and the schema name: the segments before the schema's own keywords. */\nconst ROOT_SEGMENTS = 3;\n\n/** The location a `$ref` is typed at: object properties are nested without `properties`. */\nfunction typedAt(ref: string): string {\n const segments = parseRefPointer(ref);\n const nested = segments.slice(ROOT_SEGMENTS).filter((segment) => segment !== PROPERTIES_KEYWORD);\n return createRef([...segments.slice(0, ROOT_SEGMENTS), ...nested]);\n}\n\nfunction isSchemaObject(value: unknown): value is SchemaObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The property `name` of a schema object typed at `ref`. */\nfunction ownProperty(item: SchemaObject, ref: string, name: string): DeclaredProperty | undefined {\n const property = (\"properties\" in item ? item.properties : undefined)?.[name];\n return property === undefined ? undefined : { property, path: createRef([ref, name]) };\n}\n\n/** The property `name` of the schema at `ref`, its own or from an `allOf` item, depth first. */\nfunction declaredProperty(\n ref: string,\n name: string,\n resolve: ResolveSchemaRef,\n visited: Set<string>,\n): DeclaredProperty | undefined {\n const schema = resolve(ref);\n if (visited.has(ref) || !isSchemaObject(schema)) {\n return undefined;\n }\n visited.add(ref);\n // An inline `allOf` item is typed at its parent's location, so both share the path.\n for (const item of [schema, ...(schema.allOf ?? [])]) {\n if (!isSchemaObject(item)) {\n continue;\n }\n const found =\n \"$ref\" in item\n ? declaredProperty(item.$ref as string, name, resolve, visited)\n : ownProperty(item, ref, name);\n if (found !== undefined) {\n return found;\n }\n }\n return undefined;\n}\n\n/**\n * A discriminator and the `$ref` of the schema that declares its property; `ref` is the member\n * whose value the discriminator gives, where there is one.\n */\nexport type DiscriminatorOwner = Pick<EnumPatch, \"discriminator\" | \"discriminatorRef\"> &\n Partial<Pick<EnumPatch, \"ref\">>;\n\n/**\n * The property `name` that the member at `ref` inherits through its `allOf` `$ref`s. Its own\n * keywords and inline items are left out: the scan writes the added value there.\n */\nfunction inheritedProperty(\n ref: string,\n name: string,\n resolve: ResolveSchemaRef,\n): DeclaredProperty | undefined {\n const schema = resolve(ref);\n const visited = new Set([ref]);\n for (const item of isSchemaObject(schema) ? (schema.allOf ?? []) : []) {\n const found =\n isSchemaObject(item) && \"$ref\" in item\n ? declaredProperty(item.$ref as string, name, resolve, visited)\n : undefined;\n if (found !== undefined) {\n return found;\n }\n }\n return undefined;\n}\n\n/**\n * The enum of the property that the discriminator owner declares, if it is one. An owner that\n * declares no such property (a `oneOf` with a mapping) leaves the member's type to the property\n * the member inherits, so that property's enum is the one.\n */\nexport function enumParentOf(\n patch: DiscriminatorOwner,\n resolve: ResolveSchemaRef,\n): EnumParent | undefined {\n const name = patch.discriminator.propertyName;\n const declared =\n declaredProperty(patch.discriminatorRef, name, resolve, new Set()) ??\n (patch.ref === undefined ? undefined : inheritedProperty(patch.ref, name, resolve));\n if (declared === undefined || !isSchemaObject(declared.property)) {\n return undefined;\n }\n const ref = (declared.property as { readonly $ref?: unknown }).$ref;\n const parent =\n typeof ref === \"string\"\n ? { schema: resolve(ref), path: typedAt(ref) }\n : { schema: declared.property, path: declared.path };\n return isSchemaObject(parent.schema) && Array.isArray(parent.schema.enum)\n ? { schema: parent.schema, path: parent.path }\n : undefined;\n}\n"],"names":["parseRefPointer","createRef"],"mappings":";;;;AAyBA,MAAM,kBAAA,GAAqB,YAAA;AAE3B,MAAM,aAAA,GAAgB,CAAA;AAGtB,SAAS,QAAQ,GAAA,EAAqB;AACpC,EAAA,MAAM,QAAA,GAAWA,4BAAgB,GAAG,CAAA;AACpC,EAAA,MAAM,MAAA,GAAS,SAAS,KAAA,CAAM,aAAa,EAAE,MAAA,CAAO,CAAC,OAAA,KAAY,OAAA,KAAY,kBAAkB,CAAA;AAC/F,EAAA,OAAOC,qBAAA,CAAU,CAAC,GAAG,QAAA,CAAS,KAAA,CAAM,GAAG,aAAa,CAAA,EAAG,GAAG,MAAM,CAAC,CAAA;AACnE;AAEA,SAAS,eAAe,KAAA,EAAuC;AAC7D,EAAA,OAAO,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,QAAQ,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC5E;AAGA,SAAS,WAAA,CAAY,IAAA,EAAoB,GAAA,EAAa,IAAA,EAA4C;AAChG,EAAA,MAAM,YAAY,YAAA,IAAgB,IAAA,GAAO,IAAA,CAAK,UAAA,GAAa,UAAa,IAAI,CAAA;AAC5E,EAAA,OAAO,QAAA,KAAa,MAAA,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4
|
+
const ROOT_SEGMENTS = 3;
|
|
5
|
+
function typedAt(ref) {
|
|
6
|
+
const segments = parseRefPointer(ref);
|
|
7
|
+
const nested = segments.slice(ROOT_SEGMENTS).filter((segment) => segment !== PROPERTIES_KEYWORD);
|
|
8
|
+
return createRef([...segments.slice(0, ROOT_SEGMENTS), ...nested]);
|
|
9
|
+
}
|
|
10
|
+
function isSchemaObject(value) {
|
|
11
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
function ownProperty(item, ref, name) {
|
|
14
|
+
const property = ("properties" in item ? item.properties : void 0)?.[name];
|
|
15
|
+
return property === void 0 ? void 0 : { property, path: createRef([ref, name]) };
|
|
16
|
+
}
|
|
17
|
+
function declaredProperty(ref, name, resolve, visited) {
|
|
18
|
+
const schema = resolve(ref);
|
|
19
|
+
if (visited.has(ref) || !isSchemaObject(schema)) {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
visited.add(ref);
|
|
23
|
+
for (const item of [schema, ...schema.allOf ?? []]) {
|
|
24
|
+
if (!isSchemaObject(item)) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const found = "$ref" in item ? declaredProperty(item.$ref, name, resolve, visited) : ownProperty(item, ref, name);
|
|
28
|
+
if (found !== void 0) {
|
|
29
|
+
return found;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
function inheritedProperty(ref, name, resolve) {
|
|
35
|
+
const schema = resolve(ref);
|
|
36
|
+
const visited = /* @__PURE__ */ new Set([ref]);
|
|
37
|
+
for (const item of isSchemaObject(schema) ? schema.allOf ?? [] : []) {
|
|
38
|
+
const found = isSchemaObject(item) && "$ref" in item ? declaredProperty(item.$ref, name, resolve, visited) : void 0;
|
|
39
|
+
if (found !== void 0) {
|
|
40
|
+
return found;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
function enumParentOf(patch, resolve) {
|
|
46
|
+
const name = patch.discriminator.propertyName;
|
|
47
|
+
const declared = declaredProperty(patch.discriminatorRef, name, resolve, /* @__PURE__ */ new Set()) ?? (patch.ref === void 0 ? void 0 : inheritedProperty(patch.ref, name, resolve));
|
|
48
|
+
if (declared === void 0 || !isSchemaObject(declared.property)) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
const ref = declared.property.$ref;
|
|
52
|
+
const parent = typeof ref === "string" ? { schema: resolve(ref), path: typedAt(ref) } : { schema: declared.property, path: declared.path };
|
|
53
|
+
return isSchemaObject(parent.schema) && Array.isArray(parent.schema.enum) ? { schema: parent.schema, path: parent.path } : void 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { enumParentOf };
|
|
57
|
+
//# sourceMappingURL=discriminator-enum-parent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-enum-parent.mjs","sources":["../../src/api/discriminator-enum-parent.ts"],"sourcesContent":["import { createRef, parseRefPointer } from \"../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../types.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\n\n/**\n * The `discriminator-values` fix (#1700). With `--enum`, the enum the scan adds to a member\n * (`petType: \"Cat\"`) is declared as an enum of its own (`CatPetType`), which is not assignable to\n * the parent's enum (`PetType`). The parent's enum is found here, so the member's property can be\n * typed with its members (`PetType.Cat`).\n */\n\n/** The parent's enum schema and the location it is typed at, which gives the enum its name. */\nexport interface EnumParent {\n readonly schema: SchemaObject;\n readonly path: string;\n}\n\ntype ResolveSchemaRef = (ref: string) => unknown;\n\n/** A declared property schema and the location the transformer types it at. */\ninterface DeclaredProperty {\n readonly property: unknown;\n readonly path: string;\n}\n\nconst PROPERTIES_KEYWORD = \"properties\";\n/** `components`, `schemas` and the schema name: the segments before the schema's own keywords. */\nconst ROOT_SEGMENTS = 3;\n\n/** The location a `$ref` is typed at: object properties are nested without `properties`. */\nfunction typedAt(ref: string): string {\n const segments = parseRefPointer(ref);\n const nested = segments.slice(ROOT_SEGMENTS).filter((segment) => segment !== PROPERTIES_KEYWORD);\n return createRef([...segments.slice(0, ROOT_SEGMENTS), ...nested]);\n}\n\nfunction isSchemaObject(value: unknown): value is SchemaObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The property `name` of a schema object typed at `ref`. */\nfunction ownProperty(item: SchemaObject, ref: string, name: string): DeclaredProperty | undefined {\n const property = (\"properties\" in item ? item.properties : undefined)?.[name];\n return property === undefined ? undefined : { property, path: createRef([ref, name]) };\n}\n\n/** The property `name` of the schema at `ref`, its own or from an `allOf` item, depth first. */\nfunction declaredProperty(\n ref: string,\n name: string,\n resolve: ResolveSchemaRef,\n visited: Set<string>,\n): DeclaredProperty | undefined {\n const schema = resolve(ref);\n if (visited.has(ref) || !isSchemaObject(schema)) {\n return undefined;\n }\n visited.add(ref);\n // An inline `allOf` item is typed at its parent's location, so both share the path.\n for (const item of [schema, ...(schema.allOf ?? [])]) {\n if (!isSchemaObject(item)) {\n continue;\n }\n const found =\n \"$ref\" in item\n ? declaredProperty(item.$ref as string, name, resolve, visited)\n : ownProperty(item, ref, name);\n if (found !== undefined) {\n return found;\n }\n }\n return undefined;\n}\n\n/**\n * A discriminator and the `$ref` of the schema that declares its property; `ref` is the member\n * whose value the discriminator gives, where there is one.\n */\nexport type DiscriminatorOwner = Pick<EnumPatch, \"discriminator\" | \"discriminatorRef\"> &\n Partial<Pick<EnumPatch, \"ref\">>;\n\n/**\n * The property `name` that the member at `ref` inherits through its `allOf` `$ref`s. Its own\n * keywords and inline items are left out: the scan writes the added value there.\n */\nfunction inheritedProperty(\n ref: string,\n name: string,\n resolve: ResolveSchemaRef,\n): DeclaredProperty | undefined {\n const schema = resolve(ref);\n const visited = new Set([ref]);\n for (const item of isSchemaObject(schema) ? (schema.allOf ?? []) : []) {\n const found =\n isSchemaObject(item) && \"$ref\" in item\n ? declaredProperty(item.$ref as string, name, resolve, visited)\n : undefined;\n if (found !== undefined) {\n return found;\n }\n }\n return undefined;\n}\n\n/**\n * The enum of the property that the discriminator owner declares, if it is one. An owner that\n * declares no such property (a `oneOf` with a mapping) leaves the member's type to the property\n * the member inherits, so that property's enum is the one.\n */\nexport function enumParentOf(\n patch: DiscriminatorOwner,\n resolve: ResolveSchemaRef,\n): EnumParent | undefined {\n const name = patch.discriminator.propertyName;\n const declared =\n declaredProperty(patch.discriminatorRef, name, resolve, new Set()) ??\n (patch.ref === undefined ? undefined : inheritedProperty(patch.ref, name, resolve));\n if (declared === undefined || !isSchemaObject(declared.property)) {\n return undefined;\n }\n const ref = (declared.property as { readonly $ref?: unknown }).$ref;\n const parent =\n typeof ref === \"string\"\n ? { schema: resolve(ref), path: typedAt(ref) }\n : { schema: declared.property, path: declared.path };\n return isSchemaObject(parent.schema) && Array.isArray(parent.schema.enum)\n ? { schema: parent.schema, path: parent.path }\n : undefined;\n}\n"],"names":[],"mappings":";;AAyBA,MAAM,kBAAA,GAAqB,YAAA;AAE3B,MAAM,aAAA,GAAgB,CAAA;AAGtB,SAAS,QAAQ,GAAA,EAAqB;AACpC,EAAA,MAAM,QAAA,GAAW,gBAAgB,GAAG,CAAA;AACpC,EAAA,MAAM,MAAA,GAAS,SAAS,KAAA,CAAM,aAAa,EAAE,MAAA,CAAO,CAAC,OAAA,KAAY,OAAA,KAAY,kBAAkB,CAAA;AAC/F,EAAA,OAAO,SAAA,CAAU,CAAC,GAAG,QAAA,CAAS,KAAA,CAAM,GAAG,aAAa,CAAA,EAAG,GAAG,MAAM,CAAC,CAAA;AACnE;AAEA,SAAS,eAAe,KAAA,EAAuC;AAC7D,EAAA,OAAO,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,QAAQ,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC5E;AAGA,SAAS,WAAA,CAAY,IAAA,EAAoB,GAAA,EAAa,IAAA,EAA4C;AAChG,EAAA,MAAM,Y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ObjectSchema(schema, patch) {
|
|
|
33
33
|
function isObjectSchema(schema) {
|
|
34
34
|
return typeof schema === "object" && schema !== null && "type" in schema && schema.type === "object";
|
|
35
35
|
}
|
|
36
|
+
function listedValues(property) {
|
|
37
|
+
if (typeof property !== "object" || property === null) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const { const: constant, enum: values } = property;
|
|
41
|
+
if (constant !== void 0) {
|
|
42
|
+
return [constant];
|
|
43
|
+
}
|
|
44
|
+
return Array.isArray(values) ? values : null;
|
|
45
|
+
}
|
|
46
|
+
function requiresValues(schema, name, values) {
|
|
47
|
+
if (typeof schema !== "object" || schema === null || "$ref" in schema) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const { required, properties } = schema;
|
|
51
|
+
const listed = listedValues(properties?.[name]);
|
|
52
|
+
return Boolean(required?.includes(name)) && listed !== null && listed.length === values.length && values.every((value) => listed.includes(value));
|
|
53
|
+
}
|
|
54
|
+
function declaresValues(schema, patch) {
|
|
55
|
+
const name = patch.discriminator.propertyName;
|
|
56
|
+
return [schema, ...schema?.allOf ?? []].some(
|
|
57
|
+
(item) => requiresValues(item, name, patch.values)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
36
60
|
function addEnumProperty(schema, patch) {
|
|
37
61
|
if (schema?.allOf) {
|
|
38
62
|
return patchAllOf(schema.allOf, patch);
|
|
@@ -41,4 +65,5 @@ function addEnumProperty(schema, patch) {
|
|
|
41
65
|
}
|
|
42
66
|
|
|
43
67
|
exports.addEnumProperty = addEnumProperty;
|
|
68
|
+
exports.declaresValues = declaresValues;
|
|
44
69
|
//# sourceMappingURL=discriminator-enum.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminator-enum.cjs","sources":["../../src/api/discriminator-enum.ts"],"sourcesContent":["import type {\n DiscriminatorObject,\n ObjectSubtype,\n ReferenceObject,\n SchemaObject,\n} from \"../types.js\";\n\n/**\n * The in-place patch of the discriminator pre-pass: a mapped schema gets a required enum property\n * with its discriminator values, so that TypeScript can narrow the generated union.\n */\n\n/** One mapped schema to patch: `ref` is the schema; `discriminatorRef` owns the discriminator. */\nexport interface EnumPatch {\n readonly ref: string;\n readonly values: string[];\n readonly discriminator: DiscriminatorObject;\n readonly discriminatorRef: string;\n}\n\nfunction discriminatorEnum(values: string[], previous?: SchemaObject): SchemaObject {\n return {\n type: \"string\",\n enum: values,\n description: previous?.description\n ? `${previous.description} (enum property replaced by openapi-typesafe)`\n : \"discriminator enum property added by openapi-typesafe\",\n };\n}\n\n/** An `allOf` schema gets one more item that holds the required enum property. */\nfunction patchAllOf(allOf: (SchemaObject | ReferenceObject)[], patch: EnumPatch): SchemaObject {\n const added = discriminatorEnum(patch.values);\n allOf.push({\n type: \"object\",\n required: [patch.discriminator.propertyName],\n properties: { [patch.discriminator.propertyName]: added },\n });\n return added;\n}\n\n/** An object schema gets the enum property, which is always required, added or replaced. */\nfunction patchObjectSchema(schema: SchemaObject & ObjectSubtype, patch: EnumPatch): SchemaObject {\n const name = patch.discriminator.propertyName;\n if (!schema.properties) {\n schema.properties = {};\n }\n if (!schema.required) {\n schema.required = [name];\n } else if (!schema.required.includes(name)) {\n schema.required.push(name);\n }\n const added = discriminatorEnum(patch.values, schema.properties[name] as SchemaObject);\n schema.properties[name] = added;\n return added;\n}\n\nfunction isObjectSchema(schema: unknown): schema is SchemaObject & ObjectSubtype {\n return (\n typeof schema === \"object\" && schema !== null && \"type\" in schema && schema.type === \"object\"\n );\n}\n\n/**\n * Add or replace the enum property in `schema`, an `allOf` or object schema. Returns the added\n * enum schema, or null for another kind of schema, which is left as it is.\n */\nexport function addEnumProperty(\n schema: SchemaObject | undefined,\n patch: EnumPatch,\n): SchemaObject | null {\n if (schema?.allOf) {\n return patchAllOf(schema.allOf, patch);\n }\n return isObjectSchema(schema) ? patchObjectSchema(schema, patch) : null;\n}\n"],"names":[],"mappings":";;AAoBA,SAAS,iBAAA,CAAkB,QAAkB,QAAA,EA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,WAAW,QAAA,IAAY,MAAA,KAAW,QAAQ,MAAA,IAAU,MAAA,IAAU,OAAO,IAAA,KAAS,QAAA;AAEzF;AAMO,SAAS,eAAA,CACd,QACA,KAAA,EACqB;AACrB,EAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,IAAA,OAAO,UAAA,CAAW,MAAA,CAAO,KAAA,EAAO,KAAK,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,eAAe,MAAM,CAAA,GAAI,iBAAA,CAAkB,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AACrE
|
|
1
|
+
{"version":3,"file":"discriminator-enum.cjs","sources":["../../src/api/discriminator-enum.ts"],"sourcesContent":["import type {\n DiscriminatorObject,\n ObjectSubtype,\n ReferenceObject,\n SchemaObject,\n} from \"../types.js\";\n\n/**\n * The in-place patch of the discriminator pre-pass: a mapped schema gets a required enum property\n * with its discriminator values, so that TypeScript can narrow the generated union.\n */\n\n/** One mapped schema to patch: `ref` is the schema; `discriminatorRef` owns the discriminator. */\nexport interface EnumPatch {\n readonly ref: string;\n readonly values: string[];\n readonly discriminator: DiscriminatorObject;\n readonly discriminatorRef: string;\n}\n\nfunction discriminatorEnum(values: string[], previous?: SchemaObject): SchemaObject {\n return {\n type: \"string\",\n enum: values,\n description: previous?.description\n ? `${previous.description} (enum property replaced by openapi-typesafe)`\n : \"discriminator enum property added by openapi-typesafe\",\n };\n}\n\n/** An `allOf` schema gets one more item that holds the required enum property. */\nfunction patchAllOf(allOf: (SchemaObject | ReferenceObject)[], patch: EnumPatch): SchemaObject {\n const added = discriminatorEnum(patch.values);\n allOf.push({\n type: \"object\",\n required: [patch.discriminator.propertyName],\n properties: { [patch.discriminator.propertyName]: added },\n });\n return added;\n}\n\n/** An object schema gets the enum property, which is always required, added or replaced. */\nfunction patchObjectSchema(schema: SchemaObject & ObjectSubtype, patch: EnumPatch): SchemaObject {\n const name = patch.discriminator.propertyName;\n if (!schema.properties) {\n schema.properties = {};\n }\n if (!schema.required) {\n schema.required = [name];\n } else if (!schema.required.includes(name)) {\n schema.required.push(name);\n }\n const added = discriminatorEnum(patch.values, schema.properties[name] as SchemaObject);\n schema.properties[name] = added;\n return added;\n}\n\nfunction isObjectSchema(schema: unknown): schema is SchemaObject & ObjectSubtype {\n return (\n typeof schema === \"object\" && schema !== null && \"type\" in schema && schema.type === \"object\"\n );\n}\n\n/** The values a property schema allows, from `const` or `enum`; null when it lists none. */\nfunction listedValues(property: unknown): readonly unknown[] | null {\n if (typeof property !== \"object\" || property === null) {\n return null;\n }\n const { const: constant, enum: values } = property as SchemaObject;\n if (constant !== undefined) {\n return [constant];\n }\n return Array.isArray(values) ? values : null;\n}\n\n/** Whether one schema object requires the property and allows exactly the values. */\nfunction requiresValues(schema: unknown, name: string, values: readonly string[]): boolean {\n if (typeof schema !== \"object\" || schema === null || \"$ref\" in schema) {\n return false;\n }\n const { required, properties } = schema as SchemaObject & ObjectSubtype;\n const listed = listedValues(properties?.[name]);\n return (\n Boolean(required?.includes(name)) &&\n listed !== null &&\n listed.length === values.length &&\n values.every((value) => listed.includes(value))\n );\n}\n\n/**\n * Whether `schema`, or an inline `allOf` item of it, already requires the discriminator property\n * with exactly the patch's values (the `discriminator-values` fix). Then a patch would\n * only repeat it (#2124).\n */\nexport function declaresValues(schema: SchemaObject | undefined, patch: EnumPatch): boolean {\n const name = patch.discriminator.propertyName;\n return [schema, ...(schema?.allOf ?? [])].some((item) =>\n requiresValues(item, name, patch.values),\n );\n}\n\n/**\n * Add or replace the enum property in `schema`, an `allOf` or object schema. Returns the added\n * enum schema, or null for another kind of schema, which is left as it is.\n */\nexport function addEnumProperty(\n schema: SchemaObject | undefined,\n patch: EnumPatch,\n): SchemaObject | null {\n if (schema?.allOf) {\n return patchAllOf(schema.allOf, patch);\n }\n return isObjectSchema(schema) ? patchObjectSchema(schema, patch) : null;\n}\n"],"names":[],"mappings":";;AAoBA,SAAS,iBAAA,CAAkB,QAAkB,QAAA,EAAuC;AAClF,EAAA,OAAO;AAA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AA,EAAM,MAAM,MAAM;AAAA,GACzC;AACF;AAMO,SAAS,eAAA,CACd,QACA,KAAA,EACqB;AACrB,EAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,IAAA,OAAO,UAAA,CAAW,MAAA,CAAO,KAAA,EAAO,KAAK,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,eAAe,MAAM,CAAA,GAAI,iBAAA,CAAkB,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AACrE;;;"}
|
|
@@ -31,6 +31,30 @@ function patchObjectSchema(schema, patch) {
|
|
|
31
31
|
function isObjectSchema(schema) {
|
|
32
32
|
return typeof schema === "object" && schema !== null && "type" in schema && schema.type === "object";
|
|
33
33
|
}
|
|
34
|
+
function listedValues(property) {
|
|
35
|
+
if (typeof property !== "object" || property === null) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const { const: constant, enum: values } = property;
|
|
39
|
+
if (constant !== void 0) {
|
|
40
|
+
return [constant];
|
|
41
|
+
}
|
|
42
|
+
return Array.isArray(values) ? values : null;
|
|
43
|
+
}
|
|
44
|
+
function requiresValues(schema, name, values) {
|
|
45
|
+
if (typeof schema !== "object" || schema === null || "$ref" in schema) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const { required, properties } = schema;
|
|
49
|
+
const listed = listedValues(properties?.[name]);
|
|
50
|
+
return Boolean(required?.includes(name)) && listed !== null && listed.length === values.length && values.every((value) => listed.includes(value));
|
|
51
|
+
}
|
|
52
|
+
function declaresValues(schema, patch) {
|
|
53
|
+
const name = patch.discriminator.propertyName;
|
|
54
|
+
return [schema, ...schema?.allOf ?? []].some(
|
|
55
|
+
(item) => requiresValues(item, name, patch.values)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
34
58
|
function addEnumProperty(schema, patch) {
|
|
35
59
|
if (schema?.allOf) {
|
|
36
60
|
return patchAllOf(schema.allOf, patch);
|
|
@@ -38,5 +62,5 @@ function addEnumProperty(schema, patch) {
|
|
|
38
62
|
return isObjectSchema(schema) ? patchObjectSchema(schema, patch) : null;
|
|
39
63
|
}
|
|
40
64
|
|
|
41
|
-
export { addEnumProperty };
|
|
65
|
+
export { addEnumProperty, declaresValues };
|
|
42
66
|
//# sourceMappingURL=discriminator-enum.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminator-enum.mjs","sources":["../../src/api/discriminator-enum.ts"],"sourcesContent":["import type {\n DiscriminatorObject,\n ObjectSubtype,\n ReferenceObject,\n SchemaObject,\n} from \"../types.js\";\n\n/**\n * The in-place patch of the discriminator pre-pass: a mapped schema gets a required enum property\n * with its discriminator values, so that TypeScript can narrow the generated union.\n */\n\n/** One mapped schema to patch: `ref` is the schema; `discriminatorRef` owns the discriminator. */\nexport interface EnumPatch {\n readonly ref: string;\n readonly values: string[];\n readonly discriminator: DiscriminatorObject;\n readonly discriminatorRef: string;\n}\n\nfunction discriminatorEnum(values: string[], previous?: SchemaObject): SchemaObject {\n return {\n type: \"string\",\n enum: values,\n description: previous?.description\n ? `${previous.description} (enum property replaced by openapi-typesafe)`\n : \"discriminator enum property added by openapi-typesafe\",\n };\n}\n\n/** An `allOf` schema gets one more item that holds the required enum property. */\nfunction patchAllOf(allOf: (SchemaObject | ReferenceObject)[], patch: EnumPatch): SchemaObject {\n const added = discriminatorEnum(patch.values);\n allOf.push({\n type: \"object\",\n required: [patch.discriminator.propertyName],\n properties: { [patch.discriminator.propertyName]: added },\n });\n return added;\n}\n\n/** An object schema gets the enum property, which is always required, added or replaced. */\nfunction patchObjectSchema(schema: SchemaObject & ObjectSubtype, patch: EnumPatch): SchemaObject {\n const name = patch.discriminator.propertyName;\n if (!schema.properties) {\n schema.properties = {};\n }\n if (!schema.required) {\n schema.required = [name];\n } else if (!schema.required.includes(name)) {\n schema.required.push(name);\n }\n const added = discriminatorEnum(patch.values, schema.properties[name] as SchemaObject);\n schema.properties[name] = added;\n return added;\n}\n\nfunction isObjectSchema(schema: unknown): schema is SchemaObject & ObjectSubtype {\n return (\n typeof schema === \"object\" && schema !== null && \"type\" in schema && schema.type === \"object\"\n );\n}\n\n/**\n * Add or replace the enum property in `schema`, an `allOf` or object schema. Returns the added\n * enum schema, or null for another kind of schema, which is left as it is.\n */\nexport function addEnumProperty(\n schema: SchemaObject | undefined,\n patch: EnumPatch,\n): SchemaObject | null {\n if (schema?.allOf) {\n return patchAllOf(schema.allOf, patch);\n }\n return isObjectSchema(schema) ? patchObjectSchema(schema, patch) : null;\n}\n"],"names":[],"mappings":"AAoBA,SAAS,iBAAA,CAAkB,QAAkB,QAAA,EAAuC;AAClF,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,QAAA;AAAA,IACN,IAAA,EAAM,MAAA;AAAA,IACN,aAAa,QAAA,EAAU,WAAA,GACnB,CAAA,EAAG,QAAA,CAAS,WAAW,CAAA,6CAAA,CAAA,GACvB;AAAA,GACN;AACF;AAGA,SAAS,UAAA,CAAW,OAA2C,KAAA,EAAgC;AAC7F,EAAA,MAAM,KAAA,GAAQ,iBAAA,CAAkB,KAAA,CAAM,MAAM,CAAA;AAC5C,EAAA,KAAA,CAAM,IAAA,CAAK;AAAA,IACT,IAAA,EAAM,QAAA;AAAA,IACN,QAAA,EAAU,CAAC,KAAA,CAAM,aAAA,CAAc,YAAY,CAAA;AAAA,IAC3C,YAAY,EAAE,CAAC,MAAM,aAAA,CAAc,YAAY,GAAG,KAAA;AAAM,GACzD,CAAA;AACD,EAAA,OAAO,KAAA;AACT;AAGA,SAAS,iBAAA,CAAkB,QAAsC,KAAA,EAAgC;AAC/F,EAAA,MAAM,IAAA,GAAO,MAAM,aAAA,CAAc,YAAA;AACjC,EAAA,IAAI,CAAC,OAAO,UAAA,EAAY;AACtB,IAAA,MAAA,CAAO,aAAa,EAAC;AAAA,EACvB;AACA,EAAA,IAAI,CAAC,OAAO,QAAA,EAAU;AACpB,IAAA,MAAA,CAAO,QAAA,GAAW,CAAC,IAAI,CAAA;AAAA,EACzB,WAAW,CAAC,MAAA,CAAO,QAAA,CAAS,QAAA,CAAS,IAAI,CAAA,EAAG;AAC1C,IAAA,MAAA,CAAO,QAAA,CAAS,KAAK,IAAI,CAAA;AAAA,EAC3B;AACA,EAAA,MAAM,QAAQ,iBAAA,CAAkB,KAAA,CAAM,QAAQ,MAAA,CAAO,UAAA,CAAW,IAAI,CAAiB,CAAA;AACrF,EAAA,MAAA,CAAO,UAAA,CAAW,IAAI,CAAA,GAAI,KAAA;AAC1B,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,eAAe,MAAA,EAAyD;AAC/E,EAAA,OACE,OAAO,WAAW,QAAA,IAAY,MAAA,KAAW,QAAQ,MAAA,IAAU,MAAA,IAAU,OAAO,IAAA,KAAS,QAAA;AAEzF;AAMO,SAAS,eAAA,CACd,QACA,KAAA,EACqB;AACrB,EAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,IAAA,OAAO,UAAA,CAAW,MAAA,CAAO,KAAA,EAAO,KAAK,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,eAAe,MAAM,CAAA,GAAI,iBAAA,CAAkB,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AACrE;;"}
|
|
1
|
+
{"version":3,"file":"discriminator-enum.mjs","sources":["../../src/api/discriminator-enum.ts"],"sourcesContent":["import type {\n DiscriminatorObject,\n ObjectSubtype,\n ReferenceObject,\n SchemaObject,\n} from \"../types.js\";\n\n/**\n * The in-place patch of the discriminator pre-pass: a mapped schema gets a required enum property\n * with its discriminator values, so that TypeScript can narrow the generated union.\n */\n\n/** One mapped schema to patch: `ref` is the schema; `discriminatorRef` owns the discriminator. */\nexport interface EnumPatch {\n readonly ref: string;\n readonly values: string[];\n readonly discriminator: DiscriminatorObject;\n readonly discriminatorRef: string;\n}\n\nfunction discriminatorEnum(values: string[], previous?: SchemaObject): SchemaObject {\n return {\n type: \"string\",\n enum: values,\n description: previous?.description\n ? `${previous.description} (enum property replaced by openapi-typesafe)`\n : \"discriminator enum property added by openapi-typesafe\",\n };\n}\n\n/** An `allOf` schema gets one more item that holds the required enum property. */\nfunction patchAllOf(allOf: (SchemaObject | ReferenceObject)[], patch: EnumPatch): SchemaObject {\n const added = discriminatorEnum(patch.values);\n allOf.push({\n type: \"object\",\n required: [patch.discriminator.propertyName],\n properties: { [patch.discriminator.propertyName]: added },\n });\n return added;\n}\n\n/** An object schema gets the enum property, which is always required, added or replaced. */\nfunction patchObjectSchema(schema: SchemaObject & ObjectSubtype, patch: EnumPatch): SchemaObject {\n const name = patch.discriminator.propertyName;\n if (!schema.properties) {\n schema.properties = {};\n }\n if (!schema.required) {\n schema.required = [name];\n } else if (!schema.required.includes(name)) {\n schema.required.push(name);\n }\n const added = discriminatorEnum(patch.values, schema.properties[name] as SchemaObject);\n schema.properties[name] = added;\n return added;\n}\n\nfunction isObjectSchema(schema: unknown): schema is SchemaObject & ObjectSubtype {\n return (\n typeof schema === \"object\" && schema !== null && \"type\" in schema && schema.type === \"object\"\n );\n}\n\n/** The values a property schema allows, from `const` or `enum`; null when it lists none. */\nfunction listedValues(property: unknown): readonly unknown[] | null {\n if (typeof property !== \"object\" || property === null) {\n return null;\n }\n const { const: constant, enum: values } = property as SchemaObject;\n if (constant !== undefined) {\n return [constant];\n }\n return Array.isArray(values) ? values : null;\n}\n\n/** Whether one schema object requires the property and allows exactly the values. */\nfunction requiresValues(schema: unknown, name: string, values: readonly string[]): boolean {\n if (typeof schema !== \"object\" || schema === null || \"$ref\" in schema) {\n return false;\n }\n const { required, properties } = schema as SchemaObject & ObjectSubtype;\n const listed = listedValues(properties?.[name]);\n return (\n Boolean(required?.includes(name)) &&\n listed !== null &&\n listed.length === values.length &&\n values.every((value) => listed.includes(value))\n );\n}\n\n/**\n * Whether `schema`, or an inline `allOf` item of it, already requires the discriminator property\n * with exactly the patch's values (the `discriminator-values` fix). Then a patch would\n * only repeat it (#2124).\n */\nexport function declaresValues(schema: SchemaObject | undefined, patch: EnumPatch): boolean {\n const name = patch.discriminator.propertyName;\n return [schema, ...(schema?.allOf ?? [])].some((item) =>\n requiresValues(item, name, patch.values),\n );\n}\n\n/**\n * Add or replace the enum property in `schema`, an `allOf` or object schema. Returns the added\n * enum schema, or null for another kind of schema, which is left as it is.\n */\nexport function addEnumProperty(\n schema: SchemaObject | undefined,\n patch: EnumPatch,\n): SchemaObject | null {\n if (schema?.allOf) {\n return patchAllOf(schema.allOf, patch);\n }\n return isObjectSchema(schema) ? patchObjectSchema(schema, patch) : null;\n}\n"],"names":[],"mappings":"AAoBA,SAAS,iBAAA,CAAkB,QAAkB,QAAA,EAAuC;AAClF,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,QAAA;AAAA,IACN,IAAA,EAAM,MAAA;AAAA,IACN,aAAa,QAAA,EAAU,WAAA,GACnB,CAAA,EAAG,QAAA,CAAS,WAAW,CAAA,6CAAA,CAAA,GACvB;AAAA,GACN;AACF;AAGA,SAAS,UAAA,CAAW,OAA2C,KAAA,EAAgC;AAC7F,EAAA,MAAM,KAAA,GAAQ,iBAAA,CAAkB,KAAA,CAAM,MAAM,CAAA;AAC5C,EAAA,KAAA,CAAM,IAAA,CAAK;AAAA,IACT,IAAA,EAAM,QAAA;AAAA,IACN,QAAA,EAAU,CAAC,KAAA,CAAM,aAAA,CAAc,YAAY,CAAA;AAAA,IAC3C,YAAY,EAAE,CAAC,MAAM,aAAA,CAAc,YAAY,GAAG,KAAA;AAAM,GACzD,CAAA;AACD,EAAA,OAAO,KAAA;AACT;AAGA,SAAS,iBAAA,CAAkB,QAAsC,KAAA,EAAgC;AAC/F,EAAA,MAAM,IAAA,GAAO,MAAM,aAAA,CAAc,YAAA;AACjC,EAAA,IAAI,CAAC,OAAO,UAAA,EAAY;AACtB,IAAA,MAAA,CAAO,aAAa,EAAC;AAAA,EACvB;AACA,EAAA,IAAI,CAAC,OAAO,QAAA,EAAU;AACpB,IAAA,MAAA,CAAO,QAAA,GAAW,CAAC,IAAI,CAAA;AAAA,EACzB,WAAW,CAAC,MAAA,CAAO,QAAA,CAAS,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,IACX,MAAA,CAAO,WAAW,MAAA,CAAO,MAAA,IACzB,OAAO,KAAA,CAAM,CAAC,UAAU,MAAA,CAAO,QAAA,CAAS,KAAK,CAAC,CAAA;AAElD;AAOO,SAAS,cAAA,CAAe,QAAkC,KAAA,EAA2B;AAC1F,EAAA,MAAM,IAAA,GAAO,MAAM,aAAA,CAAc,YAAA;AACjC,EAAA,OAAO,CAAC,MAAA,EAAQ,GAAI,QAAQ,KAAA,IAAS,EAAG,CAAA,CAAE,IAAA;AAAA,IAAK,CAAC,IAAA,KAC9C,cAAA,CAAe,IAAA,EAAM,IAAA,EAAM,MAAM,MAAM;AAAA,GACzC;AACF;AAMO,SAAS,eAAA,CACd,QACA,KAAA,EACqB;AACrB,EAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,IAAA,OAAO,UAAA,CAAW,MAAA,CAAO,KAAA,EAAO,KAAK,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,eAAe,MAAM,CAAA,GAAI,iBAAA,CAAkB,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AACrE;;"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const discriminatorPatch = require('./discriminator-patch.cjs');
|
|
4
|
+
const documentRefs = require('./document-refs.cjs');
|
|
5
|
+
|
|
6
|
+
function allOfRefs(state, ref) {
|
|
7
|
+
const { silent, logger } = state;
|
|
8
|
+
const schema = documentRefs.resolveDocumentRef(state.schema, ref, { silent, logger });
|
|
9
|
+
const items = schema?.allOf ?? [];
|
|
10
|
+
return items.flatMap(
|
|
11
|
+
(item) => "$ref" in item && typeof item.$ref === "string" ? [item.$ref] : []
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
function otherOwners(state, parentRef) {
|
|
15
|
+
const own = state.objects[parentRef]?.propertyName;
|
|
16
|
+
const found = /* @__PURE__ */ new Map();
|
|
17
|
+
const visited = /* @__PURE__ */ new Set();
|
|
18
|
+
const queue = [parentRef];
|
|
19
|
+
for (let ref = queue.shift(); ref !== void 0; ref = queue.shift()) {
|
|
20
|
+
if (visited.has(ref)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
visited.add(ref);
|
|
24
|
+
const discriminator = state.owners.has(ref) ? state.objects[ref] : void 0;
|
|
25
|
+
const name = discriminator?.propertyName;
|
|
26
|
+
if (discriminator && name !== void 0 && name !== own && !found.has(name)) {
|
|
27
|
+
found.set(name, { discriminator, ownerRef: ref });
|
|
28
|
+
}
|
|
29
|
+
queue.push(...allOfRefs(state, ref));
|
|
30
|
+
}
|
|
31
|
+
return [...found.values()];
|
|
32
|
+
}
|
|
33
|
+
function recordOtherProperty(state, ref, propertyName) {
|
|
34
|
+
const names = state.otherProperties[ref] ?? [];
|
|
35
|
+
if (!names.includes(propertyName)) {
|
|
36
|
+
names.push(propertyName);
|
|
37
|
+
}
|
|
38
|
+
state.otherProperties[ref] = names;
|
|
39
|
+
}
|
|
40
|
+
function inheritOtherOwners(state, parentRef, ref) {
|
|
41
|
+
const childProperty = state.objects[ref]?.propertyName;
|
|
42
|
+
for (const { discriminator, ownerRef } of otherOwners(state, parentRef)) {
|
|
43
|
+
if (discriminator.propertyName === childProperty) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
recordOtherProperty(state, ref, discriminator.propertyName);
|
|
47
|
+
const mapped = Object.entries(discriminator.mapping ?? {}).filter(([, target]) => target === ref).map(([value]) => value);
|
|
48
|
+
const name = ref.slice(ref.lastIndexOf("/") + 1);
|
|
49
|
+
const patch = { ref, values: mapped, discriminator, discriminatorRef: ownerRef };
|
|
50
|
+
if (mapped.length > 0) {
|
|
51
|
+
discriminatorPatch.patchDiscriminatorEnum(state, patch);
|
|
52
|
+
} else {
|
|
53
|
+
state.otherInferredPatches.push({ ...patch, values: [name] });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function applyOtherInferredPatches(state, mapped) {
|
|
58
|
+
for (const patch of state.otherInferredPatches) {
|
|
59
|
+
if (!mapped.has(discriminatorPatch.enumKey(patch))) {
|
|
60
|
+
discriminatorPatch.patchDiscriminatorEnum(state, patch);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.applyOtherInferredPatches = applyOtherInferredPatches;
|
|
66
|
+
exports.inheritOtherOwners = inheritOtherOwners;
|
|
67
|
+
//# sourceMappingURL=discriminator-other-owners.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-other-owners.cjs","sources":["../../src/api/discriminator-other-owners.ts"],"sourcesContent":["import type { DiscriminatorObject, ReferenceObject, SchemaObject } from \"../types.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\nimport { enumKey, patchDiscriminatorEnum, type ScanState } from \"./discriminator-patch.js\";\nimport { resolveDocumentRef } from \"./document-refs.js\";\n\n/**\n * The `discriminator-values` fix: a schema inherits one discriminator per property. A schema that\n * owns a discriminator keeps its own (#2200), so the scan does not record the one it inherits for\n * another property (`Content` owns `subtype` and `allOf`s `Element`, which owns `contentType`).\n * Its members (`Video`) still get a value of that property, found here from the owners above.\n */\n\n/** A discriminator and the schema that defines it. */\ninterface OtherOwner {\n readonly discriminator: DiscriminatorObject;\n readonly ownerRef: string;\n}\n\n/** The `$ref`s of a schema's `allOf` items. */\nfunction allOfRefs(state: ScanState, ref: string): string[] {\n const { silent, logger } = state;\n const schema = resolveDocumentRef<SchemaObject>(state.schema, ref, { silent, logger });\n const items = (schema?.allOf ?? []) as (SchemaObject | ReferenceObject)[];\n return items.flatMap((item) =>\n \"$ref\" in item && typeof item.$ref === \"string\" ? [item.$ref] : [],\n );\n}\n\n/**\n * The owners' discriminators that the schema at `parentRef` and its `allOf` parents define, the\n * nearest one per property, except the property of `parentRef`'s own discriminator.\n */\nfunction otherOwners(state: ScanState, parentRef: string): OtherOwner[] {\n const own = state.objects[parentRef]?.propertyName;\n const found = new Map<string, OtherOwner>();\n const visited = new Set<string>();\n const queue = [parentRef];\n for (let ref = queue.shift(); ref !== undefined; ref = queue.shift()) {\n if (visited.has(ref)) {\n continue;\n }\n visited.add(ref);\n const discriminator = state.owners.has(ref) ? state.objects[ref] : undefined;\n const name = discriminator?.propertyName;\n if (discriminator && name !== undefined && name !== own && !found.has(name)) {\n found.set(name, { discriminator, ownerRef: ref });\n }\n queue.push(...allOfRefs(state, ref));\n }\n return [...found.values()];\n}\n\n/**\n * The child redefines this property, so its `allOf` items omit it: a parent may have a value of\n * its own, as `Content` has when `Element`'s mapping names it.\n */\nfunction recordOtherProperty(state: ScanState, ref: string, propertyName: string): void {\n const names = state.otherProperties[ref] ?? [];\n if (!names.includes(propertyName)) {\n names.push(propertyName);\n }\n state.otherProperties[ref] = names;\n}\n\n/**\n * The child at `ref` of the schema at `parentRef` gets a value of each other property: a mapped\n * one at once, else its schema name after both passes, where no mapping gives one. The schema's\n * own discriminator property is still added, so these patches do not mark it handled.\n */\nexport function inheritOtherOwners(state: ScanState, parentRef: string, ref: string): void {\n const childProperty = state.objects[ref]?.propertyName;\n for (const { discriminator, ownerRef } of otherOwners(state, parentRef)) {\n if (discriminator.propertyName === childProperty) {\n continue;\n }\n recordOtherProperty(state, ref, discriminator.propertyName);\n const mapped = Object.entries(discriminator.mapping ?? {})\n .filter(([, target]) => target === ref)\n .map(([value]) => value);\n const name = ref.slice(ref.lastIndexOf(\"/\") + 1);\n const patch: EnumPatch = { ref, values: mapped, discriminator, discriminatorRef: ownerRef };\n if (mapped.length > 0) {\n patchDiscriminatorEnum(state, patch);\n } else {\n state.otherInferredPatches.push({ ...patch, values: [name] });\n }\n }\n}\n\n/** The deferred schema-name values of other properties; see `inheritOtherOwners`. */\nexport function applyOtherInferredPatches(state: ScanState, mapped: ReadonlySet<string>): void {\n for (const patch of state.otherInferredPatches) {\n if (!mapped.has(enumKey(patch))) {\n patchDiscriminatorEnum(state, patch);\n }\n }\n}\n"],"names":["resolveDocumentRef","patchDiscriminatorEn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,IAAA,MAAM,OAAO,GAAA,CAAI,KAAA,CAAM,IAAI,WAAA,CAAY,GAAG,IAAI,CAAC,CAAA;AAC/C,IAAA,MAAM,QAAmB,EAAE,GAAA,EAAK,QAAQ,MAAA,EAAQ,aAAA,EAAe,kBAAkB,QAAA,EAAS;AAC1F,IAAA,IAAI,MAAA,CAAO,SAAS,CAAA,EAAG;AACrB,MAAAC,yCAAA,CAAuB,OAAO,KAAK,CAAA;AAAA,IACrC,CAAA,MAAO;AACL,MAAA,KAAA,CAAM,oBAAA,CAAqB,KAAK,EAAE,GAAG,OAAO,MAAA,EAAQ,CAAC,IAAI,CAAA,EAAG,CAAA;AAAA,IAC9D;AAAA,EACF;AACF;AAGO,SAAS,yBAAA,CAA0B,OAAkB,MAAA,EAAmC;AAC7F,EAAA,KAAA,MAAW,KAAA,IAAS,MAAM,oBAAA,EAAsB;AAC9C,IAAA,IAAI,CAAC,MAAA,CAAO,GAAA,CAAIC,0BAAA,CAAQ,KAAK,CAAC,CAAA,EAAG;AAC/B,MAAAD,yCAAA,CAAuB,OAAO,KAAK,CAAA;AAAA,IACrC;AAAA,EACF;AACF;;;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { enumKey, patchDiscriminatorEnum } from './discriminator-patch.mjs';
|
|
2
|
+
import { resolveDocumentRef } from './document-refs.mjs';
|
|
3
|
+
|
|
4
|
+
function allOfRefs(state, ref) {
|
|
5
|
+
const { silent, logger } = state;
|
|
6
|
+
const schema = resolveDocumentRef(state.schema, ref, { silent, logger });
|
|
7
|
+
const items = schema?.allOf ?? [];
|
|
8
|
+
return items.flatMap(
|
|
9
|
+
(item) => "$ref" in item && typeof item.$ref === "string" ? [item.$ref] : []
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
function otherOwners(state, parentRef) {
|
|
13
|
+
const own = state.objects[parentRef]?.propertyName;
|
|
14
|
+
const found = /* @__PURE__ */ new Map();
|
|
15
|
+
const visited = /* @__PURE__ */ new Set();
|
|
16
|
+
const queue = [parentRef];
|
|
17
|
+
for (let ref = queue.shift(); ref !== void 0; ref = queue.shift()) {
|
|
18
|
+
if (visited.has(ref)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
visited.add(ref);
|
|
22
|
+
const discriminator = state.owners.has(ref) ? state.objects[ref] : void 0;
|
|
23
|
+
const name = discriminator?.propertyName;
|
|
24
|
+
if (discriminator && name !== void 0 && name !== own && !found.has(name)) {
|
|
25
|
+
found.set(name, { discriminator, ownerRef: ref });
|
|
26
|
+
}
|
|
27
|
+
queue.push(...allOfRefs(state, ref));
|
|
28
|
+
}
|
|
29
|
+
return [...found.values()];
|
|
30
|
+
}
|
|
31
|
+
function recordOtherProperty(state, ref, propertyName) {
|
|
32
|
+
const names = state.otherProperties[ref] ?? [];
|
|
33
|
+
if (!names.includes(propertyName)) {
|
|
34
|
+
names.push(propertyName);
|
|
35
|
+
}
|
|
36
|
+
state.otherProperties[ref] = names;
|
|
37
|
+
}
|
|
38
|
+
function inheritOtherOwners(state, parentRef, ref) {
|
|
39
|
+
const childProperty = state.objects[ref]?.propertyName;
|
|
40
|
+
for (const { discriminator, ownerRef } of otherOwners(state, parentRef)) {
|
|
41
|
+
if (discriminator.propertyName === childProperty) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
recordOtherProperty(state, ref, discriminator.propertyName);
|
|
45
|
+
const mapped = Object.entries(discriminator.mapping ?? {}).filter(([, target]) => target === ref).map(([value]) => value);
|
|
46
|
+
const name = ref.slice(ref.lastIndexOf("/") + 1);
|
|
47
|
+
const patch = { ref, values: mapped, discriminator, discriminatorRef: ownerRef };
|
|
48
|
+
if (mapped.length > 0) {
|
|
49
|
+
patchDiscriminatorEnum(state, patch);
|
|
50
|
+
} else {
|
|
51
|
+
state.otherInferredPatches.push({ ...patch, values: [name] });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function applyOtherInferredPatches(state, mapped) {
|
|
56
|
+
for (const patch of state.otherInferredPatches) {
|
|
57
|
+
if (!mapped.has(enumKey(patch))) {
|
|
58
|
+
patchDiscriminatorEnum(state, patch);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { applyOtherInferredPatches, inheritOtherOwners };
|
|
64
|
+
//# sourceMappingURL=discriminator-other-owners.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator-other-owners.mjs","sources":["../../src/api/discriminator-other-owners.ts"],"sourcesContent":["import type { DiscriminatorObject, ReferenceObject, SchemaObject } from \"../types.js\";\nimport type { EnumPatch } from \"./discriminator-enum.js\";\nimport { enumKey, patchDiscriminatorEnum, type ScanState } from \"./discriminator-patch.js\";\nimport { resolveDocumentRef } from \"./document-refs.js\";\n\n/**\n * The `discriminator-values` fix: a schema inherits one discriminator per property. A schema that\n * owns a discriminator keeps its own (#2200), so the scan does not record the one it inherits for\n * another property (`Content` owns `subtype` and `allOf`s `Element`, which owns `contentType`).\n * Its members (`Video`) still get a value of that property, found here from the owners above.\n */\n\n/** A discriminator and the schema that defines it. */\ninterface OtherOwner {\n readonly discriminator: DiscriminatorObject;\n readonly ownerRef: string;\n}\n\n/** The `$ref`s of a schema's `allOf` items. */\nfunction allOfRefs(state: ScanState, ref: string): string[] {\n const { silent, logger } = state;\n const schema = resolveDocumentRef<SchemaObject>(state.schema, ref, { silent, logger });\n const items = (schema?.allOf ?? []) as (SchemaObject | ReferenceObject)[];\n return items.flatMap((item) =>\n \"$ref\" in item && typeof item.$ref === \"string\" ? [item.$ref] : [],\n );\n}\n\n/**\n * The owners' discriminators that the schema at `parentRef` and its `allOf` parents define, the\n * nearest one per property, except the property of `parentRef`'s own discriminator.\n */\nfunction otherOwners(state: ScanState, parentRef: string): OtherOwner[] {\n const own = state.objects[parentRef]?.propertyName;\n const found = new Map<string, OtherOwner>();\n const visited = new Set<string>();\n const queue = [parentRef];\n for (let ref = queue.shift(); ref !== undefined; ref = queue.shift()) {\n if (visited.has(ref)) {\n continue;\n }\n visited.add(ref);\n const discriminator = state.owners.has(ref) ? state.objects[ref] : undefined;\n const name = discriminator?.propertyName;\n if (discriminator && name !== undefined && name !== own && !found.has(name)) {\n found.set(name, { discriminator, ownerRef: ref });\n }\n queue.push(...allOfRefs(state, ref));\n }\n return [...found.values()];\n}\n\n/**\n * The child redefines this property, so its `allOf` items omit it: a parent may have a value of\n * its own, as `Content` has when `Element`'s mapping names it.\n */\nfunction recordOtherProperty(state: ScanState, ref: string, propertyName: string): void {\n const names = state.otherProperties[ref] ?? [];\n if (!names.includes(propertyName)) {\n names.push(propertyName);\n }\n state.otherProperties[ref] = names;\n}\n\n/**\n * The child at `ref` of the schema at `parentRef` gets a value of each other property: a mapped\n * one at once, else its schema name after both passes, where no mapping gives one. The schema's\n * own discriminator property is still added, so these patches do not mark it handled.\n */\nexport function inheritOtherOwners(state: ScanState, parentRef: string, ref: string): void {\n const childProperty = state.objects[ref]?.propertyName;\n for (const { discriminator, ownerRef } of otherOwners(state, parentRef)) {\n if (discriminator.propertyName === childProperty) {\n continue;\n }\n recordOtherProperty(state, ref, discriminator.propertyName);\n const mapped = Object.entries(discriminator.mapping ?? {})\n .filter(([, target]) => target === ref)\n .map(([value]) => value);\n const name = ref.slice(ref.lastIndexOf(\"/\") + 1);\n const patch: EnumPatch = { ref, values: mapped, discriminator, discriminatorRef: ownerRef };\n if (mapped.length > 0) {\n patchDiscriminatorEnum(state, patch);\n } else {\n state.otherInferredPatches.push({ ...patch, values: [name] });\n }\n }\n}\n\n/** The deferred schema-name values of other properties; see `inheritOtherOwners`. */\nexport function applyOtherInferredPatches(state: ScanState, mapped: ReadonlySet<string>): void {\n for (const patch of state.otherInferredPatches) {\n if (!mapped.has(enumKey(patch))) {\n patchDiscriminatorEnum(state, patch);\n }\n }\n}\n"],"names":[],"mappings":";;;AAmBA,SAAS,SAAA,CAAU,OAAkB,GAAA,EAAuB;AAC1D,EAAA,MAAM,EAAE,M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AAA,MAAM,QAAmB,EAAE,GAAA,EAAK,QAAQ,MAAA,EAAQ,aAAA,EAAe,kBAAkB,QAAA,EAAS;AAC1F,IAAA,IAAI,MAAA,CAAO,SAAS,CAAA,EAAG;AACrB,MAAA,sBAAA,CAAuB,OAAO,KAAK,CAAA;AAAA,IACrC,CAAA,MAAO;AACL,MAAA,KAAA,CAAM,oBAAA,CAAqB,KAAK,EAAE,GAAG,OAAO,MAAA,EAAQ,CAAC,IAAI,CAAA,EAAG,CAAA;AAAA,IAC9D;AAAA,EACF;AACF;AAGO,SAAS,yBAAA,CAA0B,OAAkB,MAAA,EAAmC;AAC7F,EAAA,KAAA,MAAW,KAAA,IAAS,MAAM,oBAAA,EAAsB;AAC9C,IAAA,IAAI,CAAC,MAAA,CAAO,GAAA,CAAI,OAAA,CAAQ,KAAK,CAAC,CAAA,EAAG;AAC/B,MAAA,sBAAA,CAAuB,OAAO,KAAK,CAAA;AAAA,IACrC;AAAA,EACF;AACF;;"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const outputFixes = require('../domain/output-fixes.cjs');
|
|
4
|
+
const warnings = require('../domain/warnings.cjs');
|
|
5
|
+
const discriminatorEnum = require('./discriminator-enum.cjs');
|
|
6
|
+
const discriminatorEnumParent = require('./discriminator-enum-parent.cjs');
|
|
7
|
+
const documentRefs = require('./document-refs.cjs');
|
|
8
|
+
|
|
9
|
+
function mergesValues(state) {
|
|
10
|
+
return state.fixes.has(outputFixes.OutputFix.DISCRIMINATOR_VALUES);
|
|
11
|
+
}
|
|
12
|
+
function patchedSchema(state, patch) {
|
|
13
|
+
const { silent, logger } = state;
|
|
14
|
+
return documentRefs.resolveDocumentRef(state.schema, patch.ref, { silent, logger });
|
|
15
|
+
}
|
|
16
|
+
function isDeclared(state, patch) {
|
|
17
|
+
return state.fixes.has(outputFixes.OutputFix.DISCRIMINATOR_VALUES) && discriminatorEnum.declaresValues(patchedSchema(state, patch), patch);
|
|
18
|
+
}
|
|
19
|
+
function recordEnumParent(state, owner, key) {
|
|
20
|
+
if (!state.fixes.has(outputFixes.OutputFix.DISCRIMINATOR_VALUES)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const { silent, logger } = state;
|
|
24
|
+
const parent = discriminatorEnumParent.enumParentOf(
|
|
25
|
+
owner,
|
|
26
|
+
(ref) => documentRefs.resolveDocumentRef(state.schema, ref, { silent, logger })
|
|
27
|
+
);
|
|
28
|
+
if (parent !== void 0) {
|
|
29
|
+
state.enumParents.set(key, parent);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function addDiscriminatorEnum(state, patch) {
|
|
33
|
+
const added = discriminatorEnum.addEnumProperty(patchedSchema(state, patch), patch);
|
|
34
|
+
if (added === null) {
|
|
35
|
+
warnInvalidMapping(patch, state.logger);
|
|
36
|
+
} else {
|
|
37
|
+
recordEnumParent(state, patch, added);
|
|
38
|
+
}
|
|
39
|
+
return added;
|
|
40
|
+
}
|
|
41
|
+
function enumKey(patch) {
|
|
42
|
+
return `${patch.ref}
|
|
43
|
+
${patch.discriminator.propertyName}`;
|
|
44
|
+
}
|
|
45
|
+
function mergeIntoPatchedEnum(state, key, values) {
|
|
46
|
+
const patched = state.patchedEnums.get(key);
|
|
47
|
+
if (patched === void 0) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const merged = patched.enum;
|
|
51
|
+
merged.push(...values.filter((value) => !merged.includes(value)));
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
function patchDiscriminatorEnum(state, patch) {
|
|
55
|
+
if (isDeclared(state, patch)) {
|
|
56
|
+
state.declaredKeys.add(enumKey(patch));
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (!mergesValues(state)) {
|
|
60
|
+
return addDiscriminatorEnum(state, patch) !== null;
|
|
61
|
+
}
|
|
62
|
+
const key = enumKey(patch);
|
|
63
|
+
if (mergeIntoPatchedEnum(state, key, patch.values)) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
const added = addDiscriminatorEnum(state, patch);
|
|
67
|
+
if (added !== null) {
|
|
68
|
+
state.patchedEnums.set(key, added);
|
|
69
|
+
}
|
|
70
|
+
return added !== null;
|
|
71
|
+
}
|
|
72
|
+
function markHandled(state, ref) {
|
|
73
|
+
if (!state.refsHandled.includes(ref)) {
|
|
74
|
+
state.refsHandled.push(ref);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function warnInvalidMapping(patch, logger) {
|
|
78
|
+
const mapped = `${patch.ref} => ${patch.values.join(", ")}`;
|
|
79
|
+
logger.warn(
|
|
80
|
+
warnings.warningText(
|
|
81
|
+
`Discriminator mapping has an invalid schema (neither an object schema nor an allOf array): ${mapped} (Discriminator: ${patch.discriminatorRef})`,
|
|
82
|
+
warnings.WARNING_CODES.DISCRIMINATOR_MAPPING_INVALID
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
exports.enumKey = enumKey;
|
|
88
|
+
exports.markHandled = markHandled;
|
|
89
|
+
exports.mergesValues = mergesValues;
|
|
90
|
+
exports.patchDiscriminatorEnum = patchDiscriminatorEnum;
|
|
91
|
+
exports.recordEnumParent = recordEnumParent;
|
|
92
|
+
//# sourceMappingURL=discriminator-patch.cjs.map
|