openapi-typesafe 1.0.0-rc.1 → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -5
- package/dist/adapters/node-deprecations/node-deprecations.cjs +14 -0
- package/dist/adapters/node-deprecations/node-deprecations.cjs.map +1 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs +12 -0
- package/dist/adapters/node-deprecations/node-deprecations.mjs.map +1 -0
- package/dist/adapters/redocly-loader/configured-headers.cjs +32 -0
- package/dist/adapters/redocly-loader/configured-headers.cjs.map +1 -0
- package/dist/adapters/redocly-loader/configured-headers.mjs +30 -0
- package/dist/adapters/redocly-loader/configured-headers.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +19 -6
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +18 -5
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +37 -4
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +37 -4
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-resolution-check.cjs +191 -0
- package/dist/adapters/redocly-loader/ref-resolution-check.cjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-resolution-check.mjs +189 -0
- package/dist/adapters/redocly-loader/ref-resolution-check.mjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-resolution-steps.cjs +73 -0
- package/dist/adapters/redocly-loader/ref-resolution-steps.cjs.map +1 -0
- package/dist/adapters/redocly-loader/ref-resolution-steps.mjs +60 -0
- package/dist/adapters/redocly-loader/ref-resolution-steps.mjs.map +1 -0
- package/dist/adapters/redocly-loader/remote-fetch.cjs +41 -14
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -14
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.cjs +23 -5
- package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-load-errors.mjs +23 -5
- package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs +9 -1
- package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs +9 -1
- package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs +2 -1
- package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -1
- package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +2 -1
- package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs.map +1 -1
- package/dist/adapters/type-ast-bridge/print-typescript.cjs.map +1 -1
- package/dist/adapters/type-ast-bridge/print-typescript.mjs.map +1 -1
- package/dist/api/default-ports.cjs +14 -0
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +12 -1
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs +1 -1
- package/dist/api/discriminator-conflict-warnings.cjs.map +1 -1
- package/dist/api/discriminator-conflict-warnings.mjs +2 -2
- package/dist/api/discriminator-conflict-warnings.mjs.map +1 -1
- package/dist/api/discriminator-patch.cjs +8 -4
- package/dist/api/discriminator-patch.cjs.map +1 -1
- package/dist/api/discriminator-patch.mjs +9 -5
- package/dist/api/discriminator-patch.mjs.map +1 -1
- package/dist/api/discriminator-scan.cjs +2 -2
- package/dist/api/discriminator-scan.cjs.map +1 -1
- package/dist/api/discriminator-scan.mjs +3 -3
- package/dist/api/discriminator-scan.mjs.map +1 -1
- package/dist/api/document-refs.cjs +15 -12
- package/dist/api/document-refs.cjs.map +1 -1
- package/dist/api/document-refs.mjs +15 -12
- package/dist/api/document-refs.mjs.map +1 -1
- package/dist/api/document-run.cjs +6 -3
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +6 -3
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/footer-sink.cjs +25 -2
- package/dist/api/footer-sink.cjs.map +1 -1
- package/dist/api/footer-sink.mjs +25 -2
- package/dist/api/footer-sink.mjs.map +1 -1
- package/dist/api/legacy-callback-warning.cjs +7 -1
- package/dist/api/legacy-callback-warning.cjs.map +1 -1
- package/dist/api/legacy-callback-warning.mjs +8 -2
- package/dist/api/legacy-callback-warning.mjs.map +1 -1
- package/dist/api/legacy-ts-helpers.cjs.map +1 -1
- package/dist/api/legacy-ts-helpers.mjs.map +1 -1
- package/dist/api/legacy-utils.cjs.map +1 -1
- package/dist/api/legacy-utils.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +3 -2
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +4 -3
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/string-to-ast.cjs +7 -9
- package/dist/api/string-to-ast.cjs.map +1 -1
- package/dist/api/string-to-ast.mjs +8 -9
- package/dist/api/string-to-ast.mjs.map +1 -1
- package/dist/api/transform-context.cjs +1 -1
- package/dist/api/transform-context.cjs.map +1 -1
- package/dist/api/transform-context.mjs +1 -1
- package/dist/api/transform-context.mjs.map +1 -1
- package/dist/api/transform-schema.cjs +2 -2
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +3 -3
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/print/type-printer.cjs +2 -1
- package/dist/application/print/type-printer.cjs.map +1 -1
- package/dist/application/print/type-printer.mjs +2 -1
- package/dist/application/print/type-printer.mjs.map +1 -1
- package/dist/application/transform/document/components.cjs +1 -1
- package/dist/application/transform/document/components.cjs.map +1 -1
- package/dist/application/transform/document/components.mjs +2 -2
- package/dist/application/transform/document/components.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +2 -2
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +3 -3
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +2 -2
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +3 -3
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/footer/evaluation.cjs +9 -0
- package/dist/application/transform/footer/evaluation.cjs.map +1 -1
- package/dist/application/transform/footer/evaluation.mjs +8 -1
- package/dist/application/transform/footer/evaluation.mjs.map +1 -1
- package/dist/application/transform/footer/type-evaluation.cjs +4 -112
- package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
- package/dist/application/transform/footer/type-evaluation.mjs +4 -112
- package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
- package/dist/application/transform/footer/type-indexing.cjs +107 -0
- package/dist/application/transform/footer/type-indexing.cjs.map +1 -0
- package/dist/application/transform/footer/type-indexing.mjs +105 -0
- package/dist/application/transform/footer/type-indexing.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/pointer-type.cjs +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs +2 -2
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs +2 -2
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/array-type.cjs +2 -2
- package/dist/application/transform/schema/array-type.cjs.map +1 -1
- package/dist/application/transform/schema/array-type.mjs +3 -3
- package/dist/application/transform/schema/array-type.mjs.map +1 -1
- package/dist/application/transform/schema/composition-type.cjs +3 -3
- package/dist/application/transform/schema/composition-type.cjs.map +1 -1
- package/dist/application/transform/schema/composition-type.mjs +4 -4
- package/dist/application/transform/schema/composition-type.mjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.cjs +3 -5
- package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
- package/dist/application/transform/schema/enum-rule.mjs +4 -6
- package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
- package/dist/application/transform/schema/presence-members.cjs +1 -1
- package/dist/application/transform/schema/presence-members.cjs.map +1 -1
- package/dist/application/transform/schema/presence-members.mjs +2 -2
- package/dist/application/transform/schema/presence-members.mjs.map +1 -1
- package/dist/application/transform/schema/required-variants.cjs +2 -2
- package/dist/application/transform/schema/required-variants.cjs.map +1 -1
- package/dist/application/transform/schema/required-variants.mjs +3 -3
- package/dist/application/transform/schema/required-variants.mjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.mjs +2 -2
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
- package/dist/application/transform/schema-comment.cjs +1 -1
- package/dist/application/transform/schema-comment.cjs.map +1 -1
- package/dist/application/transform/schema-comment.mjs +2 -2
- package/dist/application/transform/schema-comment.mjs.map +1 -1
- package/dist/cli/api-settings.cjs +78 -0
- package/dist/cli/api-settings.cjs.map +1 -0
- package/dist/cli/api-settings.mjs +73 -0
- package/dist/cli/api-settings.mjs.map +1 -0
- package/dist/cli/cli-arguments.cjs +1 -0
- package/dist/cli/cli-arguments.cjs.map +1 -1
- package/dist/cli/cli-arguments.mjs +1 -1
- package/dist/cli/cli-arguments.mjs.map +1 -1
- package/dist/cli/help-text.cjs +3 -3
- package/dist/cli/help-text.cjs.map +1 -1
- package/dist/cli/help-text.mjs +3 -3
- package/dist/cli/help-text.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +8 -4
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +7 -3
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +5 -1
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +5 -1
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/deprecations.cjs +11 -0
- package/dist/domain/deprecations.cjs.map +1 -0
- package/dist/domain/deprecations.mjs +9 -0
- package/dist/domain/deprecations.mjs.map +1 -0
- package/dist/domain/errors.cjs +4 -1
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +4 -1
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/ir/constructors.cjs +2 -0
- package/dist/domain/ir/constructors.cjs.map +1 -1
- package/dist/domain/ir/constructors.mjs +2 -1
- package/dist/domain/ir/constructors.mjs.map +1 -1
- package/dist/domain/openapi/path-templates.cjs +1 -1
- package/dist/domain/openapi/path-templates.cjs.map +1 -1
- package/dist/domain/openapi/path-templates.mjs +1 -1
- package/dist/domain/openapi/path-templates.mjs.map +1 -1
- package/dist/domain/output-fixes.cjs +11 -14
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +11 -13
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/url-credentials.cjs +10 -0
- package/dist/domain/url-credentials.cjs.map +1 -0
- package/dist/domain/url-credentials.mjs +8 -0
- package/dist/domain/url-credentials.mjs.map +1 -0
- package/dist/domain/warnings.cjs +8 -1
- package/dist/domain/warnings.cjs.map +1 -1
- package/dist/domain/warnings.mjs +8 -1
- package/dist/domain/warnings.mjs.map +1 -1
- package/dist/index.cjs +4 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1185 -59
- package/dist/index.d.mts +1185 -59
- package/dist/index.d.ts +1185 -59
- package/dist/index.mjs +4 -2
- package/dist/index.mjs.map +1 -1
- package/dist/transform/path-item-object.cjs.map +1 -1
- package/dist/transform/path-item-object.mjs.map +1 -1
- package/package.json +5 -4
- package/src/adapters/node-deprecations/node-deprecations.ts +14 -0
- package/src/adapters/redocly-loader/configured-headers.ts +65 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +22 -7
- package/src/adapters/redocly-loader/ref-access.ts +60 -5
- package/src/adapters/redocly-loader/ref-resolution-check.ts +257 -0
- package/src/adapters/redocly-loader/ref-resolution-steps.ts +113 -0
- package/src/adapters/redocly-loader/remote-fetch.ts +77 -21
- package/src/adapters/redocly-loader/schema-load-errors.ts +33 -11
- package/src/adapters/redocly-loader/unsupported-keys.ts +17 -2
- package/src/adapters/terminal-logger/terminal-logger.ts +9 -5
- package/src/adapters/type-ast-bridge/ir-to-typescript.ts +2 -1
- package/src/adapters/type-ast-bridge/print-typescript.ts +3 -1
- package/src/adapters/type-ast-bridge/typescript-types.ts +57 -5
- package/src/api/default-ports.ts +23 -0
- package/src/api/discriminator-conflict-warnings.ts +2 -2
- package/src/api/discriminator-patch.ts +11 -7
- package/src/api/discriminator-scan.ts +3 -3
- package/src/api/document-refs.ts +19 -15
- package/src/api/document-run.ts +14 -6
- package/src/api/footer-sink.ts +34 -2
- package/src/api/legacy-callback-warning.ts +16 -5
- package/src/api/legacy-ts-helpers.ts +7 -5
- package/src/api/legacy-utils.ts +1 -1
- package/src/api/openapi-ts.ts +8 -2
- package/src/api/run-context.ts +37 -0
- package/src/api/string-to-ast.ts +11 -15
- package/src/api/transform-context.ts +10 -8
- package/src/api/transform-schema.ts +9 -8
- package/src/application/ports/deprecation-reporter.ts +9 -0
- package/src/application/print/type-printer.ts +2 -1
- package/src/application/transform/document/components.ts +2 -2
- package/src/application/transform/document/parameters.ts +4 -3
- package/src/application/transform/document/paths.ts +4 -3
- package/src/application/transform/footer/evaluation.ts +10 -0
- package/src/application/transform/footer/type-evaluation.ts +6 -133
- package/src/application/transform/footer/type-indexing.ts +152 -0
- package/src/application/transform/ref-pointer/pointer-type.ts +2 -4
- package/src/application/transform/schema/access-flags.ts +2 -2
- package/src/application/transform/schema/array-type.ts +3 -5
- package/src/application/transform/schema/composition-type.ts +4 -4
- package/src/application/transform/schema/enum-rule.ts +4 -6
- package/src/application/transform/schema/presence-members.ts +2 -2
- package/src/application/transform/schema/required-variants.ts +3 -3
- package/src/application/transform/schema/unevaluated-properties.ts +2 -2
- package/src/application/transform/schema-comment.ts +2 -2
- package/src/cli/api-settings.ts +109 -0
- package/src/cli/cli-arguments.ts +5 -2
- package/src/cli/help-text.ts +4 -4
- package/src/cli/redocly-apis.ts +13 -7
- package/src/cli/run-cli.ts +5 -1
- package/src/domain/deprecations.ts +15 -0
- package/src/domain/errors.ts +16 -4
- package/src/domain/ir/constructors.ts +3 -0
- package/src/domain/ir/nodes.ts +9 -6
- package/src/domain/openapi/path-templates.ts +2 -1
- package/src/domain/output-fixes.ts +16 -16
- package/src/domain/url-credentials.ts +18 -0
- package/src/domain/warnings.ts +7 -0
- package/src/index.ts +3 -6
- package/src/transform/path-item-object.ts +6 -2
- package/src/types/generator-options.ts +12 -32
- package/src/types/openapi-common.ts +1 -0
- package/src/types/openapi-request.ts +3 -0
- package/src/types/openapi-schema.ts +2 -0
- package/src/types/openapi-security.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-type.mjs","sources":["../../../../src/application/transform/schema/array-type.ts"],"sourcesContent":["import {\n irArray,\n irOptionalTupleElement,\n irReadonly,\n irTuple,\n irTupleElement,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrTupleElement, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `--array-length` writes tuples only while the estimated number of tuple elements stays below\n * this; the original chose it as roughly where TypeScript starts to struggle with tuple inference.\n */\nconst MAX_LENGTH_TUPLE_ELEMENTS = 30;\n\n/**\n * The tuple of `prefixItems` (or of an `items` list); null without either. The original closes a\n * `prefixItems` tuple and requires every element; the `prefix-items` fix does not.\n */\nfunction prefixTupleType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items } = schema;\n if (schema.prefixItems && isPrefixItemsFixed(schema, request)) {\n return prefixItemsTupleType(schema.prefixItems, schema, request);\n }\n if (!schema.prefixItems && !Array.isArray(items)) {\n return null;\n }\n const prefixItems = schema.prefixItems ?? (items as SchemaObject[]);\n return irTuple(\n prefixItems.map((item) => irTupleElement(request.transformNested(item, request.location))),\n );\n}\n\n/** The type of the items after the prefix, or null when there may be none (`false`). */\nfunction restItemType(schema: Schema, request: SchemaRequest): IrType | null {\n return schema === false ? null : request.transformNested(schema, request.location);\n}\n\n/**\n * The type of the items after a `prefixItems` tuple (JSON Schema 2020-12 §10.3.1): `items`, else\n * `unevaluatedItems`, which does not apply to the items `contains` matches, else any item. Null\n * when no item may follow. An `items` list is not a schema in 2020-12, so it allows any item.\n */\nfunction prefixRestType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items, unevaluatedItems, contains } = schema;\n if (items !== undefined && !Array.isArray(items)) {\n return restItemType(items as Schema, request);\n }\n if (unevaluatedItems === undefined || items !== undefined) {\n return UNKNOWN_TYPE;\n }\n const unevaluated = restItemType(unevaluatedItems, request);\n const matched = contains === undefined ? null : restItemType(contains, request);\n const types = [unevaluated, matched].filter((type): type is IrType => type !== null);\n return types.length === 0 ? null : unionOf(types);\n}\n\n/**\n * The `prefix-items` tuple of `prefixItems`: an array may end before the prefix does, so the\n * elements from `minItems` on are optional (`T?`), and a rest element types the items after it.\n */\nfunction prefixItemsTupleType(\n prefixItems: readonly Schema[],\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType {\n const { min } = lengthBounds(schema);\n const elements = prefixItems.map((item, index): IrTupleElement => {\n const type = request.transformNested(item, request.location);\n return index < min ? irTupleElement(type) : irOptionalTupleElement(type);\n });\n const rest = prefixRestType(schema, request);\n return irTuple(rest === null ? elements : [...elements, irTupleElement(irArray(rest), true)]);\n}\n\nfunction isPrefixItemsFixed(schema: SchemaObject, request: SchemaRequest): boolean {\n return (\n schema.prefixItems !== undefined && request.context.options.fixes.has(OutputFix.PREFIX_ITEMS)\n );\n}\n\n/** The type of one item; `unknown` without `items`. */\nfunction singleItemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { items } = schema;\n return items ? request.transformNested(items as SchemaObject, request.location) : UNKNOWN_TYPE;\n}\n\n/**\n * The item type as the original returns it: a tuple stands for the whole array, and a nested\n * `type: array` item is wrapped in an array here already.\n */\nfunction itemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return tuple;\n }\n const { items } = schema;\n // Checked first: the `in` test below throws for `items: null`.\n if (!items) {\n return UNKNOWN_TYPE;\n }\n const nested = singleItemType(schema, request);\n const isNestedArray = typeof items === \"object\" && \"type\" in items && items.type === \"array\";\n return isNestedArray ? irArray(nested) : nested;\n}\n\nfunction repeat(type: IrType, count: number): IrType[] {\n return Array.from({ length: count }, () => type);\n}\n\ninterface LengthBounds {\n readonly min: number;\n readonly max: number | undefined;\n}\n\nfunction lengthBounds(schema: SchemaObject): LengthBounds {\n const { minItems, maxItems } = schema;\n const min = typeof minItems === \"number\" && minItems >= 0 ? minItems : 0;\n const isMaxValid = typeof maxItems === \"number\" && maxItems >= 0 && min <= maxItems;\n return { min, max: isMaxValid ? maxItems : undefined };\n}\n\n/**\n * Tuples for `--array-length`, as the original builds them. With both bounds it emits tuples of\n * length 0 to `max - min` (not `min` to `max`); the `array-length-tuples` fix corrects it.\n */\nfunction lengthTupleType(schema: SchemaObject, item: IrType, bounds: LengthBounds): IrType {\n const { min, max } = bounds;\n if (min === max) {\n return unionOf([irTuple(repeat(item, min).map((type) => irTupleElement(type)))]);\n }\n if ((schema.maxItems as number) > 0) {\n const lengths = Array.from({ length: Math.max(0, (max ?? 0) - min + 1) }, (_, index) => index);\n return unionOf(\n lengths.map((length) => irTuple(repeat(item, length).map((type) => irTupleElement(type)))),\n );\n }\n const elements = repeat(item, min).map((type) => irTupleElement(type));\n return irTuple([...elements, irTupleElement(irArray(item), true)]);\n}\n\nfunction isLengthTupleWanted(bounds: LengthBounds, request: SchemaRequest): boolean {\n const { min, max } = bounds;\n const estimatedSize = max === undefined ? min : (max * (max + 1) - min * (min - 1)) / 2;\n const hasBounds = min !== 0 || max !== undefined;\n return (\n request.context.options.arrayLength && hasBounds && estimatedSize < MAX_LENGTH_TUPLE_ELEMENTS\n );\n}\n\n/** Applies `--immutable` to one array or tuple type. */\ntype ArrayWrapper = (type: IrType) => IrType;\n\nfunction tupleOf(item: IrType, length: number, isOpen: boolean): IrType {\n const elements = repeat(item, length).map((type) => irTupleElement(type));\n return irTuple(isOpen ? [...elements, irTupleElement(irArray(item), true)] : elements);\n}\n\n/** Tuples of every length from `min` to `max`; without `max`, `min` items and a rest element. */\nfunction fixedLengthTupleType(item: IrType, bounds: LengthBounds, wrap: ArrayWrapper): IrType {\n const { min, max } = bounds;\n if (max === undefined) {\n return wrap(tupleOf(item, min, true));\n }\n const lengths = Array.from({ length: max - min + 1 }, (_, index) => min + index);\n return unionOf(lengths.map((length) => wrap(tupleOf(item, length, false))));\n}\n\n/**\n * `type: array` with `--array-length` and the `array-length-tuples` fix (#2048, #2330, #2546):\n * the tuples have `min` to `max` items, the item type is used as it is (a nested array stays one\n * level deep), a `prefixItems` tuple gets no length tuples around it, and `--immutable` makes\n * every tuple `readonly`.\n */\nfunction fixedArrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n const wrap: ArrayWrapper = (type) =>\n request.context.options.immutable ? irReadonly(type) : type;\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return wrap(tuple);\n }\n const item = singleItemType(schema, request);\n const bounds = lengthBounds(schema);\n return isLengthTupleWanted(bounds, request)\n ? fixedLengthTupleType(item, bounds, wrap)\n : wrap(irArray(item));\n}\n\nfunction isArrayLengthFixed(request: SchemaRequest): boolean {\n const { arrayLength, fixes } = request.context.options;\n return arrayLength && fixes.has(OutputFix.ARRAY_LENGTH_TUPLES);\n}\n\n/** `type: array`, including tuples (`prefixItems`, array `items`) and `--array-length`. */\nexport function arrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n if (isArrayLengthFixed(request)) {\n return fixedArrayType(schema, request);\n }\n const item = itemType(schema, request);\n const bounds = lengthBounds(schema);\n // A `prefix-items` tuple has its own lengths, so `--array-length` adds no tuples around it.\n if (!isPrefixItemsFixed(schema, request) && isLengthTupleWanted(bounds, request)) {\n return lengthTupleType(schema, item, bounds);\n }\n // A tuple or an array item is used as the array type itself.\n const type = item.kind === \"tuple\" || item.kind === \"array\" ? item : irArray(item);\n return request.context.options.immutable ? irReadonly(type) : type;\n}\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,yBAAA,GAA4B,EAAA;AAMlC,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAuC;AACpF,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,IAAI,MAAA,CAAO,WAAA,IAAe,kBAAA,CAAmB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAC7D,IAAA,OAAO,oBAAA,CAAqB,MAAA,CAAO,WAAA,EAAa,MAAA,EAAQ,OAAO,CAAA;AAAA,EACjE;AACA,EAAA,IAAI,CAAC,MAAA,CAAO,WAAA,IAAe,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAA,GAAc,OAAO,WAAA,IAAgB,KAAA;AAC3C,EAAA,OAAO,OAAA;AAAA,IACL,WAAA,CAAY,GAAA,CAAI,CAAC,IAAA,KAAS,cAAA,CAAe,OAAA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AAC/C,EAAA,OAAO,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,SAAA,CAAU,mBAAmB,CAAA;AAC/D;AAGO,SAAS,SAAA,CAAU,QAAsB,OAAA,EAAgC;AAC9E,EAAA,IAAI,kBAAA,CAAmB,OAAO,CAAA,EAAG;AAC/B,IAAA,OAAO,cAAA,CAAe,QAAQ,OAAO,CAAA;AAAA,EACvC;AACA,EAAA,MAAM,IAAA,GAAO,QAAA,CAAS,MAAA,EAAQ,OAAO,CAAA;AACrC,EAAA,MAAM,MAAA,GAAS,aAAa,MAAM,CAAA;AAElC,EAAA,IAAI,CAAC,mBAAmB,MAAA,EAAQ,OAAO,KAAK,mBAAA,CAAoB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAChF,IAAA,OAAO,eAAA,CAAgB,MAAA,EAAQ,IAAA,EAAM,MAAM,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAA,GAAO,KAAK,IAAA,KAAS,OAAA,IAAW,KAAK,IAAA,KAAS,OAAA,GAAU,IAAA,GAAO,OAAA,CAAQ,IAAI,CAAA;AACjF,EAAA,OAAO,QAAQ,OAAA,CAAQ,OAAA,CAAQ,SAAA,GAAY,UAAA,CAAW,IAAI,CAAA,GAAI,IAAA;AAChE;;"}
|
|
1
|
+
{"version":3,"file":"array-type.mjs","sources":["../../../../src/application/transform/schema/array-type.ts"],"sourcesContent":["import {\n irArray,\n irOptionalTupleElement,\n irReadonly,\n irTuple,\n irTupleElement,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrTupleElement, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\n\n/**\n * `--array-length` writes tuples only while the estimated number of tuple elements stays below\n * this; the original chose it as roughly where TypeScript starts to struggle with tuple inference.\n */\nconst MAX_LENGTH_TUPLE_ELEMENTS = 30;\n\n/**\n * The tuple of `prefixItems` (or of an `items` list); null without either. The original closes a\n * `prefixItems` tuple and requires every element; the `prefix-items` fix does not.\n */\nfunction prefixTupleType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items } = schema;\n if (schema.prefixItems && isPrefixItemsFixed(schema, request)) {\n return prefixItemsTupleType(schema.prefixItems, schema, request);\n }\n if (!schema.prefixItems && !Array.isArray(items)) {\n return null;\n }\n const prefixItems = schema.prefixItems ?? (items as SchemaObject[]);\n return irTuple(\n prefixItems.map((item) => irTupleElement(request.transformNested(item, request.location))),\n );\n}\n\n/** The type of the items after the prefix, or null when there may be none (`false`). */\nfunction restItemType(schema: Schema, request: SchemaRequest): IrType | null {\n return schema === false ? null : request.transformNested(schema, request.location);\n}\n\n/**\n * The type of the items after a `prefixItems` tuple (JSON Schema 2020-12 §10.3.1): `items`, else\n * `unevaluatedItems`, which does not apply to the items `contains` matches, else any item. Null\n * when no item may follow. An `items` list is not a schema in 2020-12, so it allows any item.\n */\nfunction prefixRestType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const { items, unevaluatedItems, contains } = schema;\n if (items !== undefined && !Array.isArray(items)) {\n return restItemType(items as Schema, request);\n }\n if (unevaluatedItems === undefined || items !== undefined) {\n return UNKNOWN_TYPE;\n }\n const unevaluated = restItemType(unevaluatedItems, request);\n const matched = contains === undefined ? null : restItemType(contains, request);\n const types = [unevaluated, matched].filter((type): type is IrType => type !== null);\n return types.length === 0 ? null : unionOf(types);\n}\n\n/**\n * The `prefix-items` tuple of `prefixItems`: an array may end before the prefix does, so the\n * elements from `minItems` on are optional (`T?`), and a rest element types the items after it.\n */\nfunction prefixItemsTupleType(\n prefixItems: readonly Schema[],\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType {\n const { min } = lengthBounds(schema);\n const elements = prefixItems.map((item, index): IrTupleElement => {\n const type = request.transformNested(item, request.location);\n return index < min ? irTupleElement(type) : irOptionalTupleElement(type);\n });\n const rest = prefixRestType(schema, request);\n return irTuple(rest === null ? elements : [...elements, irTupleElement(irArray(rest), true)]);\n}\n\nfunction isPrefixItemsFixed(schema: SchemaObject, request: SchemaRequest): boolean {\n return schema.prefixItems !== undefined && request.context.options.fixes.has(FIX.PREFIX_ITEMS);\n}\n\n/** The type of one item; `unknown` without `items`. */\nfunction singleItemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { items } = schema;\n return items ? request.transformNested(items as SchemaObject, request.location) : UNKNOWN_TYPE;\n}\n\n/**\n * The item type as the original returns it: a tuple stands for the whole array, and a nested\n * `type: array` item is wrapped in an array here already.\n */\nfunction itemType(schema: SchemaObject, request: SchemaRequest): IrType {\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return tuple;\n }\n const { items } = schema;\n // Checked first: the `in` test below throws for `items: null`.\n if (!items) {\n return UNKNOWN_TYPE;\n }\n const nested = singleItemType(schema, request);\n const isNestedArray = typeof items === \"object\" && \"type\" in items && items.type === \"array\";\n return isNestedArray ? irArray(nested) : nested;\n}\n\nfunction repeat(type: IrType, count: number): IrType[] {\n return Array.from({ length: count }, () => type);\n}\n\ninterface LengthBounds {\n readonly min: number;\n readonly max: number | undefined;\n}\n\nfunction lengthBounds(schema: SchemaObject): LengthBounds {\n const { minItems, maxItems } = schema;\n const min = typeof minItems === \"number\" && minItems >= 0 ? minItems : 0;\n const isMaxValid = typeof maxItems === \"number\" && maxItems >= 0 && min <= maxItems;\n return { min, max: isMaxValid ? maxItems : undefined };\n}\n\n/**\n * Tuples for `--array-length`, as the original builds them. With both bounds it emits tuples of\n * length 0 to `max - min` (not `min` to `max`); the `array-length-tuples` fix corrects it.\n */\nfunction lengthTupleType(schema: SchemaObject, item: IrType, bounds: LengthBounds): IrType {\n const { min, max } = bounds;\n if (min === max) {\n return unionOf([irTuple(repeat(item, min).map((type) => irTupleElement(type)))]);\n }\n if ((schema.maxItems as number) > 0) {\n const lengths = Array.from({ length: Math.max(0, (max ?? 0) - min + 1) }, (_, index) => index);\n return unionOf(\n lengths.map((length) => irTuple(repeat(item, length).map((type) => irTupleElement(type)))),\n );\n }\n const elements = repeat(item, min).map((type) => irTupleElement(type));\n return irTuple([...elements, irTupleElement(irArray(item), true)]);\n}\n\nfunction isLengthTupleWanted(bounds: LengthBounds, request: SchemaRequest): boolean {\n const { min, max } = bounds;\n const estimatedSize = max === undefined ? min : (max * (max + 1) - min * (min - 1)) / 2;\n const hasBounds = min !== 0 || max !== undefined;\n return (\n request.context.options.arrayLength && hasBounds && estimatedSize < MAX_LENGTH_TUPLE_ELEMENTS\n );\n}\n\n/** Applies `--immutable` to one array or tuple type. */\ntype ArrayWrapper = (type: IrType) => IrType;\n\nfunction tupleOf(item: IrType, length: number, isOpen: boolean): IrType {\n const elements = repeat(item, length).map((type) => irTupleElement(type));\n return irTuple(isOpen ? [...elements, irTupleElement(irArray(item), true)] : elements);\n}\n\n/** Tuples of every length from `min` to `max`; without `max`, `min` items and a rest element. */\nfunction fixedLengthTupleType(item: IrType, bounds: LengthBounds, wrap: ArrayWrapper): IrType {\n const { min, max } = bounds;\n if (max === undefined) {\n return wrap(tupleOf(item, min, true));\n }\n const lengths = Array.from({ length: max - min + 1 }, (_, index) => min + index);\n return unionOf(lengths.map((length) => wrap(tupleOf(item, length, false))));\n}\n\n/**\n * `type: array` with `--array-length` and the `array-length-tuples` fix (#2048, #2330, #2546):\n * the tuples have `min` to `max` items, the item type is used as it is (a nested array stays one\n * level deep), a `prefixItems` tuple gets no length tuples around it, and `--immutable` makes\n * every tuple `readonly`.\n */\nfunction fixedArrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n const wrap: ArrayWrapper = (type) =>\n request.context.options.immutable ? irReadonly(type) : type;\n const tuple = prefixTupleType(schema, request);\n if (tuple !== null) {\n return wrap(tuple);\n }\n const item = singleItemType(schema, request);\n const bounds = lengthBounds(schema);\n return isLengthTupleWanted(bounds, request)\n ? fixedLengthTupleType(item, bounds, wrap)\n : wrap(irArray(item));\n}\n\nfunction isArrayLengthFixed(request: SchemaRequest): boolean {\n const { arrayLength, fixes } = request.context.options;\n return arrayLength && fixes.has(FIX.ARRAY_LENGTH_TUPLES);\n}\n\n/** `type: array`, including tuples (`prefixItems`, array `items`) and `--array-length`. */\nexport function arrayType(schema: SchemaObject, request: SchemaRequest): IrType {\n if (isArrayLengthFixed(request)) {\n return fixedArrayType(schema, request);\n }\n const item = itemType(schema, request);\n const bounds = lengthBounds(schema);\n // A `prefix-items` tuple has its own lengths, so `--array-length` adds no tuples around it.\n if (!isPrefixItemsFixed(schema, request) && isLengthTupleWanted(bounds, request)) {\n return lengthTupleType(schema, item, bounds);\n }\n // A tuple or an array item is used as the array type itself.\n const type = item.kind === \"tuple\" || item.kind === \"array\" ? item : irArray(item);\n return request.context.options.immutable ? irReadonly(type) : type;\n}\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,yBAAA,GAA4B,EAAA;AAMlC,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAuC;AACpF,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,IAAI,MAAA,CAAO,WAAA,IAAe,kBAAA,CAAmB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAC7D,IAAA,OAAO,oBAAA,CAAqB,MAAA,CAAO,WAAA,EAAa,MAAA,EAAQ,OAAO,CAAA;AAAA,EACjE;AACA,EAAA,IAAI,CAAC,MAAA,CAAO,WAAA,IAAe,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAA,GAAc,OAAO,WAAA,IAAgB,KAAA;AAC3C,EAAA,OAAO,OAAA;AAAA,IACL,WAAA,CAAY,GAAA,CAAI,CAAC,IAAA,KAAS,cAAA,CAAe,OAAA,CAAQ,eAAA,CAAgB,IAAA,EAAM,OAAA,CAAQ,QAAQ,CAAC,CAAC;AAAA,GAC3F;AACF;AAGA,SAA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,SAAS,SAAA,CAAU,QAAsB,OAAA,EAAgC;AAC9E,EAAA,IAAI,kBAAA,CAAmB,OAAO,CAAA,EAAG;AAC/B,IAAA,OAAO,cAAA,CAAe,QAAQ,OAAO,CAAA;AAAA,EACvC;AACA,EAAA,MAAM,IAAA,GAAO,QAAA,CAAS,MAAA,EAAQ,OAAO,CAAA;AACrC,EAAA,MAAM,MAAA,GAAS,aAAa,MAAM,CAAA;AAElC,EAAA,IAAI,CAAC,mBAAmB,MAAA,EAAQ,OAAO,KAAK,mBAAA,CAAoB,MAAA,EAAQ,OAAO,CAAA,EAAG;AAChF,IAAA,OAAO,eAAA,CAAgB,MAAA,EAAQ,IAAA,EAAM,MAAM,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAA,GAAO,KAAK,IAAA,KAAS,OAAA,IAAW,KAAK,IAAA,KAAS,OAAA,GAAU,IAAA,GAAO,OAAA,CAAQ,IAAI,CAAA;AACjF,EAAA,OAAO,QAAQ,OAAA,CAAQ,OAAA,CAAQ,SAAA,GAAY,UAAA,CAAW,IAAI,CAAA,GAAI,IAAA;AAChE;;"}
|
|
@@ -28,7 +28,7 @@ function keysToRequire(ref, target, required, request) {
|
|
|
28
28
|
if (!request.context.discriminators.isHandled(ref)) {
|
|
29
29
|
return defined;
|
|
30
30
|
}
|
|
31
|
-
if (!request.context.options.fixes.has(outputFixes.
|
|
31
|
+
if (!request.context.options.fixes.has(outputFixes.FIX.DISCRIMINATOR_MEMBER_REQUIRED)) {
|
|
32
32
|
return [];
|
|
33
33
|
}
|
|
34
34
|
return defined.filter((key) => !target.required?.includes(key));
|
|
@@ -66,7 +66,7 @@ function allOfItemType(item, required, request) {
|
|
|
66
66
|
return ownKeywordsType(own, item.$ref, request);
|
|
67
67
|
}
|
|
68
68
|
const type = isRef ? refItemType(item, required, request) : inlineItemType(item, required, request);
|
|
69
|
-
const isUnion = unionItem !== void 0 && !unionItem.isMapped && request.context.options.fixes.has(outputFixes.
|
|
69
|
+
const isUnion = unionItem !== void 0 && !unionItem.isMapped && request.context.options.fixes.has(outputFixes.FIX.ALLOF_DISCRIMINATED_UNION);
|
|
70
70
|
if (!propertyName || isUnion) {
|
|
71
71
|
return type;
|
|
72
72
|
}
|
|
@@ -86,7 +86,7 @@ function anyOfType(previous, schema, request) {
|
|
|
86
86
|
if (variants.length === 0 || previous === null) {
|
|
87
87
|
return variants.length === 0 ? previous : typeCombinators.unionOf(variants);
|
|
88
88
|
}
|
|
89
|
-
if (!request.context.options.fixes.has(outputFixes.
|
|
89
|
+
if (!request.context.options.fixes.has(outputFixes.FIX.ANYOF_PROPERTIES)) {
|
|
90
90
|
return typeCombinators.unionOf([previous, ...variants]);
|
|
91
91
|
}
|
|
92
92
|
return Array.isArray(schema.type) ? previous : typeCombinators.intersectionOf([previous, typeCombinators.unionOf(variants)]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composition-type.cjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { requirableRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { unionItemOf, unionOwnKeywords } from \"./discriminated-union.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport { requiredVariantsType } from \"./required-variants.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: createRef([request.location.path, keyword, String(index)]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/**\n * The parent's `required` keys that the target at `ref` defines. A target that the discriminator\n * scan gave its property got none: the scan made that property required, but the other keys were\n * lost too. With `discriminator-member-required` only keys the target requires already are left\n * out (#2162).\n */\nfunction keysToRequire(\n ref: string,\n target: SchemaObject,\n required: readonly string[],\n request: SchemaRequest,\n): readonly string[] {\n const defined = required.filter((key) => Boolean(target.properties?.[key]));\n if (!request.context.discriminators.isHandled(ref)) {\n return defined;\n }\n if (!request.context.options.fixes.has(OutputFix.DISCRIMINATOR_MEMBER_REQUIRED)) {\n return [];\n }\n return defined.filter((key) => !target.required?.includes(key));\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const resolved = request.context.refs.resolve(item.$ref) as SchemaObject | undefined;\n if (!resolved || typeof resolved !== \"object\" || !(\"properties\" in resolved)) {\n return type;\n }\n const keys = keysToRequire(item.$ref, resolved, required, request);\n if (keys.length === 0) {\n return type;\n }\n request.context.footer.requireWithRequired();\n return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/**\n * The union's own keywords at the union's location, so nested names (enums) stay the union's.\n * Null when the union has none.\n */\nfunction ownKeywordsType(own: SchemaObject, ref: string, request: SchemaRequest): IrType | null {\n return combinedType(own, { ...request, location: { ...request.location, path: ref } });\n}\n\n/**\n * An `allOf` item; one with a discriminator omits that property (the parent redefines it). A\n * `$ref` to a discriminated union is not such a parent: for a member of the union it is the\n * union's own keywords, since the union contains the member (#1665); with\n * `allof-discriminated-union` it is the union, since `Omit` on a union drops keys (#1464), unless\n * the union's mapping names the schema: then it is a member, as the discriminator scan has it.\n */\nfunction allOfItemType(\n item: Schema,\n required: readonly string[],\n request: SchemaRequest,\n): IrType | null {\n const isRef = isRefItem(item);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n const propertyName = discriminator?.propertyName;\n const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : undefined;\n if (isRef && propertyName && unionItem?.isMember) {\n const own = unionOwnKeywords(unionItem.union, propertyName, required);\n return ownKeywordsType(own, item.$ref, request);\n }\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const isUnion =\n unionItem !== undefined &&\n !unionItem.isMapped &&\n request.context.options.fixes.has(OutputFix.ALLOF_DISCRIMINATED_UNION);\n if (!propertyName || isUnion) {\n return type;\n }\n // With `discriminator-values` the schema also redefines the properties of other owners above\n // it, so no item may keep a value of its own for them (a parent mapped as `content`).\n const { path } = request.location;\n const others = path === undefined ? [] : request.context.discriminators.otherPropertiesAt(path);\n return omitKeys(type, [propertyName, ...others]);\n}\n\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.flatMap((item) => allOfItemType(item, required, request) ?? []);\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(OutputFix.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n return variantsType(type, schema, request);\n}\n\n/** `anyOf`, then `oneOf`, applied to the core and `allOf` type (`anyof-oneof-required` first). */\nfunction variantsType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const type =\n requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ??\n anyOfType(previous, schema, request);\n const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);\n if (oneOfRequired !== null) {\n return oneOfRequired;\n }\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_TYPE;\n const type = combinedType(schema, request) ?? empty;\n return type !== UNKNOWN_TYPE && schema.nullable ? nullableOf([type]) : type;\n}\n"],"names":["createRef","OutputFix","withRequiredKeys","requirableRefType","unionItemOf","unionOwnKeywords","omitKeys","isPrimitiveType","unionOf","intersectionOf","coreType","allOfMembers","requiredVariantsType","unevaluatedPropertiesType","irRecord","irKeyword","UNKNOWN_TYPE","nullableOf"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAS,YAAA,CACP,QAAA,EACA,OAAA,EACA,OAAA,EACU;AACV,EAAA,OAAO,QAAA,CAAS,GAAA;AAAA,IAAI,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AAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAASA,4BAAgB,MAAA,CAAO,QAAA,GAAWC,2BAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
|
|
1
|
+
{"version":3,"file":"composition-type.cjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { requirableRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { unionItemOf, unionOwnKeywords } from \"./discriminated-union.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport { requiredVariantsType } from \"./required-variants.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: createRef([request.location.path, keyword, String(index)]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/**\n * The parent's `required` keys that the target at `ref` defines. A target that the discriminator\n * scan gave its property got none: the scan made that property required, but the other keys were\n * lost too. With `discriminator-member-required` only keys the target requires already are left\n * out (#2162).\n */\nfunction keysToRequire(\n ref: string,\n target: SchemaObject,\n required: readonly string[],\n request: SchemaRequest,\n): readonly string[] {\n const defined = required.filter((key) => Boolean(target.properties?.[key]));\n if (!request.context.discriminators.isHandled(ref)) {\n return defined;\n }\n if (!request.context.options.fixes.has(FIX.DISCRIMINATOR_MEMBER_REQUIRED)) {\n return [];\n }\n return defined.filter((key) => !target.required?.includes(key));\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const resolved = request.context.refs.resolve(item.$ref) as SchemaObject | undefined;\n if (!resolved || typeof resolved !== \"object\" || !(\"properties\" in resolved)) {\n return type;\n }\n const keys = keysToRequire(item.$ref, resolved, required, request);\n if (keys.length === 0) {\n return type;\n }\n request.context.footer.requireWithRequired();\n return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/**\n * The union's own keywords at the union's location, so nested names (enums) stay the union's.\n * Null when the union has none.\n */\nfunction ownKeywordsType(own: SchemaObject, ref: string, request: SchemaRequest): IrType | null {\n return combinedType(own, { ...request, location: { ...request.location, path: ref } });\n}\n\n/**\n * An `allOf` item; one with a discriminator omits that property (the parent redefines it). A\n * `$ref` to a discriminated union is not such a parent: for a member of the union it is the\n * union's own keywords, since the union contains the member (#1665); with\n * `allof-discriminated-union` it is the union, since `Omit` on a union drops keys (#1464), unless\n * the union's mapping names the schema: then it is a member, as the discriminator scan has it.\n */\nfunction allOfItemType(\n item: Schema,\n required: readonly string[],\n request: SchemaRequest,\n): IrType | null {\n const isRef = isRefItem(item);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n const propertyName = discriminator?.propertyName;\n const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : undefined;\n if (isRef && propertyName && unionItem?.isMember) {\n const own = unionOwnKeywords(unionItem.union, propertyName, required);\n return ownKeywordsType(own, item.$ref, request);\n }\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const isUnion =\n unionItem !== undefined &&\n !unionItem.isMapped &&\n request.context.options.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION);\n if (!propertyName || isUnion) {\n return type;\n }\n // With `discriminator-values` the schema also redefines the properties of other owners above\n // it, so no item may keep a value of its own for them (a parent mapped as `content`).\n const { path } = request.location;\n const others = path === undefined ? [] : request.context.discriminators.otherPropertiesAt(path);\n return omitKeys(type, [propertyName, ...others]);\n}\n\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.flatMap((item) => allOfItemType(item, required, request) ?? []);\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(FIX.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n return variantsType(type, schema, request);\n}\n\n/** `anyOf`, then `oneOf`, applied to the core and `allOf` type (`anyof-oneof-required` first). */\nfunction variantsType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const type =\n requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ??\n anyOfType(previous, schema, request);\n const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);\n if (oneOfRequired !== null) {\n return oneOfRequired;\n }\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_TYPE;\n const type = combinedType(schema, request) ?? empty;\n return type !== UNKNOWN_TYPE && schema.nullable ? nullableOf([type]) : type;\n}\n"],"names":["createRef","FIX","withRequiredKeys","requirableRefType","unionItemOf","unionOwnKeywords","omitKeys","isPrimitiveType","unionOf","intersectionOf","coreType","allOfMembers","requiredVariantsType","unevaluatedPropertiesType","irRecord","irKeyword","UNKNOWN_TYPE","nullableOf"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAS,YAAA,CACP,QAAA,EACA,OAAA,EACA,OAAA,EACU;AACV,EAAA,OAAO,QAAA,CAAS,GAAA;AAAA,IAAI,CAAC,OAAA,EAAS,KAAA,KAC5B,OAAA,CAAQ,gBAAgB,OAAA,EAAS;AAAA,MAC/B,GAAG,OAAA,CAAQ,QAAA;AAAA,MACX,IAAA,EAAMA,qBAAA,CAAU,CAAC,OAAA,CAAQ,QAAA,CAAS,MAAM,OAAA,EAAS,MAAA,CAAO,KAAK,CAAC,CAAC;AAAA,KAChE;AAAA,GACH;AACF;AAMA,SAAS,UAAU,IAAA,EAAiD;AAClE,EAAA,OAAO,MAAA,IAAW,IAAA;AACpB;AAQA,SAAS,aAAA,CACP,GAAA,EACA,MAAA,EACA,QAAA,EACA,OAAA,EACmB;AACnB,EAAA,MAAM,O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MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA;AACzC,EAAA,MAAM,WAAA,GAAcC,+CAAA,CAA0B,MAAA,EAAQ,IAAA,EAAM,OAAO,CAAA;AACnE,EAAA,IAAI,gBAAgB,IAAA,EAAM;AACxB,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,IAAI,SAAS,IAAA,EAAM;AACjB,IAAA,OAAO,WAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAQ,IAAA,CAAK,IAAA,KAAS,iBAAiB,IAAA,CAAK,KAAA,GAAQ,CAAC,IAAI,CAAA;AAC/D,EAAA,OAAOJ,8BAAA,CAAe,CAAC,GAAG,KAAA,EAAO,WAAW,CAAC,CAAA;AAC/C;AAOO,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAgC;AACpF,EAAA,MAAM,EAAE,mBAAA,EAAoB,GAAI,OAAA,CAAQ,OAAA,CAAQ,OAAA;AAChD,EAAA,MAAM,KAAA,GACJ,MAAA,IAAU,MAAA,GACNK,qBAAA,CAASC,sBAAA,CAAU,QAAQ,CAAA,EAAG,mBAAA,GAAsBC,wBAAA,GAAeD,sBAAA,CAAU,OAAO,CAAC,CAAA,GACrFC,wBAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAASA,4BAAgB,MAAA,CAAO,QAAA,GAAWC,2BAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { irRecord, irKeyword } from '../../../domain/ir/constructors.mjs';
|
|
2
2
|
import { createRef } from '../../../domain/openapi/json-pointer.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
4
4
|
import { requirableRefType } from '../ref-pointer/pointer-type.mjs';
|
|
5
5
|
import { UNKNOWN_TYPE } from '../shared-types.mjs';
|
|
6
6
|
import { nullableOf, intersectionOf, omitKeys, unionOf, isPrimitiveType, withRequiredKeys } from '../type-combinators.mjs';
|
|
@@ -26,7 +26,7 @@ function keysToRequire(ref, target, required, request) {
|
|
|
26
26
|
if (!request.context.discriminators.isHandled(ref)) {
|
|
27
27
|
return defined;
|
|
28
28
|
}
|
|
29
|
-
if (!request.context.options.fixes.has(
|
|
29
|
+
if (!request.context.options.fixes.has(FIX.DISCRIMINATOR_MEMBER_REQUIRED)) {
|
|
30
30
|
return [];
|
|
31
31
|
}
|
|
32
32
|
return defined.filter((key) => !target.required?.includes(key));
|
|
@@ -64,7 +64,7 @@ function allOfItemType(item, required, request) {
|
|
|
64
64
|
return ownKeywordsType(own, item.$ref, request);
|
|
65
65
|
}
|
|
66
66
|
const type = isRef ? refItemType(item, required, request) : inlineItemType(item, required, request);
|
|
67
|
-
const isUnion = unionItem !== void 0 && !unionItem.isMapped && request.context.options.fixes.has(
|
|
67
|
+
const isUnion = unionItem !== void 0 && !unionItem.isMapped && request.context.options.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION);
|
|
68
68
|
if (!propertyName || isUnion) {
|
|
69
69
|
return type;
|
|
70
70
|
}
|
|
@@ -84,7 +84,7 @@ function anyOfType(previous, schema, request) {
|
|
|
84
84
|
if (variants.length === 0 || previous === null) {
|
|
85
85
|
return variants.length === 0 ? previous : unionOf(variants);
|
|
86
86
|
}
|
|
87
|
-
if (!request.context.options.fixes.has(
|
|
87
|
+
if (!request.context.options.fixes.has(FIX.ANYOF_PROPERTIES)) {
|
|
88
88
|
return unionOf([previous, ...variants]);
|
|
89
89
|
}
|
|
90
90
|
return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composition-type.mjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { OutputFix } from \"../../../domain/output-fixes.js\";\nimport { requirableRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { unionItemOf, unionOwnKeywords } from \"./discriminated-union.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport { requiredVariantsType } from \"./required-variants.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: createRef([request.location.path, keyword, String(index)]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/**\n * The parent's `required` keys that the target at `ref` defines. A target that the discriminator\n * scan gave its property got none: the scan made that property required, but the other keys were\n * lost too. With `discriminator-member-required` only keys the target requires already are left\n * out (#2162).\n */\nfunction keysToRequire(\n ref: string,\n target: SchemaObject,\n required: readonly string[],\n request: SchemaRequest,\n): readonly string[] {\n const defined = required.filter((key) => Boolean(target.properties?.[key]));\n if (!request.context.discriminators.isHandled(ref)) {\n return defined;\n }\n if (!request.context.options.fixes.has(OutputFix.DISCRIMINATOR_MEMBER_REQUIRED)) {\n return [];\n }\n return defined.filter((key) => !target.required?.includes(key));\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const resolved = request.context.refs.resolve(item.$ref) as SchemaObject | undefined;\n if (!resolved || typeof resolved !== \"object\" || !(\"properties\" in resolved)) {\n return type;\n }\n const keys = keysToRequire(item.$ref, resolved, required, request);\n if (keys.length === 0) {\n return type;\n }\n request.context.footer.requireWithRequired();\n return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/**\n * The union's own keywords at the union's location, so nested names (enums) stay the union's.\n * Null when the union has none.\n */\nfunction ownKeywordsType(own: SchemaObject, ref: string, request: SchemaRequest): IrType | null {\n return combinedType(own, { ...request, location: { ...request.location, path: ref } });\n}\n\n/**\n * An `allOf` item; one with a discriminator omits that property (the parent redefines it). A\n * `$ref` to a discriminated union is not such a parent: for a member of the union it is the\n * union's own keywords, since the union contains the member (#1665); with\n * `allof-discriminated-union` it is the union, since `Omit` on a union drops keys (#1464), unless\n * the union's mapping names the schema: then it is a member, as the discriminator scan has it.\n */\nfunction allOfItemType(\n item: Schema,\n required: readonly string[],\n request: SchemaRequest,\n): IrType | null {\n const isRef = isRefItem(item);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n const propertyName = discriminator?.propertyName;\n const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : undefined;\n if (isRef && propertyName && unionItem?.isMember) {\n const own = unionOwnKeywords(unionItem.union, propertyName, required);\n return ownKeywordsType(own, item.$ref, request);\n }\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const isUnion =\n unionItem !== undefined &&\n !unionItem.isMapped &&\n request.context.options.fixes.has(OutputFix.ALLOF_DISCRIMINATED_UNION);\n if (!propertyName || isUnion) {\n return type;\n }\n // With `discriminator-values` the schema also redefines the properties of other owners above\n // it, so no item may keep a value of its own for them (a parent mapped as `content`).\n const { path } = request.location;\n const others = path === undefined ? [] : request.context.discriminators.otherPropertiesAt(path);\n return omitKeys(type, [propertyName, ...others]);\n}\n\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.flatMap((item) => allOfItemType(item, required, request) ?? []);\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(OutputFix.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n return variantsType(type, schema, request);\n}\n\n/** `anyOf`, then `oneOf`, applied to the core and `allOf` type (`anyof-oneof-required` first). */\nfunction variantsType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const type =\n requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ??\n anyOfType(previous, schema, request);\n const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);\n if (oneOfRequired !== null) {\n return oneOfRequired;\n }\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_TYPE;\n const type = combinedType(schema, request) ?? empty;\n return type !== UNKNOWN_TYPE && schema.nullable ? nullableOf([type]) : type;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAuBA,SAAS,YAAA,CACP,QAAA,EACA,OAAA,EACA,OAAA,EACU;AACV,EAAA,OAAO,QAAA,CAAS,GAAA;AAAA,IAAI,CAAC,OAAA,EAAS,KAAA,KAC5B,OAAA,CAAQ,gBAAgB,OAAA,EAAS;AAAA,MAC/B,GAAG,OAAA,CAAQ,QAAA;AAAA,MACX,IAAA,EAAM,SAAA,CAAU,CAAC,OAAA,CAAQ,QAAA,CAAS,MAAM,OAAA,EAAS,MAAA,CAAO,KAAK,CAAC,CAAC;AAAA,KAChE;AAAA,GACH;AACF;AAMA,SAAS,UAAU,IAAA,EAAiD;AAClE,EAAA,OAAO,MAAA,IAAW,IAAA;AACpB;AAQA,SAAS,aAAA,CACP,GAAA,EACA,MAAA,EACA,QAAA,EACA,OAAA,EACmB;AACnB,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,MAAA,CAAO,CAAC,GAAA,KAAQ,QAAQ,MAAA,CAAO,UAAA,GAAa,GAAG,CAAC,CAAC,CAAA;AAC1E,EAAA,IAAI,CAAC,OAAA,CAAQ,OAAA,CAAQ,cAAA,CAAe,SAAA,CAAU,GAAG,CAAA,EAAG;AAClD,IAAA,OAAO,OAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,QAAQ,OAAA,CAAQ,OAAA,CAAQ,MAAM,GAAA,CAAI,SAAA,CAAU,6BAA6B,CAAA,EAAG;AAC/E,IAAA,OAAO,EAAC;AAAA,EACV;AACA,EAAA,OAAO,OAAA,CAAQ,OAAO,CAAC,GAAA,KAAQ,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A,CAAgB,QAAsB,OAAA,EAAgC;AACpF,EAAA,MAAM,EAAE,mBAAA,EAAoB,GAAI,OAAA,CAAQ,OAAA,CAAQ,OAAA;AAChD,EAAA,MAAM,KAAA,GACJ,MAAA,IAAU,MAAA,GACN,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA,EAAG,mBAAA,GAAsB,YAAA,GAAe,SAAA,CAAU,OAAO,CAAC,CAAA,GACrF,YAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAAS,gBAAgB,MAAA,CAAO,QAAA,GAAW,WAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
|
|
1
|
+
{"version":3,"file":"composition-type.mjs","sources":["../../../../src/application/transform/schema/composition-type.ts"],"sourcesContent":["import { irKeyword, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef } from \"../../../domain/openapi/json-pointer.js\";\nimport type { Schema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { requirableRefType } from \"../ref-pointer/pointer-type.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport {\n intersectionOf,\n isPrimitiveType,\n nullableOf,\n omitKeys,\n unionOf,\n withRequiredKeys,\n} from \"../type-combinators.js\";\nimport { coreType } from \"./core-type.js\";\nimport { unionItemOf, unionOwnKeywords } from \"./discriminated-union.js\";\nimport { allOfMembers } from \"./presence-members.js\";\nimport { requiredVariantsType } from \"./required-variants.js\";\nimport type { SchemaRequest } from \"./schema-rule.js\";\nimport { unevaluatedPropertiesType } from \"./unevaluated-properties.js\";\n\n/** `anyOf` / `oneOf` variants; the position is part of the path so nested names stay unique. */\nfunction variantTypes(\n variants: readonly Schema[],\n keyword: \"anyOf\" | \"oneOf\",\n request: SchemaRequest,\n): IrType[] {\n return variants.map((variant, index) =>\n request.transformNested(variant, {\n ...request.location,\n path: createRef([request.location.path, keyword, String(index)]),\n }),\n );\n}\n\n/**\n * Whether an `allOf` item is a `$ref`. Like the original, this uses `in`, so a boolean item throws\n * a TypeError instead of being accepted.\n */\nfunction isRefItem(item: Schema): item is { readonly $ref: string } {\n return \"$ref\" in (item as object);\n}\n\n/**\n * The parent's `required` keys that the target at `ref` defines. A target that the discriminator\n * scan gave its property got none: the scan made that property required, but the other keys were\n * lost too. With `discriminator-member-required` only keys the target requires already are left\n * out (#2162).\n */\nfunction keysToRequire(\n ref: string,\n target: SchemaObject,\n required: readonly string[],\n request: SchemaRequest,\n): readonly string[] {\n const defined = required.filter((key) => Boolean(target.properties?.[key]));\n if (!request.context.discriminators.isHandled(ref)) {\n return defined;\n }\n if (!request.context.options.fixes.has(FIX.DISCRIMINATOR_MEMBER_REQUIRED)) {\n return [];\n }\n return defined.filter((key) => !target.required?.includes(key));\n}\n\n/** A `$ref` item gets the parent's `required` keys that its target defines (`WithRequired`). */\nfunction refItemType(\n item: { readonly $ref: string },\n required: readonly string[],\n request: SchemaRequest,\n): IrType {\n const type = request.transformNested(item, request.location);\n const resolved = request.context.refs.resolve(item.$ref) as SchemaObject | undefined;\n if (!resolved || typeof resolved !== \"object\" || !(\"properties\" in resolved)) {\n return type;\n }\n const keys = keysToRequire(item.$ref, resolved, required, request);\n if (keys.length === 0) {\n return type;\n }\n request.context.footer.requireWithRequired();\n return withRequiredKeys(requirableRefType(item.$ref, type, request), keys);\n}\n\n/** An inline item merges the parent's `required` keys with its own. */\nfunction inlineItemType(item: Schema, required: readonly string[], request: SchemaRequest): IrType {\n const own =\n typeof item === \"object\" && Array.isArray((item as SchemaObject).required)\n ? ((item as SchemaObject).required ?? [])\n : [];\n return request.transformNested(\n { ...(item as SchemaObject), required: [...required, ...own] },\n request.location,\n );\n}\n\n/**\n * The union's own keywords at the union's location, so nested names (enums) stay the union's.\n * Null when the union has none.\n */\nfunction ownKeywordsType(own: SchemaObject, ref: string, request: SchemaRequest): IrType | null {\n return combinedType(own, { ...request, location: { ...request.location, path: ref } });\n}\n\n/**\n * An `allOf` item; one with a discriminator omits that property (the parent redefines it). A\n * `$ref` to a discriminated union is not such a parent: for a member of the union it is the\n * union's own keywords, since the union contains the member (#1665); with\n * `allof-discriminated-union` it is the union, since `Omit` on a union drops keys (#1464), unless\n * the union's mapping names the schema: then it is a member, as the discriminator scan has it.\n */\nfunction allOfItemType(\n item: Schema,\n required: readonly string[],\n request: SchemaRequest,\n): IrType | null {\n const isRef = isRefItem(item);\n const discriminator =\n (isRef && request.context.discriminators.objectAt(item.$ref)) ||\n (item as SchemaObject).discriminator;\n const propertyName = discriminator?.propertyName;\n const unionItem = isRef && propertyName ? unionItemOf(item.$ref, request) : undefined;\n if (isRef && propertyName && unionItem?.isMember) {\n const own = unionOwnKeywords(unionItem.union, propertyName, required);\n return ownKeywordsType(own, item.$ref, request);\n }\n const type = isRef\n ? refItemType(item, required, request)\n : inlineItemType(item, required, request);\n const isUnion =\n unionItem !== undefined &&\n !unionItem.isMapped &&\n request.context.options.fixes.has(FIX.ALLOF_DISCRIMINATED_UNION);\n if (!propertyName || isUnion) {\n return type;\n }\n // With `discriminator-values` the schema also redefines the properties of other owners above\n // it, so no item may keep a value of its own for them (a parent mapped as `content`).\n const { path } = request.location;\n const others = path === undefined ? [] : request.context.discriminators.otherPropertiesAt(path);\n return omitKeys(type, [propertyName, ...others]);\n}\n\nfunction allOfTypes(\n items: readonly Schema[],\n required: readonly string[],\n request: SchemaRequest,\n): IrType[] {\n return items.flatMap((item) => allOfItemType(item, required, request) ?? []);\n}\n\nfunction oneOfType(previous: IrType | null, variants: readonly IrType[]): IrType {\n const before = previous === null ? [] : [previous];\n // Only `oneOf` may list primitives; then it stays a flat union.\n return variants.every(isPrimitiveType)\n ? unionOf([...before, ...variants])\n : intersectionOf([...before, unionOf(variants)]);\n}\n\n/**\n * `anyOf` is a union: TypeScript unions are not exclusive, which matches anyOf better than oneOf.\n * By default the sibling type is one more member, as in the original. With `anyof-properties` it\n * is intersected with the union, so it applies to every variant (#2380); for a `type` list, each\n * listed type has applied `anyOf` already (`multipleTypes`), so the list is the whole type.\n */\nfunction anyOfType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const variants = variantTypes(schema.anyOf ?? [], \"anyOf\", request);\n if (variants.length === 0 || previous === null) {\n return variants.length === 0 ? previous : unionOf(variants);\n }\n if (!request.context.options.fixes.has(FIX.ANYOF_PROPERTIES)) {\n return unionOf([previous, ...variants]);\n }\n return Array.isArray(schema.type) ? previous : intersectionOf([previous, unionOf(variants)]);\n}\n\n/** Object enums are written as `oneOf` over their values. */\nfunction oneOfVariants(schema: SchemaObject): readonly Schema[] {\n const objectEnum =\n \"type\" in schema && schema.type === \"object\" && (schema.enum as Schema[] | undefined);\n return schema.oneOf || objectEnum || [];\n}\n\n/**\n * The parent's `required` keys, plus the keys of left-out `allOf` members (`allof-required`).\n * Without such keys the parent's list stays as it is, duplicates included, as in the original.\n */\nfunction requiredKeys(schema: SchemaObject, presenceKeys: readonly string[]): readonly string[] {\n const own = schema.required ?? [];\n return presenceKeys.length === 0 ? own : [...new Set([...own, ...presenceKeys])];\n}\n\nfunction composedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n let type: IrType | null = null;\n const core = coreType(schema, request);\n const { members, required } = allOfMembers(schema.allOf ?? [], request);\n const allOf = allOfTypes(members, requiredKeys(schema, required), request);\n if (core !== null || allOf.length > 0) {\n const allOfType = allOf.length > 0 ? [intersectionOf(allOf)] : [];\n type = intersectionOf([...(core === null ? [] : [core]), ...allOfType]);\n }\n return variantsType(type, schema, request);\n}\n\n/** `anyOf`, then `oneOf`, applied to the core and `allOf` type (`anyof-oneof-required` first). */\nfunction variantsType(\n previous: IrType | null,\n schema: SchemaObject,\n request: SchemaRequest,\n): IrType | null {\n const type =\n requiredVariantsType(previous, schema, schema.anyOf ?? [], request) ??\n anyOfType(previous, schema, request);\n const oneOfRequired = requiredVariantsType(type, schema, schema.oneOf ?? [], request);\n if (oneOfRequired !== null) {\n return oneOfRequired;\n }\n const oneOf = variantTypes(oneOfVariants(schema), \"oneOf\", request);\n return oneOf.length > 0 ? oneOfType(type, oneOf) : type;\n}\n\n/** The composed type, with the `unevaluatedProperties` index signature when it applies. */\nfunction combinedType(schema: SchemaObject, request: SchemaRequest): IrType | null {\n const type = composedType(schema, request);\n const unevaluated = unevaluatedPropertiesType(schema, type, request);\n if (unevaluated === null) {\n return type;\n }\n if (type === null) {\n return unevaluated;\n }\n // One flat intersection, so an `allOf` intersection is not printed in parentheses.\n const parts = type.kind === \"intersection\" ? type.types : [type];\n return intersectionOf([...parts, unevaluated]);\n}\n\n/**\n * The schema with composition: core type and `allOf` intersected, then `anyOf` and `oneOf`. Without\n * any of them: `Record<string, never>` (or `unknown` with `--empty-objects-unknown`) when `type` is\n * present, else `unknown`. `nullable: true` adds `null`, except to the shared `unknown`.\n */\nexport function compositionType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { emptyObjectsUnknown } = request.context.options;\n const empty =\n \"type\" in schema\n ? irRecord(irKeyword(\"string\"), emptyObjectsUnknown ? UNKNOWN_TYPE : irKeyword(\"never\"))\n : UNKNOWN_TYPE;\n const type = combinedType(schema, request) ?? empty;\n return type !== UNKNOWN_TYPE && schema.nullable ? nullableOf([type]) : type;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAuBA,SAAS,YAAA,CACP,QAAA,EACA,OAAA,EACA,OAAA,EACU;AACV,EAAA,OAAO,QAAA,CAAS,GAAA;AAAA,IAAI,CAAC,OAAA,EAAS,KAAA,KAC5B,OAAA,CAAQ,gBAAgB,OAAA,EAAS;AAAA,MAC/B,GAAG,OAAA,CAAQ,QAAA;AAAA,MACX,IAAA,EAAM,SAAA,CAAU,CAAC,OAAA,CAAQ,QAAA,CAAS,MAAM,OAAA,EAAS,MAAA,CAAO,KAAK,CAAC,CAAC;AAAA,KAChE;AAAA,GACH;AAC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AAA,GAAI,SAAA,CAAU,IAAA,EAAM,KAAK,CAAA,GAAI,IAAA;AACrD;AAGA,SAAS,YAAA,CAAa,QAAsB,OAAA,EAAuC;AACjF,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA;AACzC,EAAA,MAAM,WAAA,GAAc,yBAAA,CAA0B,MAAA,EAAQ,IAAA,EAAM,OAAO,CAAA;AACnE,EAAA,IAAI,gBAAgB,IAAA,EAAM;AACxB,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,IAAI,SAAS,IAAA,EAAM;AACjB,IAAA,OAAO,WAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAQ,IAAA,CAAK,IAAA,KAAS,iBAAiB,IAAA,CAAK,KAAA,GAAQ,CAAC,IAAI,CAAA;AAC/D,EAAA,OAAO,cAAA,CAAe,CAAC,GAAG,KAAA,EAAO,WAAW,CAAC,CAAA;AAC/C;AAOO,SAAS,eAAA,CAAgB,QAAsB,OAAA,EAAgC;AACpF,EAAA,MAAM,EAAE,mBAAA,EAAoB,GAAI,OAAA,CAAQ,OAAA,CAAQ,OAAA;AAChD,EAAA,MAAM,KAAA,GACJ,MAAA,IAAU,MAAA,GACN,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA,EAAG,mBAAA,GAAsB,YAAA,GAAe,SAAA,CAAU,OAAO,CAAC,CAAA,GACrF,YAAA;AACN,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA,IAAK,KAAA;AAC9C,EAAA,OAAO,IAAA,KAAS,gBAAgB,MAAA,CAAO,QAAA,GAAW,WAAW,CAAC,IAAI,CAAC,CAAA,GAAI,IAAA;AACzE;;"}
|
|
@@ -27,7 +27,7 @@ function hasEnumMetadata(schema) {
|
|
|
27
27
|
}
|
|
28
28
|
function tsEnumEntries(schema, options) {
|
|
29
29
|
const entries = (schema.enum ?? []).map((value, index) => [value, index]);
|
|
30
|
-
return options.fixes.has(outputFixes.
|
|
30
|
+
return options.fixes.has(outputFixes.FIX.NULLABLE_ENUMS) ? entries.filter(([value]) => value !== null) : entries;
|
|
31
31
|
}
|
|
32
32
|
function isTsEnum(schema, options) {
|
|
33
33
|
if (!options.enum || !schema.enum) {
|
|
@@ -69,9 +69,7 @@ function enumMemberType(enumName, member) {
|
|
|
69
69
|
}
|
|
70
70
|
function ownerEnumMembersType(key, values, request) {
|
|
71
71
|
const { options, discriminators, footer } = request.context;
|
|
72
|
-
const parent = options.fixes.has(
|
|
73
|
-
outputFixes.OutputFix.DISCRIMINATOR_VALUES
|
|
74
|
-
) ? discriminators.enumParentOf(key) : void 0;
|
|
72
|
+
const parent = options.fixes.has(outputFixes.FIX.DISCRIMINATOR_VALUES) ? discriminators.enumParentOf(key) : void 0;
|
|
75
73
|
if (parent === void 0 || !isTsEnum(parent.schema, options)) {
|
|
76
74
|
return null;
|
|
77
75
|
}
|
|
@@ -91,7 +89,7 @@ function tsEnumType(schema, request) {
|
|
|
91
89
|
constructors.irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),
|
|
92
90
|
schema
|
|
93
91
|
);
|
|
94
|
-
return options.fixes.has(outputFixes.
|
|
92
|
+
return options.fixes.has(outputFixes.FIX.NULLABLE_ENUMS) && isNullAllowed(schema) ? typeCombinators.unionOf([type, constructors.irKeyword("null")]) : type;
|
|
95
93
|
}
|
|
96
94
|
function isUnionPosition(pointer, index) {
|
|
97
95
|
const next = pointer[index + 1];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-rule.cjs","sources":["../../../../src/application/transform/schema/enum-rule.ts"],"sourcesContent":["import {\n irIndexedAccess,\n irKeyword,\n irObject,\n irReference,\n irString,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef, parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { 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":["parseRefPointer","OutputFix","unionOf","intersectionOf","irKeyword","irObject","irIndexedAccess","irReference","irString","createRef","refType","literalType"],"mappings":";;;;;;;;;AAuBA,MAAM,wBAAA,GAA2B,oBAAA;AACjC,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,OAAO,CAAC,CAAA;AACtE,MAAM,QAAA,GAAW,OAAA;AAEjB,SAAS,wBAAwB,MAAA,EAA+B;AAC9D,EAAA,OAAO,sBAAA,IAA0B,MAAA,IAAU,OAAA,CAAQ,MAAA,CAAO,oBAAoB,CAAA;AAChF;AAGA,SAAS,aAAa,IAAA,EAAkC;AACtD,EAAA,OAAOA,2BAAA,CAAgB,QAAQ,EAAE,CAAA,CAC9B,KAAK,GAAG,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ule.cjs","sources":["../../../../src/application/transform/schema/enum-rule.ts"],"sourcesContent":["import {\n irIndexedAccess,\n irKeyword,\n irObject,\n irReference,\n irString,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef, parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { refType } from \"../ref-type.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport type {\n DiscriminatorEnumParent,\n EnumDeclarationRequest,\n EnumMemberMetadata,\n SchemaOptions,\n} from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\n/** Removed from generated names, so `#/components/schemas/Status` gives `Status`. */\nconst COMPONENT_SCHEMAS_PREFIX = \"components/schemas\";\nconst UNION_KEYWORDS: ReadonlySet<string> = new Set([\"anyOf\", \"oneOf\"]);\nconst INDEX_RE = /^\\d+$/;\n\nfunction hasAdditionalProperties(schema: SchemaObject): boolean {\n return \"additionalProperties\" in schema && Boolean(schema.additionalProperties);\n}\n\n/** A name from the schema's pointer: `#/components/schemas/Pet/status` → `/Pet/status`. */\nfunction nameFromPath(path: string | undefined): string {\n return parseRefPointer(path ?? \"\")\n .join(\"/\")\n .replace(COMPONENT_SCHEMAS_PREFIX, \"\");\n}\n\n/** `#/components/schemas/Name`, and no deeper pointer. */\nconst COMPONENT_SCHEMA_RE = /^#\\/components\\/schemas\\/[^/]+$/;\n\nfunction hasEnumMetadata(schema: SchemaObject): boolean {\n return [\n schema[\"x-enum-varnames\"],\n schema[\"x-enumNames\"],\n schema[\"x-enum-descriptions\"],\n schema[\"x-enumDescriptions\"],\n ].some(Array.isArray);\n}\n\n/**\n * The values a TypeScript enum declares, with their positions in `enum`. With the\n * `nullable-enums` fix a `null` value is left out (upstream #1872): an enum member cannot be\n * `null`, so the type adds it as `| null` instead (`tsEnumType`).\n */\nfunction tsEnumEntries(schema: SchemaObject, options: SchemaOptions): [unknown, number][] {\n const entries = (schema.enum ?? []).map((value, index): [unknown, number] => [value, index]);\n return options.fixes.has(FIX.NULLABLE_ENUMS)\n ? entries.filter(([value]) => value !== null)\n : entries;\n}\n\n/**\n * `--enum`: string and number enums become TypeScript enums. The original meant to allow `null`\n * too, but tested `typeof value` against `null`, so an enum containing null stays a union; the\n * `nullable-enums` fix declares its other values.\n */\nfunction isTsEnum(schema: SchemaObject, options: SchemaOptions): boolean {\n if (!options.enum || !schema.enum) {\n return false;\n }\n const entries = tsEnumEntries(schema, options);\n // An empty `enum` stays an empty TypeScript enum, as the original made it; an enum of only\n // `null` has no member left once the fix drops `null`, so it stays a union.\n const isOnlyNull = entries.length === 0 && schema.enum.length > 0;\n const isSupported =\n !isOnlyNull && entries.every(([value]) => [\"string\", \"number\"].includes(typeof value));\n // `--conditional-enums` converts only enums that carry x-enum-* metadata.\n return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));\n}\n\nfunction enumMetadata(\n schema: SchemaObject,\n entries: readonly [unknown, number][],\n): EnumMemberMetadata[] {\n return entries.map(([, index]) => ({\n name: schema[\"x-enum-varnames\"]?.[index] ?? schema[\"x-enumNames\"]?.[index],\n description: schema[\"x-enum-descriptions\"]?.[index] ?? schema[\"x-enumDescriptions\"]?.[index],\n }));\n}\n\n/**\n * Whether `null` is a valid value: it is in `enum` and the schema's type admits it (`type`\n * absent or listing `\"null\"`, or OpenAPI 3.0 `nullable: true`). Both keywords must pass.\n */\nfunction isNullAllowed(schema: SchemaObject): boolean {\n const { type } = schema;\n const isTypeNullable =\n type === undefined ||\n (Array.isArray(type) && type.includes(\"null\")) ||\n Boolean(schema.nullable);\n return (schema.enum ?? []).includes(null) && isTypeNullable;\n}\n\n/**\n * `additionalProperties: true` on a string enum keeps other strings allowed but still offers the\n * listed values in editors: `\"a\" | \"b\" | (string & {})`.\n */\nfunction withOtherStrings(type: IrType, schema: SchemaObject): IrType {\n if (!hasAdditionalProperties(schema) || schema.type !== \"string\") {\n return type;\n }\n return unionOf([type, intersectionOf([irKeyword(\"string\"), irObject([])])]);\n}\n\n/** The enum declaration of `schema` typed at `path`; its values are strings and numbers. */\nfunction enumRequest(\n schema: SchemaObject,\n path: string | undefined,\n options: SchemaOptions,\n): EnumDeclarationRequest {\n const entries = tsEnumEntries(schema, options);\n return {\n name: nameFromPath(path),\n isComponentSchema: COMPONENT_SCHEMA_RE.test(path ?? \"\"),\n values: entries.map(([value]) => value as string | number),\n metadata: enumMetadata(schema, entries),\n };\n}\n\n/** One member's type; a quoted member cannot follow a dot, `typeof E[\"+\"]` is the same type. */\nfunction enumMemberType(enumName: string, member: string): IrType {\n return member.startsWith('\"')\n ? irIndexedAccess(irReference(`typeof ${enumName}`), irString(JSON.parse(member), \"escaped\"))\n : irReference(`${enumName}.${member}`);\n}\n\n/**\n * The `discriminator-values` fix: a member's discriminator value is typed with members of\n * the owner's enum (`PetType.Cat`), so the member is one of the owner's type (#1700). `key` is the\n * enum the scan added or the inherited discriminator object. Null when the fix is off, or the\n * owner's property is no TypeScript enum with every value.\n */\nexport function ownerEnumMembersType(\n key: object,\n values: readonly unknown[],\n request: SchemaRequest,\n): IrType | null {\n const { options, discriminators, footer } = request.context;\n const parent: DiscriminatorEnumParent | undefined = options.fixes.has(FIX.DISCRIMINATOR_VALUES)\n ? discriminators.enumParentOf(key)\n : undefined;\n if (parent === undefined || !isTsEnum(parent.schema, options)) {\n return null;\n }\n const reference = { ...enumRequest(parent.schema, parent.path, options), isOwnerReference: true };\n const name = footer.addEnum(reference);\n const members = footer.enumMembers(name);\n const names = values.map((value) => members.get(value as string | number));\n if (names.length === 0 || names.some((member) => member === undefined)) {\n return null;\n }\n return unionOf(names.map((member) => enumMemberType(name, member as string)));\n}\n\nfunction tsEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { options, footer } = request.context;\n // `isTsEnum` admits only strings and numbers, and the fix leaves `null` out of the members.\n const values = tsEnumEntries(schema, options).map(([value]) => value);\n const type =\n ownerEnumMembersType(schema, values, request) ??\n withOtherStrings(\n irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),\n schema,\n );\n return options.fixes.has(FIX.NULLABLE_ENUMS) && isNullAllowed(schema)\n ? unionOf([type, irKeyword(\"null\")])\n : type;\n}\n\nfunction isUnionPosition(pointer: readonly string[], index: number): boolean {\n const next = pointer[index + 1];\n return UNION_KEYWORDS.has(pointer[index] as string) && next !== undefined && INDEX_RE.test(next);\n}\n\nconst PARAMETERS = \"parameters\";\n\n/** Where the `parameters` of a path item sit in its pointer: `paths/<key>/…`, `components/…`. */\nfunction pathItemParametersIndex(pointer: readonly string[]): number | null {\n if (pointer[0] === \"paths\" || pointer[0] === \"webhooks\") {\n return 2;\n }\n return pointer[0] === \"components\" && pointer[1] === \"pathItems\" ? 3 : null;\n}\n\n/**\n * The location of a path item parameter repeats `parameters` (`paths/~1a/parameters/parameters/\n * path/id`), which keeps the generated names as they were. The generated type has the segment\n * once: `paths[\"/a\"][\"parameters\"][\"path\"][\"id\"]`.\n */\nfunction withSingleParametersSegment(pointer: readonly string[]): readonly string[] {\n const index = pathItemParametersIndex(pointer);\n const isRepeated =\n index !== null && pointer[index] === PARAMETERS && pointer[index + 1] === PARAMETERS;\n return isRepeated ? [...pointer.slice(0, index), ...pointer.slice(index + 1)] : pointer;\n}\n\n/**\n * The pointer of `--enum-values` arrays without union positions (`anyOf/0`), so names stay\n * stable. Every property after the first union position is narrowed with `Extract`: a no-op where\n * all variants have it, and the needed narrowing where only some do.\n */\nfunction enumValuesPointer(path: string | undefined): { ref: string; extract: string[] } {\n const pointer = withSingleParametersSegment(parseRefPointer(path ?? \"\"));\n const kept: string[] = [];\n let firstVariantStart: number | null = null;\n for (let index = 0; index < pointer.length; index++) {\n if (isUnionPosition(pointer, index)) {\n firstVariantStart ??= index + 2;\n index++;\n continue;\n }\n kept.push(pointer[index] as string);\n }\n const extract =\n firstVariantStart === null\n ? []\n : pointer\n .slice(firstVariantStart)\n .filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));\n return { ref: createRef(kept), extract };\n}\n\nfunction addEnumValues(schema: SchemaObject, request: SchemaRequest): void {\n const { ref, extract } = enumValuesPointer(request.location.path);\n const valuesType = refType(ref, { isDeep: true, extractProperties: extract });\n request.context.footer.addEnumValues({\n name: `${nameFromPath(request.location.path)}Values`,\n // A record value (`additionalProperties`) is reached by indexing with `string`.\n type: request.isFromAdditionalProperties\n ? irIndexedAccess(valuesType, irReference(\"string\"))\n : valuesType,\n values: (schema.enum ?? []) as (string | number)[],\n });\n}\n\nfunction literalEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const values = schema.enum ?? [];\n const isNullable =\n (Array.isArray(schema.type) && schema.type.includes(\"null\")) || Boolean(schema.nullable);\n const literals = [...values.map(literalType), ...(isNullable ? [irKeyword(\"null\")] : [])];\n const type = withOtherStrings(unionOf(literals), schema);\n const isListable = values.every(\n (value) => typeof value === \"string\" || typeof value === \"number\",\n );\n if (request.context.options.enumValues && isListable) {\n addEnumValues(schema, request);\n }\n return type;\n}\n\n/**\n * `enum` on anything but an object (object enums are handled as `oneOf`). With\n * `additionalProperties`, only string enums are handled here; others fall through to composition.\n */\nexport const enumRule: SchemaRule = {\n name: \"enum\",\n matches(schema) {\n const isCandidate =\n Array.isArray(schema.enum) && schema.type !== \"object\" && !(\"properties\" in schema);\n return isCandidate && (!hasAdditionalProperties(schema) || schema.type === \"string\");\n },\n transform(schema, request) {\n return isTsEnum(schema, request.context.options)\n ? tsEnumType(schema, request)\n : literalEnumType(schema, request);\n },\n};\n"],"names":["parseRefPointer","FIX","unionOf","intersectionOf","irKeyword","irObject","irIndexedAccess","irReference","irString","createRef","refType","literalType"],"mappings":";;;;;;;;;AAuBA,MAAM,wBAAA,GAA2B,oBAAA;AACjC,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,OAAO,CAAC,CAAA;AAC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A,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,6 +1,6 @@
|
|
|
1
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 {
|
|
3
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
4
4
|
import { literalType } from '../literal-type.mjs';
|
|
5
5
|
import { refType } from '../ref-type.mjs';
|
|
6
6
|
import { unionOf, intersectionOf } from '../type-combinators.mjs';
|
|
@@ -25,7 +25,7 @@ function hasEnumMetadata(schema) {
|
|
|
25
25
|
}
|
|
26
26
|
function tsEnumEntries(schema, options) {
|
|
27
27
|
const entries = (schema.enum ?? []).map((value, index) => [value, index]);
|
|
28
|
-
return options.fixes.has(
|
|
28
|
+
return options.fixes.has(FIX.NULLABLE_ENUMS) ? entries.filter(([value]) => value !== null) : entries;
|
|
29
29
|
}
|
|
30
30
|
function isTsEnum(schema, options) {
|
|
31
31
|
if (!options.enum || !schema.enum) {
|
|
@@ -67,9 +67,7 @@ function enumMemberType(enumName, member) {
|
|
|
67
67
|
}
|
|
68
68
|
function ownerEnumMembersType(key, values, request) {
|
|
69
69
|
const { options, discriminators, footer } = request.context;
|
|
70
|
-
const parent = options.fixes.has(
|
|
71
|
-
OutputFix.DISCRIMINATOR_VALUES
|
|
72
|
-
) ? discriminators.enumParentOf(key) : void 0;
|
|
70
|
+
const parent = options.fixes.has(FIX.DISCRIMINATOR_VALUES) ? discriminators.enumParentOf(key) : void 0;
|
|
73
71
|
if (parent === void 0 || !isTsEnum(parent.schema, options)) {
|
|
74
72
|
return null;
|
|
75
73
|
}
|
|
@@ -89,7 +87,7 @@ function tsEnumType(schema, request) {
|
|
|
89
87
|
irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),
|
|
90
88
|
schema
|
|
91
89
|
);
|
|
92
|
-
return options.fixes.has(
|
|
90
|
+
return options.fixes.has(FIX.NULLABLE_ENUMS) && isNullAllowed(schema) ? unionOf([type, irKeyword("null")]) : type;
|
|
93
91
|
}
|
|
94
92
|
function isUnionPosition(pointer, index) {
|
|
95
93
|
const next = pointer[index + 1];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-rule.mjs","sources":["../../../../src/application/transform/schema/enum-rule.ts"],"sourcesContent":["import {\n irIndexedAccess,\n irKeyword,\n irObject,\n irReference,\n irString,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { createRef, parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { 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,EAAC,EAAG,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,KAA6B,CAAC,KAAA,EAAO,KAAK,CAAC,CAAA;AAC3F,EAAA,OAAO,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAI,SAAA,CAAU,cAAc,CAAA,GAC7C,OAAA,CAAQ,MAAA,CAAO,CAAC,CAAC,KAAK,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ACd,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 { FIX } from \"../../../domain/output-fixes.js\";\nimport { literalType } from \"../literal-type.js\";\nimport { refType } from \"../ref-type.js\";\nimport { intersectionOf, unionOf } from \"../type-combinators.js\";\nimport type {\n DiscriminatorEnumParent,\n EnumDeclarationRequest,\n EnumMemberMetadata,\n SchemaOptions,\n} from \"./schema-context.js\";\nimport type { SchemaRequest, SchemaRule } from \"./schema-rule.js\";\n\n/** Removed from generated names, so `#/components/schemas/Status` gives `Status`. */\nconst COMPONENT_SCHEMAS_PREFIX = \"components/schemas\";\nconst UNION_KEYWORDS: ReadonlySet<string> = new Set([\"anyOf\", \"oneOf\"]);\nconst INDEX_RE = /^\\d+$/;\n\nfunction hasAdditionalProperties(schema: SchemaObject): boolean {\n return \"additionalProperties\" in schema && Boolean(schema.additionalProperties);\n}\n\n/** A name from the schema's pointer: `#/components/schemas/Pet/status` → `/Pet/status`. */\nfunction nameFromPath(path: string | undefined): string {\n return parseRefPointer(path ?? \"\")\n .join(\"/\")\n .replace(COMPONENT_SCHEMAS_PREFIX, \"\");\n}\n\n/** `#/components/schemas/Name`, and no deeper pointer. */\nconst COMPONENT_SCHEMA_RE = /^#\\/components\\/schemas\\/[^/]+$/;\n\nfunction hasEnumMetadata(schema: SchemaObject): boolean {\n return [\n schema[\"x-enum-varnames\"],\n schema[\"x-enumNames\"],\n schema[\"x-enum-descriptions\"],\n schema[\"x-enumDescriptions\"],\n ].some(Array.isArray);\n}\n\n/**\n * The values a TypeScript enum declares, with their positions in `enum`. With the\n * `nullable-enums` fix a `null` value is left out (upstream #1872): an enum member cannot be\n * `null`, so the type adds it as `| null` instead (`tsEnumType`).\n */\nfunction tsEnumEntries(schema: SchemaObject, options: SchemaOptions): [unknown, number][] {\n const entries = (schema.enum ?? []).map((value, index): [unknown, number] => [value, index]);\n return options.fixes.has(FIX.NULLABLE_ENUMS)\n ? entries.filter(([value]) => value !== null)\n : entries;\n}\n\n/**\n * `--enum`: string and number enums become TypeScript enums. The original meant to allow `null`\n * too, but tested `typeof value` against `null`, so an enum containing null stays a union; the\n * `nullable-enums` fix declares its other values.\n */\nfunction isTsEnum(schema: SchemaObject, options: SchemaOptions): boolean {\n if (!options.enum || !schema.enum) {\n return false;\n }\n const entries = tsEnumEntries(schema, options);\n // An empty `enum` stays an empty TypeScript enum, as the original made it; an enum of only\n // `null` has no member left once the fix drops `null`, so it stays a union.\n const isOnlyNull = entries.length === 0 && schema.enum.length > 0;\n const isSupported =\n !isOnlyNull && entries.every(([value]) => [\"string\", \"number\"].includes(typeof value));\n // `--conditional-enums` converts only enums that carry x-enum-* metadata.\n return isSupported && (!options.conditionalEnums || hasEnumMetadata(schema));\n}\n\nfunction enumMetadata(\n schema: SchemaObject,\n entries: readonly [unknown, number][],\n): EnumMemberMetadata[] {\n return entries.map(([, index]) => ({\n name: schema[\"x-enum-varnames\"]?.[index] ?? schema[\"x-enumNames\"]?.[index],\n description: schema[\"x-enum-descriptions\"]?.[index] ?? schema[\"x-enumDescriptions\"]?.[index],\n }));\n}\n\n/**\n * Whether `null` is a valid value: it is in `enum` and the schema's type admits it (`type`\n * absent or listing `\"null\"`, or OpenAPI 3.0 `nullable: true`). Both keywords must pass.\n */\nfunction isNullAllowed(schema: SchemaObject): boolean {\n const { type } = schema;\n const isTypeNullable =\n type === undefined ||\n (Array.isArray(type) && type.includes(\"null\")) ||\n Boolean(schema.nullable);\n return (schema.enum ?? []).includes(null) && isTypeNullable;\n}\n\n/**\n * `additionalProperties: true` on a string enum keeps other strings allowed but still offers the\n * listed values in editors: `\"a\" | \"b\" | (string & {})`.\n */\nfunction withOtherStrings(type: IrType, schema: SchemaObject): IrType {\n if (!hasAdditionalProperties(schema) || schema.type !== \"string\") {\n return type;\n }\n return unionOf([type, intersectionOf([irKeyword(\"string\"), irObject([])])]);\n}\n\n/** The enum declaration of `schema` typed at `path`; its values are strings and numbers. */\nfunction enumRequest(\n schema: SchemaObject,\n path: string | undefined,\n options: SchemaOptions,\n): EnumDeclarationRequest {\n const entries = tsEnumEntries(schema, options);\n return {\n name: nameFromPath(path),\n isComponentSchema: COMPONENT_SCHEMA_RE.test(path ?? \"\"),\n values: entries.map(([value]) => value as string | number),\n metadata: enumMetadata(schema, entries),\n };\n}\n\n/** One member's type; a quoted member cannot follow a dot, `typeof E[\"+\"]` is the same type. */\nfunction enumMemberType(enumName: string, member: string): IrType {\n return member.startsWith('\"')\n ? irIndexedAccess(irReference(`typeof ${enumName}`), irString(JSON.parse(member), \"escaped\"))\n : irReference(`${enumName}.${member}`);\n}\n\n/**\n * The `discriminator-values` fix: a member's discriminator value is typed with members of\n * the owner's enum (`PetType.Cat`), so the member is one of the owner's type (#1700). `key` is the\n * enum the scan added or the inherited discriminator object. Null when the fix is off, or the\n * owner's property is no TypeScript enum with every value.\n */\nexport function ownerEnumMembersType(\n key: object,\n values: readonly unknown[],\n request: SchemaRequest,\n): IrType | null {\n const { options, discriminators, footer } = request.context;\n const parent: DiscriminatorEnumParent | undefined = options.fixes.has(FIX.DISCRIMINATOR_VALUES)\n ? discriminators.enumParentOf(key)\n : undefined;\n if (parent === undefined || !isTsEnum(parent.schema, options)) {\n return null;\n }\n const reference = { ...enumRequest(parent.schema, parent.path, options), isOwnerReference: true };\n const name = footer.addEnum(reference);\n const members = footer.enumMembers(name);\n const names = values.map((value) => members.get(value as string | number));\n if (names.length === 0 || names.some((member) => member === undefined)) {\n return null;\n }\n return unionOf(names.map((member) => enumMemberType(name, member as string)));\n}\n\nfunction tsEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const { options, footer } = request.context;\n // `isTsEnum` admits only strings and numbers, and the fix leaves `null` out of the members.\n const values = tsEnumEntries(schema, options).map(([value]) => value);\n const type =\n ownerEnumMembersType(schema, values, request) ??\n withOtherStrings(\n irReference(footer.addEnum(enumRequest(schema, request.location.path, options))),\n schema,\n );\n return options.fixes.has(FIX.NULLABLE_ENUMS) && isNullAllowed(schema)\n ? unionOf([type, irKeyword(\"null\")])\n : type;\n}\n\nfunction isUnionPosition(pointer: readonly string[], index: number): boolean {\n const next = pointer[index + 1];\n return UNION_KEYWORDS.has(pointer[index] as string) && next !== undefined && INDEX_RE.test(next);\n}\n\nconst PARAMETERS = \"parameters\";\n\n/** Where the `parameters` of a path item sit in its pointer: `paths/<key>/…`, `components/…`. */\nfunction pathItemParametersIndex(pointer: readonly string[]): number | null {\n if (pointer[0] === \"paths\" || pointer[0] === \"webhooks\") {\n return 2;\n }\n return pointer[0] === \"components\" && pointer[1] === \"pathItems\" ? 3 : null;\n}\n\n/**\n * The location of a path item parameter repeats `parameters` (`paths/~1a/parameters/parameters/\n * path/id`), which keeps the generated names as they were. The generated type has the segment\n * once: `paths[\"/a\"][\"parameters\"][\"path\"][\"id\"]`.\n */\nfunction withSingleParametersSegment(pointer: readonly string[]): readonly string[] {\n const index = pathItemParametersIndex(pointer);\n const isRepeated =\n index !== null && pointer[index] === PARAMETERS && pointer[index + 1] === PARAMETERS;\n return isRepeated ? [...pointer.slice(0, index), ...pointer.slice(index + 1)] : pointer;\n}\n\n/**\n * The pointer of `--enum-values` arrays without union positions (`anyOf/0`), so names stay\n * stable. Every property after the first union position is narrowed with `Extract`: a no-op where\n * all variants have it, and the needed narrowing where only some do.\n */\nfunction enumValuesPointer(path: string | undefined): { ref: string; extract: string[] } {\n const pointer = withSingleParametersSegment(parseRefPointer(path ?? \"\"));\n const kept: string[] = [];\n let firstVariantStart: number | null = null;\n for (let index = 0; index < pointer.length; index++) {\n if (isUnionPosition(pointer, index)) {\n firstVariantStart ??= index + 2;\n index++;\n continue;\n }\n kept.push(pointer[index] as string);\n }\n const extract =\n firstVariantStart === null\n ? []\n : pointer\n .slice(firstVariantStart)\n .filter((segment) => !UNION_KEYWORDS.has(segment) && !INDEX_RE.test(segment));\n return { ref: createRef(kept), extract };\n}\n\nfunction addEnumValues(schema: SchemaObject, request: SchemaRequest): void {\n const { ref, extract } = enumValuesPointer(request.location.path);\n const valuesType = refType(ref, { isDeep: true, extractProperties: extract });\n request.context.footer.addEnumValues({\n name: `${nameFromPath(request.location.path)}Values`,\n // A record value (`additionalProperties`) is reached by indexing with `string`.\n type: request.isFromAdditionalProperties\n ? irIndexedAccess(valuesType, irReference(\"string\"))\n : valuesType,\n values: (schema.enum ?? []) as (string | number)[],\n });\n}\n\nfunction literalEnumType(schema: SchemaObject, request: SchemaRequest): IrType {\n const values = schema.enum ?? [];\n const isNullable =\n (Array.isArray(schema.type) && schema.type.includes(\"null\")) || Boolean(schema.nullable);\n const literals = [...values.map(literalType), ...(isNullable ? [irKeyword(\"null\")] : [])];\n const type = withOtherStrings(unionOf(literals), schema);\n const isListable = values.every(\n (value) => typeof value === \"string\" || typeof value === \"number\",\n );\n if (request.context.options.enumValues && isListable) {\n addEnumValues(schema, request);\n }\n return type;\n}\n\n/**\n * `enum` on anything but an object (object enums are handled as `oneOf`). With\n * `additionalProperties`, only string enums are handled here; others fall through to composition.\n */\nexport const enumRule: SchemaRule = {\n name: \"enum\",\n matches(schema) {\n const isCandidate =\n Array.isArray(schema.enum) && schema.type !== \"object\" && !(\"properties\" in schema);\n return isCandidate && (!hasAdditionalProperties(schema) || schema.type === \"string\");\n },\n transform(schema, request) {\n return isTsEnum(schema, request.context.options)\n ? tsEnumType(schema, request)\n : literalEnumType(schema, request);\n },\n};\n"],"names":[],"mappings":";;;;;;;AAuBA,MAAM,wBAAA,GAA2B,oBAAA;AACjC,MAAM,iCAAsC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,OAAO,CAAC,CAAA;AACtE,MAAM,QAAA,GAAW,OAAA;AAEjB,SAAS,wBAAwB,MAAA,EAA+B;AAC9D,EAAA,OAAO,sBAAA,IAA0B,MAAA,IAAU,OAAA,CAAQ,MAAA,CAAO,oBAAoB,CAAA;AAChF;AAGA,SAAS,aAAa,IAAA,EAAkC;AACtD,EAAA,OAAO,eAAA,CAAgB,QAAQ,EAAE,CAAA,CAC9B,KAAK,GAAG,CAAA,CACR,OAAA,CAAQ,wBAAA,EAA0B,EAAE,CAAA;AACzC;AAGA,MAAM,mBAAA,GAAsB,iCAAA;AAE5B,SAAS,gBAAgB,MAAA,EAA+B;AACtD,EAAA,OAAO;AAAA,IACL,OAAO,iBAAiB,CAAA;AAAA,IACxB,OAAO,aAAa,CAAA;AAAA,IACpB,OAAO,qBAAqB,CAAA;AAAA,IAC5B,OAAO,oBAAoB;AAAA,GAC7B,CAAE,IAAA,CAAK,KAAA,CAAM,OAAO,CAAA;AACtB;AAOA,SAAS,aAAA,CAAc,QAAsB,OAAA,EAA6C;AACxF,EAAA,MAAM,OAAA,GAAA,CAAW,MAAA,CAAO,IAAA,IAAQ,EAAC,EAAG,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,KAA6B,CAAC,KAAA,EAAO,KAAK,CAAC,CAAA;AAC3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;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;;"}
|
|
@@ -41,7 +41,7 @@ function memberSchema(member, request) {
|
|
|
41
41
|
}
|
|
42
42
|
function allOfMembers(members, request) {
|
|
43
43
|
const unchanged = { members, required: [] };
|
|
44
|
-
if (!request.context.options.fixes.has(outputFixes.
|
|
44
|
+
if (!request.context.options.fixes.has(outputFixes.FIX.ALLOF_REQUIRED)) {
|
|
45
45
|
return unchanged;
|
|
46
46
|
}
|
|
47
47
|
const schemas = members.map((member) => memberSchema(member, request));
|