openapi-typesafe 1.0.0-rc.0 → 1.0.0-rc.1
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/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 +15 -5
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +15 -5
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs +3 -0
- package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -1
- package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +3 -0
- package/dist/adapters/type-ast-bridge/ir-to-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/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 +88 -0
- package/dist/api/discriminator-patch.cjs.map +1 -0
- package/dist/api/discriminator-patch.mjs +82 -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-run.cjs +18 -3
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +19 -4
- 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/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 +3 -1
- package/dist/api/transform-context.cjs.map +1 -1
- package/dist/api/transform-context.mjs +3 -1
- 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 +5 -0
- package/dist/application/print/type-printer.cjs.map +1 -1
- package/dist/application/print/type-printer.mjs +5 -0
- 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 +40 -8
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +41 -9
- 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 +54 -28
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +53 -29
- 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 +33 -0
- package/dist/application/transform/footer/evaluation.cjs.map +1 -0
- package/dist/application/transform/footer/evaluation.mjs +26 -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 +246 -0
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -0
- package/dist/application/transform/footer/type-evaluation.mjs +244 -0
- package/dist/application/transform/footer/type-evaluation.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/cli-arguments.cjs +11 -3
- package/dist/cli/cli-arguments.cjs.map +1 -1
- package/dist/cli/cli-arguments.mjs +11 -3
- 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/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 +7 -3
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +8 -4
- 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 +15 -2
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +16 -3
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/errors.cjs +2 -0
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +2 -0
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/constructors.cjs +5 -1
- package/dist/domain/ir/constructors.cjs.map +1 -1
- package/dist/domain/ir/constructors.mjs +5 -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/warnings.cjs +15 -0
- package/dist/domain/warnings.cjs.map +1 -0
- package/dist/domain/warnings.mjs +12 -0
- package/dist/domain/warnings.mjs.map +1 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.mts +29 -0
- package/dist/index.d.ts +29 -0
- 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/package.json +1 -1
- package/src/adapters/redocly-loader/redocly-config-source.ts +41 -6
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +22 -6
- package/src/adapters/type-ast-bridge/ir-to-typescript.ts +3 -0
- package/src/adapters/type-ast-bridge/typescript-to-ir.ts +26 -12
- 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 +147 -0
- package/src/api/discriminator-scan.ts +78 -90
- package/src/api/document-run.ts +24 -6
- package/src/api/enum-values-warnings.ts +21 -0
- package/src/api/path-template-warnings.ts +27 -0
- package/src/api/transform-context.ts +7 -1
- package/src/api/transform-schema.ts +88 -4
- 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 +6 -0
- 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 +76 -11
- 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 +99 -37
- 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 +47 -0
- package/src/application/transform/footer/shared-enum-names.ts +86 -0
- package/src/application/transform/footer/type-evaluation.ts +294 -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/cli-arguments.ts +13 -3
- 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/main.ts +6 -0
- package/src/cli/redocly-apis.ts +8 -4
- package/src/cli/ref-limits.ts +2 -2
- package/src/cli/run-cli.ts +20 -3
- package/src/domain/errors.ts +2 -0
- package/src/domain/ir/constructors.ts +6 -1
- package/src/domain/ir/nodes.ts +2 -1
- 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 +31 -0
- package/src/domain/openapi/schema-object.ts +2 -0
- package/src/domain/output-fixes.ts +43 -2
- package/src/domain/warnings.ts +20 -0
- package/src/transform/components-object.ts +3 -1
- package/src/types/generator-options.ts +11 -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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { irKeyword, irIndexedAccess,
|
|
1
|
+
import { irReference, irKeyword, irIndexedAccess, irString, irObject } from '../../../domain/ir/constructors.mjs';
|
|
2
2
|
import { parseRefPointer, createRef } from '../../../domain/openapi/json-pointer.mjs';
|
|
3
|
+
import { OutputFix } from '../../../domain/output-fixes.mjs';
|
|
3
4
|
import { literalType } from '../literal-type.mjs';
|
|
4
5
|
import { refType } from '../ref-type.mjs';
|
|
5
6
|
import { unionOf, intersectionOf } from '../type-combinators.mjs';
|
|
@@ -13,6 +14,7 @@ function hasAdditionalProperties(schema) {
|
|
|
13
14
|
function nameFromPath(path) {
|
|
14
15
|
return parseRefPointer(path ?? "").join("/").replace(COMPONENT_SCHEMAS_PREFIX, "");
|
|
15
16
|
}
|
|
17
|
+
const COMPONENT_SCHEMA_RE = /^#\/components\/schemas\/[^/]+$/;
|
|
16
18
|
function hasEnumMetadata(schema) {
|
|
17
19
|
return [
|
|
18
20
|
schema["x-enum-varnames"],
|
|
@@ -21,39 +23,92 @@ function hasEnumMetadata(schema) {
|
|
|
21
23
|
schema["x-enumDescriptions"]
|
|
22
24
|
].some(Array.isArray);
|
|
23
25
|
}
|
|
26
|
+
function tsEnumEntries(schema, options) {
|
|
27
|
+
const entries = (schema.enum ?? []).map((value, index) => [value, index]);
|
|
28
|
+
return options.fixes.has(OutputFix.NULLABLE_ENUMS) ? entries.filter(([value]) => value !== null) : entries;
|
|
29
|
+
}
|
|
24
30
|
function isTsEnum(schema, options) {
|
|
25
31
|
if (!options.enum || !schema.enum) {
|
|
26
32
|
return false;
|
|
27
33
|
}
|
|
28
|
-
const
|
|
34
|
+
const entries = tsEnumEntries(schema, options);
|
|
35
|
+
const isOnlyNull = entries.length === 0 && schema.enum.length > 0;
|
|
36
|
+
const isSupported = !isOnlyNull && entries.every(([value]) => ["string", "number"].includes(typeof value));
|
|
29
37
|
return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));
|
|
30
38
|
}
|
|
31
|
-
function enumMetadata(schema) {
|
|
32
|
-
return
|
|
39
|
+
function enumMetadata(schema, entries) {
|
|
40
|
+
return entries.map(([, index]) => ({
|
|
33
41
|
name: schema["x-enum-varnames"]?.[index] ?? schema["x-enumNames"]?.[index],
|
|
34
42
|
description: schema["x-enum-descriptions"]?.[index] ?? schema["x-enumDescriptions"]?.[index]
|
|
35
43
|
}));
|
|
36
44
|
}
|
|
45
|
+
function isNullAllowed(schema) {
|
|
46
|
+
const { type } = schema;
|
|
47
|
+
const isTypeNullable = type === void 0 || Array.isArray(type) && type.includes("null") || Boolean(schema.nullable);
|
|
48
|
+
return (schema.enum ?? []).includes(null) && isTypeNullable;
|
|
49
|
+
}
|
|
37
50
|
function withOtherStrings(type, schema) {
|
|
38
51
|
if (!hasAdditionalProperties(schema) || schema.type !== "string") {
|
|
39
52
|
return type;
|
|
40
53
|
}
|
|
41
54
|
return unionOf([type, intersectionOf([irKeyword("string"), irObject([])])]);
|
|
42
55
|
}
|
|
56
|
+
function enumRequest(schema, path, options) {
|
|
57
|
+
const entries = tsEnumEntries(schema, options);
|
|
58
|
+
return {
|
|
59
|
+
name: nameFromPath(path),
|
|
60
|
+
isComponentSchema: COMPONENT_SCHEMA_RE.test(path ?? ""),
|
|
61
|
+
values: entries.map(([value]) => value),
|
|
62
|
+
metadata: enumMetadata(schema, entries)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function enumMemberType(enumName, member) {
|
|
66
|
+
return member.startsWith('"') ? irIndexedAccess(irReference(`typeof ${enumName}`), irString(JSON.parse(member), "escaped")) : irReference(`${enumName}.${member}`);
|
|
67
|
+
}
|
|
68
|
+
function ownerEnumMembersType(key, values, request) {
|
|
69
|
+
const { options, discriminators, footer } = request.context;
|
|
70
|
+
const parent = options.fixes.has(
|
|
71
|
+
OutputFix.DISCRIMINATOR_VALUES
|
|
72
|
+
) ? discriminators.enumParentOf(key) : void 0;
|
|
73
|
+
if (parent === void 0 || !isTsEnum(parent.schema, options)) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const reference = { ...enumRequest(parent.schema, parent.path, options), isOwnerReference: true };
|
|
77
|
+
const name = footer.addEnum(reference);
|
|
78
|
+
const members = footer.enumMembers(name);
|
|
79
|
+
const names = values.map((value) => members.get(value));
|
|
80
|
+
if (names.length === 0 || names.some((member) => member === void 0)) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return unionOf(names.map((member) => enumMemberType(name, member)));
|
|
84
|
+
}
|
|
43
85
|
function tsEnumType(schema, request) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
86
|
+
const { options, footer } = request.context;
|
|
87
|
+
const values = tsEnumEntries(schema, options).map(([value]) => value);
|
|
88
|
+
const type = ownerEnumMembersType(schema, values, request) ?? withOtherStrings(
|
|
89
|
+
irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),
|
|
90
|
+
schema
|
|
91
|
+
);
|
|
92
|
+
return options.fixes.has(OutputFix.NULLABLE_ENUMS) && isNullAllowed(schema) ? unionOf([type, irKeyword("null")]) : type;
|
|
50
93
|
}
|
|
51
94
|
function isUnionPosition(pointer, index) {
|
|
52
95
|
const next = pointer[index + 1];
|
|
53
96
|
return UNION_KEYWORDS.has(pointer[index]) && next !== void 0 && INDEX_RE.test(next);
|
|
54
97
|
}
|
|
98
|
+
const PARAMETERS = "parameters";
|
|
99
|
+
function pathItemParametersIndex(pointer) {
|
|
100
|
+
if (pointer[0] === "paths" || pointer[0] === "webhooks") {
|
|
101
|
+
return 2;
|
|
102
|
+
}
|
|
103
|
+
return pointer[0] === "components" && pointer[1] === "pathItems" ? 3 : null;
|
|
104
|
+
}
|
|
105
|
+
function withSingleParametersSegment(pointer) {
|
|
106
|
+
const index = pathItemParametersIndex(pointer);
|
|
107
|
+
const isRepeated = index !== null && pointer[index] === PARAMETERS && pointer[index + 1] === PARAMETERS;
|
|
108
|
+
return isRepeated ? [...pointer.slice(0, index), ...pointer.slice(index + 1)] : pointer;
|
|
109
|
+
}
|
|
55
110
|
function enumValuesPointer(path) {
|
|
56
|
-
const pointer = parseRefPointer(path ?? "");
|
|
111
|
+
const pointer = withSingleParametersSegment(parseRefPointer(path ?? ""));
|
|
57
112
|
const kept = [];
|
|
58
113
|
let firstVariantStart = null;
|
|
59
114
|
for (let index = 0; index < pointer.length; index++) {
|
|
@@ -101,5 +156,5 @@ const enumRule = {
|
|
|
101
156
|
}
|
|
102
157
|
};
|
|
103
158
|
|
|
104
|
-
export { enumRule };
|
|
159
|
+
export { enumRule, ownerEnumMembersType };
|
|
105
160
|
//# sourceMappingURL=enum-rule.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-rule.mjs","sources":["../../../../src/application/transform/schema/enum-rule.ts"],"sourcesContent":["import {\n irIndexedAccess,\n irKeyword,\n irObject,\n irReference,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef, parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { refType } from \"../ref-type.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport type { EnumMemberMetadata, SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\n/** Removed from generated names, so `#/components/schemas/Status` gives `Status`. */\nconst COMPONENT_SCHEMAS_PREFIX = \"components/schemas\";\nconst UNION_KEYWORDS: ReadonlySet<string> = new Set([\"anyOf\", \"oneOf\"]);\nconst INDEX_RE = /^\\d+$/;\n\nfunction hasAdditionalProperties(schema: SchemaObject): boolean {\n return \"additionalProperties\" in schema && Boolean(schema.additionalProperties);\n}\n\n/** A name from the schema's pointer: `#/components/schemas/Pet/status` → `/Pet/status`. */\nfunction nameFromPath(path: string | undefined): string {\n return parseRefPointer(path ?? \"\")\n .join(\"/\")\n .replace(COMPONENT_SCHEMAS_PREFIX, \"\");\n}\n\nfunction hasEnumMetadata(schema: SchemaObject): boolean {\n return [\n schema[\"x-enum-varnames\"],\n schema[\"x-enumNames\"],\n schema[\"x-enum-descriptions\"],\n schema[\"x-enumDescriptions\"],\n ].some(Array.isArray);\n}\n\n/**\n * `--enum`: string and number enums become TypeScript enums. The original meant to allow `null`\n * too, but tested `typeof value` against `null`, so an enum containing null stays a union.\n */\nfunction isTsEnum(schema: SchemaObject, options: SchemaOptions): boolean {\n if (!options.enum || !schema.enum) {\n return false;\n }\n const isSupported = schema.enum.every((value) => [\"string\", \"number\"].includes(typeof value));\n // `--conditional-enums` converts only enums that carry x-enum-* metadata.\n return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));\n}\n\nfunction enumMetadata(schema: SchemaObject): EnumMemberMetadata[] {\n return (schema.enum ?? []).map((_, index) => ({\n name: schema[\"x-enum-varnames\"]?.[index] ?? schema[\"x-enumNames\"]?.[index],\n description: schema[\"x-enum-descriptions\"]?.[index] ?? schema[\"x-enumDescriptions\"]?.[index],\n }));\n}\n\n/**\n * `additionalProperties: true` on a string enum keeps other strings allowed but still offers the\n * listed values in editors: `\"a\" | \"b\" | (string & {})`.\n */\nfunction withOtherStrings(type: IrType, schema: SchemaObject): IrType {\n if (!hasAdditionalProperties(schema) || schema.type !== \"string\") {\n return type;\n }\n return unionOf([type, intersectionOf([irKeyword(\"string\"), irObject([])])]);\n}\n\nfunction tsEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n // `isTsEnum` admits only strings and numbers, so there is no null member to split off.\n const name = request.context.footer.addEnum({\n name: nameFromPath(request.location.path),\n values: (schema.enum ?? []) as (string | number)[],\n metadata: enumMetadata(schema),\n });\n return withOtherStrings(irReference(name), schema);\n}\n\nfunction isUnionPosition(pointer: readonly string[], index: number): boolean {\n const next = pointer[index + 1];\n return UNION_KEYWORDS.has(pointer[index] as string) && next !== undefined && INDEX_RE.test(next);\n}\n\n/**\n * The pointer of `--enum-values` arrays without union positions (`anyOf/0`), so names stay\n * stable. Every property after the first union position is narrowed with `Extract`: a no-op where\n * all variants have it, and the needed narrowing where only some do.\n */\nfunction enumValuesPointer(path: string | undefined): { ref: string; extract: string[] } {\n const pointer = parseRefPointer(path ?? \"\");\n const kept: string[] = [];\n let firstVariantStart: number | null = null;\n for (let index = 0; index < pointer.length; index++) {\n if (isUnionPosition(pointer, index)) {\n firstVariantStart ??= index + 2;\n index++;\n continue;\n }\n kept.push(pointer[index] as string);\n }\n const extract =\n firstVariantStart === null\n ? []\n : pointer\n .slice(firstVariantStart)\n .filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));\n return { ref: createRef(kept), extract };\n}\n\nfunction addEnumValues(schema: SchemaObject, request: SchemaRequest): void {\n const { ref, extract } = enumValuesPointer(request.location.path);\n const valuesType = refType(ref, { isDeep: true, extractProperties: extract });\n request.context.footer.addEnumValues({\n name: `${nameFromPath(request.location.path)}Values`,\n // A record value (`additionalProperties`) is reached by indexing with `string`.\n type: request.isFromAdditionalProperties\n ? irIndexedAccess(valuesType, irReference(\"string\"))\n : valuesType,\n values: (schema.enum ?? []) as (string | number)[],\n });\n}\n\nfunction literalEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const values = schema.enum ?? [];\n const isNullable =\n (Array.isArray(schema.type) && schema.type.includes(\"null\")) || Boolean(schema.nullable);\n const literals = [...values.map(literalType), ...(isNullable ? [irKeyword(\"null\")] : [])];\n const type = withOtherStrings(unionOf(literals), schema);\n const isListable = values.every(\n (value) => typeof value === \"string\" || typeof value === \"number\",\n );\n if (request.context.options.enumValues && isListable) {\n addEnumValues(schema, request);\n }\n return type;\n}\n\n/**\n * `enum` on anything but an object (object enums are handled as `oneOf`). With\n * `additionalProperties`, only string enums are handled here; others fall through to composition.\n */\nexport const enumRule: SchemaRule = {\n name: \"enum\",\n matches(schema) {\n const isCandidate =\n Array.isArray(schema.enum) && schema.type !== \"object\" && !(\"properties\" in schema);\n return isCandidate && (!hasAdditionalProperties(schema) || schema.type === \"string\");\n },\n transform(schema, request) {\n return isTsEnum(schema, request.context.options)\n ? tsEnumType(schema, request)\n : literalEnumType(schema, request);\n },\n};\n"],"names":[],"mappings":";;;;;;AAgBA,MAAM,wBAAA,GAA2B,oBAAA;AACjC,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,OAAO,CAAC,CAAA;AACtE,MAAM,QAAA,GAAW,OAAA;AAEjB,SAAS,wBAAwB,MAAA,EAA+B;AAC9D,EAAA,OAAO,sBAAA,IAA0B,MAAA,IAAU,OAAA,CAAQ,MAAA,CAAO,oBAAoB,CAAA;AAChF;AAGA,SAAS,aAAa,IAAA,EAAkC;AACtD,EAAA,OAAO,eAAA,CAAgB,QAAQ,EAAE,CAAA,CAC9B,KAAK,GAAG,CAAA,CACR,OAAA,CAAQ,wBAAA,EAA0B,EAAE,CAAA;AACzC;AAEA,SAAS,gBAAgB,MAAA,EAA+B;AACtD,EAAA,OAAO;AAAA,IACL,OAAO,iBAAiB,CAAA;AAAA,IACxB,OAAO,aAAa,CAAA;AAAA,IACpB,OAAO,qBAAqB,CAAA;AAAA,IAC5B,OAAO,oBAAoB;AAAA,GAC7B,CAAE,IAAA,CAAK,KAAA,CAAM,OAAO,CAAA;AACtB;AAMA,SAAS,QAAA,CAAS,QAAsB,OAAA,EAAiC;AACvE,EAAA,IAAI,CAAC,OAAA,CAAQ,IAAA,IAAQ,CAAC,OAAO,IAAA,EAAM;AACjC,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAA,GAAc,MAAA,CAAO,IAAA,CAAK,KAAA,CAAM,CAAC,KAAA,KAAU,CAAC,QAAA,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AM,QAAA,GAAuB;AAAA,EAClC,IAAA,EAAM,MAAA;AAAA,EACN,QAAQ,MAAA,EAAQ;AACd,IAAA,MAAM,WAAA,GACJ,KAAA,CAAM,OAAA,CAAQ,MAAA,CAAO,IAAI,KAAK,MAAA,CAAO,IAAA,KAAS,QAAA,IAAY,EAAE,YAAA,IAAgB,MAAA,CAAA;AAC9E,IAAA,OAAO,gBAAgB,CAAC,uBAAA,CAAwB,MAAM,CAAA,IAAK,OAAO,IAAA,KAAS,QAAA,CAAA;AAAA,EAC7E,CAAA;AAAA,EACA,SAAA,CAAU,QAAQ,OAAA,EAAS;AACzB,IAAA,OAAO,QAAA,CAAS,MAAA,EAAQ,OAAA,CAAQ,OAAA,CAAQ,OAAO,CAAA,GAC3C,UAAA,CAAW,MAAA,EAAQ,OAAO,CAAA,GAC1B,eAAA,CAAgB,MAAA,EAAQ,OAAO,CAAA;AAAA,EACrC;AACF;;"}
|
|
1
|
+
{"version":3,"file":"enum-rule.mjs","sources":["../../../../src/application/transform/schema/enum-rule.ts"],"sourcesContent":["import {\n irIndexedAccess,\n irKeyword,\n irObject,\n irReference,\n irString,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef, parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { refType } from \"../ref-type.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport type {\n DiscriminatorEnumParent,\n EnumDeclarationRequest,\n EnumMemberMetadata,\n SchemaOptions,\n} from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\n/** Removed from generated names, so `#/components/schemas/Status` gives `Status`. */\nconst COMPONENT_SCHEMAS_PREFIX = \"components/schemas\";\nconst UNION_KEYWORDS: ReadonlySet<string> = new Set([\"anyOf\", \"oneOf\"]);\nconst INDEX_RE = /^\\d+$/;\n\nfunction hasAdditionalProperties(schema: SchemaObject): boolean {\n return \"additionalProperties\" in schema && Boolean(schema.additionalProperties);\n}\n\n/** A name from the schema's pointer: `#/components/schemas/Pet/status` → `/Pet/status`. */\nfunction nameFromPath(path: string | undefined): string {\n return parseRefPointer(path ?? \"\")\n .join(\"/\")\n .replace(COMPONENT_SCHEMAS_PREFIX, \"\");\n}\n\n/** `#/components/schemas/Name`, and no deeper pointer. */\nconst COMPONENT_SCHEMA_RE = /^#\\/components\\/schemas\\/[^/]+$/;\n\nfunction hasEnumMetadata(schema: SchemaObject): boolean {\n return [\n schema[\"x-enum-varnames\"],\n schema[\"x-enumNames\"],\n schema[\"x-enum-descriptions\"],\n schema[\"x-enumDescriptions\"],\n ].some(Array.isArray);\n}\n\n/**\n * The values a TypeScript enum declares, with their positions in `enum`. With the\n * `nullable-enums` fix a `null` value is left out (upstream #1872): an enum member cannot be\n * `null`, so the type adds it as `| null` instead (`tsEnumType`).\n */\nfunction tsEnumEntries(schema: SchemaObject, options: SchemaOptions): [unknown, number][] {\n const entries = (schema.enum ?? []).map((value, index): [unknown, number] => [value, index]);\n return options.fixes.has(OutputFix.NULLABLE_ENUMS)\n ? entries.filter(([value]) => value !== null)\n : entries;\n}\n\n/**\n * `--enum`: string and number enums become TypeScript enums. The original meant to allow `null`\n * too, but tested `typeof value` against `null`, so an enum containing null stays a union; the\n * `nullable-enums` fix declares its other values.\n */\nfunction isTsEnum(schema: SchemaObject, options: SchemaOptions): boolean {\n if (!options.enum || !schema.enum) {\n return false;\n }\n const entries = tsEnumEntries(schema, options);\n // An empty `enum` stays an empty TypeScript enum, as the original made it; an enum of only\n // `null` has no member left once the fix drops `null`, so it stays a union.\n const isOnlyNull = entries.length === 0 && schema.enum.length > 0;\n const isSupported =\n !isOnlyNull && entries.every(([value]) => [\"string\", \"number\"].includes(typeof value));\n // `--conditional-enums` converts only enums that carry x-enum-* metadata.\n return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));\n}\n\nfunction enumMetadata(\n schema: SchemaObject,\n entries: readonly [unknown, number][],\n): EnumMemberMetadata[] {\n return entries.map(([, index]) => ({\n name: schema[\"x-enum-varnames\"]?.[index] ?? schema[\"x-enumNames\"]?.[index],\n description: schema[\"x-enum-descriptions\"]?.[index] ?? schema[\"x-enumDescriptions\"]?.[index],\n }));\n}\n\n/**\n * Whether `null` is a valid value: it is in `enum` and the schema's type admits it (`type`\n * absent or listing `\"null\"`, or OpenAPI 3.0 `nullable: true`). Both keywords must pass.\n */\nfunction isNullAllowed(schema: SchemaObject): boolean {\n const { type } = schema;\n const isTypeNullable =\n type === undefined ||\n (Array.isArray(type) && type.includes(\"null\")) ||\n Boolean(schema.nullable);\n return (schema.enum ?? []).includes(null) && isTypeNullable;\n}\n\n/**\n * `additionalProperties: true` on a string enum keeps other strings allowed but still offers the\n * listed values in editors: `\"a\" | \"b\" | (string & {})`.\n */\nfunction withOtherStrings(type: IrType, schema: SchemaObject): IrType {\n if (!hasAdditionalProperties(schema) || schema.type !== \"string\") {\n return type;\n }\n return unionOf([type, intersectionOf([irKeyword(\"string\"), irObject([])])]);\n}\n\n/** The enum declaration of `schema` typed at `path`; its values are strings and numbers. */\nfunction enumRequest(\n schema: SchemaObject,\n path: string | undefined,\n options: SchemaOptions,\n): EnumDeclarationRequest {\n const entries = tsEnumEntries(schema, options);\n return {\n name: nameFromPath(path),\n isComponentSchema: COMPONENT_SCHEMA_RE.test(path ?? \"\"),\n values: entries.map(([value]) => value as string | number),\n metadata: enumMetadata(schema, entries),\n };\n}\n\n/** One member's type; a quoted member cannot follow a dot, `typeof E[\"+\"]` is the same type. */\nfunction enumMemberType(enumName: string, member: string): IrType {\n return member.startsWith('\"')\n ? irIndexedAccess(irReference(`typeof ${enumName}`), irString(JSON.parse(member), \"escaped\"))\n : irReference(`${enumName}.${member}`);\n}\n\n/**\n * The `discriminator-values` fix: a member's discriminator value is typed with members of\n * the owner's enum (`PetType.Cat`), so the member is one of the owner's type (#1700). `key` is the\n * enum the scan added or the inherited discriminator object. Null when the fix is off, or the\n * owner's property is no TypeScript enum with every value.\n */\nexport function ownerEnumMembersType(\n key: object,\n values: readonly unknown[],\n request: SchemaRequest,\n): IrType | null {\n const { options, discriminators, footer } = request.context;\n const parent: DiscriminatorEnumParent | undefined = options.fixes.has(\n OutputFix.DISCRIMINATOR_VALUES,\n )\n ? discriminators.enumParentOf(key)\n : undefined;\n if (parent === undefined || !isTsEnum(parent.schema, options)) {\n return null;\n }\n const reference = { ...enumRequest(parent.schema, parent.path, options), isOwnerReference: true };\n const name = footer.addEnum(reference);\n const members = footer.enumMembers(name);\n const names = values.map((value) => members.get(value as string | number));\n if (names.length === 0 || names.some((member) => member === undefined)) {\n return null;\n }\n return unionOf(names.map((member) => enumMemberType(name, member as string)));\n}\n\nfunction tsEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { options, footer } = request.context;\n // `isTsEnum` admits only strings and numbers, and the fix leaves `null` out of the members.\n const values = tsEnumEntries(schema, options).map(([value]) => value);\n const type =\n ownerEnumMembersType(schema, values, request) ??\n withOtherStrings(\n irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),\n schema,\n );\n return options.fixes.has(OutputFix.NULLABLE_ENUMS) && isNullAllowed(schema)\n ? unionOf([type, irKeyword(\"null\")])\n : type;\n}\n\nfunction isUnionPosition(pointer: readonly string[], index: number): boolean {\n const next = pointer[index + 1];\n return UNION_KEYWORDS.has(pointer[index] as string) && next !== undefined && INDEX_RE.test(next);\n}\n\nconst PARAMETERS = \"parameters\";\n\n/** Where the `parameters` of a path item sit in its pointer: `paths/<key>/…`, `components/…`. */\nfunction pathItemParametersIndex(pointer: readonly string[]): number | null {\n if (pointer[0] === \"paths\" || pointer[0] === \"webhooks\") {\n return 2;\n }\n return pointer[0] === \"components\" && pointer[1] === \"pathItems\" ? 3 : null;\n}\n\n/**\n * The location of a path item parameter repeats `parameters` (`paths/~1a/parameters/parameters/\n * path/id`), which keeps the generated names as they were. The generated type has the segment\n * once: `paths[\"/a\"][\"parameters\"][\"path\"][\"id\"]`.\n */\nfunction withSingleParametersSegment(pointer: readonly string[]): readonly string[] {\n const index = pathItemParametersIndex(pointer);\n const isRepeated =\n index !== null && pointer[index] === PARAMETERS && pointer[index + 1] === PARAMETERS;\n return isRepeated ? [...pointer.slice(0, index), ...pointer.slice(index + 1)] : pointer;\n}\n\n/**\n * The pointer of `--enum-values` arrays without union positions (`anyOf/0`), so names stay\n * stable. Every property after the first union position is narrowed with `Extract`: a no-op where\n * all variants have it, and the needed narrowing where only some do.\n */\nfunction enumValuesPointer(path: string | undefined): { ref: string; extract: string[] } {\n const pointer = withSingleParametersSegment(parseRefPointer(path ?? \"\"));\n const kept: string[] = [];\n let firstVariantStart: number | null = null;\n for (let index = 0; index < pointer.length; index++) {\n if (isUnionPosition(pointer, index)) {\n firstVariantStart ??= index + 2;\n index++;\n continue;\n }\n kept.push(pointer[index] as string);\n }\n const extract =\n firstVariantStart === null\n ? []\n : pointer\n .slice(firstVariantStart)\n .filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));\n return { ref: createRef(kept), extract };\n}\n\nfunction addEnumValues(schema: SchemaObject, request: SchemaRequest): void {\n const { ref, extract } = enumValuesPointer(request.location.path);\n const valuesType = refType(ref, { isDeep: true, extractProperties: extract });\n request.context.footer.addEnumValues({\n name: `${nameFromPath(request.location.path)}Values`,\n // A record value (`additionalProperties`) is reached by indexing with `string`.\n type: request.isFromAdditionalProperties\n ? irIndexedAccess(valuesType, irReference(\"string\"))\n : valuesType,\n values: (schema.enum ?? []) as (string | number)[],\n });\n}\n\nfunction literalEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const values = schema.enum ?? [];\n const isNullable =\n (Array.isArray(schema.type) && schema.type.includes(\"null\")) || Boolean(schema.nullable);\n const literals = [...values.map(literalType), ...(isNullable ? [irKeyword(\"null\")] : [])];\n const type = withOtherStrings(unionOf(literals), schema);\n const isListable = values.every(\n (value) => typeof value === \"string\" || typeof value === \"number\",\n );\n if (request.context.options.enumValues && isListable) {\n addEnumValues(schema, request);\n }\n return type;\n}\n\n/**\n * `enum` on anything but an object (object enums are handled as `oneOf`). With\n * `additionalProperties`, only string enums are handled here; others fall through to composition.\n */\nexport const enumRule: SchemaRule = {\n name: \"enum\",\n matches(schema) {\n const isCandidate =\n Array.isArray(schema.enum) && schema.type !== \"object\" && !(\"properties\" in schema);\n return isCandidate && (!hasAdditionalProperties(schema) || schema.type === \"string\");\n },\n transform(schema, request) {\n return isTsEnum(schema, request.context.options)\n ? tsEnumType(schema, request)\n : literalEnumType(schema, request);\n },\n};\n"],"names":[],"mappings":";;;;;;;AAuBA,MAAM,wBAAA,GAA2B,oBAAA;AACjC,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,OAAO,CAAC,CAAA;AACtE,MAAM,QAAA,GAAW,OAAA;AAEjB,SAAS,wBAAwB,MAAA,EAA+B;AAC9D,EAAA,OAAO,sBAAA,IAA0B,MAAA,IAAU,OAAA,CAAQ,MAAA,CAAO,oBAAoB,CAAA;AAChF;AAGA,SAAS,aAAa,IAAA,EAAkC;AACtD,EAAA,OAAO,eAAA,CAAgB,QAAQ,EAAE,CAAA,CAC9B,KAAK,GAAG,CAAA,CACR,OAAA,CAAQ,wBAAA,EAA0B,EAAE,CAAA;AACzC;AAGA,MAAM,mBAAA,GAAsB,iCAAA;AAE5B,SAAS,gBAAgB,MAAA,EAA+B;AACtD,EAAA,OAAO;AAAA,IACL,OAAO,iBAAiB,CAAA;AAAA,IACxB,OAAO,aAAa,CAAA;AAAA,IACpB,OAAO,qBAAqB,CAAA;AAAA,IAC5B,OAAO,oBAAoB;AAAA,GAC7B,CAAE,IAAA,CAAK,KAAA,CAAM,OAAO,CAAA;AACtB;AAOA,SAAS,aAAA,CAAc,QAAsB,OAAA,EAA6C;AACxF,EAAA,MAAM,OAAA,GAAA,CAAW,MAAA,CAAO,IAAA,IAAQ,E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AAA,CAAQ,OAAA,CAAQ,UAAA,IAAc,UAAA,EAAY;AACpD,IAAA,aAAA,CAAc,QAAQ,OAAO,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,IAAA;AACT;AAMO,MAAM,QAAA,GAAuB;AAAA,EAClC,IAAA,EAAM,MAAA;AAAA,EACN,QAAQ,MAAA,EAAQ;AACd,IAAA,MAAM,WAAA,GACJ,KAAA,CAAM,OAAA,CAAQ,MAAA,CAAO,IAAI,KAAK,MAAA,CAAO,IAAA,KAAS,QAAA,IAAY,EAAE,YAAA,IAAgB,MAAA,CAAA;AAC9E,IAAA,OAAO,gBAAgB,CAAC,uBAAA,CAAwB,MAAM,CAAA,IAAK,OAAO,IAAA,KAAS,QAAA,CAAA;AAAA,EAC7E,CAAA;AAAA,EACA,SAAA,CAAU,QAAQ,OAAA,EAAS;AACzB,IAAA,OAAO,QAAA,CAAS,MAAA,EAAQ,OAAA,CAAQ,OAAA,CAAQ,OAAO,CAAA,GAC3C,UAAA,CAAW,MAAA,EAAQ,OAAO,CAAA,GAC1B,eAAA,CAAgB,MAAA,EAAQ,OAAO,CAAA;AAAA,EACrC;AACF;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const discriminatedUnion = require('../../../domain/openapi/discriminated-union.cjs');
|
|
4
|
+
const discriminatorProperty = require('./discriminator-property.cjs');
|
|
5
|
+
const enumRule = require('./enum-rule.cjs');
|
|
6
|
+
|
|
7
|
+
function isInheritedUnion(path, request) {
|
|
8
|
+
const resolve = (ref) => request.context.refs.resolve(ref);
|
|
9
|
+
const union = discriminatedUnion.unionAt(path, resolve);
|
|
10
|
+
return union !== void 0 && discriminatedUnion.unionReaches(union, path, resolve);
|
|
11
|
+
}
|
|
12
|
+
function inheritedDiscriminator(schema, request) {
|
|
13
|
+
const { path } = request.location;
|
|
14
|
+
if (!schema.allOf && !schema.anyOf || path === void 0) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
const { discriminators } = request.context;
|
|
18
|
+
const isAdded = !schema.discriminator && !discriminators.isHandled(path);
|
|
19
|
+
const discriminator = isAdded ? discriminators.objectAt(path) : void 0;
|
|
20
|
+
return discriminator && !isInheritedUnion(path, request) ? { discriminator, path } : void 0;
|
|
21
|
+
}
|
|
22
|
+
function discriminatorMember({ discriminator, path }, request) {
|
|
23
|
+
const valueType = (value) => enumRule.ownerEnumMembersType(discriminator, [value], request);
|
|
24
|
+
return discriminatorProperty.discriminatorProperty(discriminator, path, request.context.options.immutable, valueType);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.discriminatorMember = discriminatorMember;
|
|
28
|
+
exports.inheritedDiscriminator = inheritedDiscriminator;
|
|
29
|
+
//# sourceMappingURL=inherited-discriminator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inherited-discriminator.cjs","sources":["../../../../src/application/transform/schema/inherited-discriminator.ts"],"sourcesContent":["import type { IrMember } from \"../../../domain/ir/nodes.js\";\nimport { unionAt, unionReaches } from \"../../../domain/openapi/discriminated-union.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { discriminatorProperty } from \"./discriminator-property.js\";\nimport { ownerEnumMembersType } from \"./enum-rule.js\";\nimport type { Discriminator } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * Whether the schema at `path` is a union that its own members inherit from (upstream #1665).\n * Each member sets the discriminator value, so a value of the union's own would make every member\n * `never`. The union's own keywords, which its members get, are typed at the same path.\n */\nfunction isInheritedUnion(path: string, request: SchemaRequest): boolean {\n const resolve = (ref: string) => request.context.refs.resolve(ref);\n const union = unionAt(path, resolve);\n return union !== undefined && unionReaches(union, path, resolve);\n}\n\n/** A discriminator a parent's mapping implies for the schema at `path`. */\nexport interface InheritedDiscriminator {\n readonly discriminator: Discriminator;\n readonly path: string;\n}\n\n/**\n * The discriminator a parent's mapping implies for this schema, if it adds a property. A schema\n * with no path (a caller's own schema) is no component, so no mapping names it.\n */\nexport function inheritedDiscriminator(\n schema: SchemaObject,\n request: SchemaRequest,\n): InheritedDiscriminator | undefined {\n const { path } = request.location;\n if ((!schema.allOf && !schema.anyOf) || path === undefined) {\n return undefined;\n }\n const { discriminators } = request.context;\n // A schema does not get the discriminator it defines for its children, nor one added already.\n const isAdded = !schema.discriminator && !discriminators.isHandled(path);\n const discriminator = isAdded ? discriminators.objectAt(path) : undefined;\n return discriminator && !isInheritedUnion(path, request) ? { discriminator, path } : undefined;\n}\n\n/** The property of an inherited discriminator, typed as the schema's value. */\nexport function discriminatorMember(\n { discriminator, path }: InheritedDiscriminator,\n request: SchemaRequest,\n): IrMember {\n // With `discriminator-values`, the value is a member of the owner's enum (#1700).\n const valueType = (value: string | undefined) =>\n ownerEnumMembersType(discriminator, [value], request);\n return discriminatorProperty(discriminator, path, request.context.options.immutable, valueType);\n}\n"],"names":["unionAt","unionReaches","ownerEnumMembersType","discriminatorProperty"],"mappings":";;;;;;AAaA,SAAS,gBAAA,CAAiB,MAAc,OAAA,EAAiC;AACvE,EAAA,MAAM,UAAU,CAAC,GAAA,KAAgB,QAAQ,OAAA,CAAQ,IAAA,CAAK,QAAQ,GAAG,CAAA;AACjE,EAAA,MAAM,KAAA,GAAQA,0BAAA,CAAQ,IAAA,EAAM,OAAO,CAAA;AACnC,EAAA,OAAO,KAAA,KAAU,MAAA,IAAaC,+BAAA,CAAa,KAAA,EAAO,MAAM,OAAO,CAAA;AACjE;AAYO,SAAS,sBAAA,CACd,QACA,OAAA,EACoC;AACpC,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,OAAA,CAAQ,QAAA;AACzB,EAAA,IAAK,CAAC,MAAA,CAAO,KAAA,IAAS,CAAC,MAAA,CAAO,KAAA,IAAU,SAAS,MAAA,EAAW;AAC1D,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,OAAA,CAAQ,OAAA;AAEnC,EAAA,MAAM,UAAU,CAAC,MAAA,CAAO,iBAAiB,CAAC,cAAA,CAAe,UAAU,IAAI,CAAA;AACvE,EAAA,MAAM,aAAA,GAAgB,OAAA,GAAU,cAAA,CAAe,QAAA,CAAS,IAAI,CAAA,GAAI,MAAA;AAChE,EAAA,OAAO,aAAA,IAAiB,CAAC,gBAAA,CAAiB,IAAA,EAAM,OAAO,CAAA,GAAI,EAAE,aAAA,EAAe,IAAA,EAAK,GAAI,MAAA;AACvF;AAGO,SAAS,mBAAA,CACd,EAAE,aAAA,EAAe,IAAA,IACjB,OAAA,EACU;AAEV,EAAA,MAAM,SAAA,GAAY,CAAC,KAAA,KACjBC,6BAAA,CAAqB,eAAe,CAAC,KAAK,GAAG,OAAO,CAAA;AACtD,EAAA,OAAOC,4CAAsB,aAAA,EAAe,IAAA,EAAM,QAAQ,OAAA,CAAQ,OAAA,CAAQ,WAAW,SAAS,CAAA;AAChG;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { unionAt, unionReaches } from '../../../domain/openapi/discriminated-union.mjs';
|
|
2
|
+
import { discriminatorProperty } from './discriminator-property.mjs';
|
|
3
|
+
import { ownerEnumMembersType } from './enum-rule.mjs';
|
|
4
|
+
|
|
5
|
+
function isInheritedUnion(path, request) {
|
|
6
|
+
const resolve = (ref) => request.context.refs.resolve(ref);
|
|
7
|
+
const union = unionAt(path, resolve);
|
|
8
|
+
return union !== void 0 && unionReaches(union, path, resolve);
|
|
9
|
+
}
|
|
10
|
+
function inheritedDiscriminator(schema, request) {
|
|
11
|
+
const { path } = request.location;
|
|
12
|
+
if (!schema.allOf && !schema.anyOf || path === void 0) {
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
const { discriminators } = request.context;
|
|
16
|
+
const isAdded = !schema.discriminator && !discriminators.isHandled(path);
|
|
17
|
+
const discriminator = isAdded ? discriminators.objectAt(path) : void 0;
|
|
18
|
+
return discriminator && !isInheritedUnion(path, request) ? { discriminator, path } : void 0;
|
|
19
|
+
}
|
|
20
|
+
function discriminatorMember({ discriminator, path }, request) {
|
|
21
|
+
const valueType = (value) => ownerEnumMembersType(discriminator, [value], request);
|
|
22
|
+
return discriminatorProperty(discriminator, path, request.context.options.immutable, valueType);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { discriminatorMember, inheritedDiscriminator };
|
|
26
|
+
//# sourceMappingURL=inherited-discriminator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inherited-discriminator.mjs","sources":["../../../../src/application/transform/schema/inherited-discriminator.ts"],"sourcesContent":["import type { IrMember } from \"../../../domain/ir/nodes.js\";\nimport { unionAt, unionReaches } from \"../../../domain/openapi/discriminated-union.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { discriminatorProperty } from \"./discriminator-property.js\";\nimport { ownerEnumMembersType } from \"./enum-rule.js\";\nimport type { Discriminator } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * Whether the schema at `path` is a union that its own members inherit from (upstream #1665).\n * Each member sets the discriminator value, so a value of the union's own would make every member\n * `never`. The union's own keywords, which its members get, are typed at the same path.\n */\nfunction isInheritedUnion(path: string, request: SchemaRequest): boolean {\n const resolve = (ref: string) => request.context.refs.resolve(ref);\n const union = unionAt(path, resolve);\n return union !== undefined && unionReaches(union, path, resolve);\n}\n\n/** A discriminator a parent's mapping implies for the schema at `path`. */\nexport interface InheritedDiscriminator {\n readonly discriminator: Discriminator;\n readonly path: string;\n}\n\n/**\n * The discriminator a parent's mapping implies for this schema, if it adds a property. A schema\n * with no path (a caller's own schema) is no component, so no mapping names it.\n */\nexport function inheritedDiscriminator(\n schema: SchemaObject,\n request: SchemaRequest,\n): InheritedDiscriminator | undefined {\n const { path } = request.location;\n if ((!schema.allOf && !schema.anyOf) || path === undefined) {\n return undefined;\n }\n const { discriminators } = request.context;\n // A schema does not get the discriminator it defines for its children, nor one added already.\n const isAdded = !schema.discriminator && !discriminators.isHandled(path);\n const discriminator = isAdded ? discriminators.objectAt(path) : undefined;\n return discriminator && !isInheritedUnion(path, request) ? { discriminator, path } : undefined;\n}\n\n/** The property of an inherited discriminator, typed as the schema's value. */\nexport function discriminatorMember(\n { discriminator, path }: InheritedDiscriminator,\n request: SchemaRequest,\n): IrMember {\n // With `discriminator-values`, the value is a member of the owner's enum (#1700).\n const valueType = (value: string | undefined) =>\n ownerEnumMembersType(discriminator, [value], request);\n return discriminatorProperty(discriminator, path, request.context.options.immutable, valueType);\n}\n"],"names":[],"mappings":";;;;AAaA,SAAS,gBAAA,CAAiB,MAAc,OAAA,EAAiC;AACvE,EAAA,MAAM,UAAU,CAAC,GAAA,KAAgB,QAAQ,OAAA,CAAQ,IAAA,CAAK,QAAQ,GAAG,CAAA;AACjE,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAA;AACnC,EAAA,OAAO,KAAA,KAAU,MAAA,IAAa,YAAA,CAAa,KAAA,EAAO,MAAM,OAAO,CAAA;AACjE;AAYO,SAAS,sBAAA,CACd,QACA,OAAA,EACoC;AACpC,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,OAAA,CAAQ,QAAA;AACzB,EAAA,IAAK,CAAC,MAAA,CAAO,KAAA,IAAS,CAAC,MAAA,CAAO,KAAA,IAAU,SAAS,MAAA,EAAW;AAC1D,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,OAAA,CAAQ,OAAA;AAEnC,EAAA,MAAM,UAAU,CAAC,MAAA,CAAO,iBAAiB,CAAC,cAAA,CAAe,UAAU,IAAI,CAAA;AACvE,EAAA,MAAM,aAAA,GAAgB,OAAA,GAAU,cAAA,CAAe,QAAA,CAAS,IAAI,CAAA,GAAI,MAAA;AAChE,EAAA,OAAO,aAAA,IAAiB,CAAC,gBAAA,CAAiB,IAAA,EAAM,OAAO,CAAA,GAAI,EAAE,aAAA,EAAe,IAAA,EAAK,GAAI,MAAA;AACvF;AAGO,SAAS,mBAAA,CACd,EAAE,aAAA,EAAe,IAAA,IACjB,OAAA,EACU;AAEV,EAAA,MAAM,SAAA,GAAY,CAAC,KAAA,KACjB,oBAAA,CAAqB,eAAe,CAAC,KAAK,GAAG,OAAO,CAAA;AACtD,EAAA,OAAO,sBAAsB,aAAA,EAAe,IAAA,EAAM,QAAQ,OAAA,CAAQ,OAAA,CAAQ,WAAW,SAAS,CAAA;AAChG;;"}
|
|
@@ -5,11 +5,12 @@ const constructors = require('../../../domain/ir/constructors.cjs');
|
|
|
5
5
|
const propertyName = require('../../../domain/ir/property-name.cjs');
|
|
6
6
|
const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
|
|
7
7
|
const documentEntries = require('../document-entries.cjs');
|
|
8
|
-
const
|
|
8
|
+
const pointerType = require('../ref-pointer/pointer-type.cjs');
|
|
9
9
|
const schemaComment = require('../schema-comment.cjs');
|
|
10
10
|
const sharedTypes = require('../shared-types.cjs');
|
|
11
11
|
const typeCombinators = require('../type-combinators.cjs');
|
|
12
|
-
const
|
|
12
|
+
const accessFlags = require('./access-flags.cjs');
|
|
13
|
+
const inheritedDiscriminator = require('./inherited-discriminator.cjs');
|
|
13
14
|
|
|
14
15
|
const INPUT_PATH_PARTS = ["parameters", "requestBody", "requestBodies"];
|
|
15
16
|
class InvalidPropertyError extends errors.OpenAPITypesafeError {
|
|
@@ -32,17 +33,18 @@ function withReadWriteMarker(type, flags, options) {
|
|
|
32
33
|
function finishProperty(property, schema, path, request) {
|
|
33
34
|
const location = { ...request.location, path };
|
|
34
35
|
const transformed = request.context.callbacks.transformProperty(property, schema, location) ?? property;
|
|
35
|
-
return schemaComment.withSchemaComment(
|
|
36
|
+
return schemaComment.withSchemaComment(
|
|
37
|
+
transformed,
|
|
38
|
+
schema,
|
|
39
|
+
schemaComment.schemaCommentOptionsOf(request.context.options.fixes)
|
|
40
|
+
);
|
|
36
41
|
}
|
|
37
|
-
function propertyFacts(value) {
|
|
42
|
+
function propertyFacts(value, request) {
|
|
38
43
|
if (typeof value !== "object") {
|
|
39
44
|
return { ref: void 0, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };
|
|
40
45
|
}
|
|
41
46
|
const ref = "$ref" in value && value.$ref ? value.$ref : void 0;
|
|
42
|
-
const flags =
|
|
43
|
-
isReadOnly: Boolean("readOnly" in value && value.readOnly),
|
|
44
|
-
isWriteOnly: Boolean("writeOnly" in value && value.writeOnly)
|
|
45
|
-
};
|
|
47
|
+
const flags = accessFlags.propertyAccessFlags(value, request.context);
|
|
46
48
|
return { ref, flags, hasDefault: "default" in value && value.default !== void 0 };
|
|
47
49
|
}
|
|
48
50
|
function isOptionalProperty(key, facts, schema, request) {
|
|
@@ -61,7 +63,7 @@ function isExcluded(value, facts, request) {
|
|
|
61
63
|
}
|
|
62
64
|
function propertyType(key, value, facts, request) {
|
|
63
65
|
const path = jsonPointer.createRef([request.location.path, key]);
|
|
64
|
-
const type = facts.ref ?
|
|
66
|
+
const type = facts.ref ? pointerType.schemaRefType(facts.ref, request) : request.transformNested(value, { ...request.location, path });
|
|
65
67
|
const custom = request.context.callbacks.transform(value, request.location);
|
|
66
68
|
return custom === null ? { type, isOptional: null } : { type: custom.type, isOptional: custom.isOptional || null };
|
|
67
69
|
}
|
|
@@ -69,7 +71,7 @@ function propertyMember(key, value, schema, request) {
|
|
|
69
71
|
if (typeof value !== "object" && typeof value !== "boolean" || Array.isArray(value)) {
|
|
70
72
|
throw new InvalidPropertyError(request.location.path, key, value);
|
|
71
73
|
}
|
|
72
|
-
const facts = propertyFacts(value);
|
|
74
|
+
const facts = propertyFacts(value, request);
|
|
73
75
|
if (isExcluded(value, facts, request)) {
|
|
74
76
|
return null;
|
|
75
77
|
}
|
|
@@ -100,10 +102,7 @@ function defsMember(defs, request) {
|
|
|
100
102
|
const { options } = request.context;
|
|
101
103
|
const members = Object.entries(defs).map(([key, value]) => {
|
|
102
104
|
const path = jsonPointer.createRef([request.location.path, "$defs", key]);
|
|
103
|
-
const flags =
|
|
104
|
-
isReadOnly: "readOnly" in value && !!value.readOnly,
|
|
105
|
-
isWriteOnly: "writeOnly" in value && !!value.writeOnly
|
|
106
|
-
};
|
|
105
|
+
const flags = accessFlags.propertyAccessFlags(value, request.context);
|
|
107
106
|
const type = withReadWriteMarker(
|
|
108
107
|
request.transformNested(value, { ...request.location, path }),
|
|
109
108
|
flags,
|
|
@@ -140,21 +139,34 @@ function indexValueTypes(schema, request) {
|
|
|
140
139
|
}
|
|
141
140
|
return types;
|
|
142
141
|
}
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
return
|
|
142
|
+
function isKeptProperty(schema, key, request) {
|
|
143
|
+
const properties = schema.properties ?? {};
|
|
144
|
+
if (!Object.hasOwn(properties, key)) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
const value = properties[key];
|
|
148
|
+
const isExcludable = request.context.options.excludeDeprecated && typeof value === "object";
|
|
149
|
+
return !isExcludable || !isExcluded(value, propertyFacts(value, request), request);
|
|
150
|
+
}
|
|
151
|
+
function discriminatorAndPropertyMembers(schema, request) {
|
|
152
|
+
const inherited = inheritedDiscriminator.inheritedDiscriminator(schema, request);
|
|
153
|
+
if (inherited === void 0) {
|
|
154
|
+
return propertyMembers(schema, request);
|
|
155
|
+
}
|
|
156
|
+
const name = inherited.discriminator.propertyName;
|
|
157
|
+
if (!isKeptProperty(schema, name, request)) {
|
|
158
|
+
return [inheritedDiscriminator.discriminatorMember(inherited, request), ...propertyMembers(schema, request)];
|
|
159
|
+
}
|
|
160
|
+
const isAllRequired = schema.required === void 0 && request.context.options.propertiesRequiredByDefault;
|
|
161
|
+
const required = isAllRequired ? void 0 : [...schema.required ?? [], name];
|
|
162
|
+
return propertyMembers({ ...schema, required }, request);
|
|
151
163
|
}
|
|
152
164
|
function objectType(schema, request) {
|
|
153
|
-
const members = discriminatorMembers(schema, request);
|
|
154
165
|
if (!hasObjectKeywords(schema)) {
|
|
155
|
-
|
|
166
|
+
const inherited = inheritedDiscriminator.inheritedDiscriminator(schema, request);
|
|
167
|
+
return inherited ? constructors.irObject([inheritedDiscriminator.discriminatorMember(inherited, request)]) : null;
|
|
156
168
|
}
|
|
157
|
-
members
|
|
169
|
+
const members = discriminatorAndPropertyMembers(schema, request);
|
|
158
170
|
if ("$defs" in schema && typeof schema.$defs === "object" && Object.keys(schema.$defs).length > 0) {
|
|
159
171
|
members.push(defsMember(schema.$defs, request));
|
|
160
172
|
}
|
|
@@ -169,5 +181,6 @@ function objectType(schema, request) {
|
|
|
169
181
|
}
|
|
170
182
|
|
|
171
183
|
exports.InvalidPropertyError = InvalidPropertyError;
|
|
184
|
+
exports.isKeptProperty = isKeptProperty;
|
|
172
185
|
exports.objectType = objectType;
|
|
173
186
|
//# sourceMappingURL=object-type.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-type.cjs","sources":["../../../../src/application/transform/schema/object-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport {\n irObject,\n irProperty,\n irReference,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport { withSchemaComment } from \"../schema-comment.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport { discriminatorProperty } from \"./discriminator-property.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/** Path parts where a default value cannot make a property required (inputs may omit it). */\nconst INPUT_PATH_PARTS = [\"parameters\", \"requestBody\", \"requestBodies\"] as const;\n\nexport class InvalidPropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined, key: string, value: unknown) {\n const received = Array.isArray(value) ? \"Array\" : typeof value;\n super({\n code: ERROR_CODES.SCHEMA_PROPERTY_INVALID,\n message:\n `${path}: invalid property ${key}. ` + `Expected Schema Object or boolean, got ${received}`,\n details: { path, property: key, received },\n });\n this.name = \"InvalidPropertyError\";\n }\n}\n\n/** `--read-write-markers`: `$Read<T>` / `$Write<T>`, unless the property is both or neither. */\nfunction withReadWriteMarker(type: IrType, flags: AccessFlags, options: SchemaOptions): IrType {\n if (!options.readWriteMarkers || flags.isReadOnly === flags.isWriteOnly) {\n return type;\n }\n return irReference(flags.isReadOnly ? \"$Read\" : \"$Write\", [type]);\n}\n\ninterface AccessFlags {\n readonly isReadOnly: boolean;\n readonly isWriteOnly: boolean;\n}\n\n/** Apply `transformProperty`, then the schema's JSDoc. */\nfunction finishProperty(\n property: IrPropertySignature,\n schema: Schema,\n path: string,\n request: SchemaRequest,\n): IrPropertySignature {\n const location = { ...request.location, path };\n const transformed =\n request.context.callbacks.transformProperty(property, schema, location) ?? property;\n // The original adds the schema's comment after any comment the callback set.\n return withSchemaComment(transformed, schema);\n}\n\n/** What the property loop reads from a property schema, in the original order. */\ninterface PropertyFacts {\n readonly ref: string | undefined;\n readonly flags: AccessFlags;\n readonly hasDefault: boolean;\n}\n\nfunction propertyFacts(value: Schema): PropertyFacts {\n if (typeof value !== \"object\") {\n return { ref: undefined, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };\n }\n // `in` throws for a null value, as in the original (which also reads `$ref` first).\n const ref = \"$ref\" in value && value.$ref ? value.$ref : undefined;\n const flags = {\n isReadOnly: Boolean(\"readOnly\" in value && value.readOnly),\n isWriteOnly: Boolean(\"writeOnly\" in value && value.writeOnly),\n };\n return { ref, flags, hasDefault: \"default\" in value && value.default !== undefined };\n}\n\nfunction isOptionalProperty(\n key: string,\n facts: PropertyFacts,\n schema: SchemaObject,\n request: SchemaRequest,\n): boolean {\n const { options } = request.context;\n const path = request.location.path;\n const isDefaultRequired =\n facts.hasDefault &&\n options.defaultNonNullable &&\n !INPUT_PATH_PARTS.some((part) => path?.includes(part));\n const isRequired =\n schema.required?.includes(key) ||\n (schema.required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\nfunction isExcluded(value: Schema, facts: PropertyFacts, request: SchemaRequest): boolean {\n if (!request.context.options.excludeDeprecated) {\n return false;\n }\n const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;\n return Boolean((resolved as SchemaObject | undefined)?.deprecated);\n}\n\n/** A type, and whether a callback forced the property optional (null: no override). */\ninterface CustomResult {\n readonly type: IrType;\n readonly isOptional: true | null;\n}\n\nfunction propertyType(\n key: string,\n value: Schema,\n facts: PropertyFacts,\n request: SchemaRequest,\n): CustomResult {\n const path = createRef([request.location.path, key]);\n const type = facts.ref\n ? refType(facts.ref)\n : request.transformNested(value, { ...request.location, path });\n const custom = request.context.callbacks.transform(value, request.location);\n return custom === null\n ? { type, isOptional: null }\n : { type: custom.type, isOptional: custom.isOptional || null };\n}\n\nfunction propertyMember(\n key: string,\n value: Schema,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrMember | null {\n if ((typeof value !== \"object\" && typeof value !== \"boolean\") || Array.isArray(value)) {\n throw new InvalidPropertyError(request.location.path, key, value);\n }\n const facts = propertyFacts(value);\n if (isExcluded(value, facts, request)) {\n return null;\n }\n const { options } = request.context;\n const isOptional = isOptionalProperty(key, facts, schema, request);\n const result = propertyType(key, value, facts, request);\n const property = irProperty(\n toPropertyName(key),\n withReadWriteMarker(result.type, facts.flags, options),\n {\n isOptional: result.isOptional ?? isOptional,\n isReadonly: options.immutable || (!options.readWriteMarkers && facts.flags.isReadOnly),\n },\n );\n return finishProperty(property, value, createRef([request.location.path, key]), request);\n}\n\nfunction propertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const members: IrMember[] = [];\n for (const [key, value] of documentEntries(schema.properties ?? {}, request.context.options)) {\n const member = propertyMember(key, value, schema, request);\n if (member !== null) {\n members.push(member);\n }\n }\n return members;\n}\n\n/**\n * `$defs` as a nested `$defs?: { … }` member, in document order (never alphabetized). It is\n * optional because `$defs` is a schema keyword, not data: the original made it required, so a\n * value of the type needed a `$defs` key (research/legacy-bugs.md, item 17, upstream #2664).\n */\nfunction defsMember(\n defs: Readonly<Record<string, SchemaObject>>,\n request: SchemaRequest,\n): IrMember {\n const { options } = request.context;\n const members = Object.entries(defs).map(([key, value]) => {\n const path = createRef([request.location.path, \"$defs\", key]);\n const flags = {\n isReadOnly: \"readOnly\" in value && !!value.readOnly,\n isWriteOnly: \"writeOnly\" in value && !!value.writeOnly,\n };\n const type = withReadWriteMarker(\n request.transformNested(value, { ...request.location, path }),\n flags,\n options,\n );\n const property = irProperty(toPropertyName(key), type, {\n isReadonly: options.immutable || (!options.readWriteMarkers && flags.isReadOnly),\n });\n return finishProperty(property, value, path, request);\n });\n return irProperty(toPropertyName(\"$defs\"), irObject(members), { isOptional: true });\n}\n\nfunction hasObjectKeywords(schema: SchemaObject): boolean {\n const hasProperties = Boolean(schema.properties && Object.keys(schema.properties).length);\n return (\n hasProperties ||\n Boolean(schema.additionalProperties || schema.patternProperties || schema.$defs)\n );\n}\n\n/** Value types of the `[key: string]` index signature, in the original order. */\nfunction indexValueTypes(schema: SchemaObject, request: SchemaRequest): IrType[] {\n const { additionalProperties } = schema;\n const isObject = typeof additionalProperties === \"object\";\n const hasExplicit = isObject && Object.keys(additionalProperties).length > 0;\n const hasImplicit =\n additionalProperties === true || (isObject && Object.keys(additionalProperties).length === 0);\n const types: IrType[] = [];\n if (hasExplicit) {\n types.push(request.transformNested(additionalProperties as Schema, request.location, true));\n }\n if (hasImplicit || (!additionalProperties && request.context.options.additionalProperties)) {\n types.push(UNKNOWN_TYPE);\n }\n const patterns = schema.patternProperties;\n if (typeof patterns === \"object\" && patterns !== null && Object.keys(patterns).length > 0) {\n for (const [, value] of documentEntries(patterns, request.context.options)) {\n types.push(request.transformNested(value, request.location));\n }\n }\n return types;\n}\n\n/** The discriminator property that a parent's mapping implies for this schema, if any. */\nfunction discriminatorMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n if (!schema.allOf && !schema.anyOf) {\n return [];\n }\n const path = request.location.path ?? \"\";\n const { discriminators, options } = request.context;\n // A schema does not get the discriminator it defines for its children, nor one added already.\n const discriminator =\n !schema.discriminator && !discriminators.isHandled(path) && discriminators.objectAt(path);\n return discriminator ? [discriminatorProperty(discriminator, path, options.immutable)] : [];\n}\n\n/**\n * Object keywords: discriminator, `properties`, `$defs`, and an index signature for\n * `additionalProperties` / `patternProperties` (or `--additional-properties`). Null when the schema\n * has none of them.\n */\nexport function objectType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const members = discriminatorMembers(schema, request);\n if (!hasObjectKeywords(schema)) {\n return members.length > 0 ? irObject(members) : null;\n }\n members.push(...propertyMembers(schema, request));\n // As in the original, a null `$defs` throws here (Object.keys) instead of being skipped.\n if (\n \"$defs\" in schema &&\n typeof schema.$defs === \"object\" &&\n Object.keys(schema.$defs).length > 0\n ) {\n members.push(defsMember(schema.$defs, request));\n }\n const valueTypes = indexValueTypes(schema, request);\n if (valueTypes.length === 0) {\n return members.length > 0 ? irObject(members) : null;\n }\n const index = irObject([\n irStringIndexSignature(\"key\", unionOf(valueTypes), request.context.options.immutable),\n ]);\n return intersectionOf([...(members.length > 0 ? [irObject(members)] : []), index]);\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","irReference","withSchemaComment","createRef","refType","irProperty","toPropertyName","documentEntries","irObject","UNKNOWN_TYPE","discriminatorProperty","irStringIndexSignature","unionOf","intersectionOf"],"mappings":";;;;;;;;;;;;;AAqBA,MAAM,gBAAA,GAAmB,CAAC,YAAA,EAAc,aAAA,EAAe,eAAe,CA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,CAAA;AAClD,EAAA,IAAI,UAAA,CAAW,WAAW,CAAA,EAAG;AAC3B,IAAA,OAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,GAAIA,qBAAA,CAAS,OAAO,CAAA,GAAI,IAAA;AAAA,EAClD;AACA,EAAA,MAAM,QAAQA,qBAAA,CAAS;AAAA,IACrBG,mCAAA,CAAuB,OAAOC,uBAAA,CAAQ,UAAU,GAAG,OAAA,CAAQ,OAAA,CAAQ,QAAQ,SAAS;AAAA,GACrF,CAAA;AACD,EAAA,OAAOC,8BAAA,CAAe,CAAC,GAAI,OAAA,CAAQ,SAAS,CAAA,GAAI,CAACL,qBAAA,CAAS,OAAO,CAAC,CAAA,GAAI,EAAC,EAAI,KAAK,CAAC,CAAA;AACnF;;;"}
|
|
1
|
+
{"version":3,"file":"object-type.cjs","sources":["../../../../src/application/transform/schema/object-type.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../../domain/errors.js\";\nimport {\n irObject,\n irProperty,\n irReference,\n irStringIndexSignature,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { schemaRefType } from \"../ref-pointer/pointer-type.js\";\nimport { schemaCommentOptionsOf, withSchemaComment } from \"../schema-comment.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport { type AccessFlags, propertyAccessFlags } from \"./access-flags.js\";\nimport { discriminatorMember, inheritedDiscriminator } from \"./inherited-discriminator.js\";\nimport type { SchemaOptions } from \"./schema-context.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/** Path parts where a default value cannot make a property required (inputs may omit it). */\nconst INPUT_PATH_PARTS = [\"parameters\", \"requestBody\", \"requestBodies\"] as const;\n\nexport class InvalidPropertyError extends OpenAPITypesafeError {\n constructor(path: string | undefined, key: string, value: unknown) {\n const received = Array.isArray(value) ? \"Array\" : typeof value;\n super({\n code: ERROR_CODES.SCHEMA_PROPERTY_INVALID,\n message:\n `${path}: invalid property ${key}. ` + `Expected Schema Object or boolean, got ${received}`,\n details: { path, property: key, received },\n });\n this.name = \"InvalidPropertyError\";\n }\n}\n\n/** `--read-write-markers`: `$Read<T>` / `$Write<T>`, unless the property is both or neither. */\nfunction withReadWriteMarker(type: IrType, flags: AccessFlags, options: SchemaOptions): IrType {\n if (!options.readWriteMarkers || flags.isReadOnly === flags.isWriteOnly) {\n return type;\n }\n return irReference(flags.isReadOnly ? \"$Read\" : \"$Write\", [type]);\n}\n\n/** Apply `transformProperty`, then the schema's JSDoc. */\nfunction finishProperty(\n property: IrPropertySignature,\n schema: Schema,\n path: string,\n request: SchemaRequest,\n): IrPropertySignature {\n const location = { ...request.location, path };\n const transformed =\n request.context.callbacks.transformProperty(property, schema, location) ?? property;\n // The original adds the schema's comment after any comment the callback set.\n return withSchemaComment(\n transformed,\n schema,\n schemaCommentOptionsOf(request.context.options.fixes),\n );\n}\n\n/** What the property loop reads from a property schema, in the original order. */\ninterface PropertyFacts {\n readonly ref: string | undefined;\n readonly flags: AccessFlags;\n readonly hasDefault: boolean;\n}\n\nfunction propertyFacts(value: Schema, request: SchemaRequest): PropertyFacts {\n if (typeof value !== \"object\") {\n return { ref: undefined, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };\n }\n // `in` throws for a null value, as in the original (which also reads `$ref` first).\n const ref = \"$ref\" in value && value.$ref ? value.$ref : undefined;\n const flags = propertyAccessFlags(value, request.context);\n return { ref, flags, hasDefault: \"default\" in value && value.default !== undefined };\n}\n\nfunction isOptionalProperty(\n key: string,\n facts: PropertyFacts,\n schema: SchemaObject,\n request: SchemaRequest,\n): boolean {\n const { options } = request.context;\n const path = request.location.path;\n const isDefaultRequired =\n facts.hasDefault &&\n options.defaultNonNullable &&\n !INPUT_PATH_PARTS.some((part) => path?.includes(part));\n const isRequired =\n schema.required?.includes(key) ||\n (schema.required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\nfunction isExcluded(value: Schema, facts: PropertyFacts, request: SchemaRequest): boolean {\n if (!request.context.options.excludeDeprecated) {\n return false;\n }\n const resolved = facts.ref ? request.context.refs.resolve(facts.ref) : value;\n return Boolean((resolved as SchemaObject | undefined)?.deprecated);\n}\n\n/** A type, and whether a callback forced the property optional (null: no override). */\ninterface CustomResult {\n readonly type: IrType;\n readonly isOptional: true | null;\n}\n\nfunction propertyType(\n key: string,\n value: Schema,\n facts: PropertyFacts,\n request: SchemaRequest,\n): CustomResult {\n const path = createRef([request.location.path, key]);\n const type = facts.ref\n ? schemaRefType(facts.ref, request)\n : request.transformNested(value, { ...request.location, path });\n const custom = request.context.callbacks.transform(value, request.location);\n return custom === null\n ? { type, isOptional: null }\n : { type: custom.type, isOptional: custom.isOptional || null };\n}\n\nfunction propertyMember(\n key: string,\n value: Schema,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrMember | null {\n if ((typeof value !== \"object\" && typeof value !== \"boolean\") || Array.isArray(value)) {\n throw new InvalidPropertyError(request.location.path, key, value);\n }\n const facts = propertyFacts(value, request);\n if (isExcluded(value, facts, request)) {\n return null;\n }\n const { options } = request.context;\n const isOptional = isOptionalProperty(key, facts, schema, request);\n const result = propertyType(key, value, facts, request);\n const property = irProperty(\n toPropertyName(key),\n withReadWriteMarker(result.type, facts.flags, options),\n {\n isOptional: result.isOptional ?? isOptional,\n isReadonly: options.immutable || (!options.readWriteMarkers && facts.flags.isReadOnly),\n },\n );\n return finishProperty(property, value, createRef([request.location.path, key]), request);\n}\n\nfunction propertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const members: IrMember[] = [];\n for (const [key, value] of documentEntries(schema.properties ?? {}, request.context.options)) {\n const member = propertyMember(key, value, schema, request);\n if (member !== null) {\n members.push(member);\n }\n }\n return members;\n}\n\n/**\n * `$defs` as a nested `$defs?: { … }` member, in document order (never alphabetized). It is\n * optional because `$defs` is a schema keyword, not data: the original made it required, so a\n * value of the type needed a `$defs` key (research/legacy-bugs.md, item 17, upstream #2664).\n */\nfunction defsMember(\n defs: Readonly<Record<string, SchemaObject>>,\n request: SchemaRequest,\n): IrMember {\n const { options } = request.context;\n const members = Object.entries(defs).map(([key, value]) => {\n const path = createRef([request.location.path, \"$defs\", key]);\n const flags = propertyAccessFlags(value, request.context);\n const type = withReadWriteMarker(\n request.transformNested(value, { ...request.location, path }),\n flags,\n options,\n );\n const property = irProperty(toPropertyName(key), type, {\n isReadonly: options.immutable || (!options.readWriteMarkers && flags.isReadOnly),\n });\n return finishProperty(property, value, path, request);\n });\n return irProperty(toPropertyName(\"$defs\"), irObject(members), { isOptional: true });\n}\n\nfunction hasObjectKeywords(schema: SchemaObject): boolean {\n const hasProperties = Boolean(schema.properties && Object.keys(schema.properties).length);\n return (\n hasProperties ||\n Boolean(schema.additionalProperties || schema.patternProperties || schema.$defs)\n );\n}\n\n/** Value types of the `[key: string]` index signature, in the original order. */\nfunction indexValueTypes(schema: SchemaObject, request: SchemaRequest): IrType[] {\n const { additionalProperties } = schema;\n const isObject = typeof additionalProperties === \"object\";\n const hasExplicit = isObject && Object.keys(additionalProperties).length > 0;\n const hasImplicit =\n additionalProperties === true || (isObject && Object.keys(additionalProperties).length === 0);\n const types: IrType[] = [];\n if (hasExplicit) {\n types.push(request.transformNested(additionalProperties as Schema, request.location, true));\n }\n if (hasImplicit || (!additionalProperties && request.context.options.additionalProperties)) {\n types.push(UNKNOWN_TYPE);\n }\n const patterns = schema.patternProperties;\n if (typeof patterns === \"object\" && patterns !== null && Object.keys(patterns).length > 0) {\n for (const [, value] of documentEntries(patterns, request.context.options)) {\n types.push(request.transformNested(value, request.location));\n }\n }\n return types;\n}\n\n/**\n * Whether the schema declares property `key` and the type keeps it: `--exclude-deprecated` drops\n * a deprecated one.\n */\nexport function isKeptProperty(schema: SchemaObject, key: string, request: SchemaRequest): boolean {\n const properties = schema.properties ?? {};\n if (!Object.hasOwn(properties, key)) {\n return false;\n }\n const value = properties[key] as Schema;\n const isExcludable = request.context.options.excludeDeprecated && typeof value === \"object\";\n return !isExcludable || !isExcluded(value, propertyFacts(value, request), request);\n}\n\n/**\n * The members for the discriminator and `properties`. A schema that declares the discriminator\n * property itself keeps its own declaration, required as the discriminator needs: both in one\n * object type do not compile (TS2300, the Apple SiriKit Cloud Media API). A declaration that\n * `--exclude-deprecated` drops does not count, so the discriminator property stays.\n */\nfunction discriminatorAndPropertyMembers(schema: SchemaObject, request: SchemaRequest): IrMember[] {\n const inherited = inheritedDiscriminator(schema, request);\n if (inherited === undefined) {\n return propertyMembers(schema, request);\n }\n const name = inherited.discriminator.propertyName;\n if (!isKeptProperty(schema, name, request)) {\n return [discriminatorMember(inherited, request), ...propertyMembers(schema, request)];\n }\n // Without `required`, `--properties-required-by-default` requires every property already; a\n // list of one would make the others optional.\n const isAllRequired =\n schema.required === undefined && request.context.options.propertiesRequiredByDefault;\n const required = isAllRequired ? undefined : [...(schema.required ?? []), name];\n return propertyMembers({ ...schema, required } as SchemaObject, request);\n}\n\n/**\n * Object keywords: discriminator, `properties`, `$defs`, and an index signature for\n * `additionalProperties` / `patternProperties` (or `--additional-properties`). Null when the schema\n * has none of them.\n */\nexport function objectType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n if (!hasObjectKeywords(schema)) {\n const inherited = inheritedDiscriminator(schema, request);\n return inherited ? irObject([discriminatorMember(inherited, request)]) : null;\n }\n const members = discriminatorAndPropertyMembers(schema, request);\n // As in the original, a null `$defs` throws here (Object.keys) instead of being skipped.\n if (\n \"$defs\" in schema &&\n typeof schema.$defs === \"object\" &&\n Object.keys(schema.$defs).length > 0\n ) {\n members.push(defsMember(schema.$defs, request));\n }\n const valueTypes = indexValueTypes(schema, request);\n if (valueTypes.length === 0) {\n return members.length > 0 ? irObject(members) : null;\n }\n const index = irObject([\n irStringIndexSignature(\"key\", unionOf(valueTypes), request.context.options.immutable),\n ]);\n return intersectionOf([...(members.length > 0 ? [irObject(members)] : []), index]);\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","irReference","withSchemaComment","schemaCommentOptionsOf","propertyAccessFlags","createRef","schemaRefType","irProperty","toPropertyName","documentEntries","irObject","UNKNOWN_TYPE","inheritedDiscriminator","discriminatorMember","irStringIndexSignature","unionOf","intersectionOf"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAM,gBAAA,GAAmB,CAAC,YAAA,EAAc,aAAA,EAAe,eAAe,CAAA;AAE/D,MAAM,6BAA6BA,2BAAA,CAAqB;AAAA,EAC7D,WAAA,CAAY,IAAA,EAA0B,GAAA,EAAa,KAAA,EAAgB;AACjE,IAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,UAAU,OAAO,KAAA;AACzD,IAAA,KAAA,CAAM;AAAA,MACJ,MAAMC,kBAAA,CAAY,uBAAA;AAAA,MAClB,SACE,CAAA,EAAG,IAAI,CAAA,mBAAA,EAAsB,GAAG,4CAAiD,QAAQ,CAAA,CAAA;AAAA,MAC3F,OAAA,EAAS,EAAE,IAAA,EAAM,QAAA,EAAU,KAAK,QAAA;AAAS,KAC1C,CAAA;AACD,IAAA,IAAA,CAAK,IAAA,GAAO,sBAAA;AAAA,EACd;AACF;AAGA,SAAS,mBAAA,CAAoB,IAAA,EAAc,KAAA,EAAoB,OAAA,EAAgC;AAC7F,EAAA,IAAI,CAAC,OAAA,CAAQ,gBAAA,IAAoB,KAAA,CAAM,UAAA,KAAe,MAAM,WAAA,EAAa;AACvE,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAOC,yBAAY,KAAA,CAAM,UAAA,GAAa,UAAU,QAAA,EAAU,CAAC,IAAI,CAAC,CAAA;AAClE;AAGA,SAAS,cAAA,CACP,QAAA,EACA,M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,CAAuB,OAAOC,uBAAA,CAAQ,UAAU,GAAG,OAAA,CAAQ,OAAA,CAAQ,QAAQ,SAAS;AAAA,GACrF,CAAA;AACD,EAAA,OAAOC,8BAAA,CAAe,CAAC,GAAI,OAAA,CAAQ,SAAS,CAAA,GAAI,CAACN,qBAAA,CAAS,OAAO,CAAC,CAAA,GAAI,EAAC,EAAI,KAAK,CAAC,CAAA;AACnF;;;;"}
|
|
@@ -3,11 +3,12 @@ import { irObject, irStringIndexSignature, irProperty, irReference } from '../..
|
|
|
3
3
|
import { toPropertyName } from '../../../domain/ir/property-name.mjs';
|
|
4
4
|
import { createRef } from '../../../domain/openapi/json-pointer.mjs';
|
|
5
5
|
import { documentEntries } from '../document-entries.mjs';
|
|
6
|
-
import {
|
|
7
|
-
import { withSchemaComment } from '../schema-comment.mjs';
|
|
6
|
+
import { schemaRefType } from '../ref-pointer/pointer-type.mjs';
|
|
7
|
+
import { withSchemaComment, schemaCommentOptionsOf } from '../schema-comment.mjs';
|
|
8
8
|
import { UNKNOWN_TYPE } from '../shared-types.mjs';
|
|
9
9
|
import { unionOf, intersectionOf } from '../type-combinators.mjs';
|
|
10
|
-
import {
|
|
10
|
+
import { propertyAccessFlags } from './access-flags.mjs';
|
|
11
|
+
import { inheritedDiscriminator, discriminatorMember } from './inherited-discriminator.mjs';
|
|
11
12
|
|
|
12
13
|
const INPUT_PATH_PARTS = ["parameters", "requestBody", "requestBodies"];
|
|
13
14
|
class InvalidPropertyError extends OpenAPITypesafeError {
|
|
@@ -30,17 +31,18 @@ function withReadWriteMarker(type, flags, options) {
|
|
|
30
31
|
function finishProperty(property, schema, path, request) {
|
|
31
32
|
const location = { ...request.location, path };
|
|
32
33
|
const transformed = request.context.callbacks.transformProperty(property, schema, location) ?? property;
|
|
33
|
-
return withSchemaComment(
|
|
34
|
+
return withSchemaComment(
|
|
35
|
+
transformed,
|
|
36
|
+
schema,
|
|
37
|
+
schemaCommentOptionsOf(request.context.options.fixes)
|
|
38
|
+
);
|
|
34
39
|
}
|
|
35
|
-
function propertyFacts(value) {
|
|
40
|
+
function propertyFacts(value, request) {
|
|
36
41
|
if (typeof value !== "object") {
|
|
37
42
|
return { ref: void 0, flags: { isReadOnly: false, isWriteOnly: false }, hasDefault: false };
|
|
38
43
|
}
|
|
39
44
|
const ref = "$ref" in value && value.$ref ? value.$ref : void 0;
|
|
40
|
-
const flags =
|
|
41
|
-
isReadOnly: Boolean("readOnly" in value && value.readOnly),
|
|
42
|
-
isWriteOnly: Boolean("writeOnly" in value && value.writeOnly)
|
|
43
|
-
};
|
|
45
|
+
const flags = propertyAccessFlags(value, request.context);
|
|
44
46
|
return { ref, flags, hasDefault: "default" in value && value.default !== void 0 };
|
|
45
47
|
}
|
|
46
48
|
function isOptionalProperty(key, facts, schema, request) {
|
|
@@ -59,7 +61,7 @@ function isExcluded(value, facts, request) {
|
|
|
59
61
|
}
|
|
60
62
|
function propertyType(key, value, facts, request) {
|
|
61
63
|
const path = createRef([request.location.path, key]);
|
|
62
|
-
const type = facts.ref ?
|
|
64
|
+
const type = facts.ref ? schemaRefType(facts.ref, request) : request.transformNested(value, { ...request.location, path });
|
|
63
65
|
const custom = request.context.callbacks.transform(value, request.location);
|
|
64
66
|
return custom === null ? { type, isOptional: null } : { type: custom.type, isOptional: custom.isOptional || null };
|
|
65
67
|
}
|
|
@@ -67,7 +69,7 @@ function propertyMember(key, value, schema, request) {
|
|
|
67
69
|
if (typeof value !== "object" && typeof value !== "boolean" || Array.isArray(value)) {
|
|
68
70
|
throw new InvalidPropertyError(request.location.path, key, value);
|
|
69
71
|
}
|
|
70
|
-
const facts = propertyFacts(value);
|
|
72
|
+
const facts = propertyFacts(value, request);
|
|
71
73
|
if (isExcluded(value, facts, request)) {
|
|
72
74
|
return null;
|
|
73
75
|
}
|
|
@@ -98,10 +100,7 @@ function defsMember(defs, request) {
|
|
|
98
100
|
const { options } = request.context;
|
|
99
101
|
const members = Object.entries(defs).map(([key, value]) => {
|
|
100
102
|
const path = createRef([request.location.path, "$defs", key]);
|
|
101
|
-
const flags =
|
|
102
|
-
isReadOnly: "readOnly" in value && !!value.readOnly,
|
|
103
|
-
isWriteOnly: "writeOnly" in value && !!value.writeOnly
|
|
104
|
-
};
|
|
103
|
+
const flags = propertyAccessFlags(value, request.context);
|
|
105
104
|
const type = withReadWriteMarker(
|
|
106
105
|
request.transformNested(value, { ...request.location, path }),
|
|
107
106
|
flags,
|
|
@@ -138,21 +137,34 @@ function indexValueTypes(schema, request) {
|
|
|
138
137
|
}
|
|
139
138
|
return types;
|
|
140
139
|
}
|
|
141
|
-
function
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
return
|
|
140
|
+
function isKeptProperty(schema, key, request) {
|
|
141
|
+
const properties = schema.properties ?? {};
|
|
142
|
+
if (!Object.hasOwn(properties, key)) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
const value = properties[key];
|
|
146
|
+
const isExcludable = request.context.options.excludeDeprecated && typeof value === "object";
|
|
147
|
+
return !isExcludable || !isExcluded(value, propertyFacts(value, request), request);
|
|
148
|
+
}
|
|
149
|
+
function discriminatorAndPropertyMembers(schema, request) {
|
|
150
|
+
const inherited = inheritedDiscriminator(schema, request);
|
|
151
|
+
if (inherited === void 0) {
|
|
152
|
+
return propertyMembers(schema, request);
|
|
153
|
+
}
|
|
154
|
+
const name = inherited.discriminator.propertyName;
|
|
155
|
+
if (!isKeptProperty(schema, name, request)) {
|
|
156
|
+
return [discriminatorMember(inherited, request), ...propertyMembers(schema, request)];
|
|
157
|
+
}
|
|
158
|
+
const isAllRequired = schema.required === void 0 && request.context.options.propertiesRequiredByDefault;
|
|
159
|
+
const required = isAllRequired ? void 0 : [...schema.required ?? [], name];
|
|
160
|
+
return propertyMembers({ ...schema, required }, request);
|
|
149
161
|
}
|
|
150
162
|
function objectType(schema, request) {
|
|
151
|
-
const members = discriminatorMembers(schema, request);
|
|
152
163
|
if (!hasObjectKeywords(schema)) {
|
|
153
|
-
|
|
164
|
+
const inherited = inheritedDiscriminator(schema, request);
|
|
165
|
+
return inherited ? irObject([discriminatorMember(inherited, request)]) : null;
|
|
154
166
|
}
|
|
155
|
-
members
|
|
167
|
+
const members = discriminatorAndPropertyMembers(schema, request);
|
|
156
168
|
if ("$defs" in schema && typeof schema.$defs === "object" && Object.keys(schema.$defs).length > 0) {
|
|
157
169
|
members.push(defsMember(schema.$defs, request));
|
|
158
170
|
}
|
|
@@ -166,5 +178,5 @@ function objectType(schema, request) {
|
|
|
166
178
|
return intersectionOf([...members.length > 0 ? [irObject(members)] : [], index]);
|
|
167
179
|
}
|
|
168
180
|
|
|
169
|
-
export { InvalidPropertyError, objectType };
|
|
181
|
+
export { InvalidPropertyError, isKeptProperty, objectType };
|
|
170
182
|
//# sourceMappingURL=object-type.mjs.map
|