openapi-typesafe 1.0.0-rc.4 → 1.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +141 -0
- package/dist/adapters/node-file-system/node-file-system.cjs +7 -0
- package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
- package/dist/adapters/node-file-system/node-file-system.mjs +7 -0
- package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs +19 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs.map +1 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs +17 -0
- package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs.map +1 -0
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +5 -32
- package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -1
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +6 -33
- package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -1
- package/dist/adapters/redocly-loader/component-schemas.cjs +17 -0
- package/dist/adapters/redocly-loader/component-schemas.cjs.map +1 -0
- package/dist/adapters/redocly-loader/component-schemas.mjs +14 -0
- package/dist/adapters/redocly-loader/component-schemas.mjs.map +1 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.cjs +22 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.cjs.map +1 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.mjs +20 -0
- package/dist/adapters/redocly-loader/mapping-schema-names.mjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs +137 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs +134 -0
- package/dist/adapters/redocly-loader/query-named-components.mjs.map +1 -0
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +26 -14
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +26 -14
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +16 -3
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +16 -3
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.cjs +52 -10
- package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-holders.mjs +52 -11
- package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.cjs +5 -3
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +5 -3
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.cjs +17 -3
- package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-node-limit.mjs +17 -3
- package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.cjs +7 -2
- package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/schema-source.mjs +8 -3
- package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.cjs +7 -3
- package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
- package/dist/adapters/terminal-logger/terminal-logger.mjs +7 -3
- package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
- package/dist/api/document-refs.cjs +16 -1
- package/dist/api/document-refs.cjs.map +1 -1
- package/dist/api/document-refs.mjs +16 -1
- package/dist/api/document-refs.mjs.map +1 -1
- package/dist/api/document-run.cjs +4 -10
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +4 -10
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs +1 -2
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs +2 -3
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/ref-limit-options.cjs +63 -0
- package/dist/api/ref-limit-options.cjs.map +1 -0
- package/dist/api/ref-limit-options.mjs +57 -0
- package/dist/api/ref-limit-options.mjs.map +1 -0
- package/dist/api/transform-schema.cjs +12 -5
- package/dist/api/transform-schema.cjs.map +1 -1
- package/dist/api/transform-schema.mjs +12 -5
- package/dist/api/transform-schema.mjs.map +1 -1
- package/dist/application/transform/declared-value-types.cjs +36 -0
- package/dist/application/transform/declared-value-types.cjs.map +1 -0
- package/dist/application/transform/declared-value-types.mjs +34 -0
- package/dist/application/transform/declared-value-types.mjs.map +1 -0
- package/dist/application/transform/document/document.cjs +3 -1
- package/dist/application/transform/document/document.cjs.map +1 -1
- package/dist/application/transform/document/document.mjs +3 -1
- package/dist/application/transform/document/document.mjs.map +1 -1
- package/dist/application/transform/document/exploded-query-values.cjs +63 -0
- package/dist/application/transform/document/exploded-query-values.cjs.map +1 -0
- package/dist/application/transform/document/exploded-query-values.mjs +59 -0
- package/dist/application/transform/document/exploded-query-values.mjs.map +1 -0
- package/dist/application/transform/document/header.cjs +11 -3
- package/dist/application/transform/document/header.cjs.map +1 -1
- package/dist/application/transform/document/header.mjs +10 -2
- package/dist/application/transform/document/header.mjs.map +1 -1
- package/dist/application/transform/document/parameter.cjs +1 -1
- package/dist/application/transform/document/parameter.cjs.map +1 -1
- package/dist/application/transform/document/parameter.mjs +1 -1
- package/dist/application/transform/document/parameter.mjs.map +1 -1
- package/dist/application/transform/document/parameters.cjs +23 -5
- package/dist/application/transform/document/parameters.cjs.map +1 -1
- package/dist/application/transform/document/parameters.mjs +23 -5
- package/dist/application/transform/document/parameters.mjs.map +1 -1
- package/dist/application/transform/document/path-item.cjs +4 -3
- package/dist/application/transform/document/path-item.cjs.map +1 -1
- package/dist/application/transform/document/path-item.mjs +4 -4
- package/dist/application/transform/document/path-item.mjs.map +1 -1
- package/dist/application/transform/document/path-template-key.cjs +84 -0
- package/dist/application/transform/document/path-template-key.cjs.map +1 -0
- package/dist/application/transform/document/path-template-key.mjs +79 -0
- package/dist/application/transform/document/path-template-key.mjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.cjs +70 -0
- package/dist/application/transform/document/path-template-refs.cjs.map +1 -0
- package/dist/application/transform/document/path-template-refs.mjs +67 -0
- package/dist/application/transform/document/path-template-refs.mjs.map +1 -0
- package/dist/application/transform/document/paths-enum.cjs +7 -6
- package/dist/application/transform/document/paths-enum.cjs.map +1 -1
- package/dist/application/transform/document/paths-enum.mjs +7 -6
- package/dist/application/transform/document/paths-enum.mjs.map +1 -1
- package/dist/application/transform/document/paths.cjs +38 -66
- package/dist/application/transform/document/paths.cjs.map +1 -1
- package/dist/application/transform/document/paths.mjs +36 -66
- package/dist/application/transform/document/paths.mjs.map +1 -1
- package/dist/application/transform/document/webhooks.cjs +10 -3
- package/dist/application/transform/document/webhooks.cjs.map +1 -1
- package/dist/application/transform/document/webhooks.mjs +9 -2
- package/dist/application/transform/document/webhooks.mjs.map +1 -1
- package/dist/application/transform/footer/document-footer.cjs +6 -3
- package/dist/application/transform/footer/document-footer.cjs.map +1 -1
- package/dist/application/transform/footer/document-footer.mjs +6 -3
- package/dist/application/transform/footer/document-footer.mjs.map +1 -1
- package/dist/application/transform/helper-types.cjs +3 -3
- package/dist/application/transform/helper-types.cjs.map +1 -1
- package/dist/application/transform/helper-types.mjs +3 -3
- package/dist/application/transform/helper-types.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.cjs +4 -4
- package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs +1 -1
- package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.cjs +47 -66
- package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.mjs +36 -50
- package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.cjs +2 -2
- package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.mjs +1 -1
- package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/located-node.cjs +23 -0
- package/dist/application/transform/ref-pointer/located-node.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/located-node.mjs +18 -0
- package/dist/application/transform/ref-pointer/located-node.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/original-index.cjs +68 -13
- package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/original-index.mjs +70 -15
- package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.cjs +2 -2
- package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs +1 -1
- package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-walk.cjs +54 -13
- package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/pointer-walk.mjs +46 -7
- package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/property-shape.cjs +52 -0
- package/dist/application/transform/ref-pointer/property-shape.cjs.map +1 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs +45 -0
- package/dist/application/transform/ref-pointer/property-shape.mjs.map +1 -0
- package/dist/application/transform/ref-pointer/typed-walk.cjs +79 -21
- package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/typed-walk.mjs +76 -18
- package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -1
- package/dist/application/transform/schema/access-flags.cjs.map +1 -1
- package/dist/application/transform/schema/access-flags.mjs.map +1 -1
- package/dist/application/transform/schema/index-signature-type.cjs +21 -0
- package/dist/application/transform/schema/index-signature-type.cjs.map +1 -0
- package/dist/application/transform/schema/index-signature-type.mjs +19 -0
- package/dist/application/transform/schema/index-signature-type.mjs.map +1 -0
- package/dist/application/transform/schema/input-location.cjs +23 -0
- package/dist/application/transform/schema/input-location.cjs.map +1 -0
- package/dist/application/transform/schema/input-location.mjs +21 -0
- package/dist/application/transform/schema/input-location.mjs.map +1 -0
- package/dist/application/transform/schema/object-type.cjs +15 -5
- package/dist/application/transform/schema/object-type.cjs.map +1 -1
- package/dist/application/transform/schema/object-type.mjs +15 -5
- package/dist/application/transform/schema/object-type.mjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.cjs +2 -1
- package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
- package/dist/application/transform/schema/schema-transform.mjs +2 -1
- package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.cjs +2 -30
- package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
- package/dist/application/transform/schema/unevaluated-properties.mjs +3 -31
- package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
- package/dist/cli/api-logger.cjs +13 -0
- package/dist/cli/api-logger.cjs.map +1 -0
- package/dist/cli/api-logger.mjs +11 -0
- package/dist/cli/api-logger.mjs.map +1 -0
- package/dist/cli/api-settings.cjs +7 -15
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +8 -16
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/cli-arguments.cjs +51 -11
- package/dist/cli/cli-arguments.cjs.map +1 -1
- package/dist/cli/cli-arguments.mjs +51 -11
- package/dist/cli/cli-arguments.mjs.map +1 -1
- package/dist/cli/cli-errors.cjs +17 -0
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +17 -1
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-output.cjs +6 -4
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +7 -5
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +10 -4
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +10 -4
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +20 -9
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +22 -11
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/ref-limits.cjs +15 -1
- package/dist/cli/ref-limits.cjs.map +1 -1
- package/dist/cli/ref-limits.mjs +15 -2
- package/dist/cli/ref-limits.mjs.map +1 -1
- package/dist/cli/run-cli.cjs +24 -7
- package/dist/cli/run-cli.cjs.map +1 -1
- package/dist/cli/run-cli.mjs +25 -8
- package/dist/cli/run-cli.mjs.map +1 -1
- package/dist/domain/cause-secrets.cjs +31 -16
- package/dist/domain/cause-secrets.cjs.map +1 -1
- package/dist/domain/cause-secrets.mjs +31 -16
- package/dist/domain/cause-secrets.mjs.map +1 -1
- package/dist/domain/errors.cjs +2 -0
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +2 -0
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/location-text.cjs +9 -0
- package/dist/domain/location-text.cjs.map +1 -0
- package/dist/domain/location-text.mjs +7 -0
- package/dist/domain/location-text.mjs.map +1 -0
- package/dist/domain/openapi/document-places.cjs +55 -0
- package/dist/domain/openapi/document-places.cjs.map +1 -0
- package/dist/domain/openapi/document-places.mjs +53 -0
- package/dist/domain/openapi/document-places.mjs.map +1 -0
- package/dist/domain/output-fixes.cjs +8 -2
- package/dist/domain/output-fixes.cjs.map +1 -1
- package/dist/domain/output-fixes.mjs +8 -2
- package/dist/domain/output-fixes.mjs.map +1 -1
- package/dist/domain/terminal-text.cjs +31 -0
- package/dist/domain/terminal-text.cjs.map +1 -0
- package/dist/domain/terminal-text.mjs +29 -0
- package/dist/domain/terminal-text.mjs.map +1 -0
- package/dist/domain/warnings.cjs +1 -0
- package/dist/domain/warnings.cjs.map +1 -1
- package/dist/domain/warnings.mjs +1 -0
- package/dist/domain/warnings.mjs.map +1 -1
- package/dist/index.d.cts +26 -18
- package/dist/index.d.mts +26 -18
- package/dist/index.d.ts +26 -18
- package/package.json +1 -1
- package/src/adapters/node-file-system/node-file-system.ts +14 -1
- package/src/adapters/pipe-safe-writer/pipe-safe-writer.ts +29 -0
- package/src/adapters/redocly-loader/bundled-mapping-copies.ts +7 -42
- package/src/adapters/redocly-loader/component-schemas.ts +19 -0
- package/src/adapters/redocly-loader/mapping-schema-names.ts +25 -0
- package/src/adapters/redocly-loader/query-named-components.ts +201 -0
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +46 -14
- package/src/adapters/redocly-loader/ref-access.ts +16 -3
- package/src/adapters/redocly-loader/ref-holders.ts +75 -14
- package/src/adapters/redocly-loader/remote-fetch.ts +11 -2
- package/src/adapters/redocly-loader/remote-node-limit.ts +44 -4
- package/src/adapters/redocly-loader/schema-source.ts +15 -3
- package/src/adapters/terminal-logger/terminal-logger.ts +10 -4
- package/src/api/document-refs.ts +29 -1
- package/src/api/document-run.ts +6 -16
- package/src/api/openapi-ts.ts +6 -3
- package/src/api/ref-limit-options.ts +76 -0
- package/src/api/transform-schema.ts +20 -5
- package/src/application/ports/file-system.ts +8 -0
- package/src/application/transform/declared-value-types.ts +42 -0
- package/src/application/transform/document/document.ts +4 -2
- package/src/application/transform/document/exploded-query-values.ts +88 -0
- package/src/application/transform/document/header.ts +25 -5
- package/src/application/transform/document/parameter.ts +4 -4
- package/src/application/transform/document/parameters.ts +45 -10
- package/src/application/transform/document/path-item.ts +3 -3
- package/src/application/transform/document/path-template-key.ts +152 -0
- package/src/application/transform/document/path-template-refs.ts +106 -0
- package/src/application/transform/document/paths-enum.ts +23 -9
- package/src/application/transform/document/paths.ts +53 -123
- package/src/application/transform/document/webhooks.ts +18 -5
- package/src/application/transform/footer/document-footer.ts +18 -8
- package/src/application/transform/helper-types.ts +4 -4
- package/src/application/transform/ref-pointer/generated-location.ts +1 -1
- package/src/application/transform/ref-pointer/generated-shape.ts +67 -78
- package/src/application/transform/ref-pointer/inline-cycles.ts +1 -1
- package/src/application/transform/ref-pointer/located-node.ts +38 -0
- package/src/application/transform/ref-pointer/original-index.ts +100 -17
- package/src/application/transform/ref-pointer/pointer-type.ts +1 -1
- package/src/application/transform/ref-pointer/pointer-walk.ts +82 -8
- package/src/application/transform/ref-pointer/property-shape.ts +97 -0
- package/src/application/transform/ref-pointer/typed-walk.ts +117 -25
- package/src/application/transform/schema/access-flags.ts +5 -2
- package/src/application/transform/schema/index-signature-type.ts +31 -0
- package/src/application/transform/schema/input-location.ts +35 -0
- package/src/application/transform/schema/object-type.ts +18 -8
- package/src/application/transform/schema/schema-transform.ts +2 -1
- package/src/application/transform/schema/unevaluated-properties.ts +4 -44
- package/src/cli/api-logger.ts +17 -0
- package/src/cli/api-settings.ts +12 -20
- package/src/cli/cli-arguments.ts +90 -14
- package/src/cli/cli-dependencies.ts +7 -2
- package/src/cli/cli-errors.ts +22 -0
- package/src/cli/cli-output.ts +11 -10
- package/src/cli/main.ts +10 -4
- package/src/cli/redocly-apis.ts +37 -17
- package/src/cli/ref-limits.ts +21 -2
- package/src/cli/run-cli.ts +39 -7
- package/src/domain/cause-secrets.ts +59 -25
- package/src/domain/errors.ts +2 -0
- package/src/domain/location-text.ts +12 -0
- package/src/domain/openapi/document-places.ts +78 -0
- package/src/domain/output-fixes.ts +9 -2
- package/src/domain/terminal-text.ts +44 -0
- package/src/domain/warnings.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pointer-walk.cjs","sources":["../../../../src/application/transform/ref-pointer/pointer-walk.ts"],"sourcesContent":["import { parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { RefResolver } from \"../schema/schema-context.js\";\nimport { followRefs, isJsonObject } from \"./generated-shape.js\";\n\n/** The parts of a `$ref` pointer that both the original and the new types walk. */\n\nexport interface RefPointer {\n readonly rootSegment: string;\n /** The segments after the root: `#/components/schemas/A` gives `[\"schemas\", \"A\"]`. */\n readonly segments: readonly string[];\n}\n\n/** Roots whose generated type is keyed by one segment: the path or webhook name. */\nconst NAMED_ROOTS: ReadonlySet<string> = new Set([\"paths\", \"webhooks\"]);\n\n/**\n * How many segments after the root index the generated root type directly: one for `paths` and\n * `webhooks` (`paths[\"/a\"]`, so the path item's own `parameters/0` is walked), two otherwise\n * (`components[\"schemas\"][\"A\"]`).\n */\nexport function leadingSegmentsOf(pointer: RefPointer): number {\n return NAMED_ROOTS.has(pointer.rootSegment) ? 1 : 2;\n}\n\nexport function refPointerOf(ref: string): RefPointer | null {\n const [rootSegment, ...segments] = parseRefPointer(ref);\n return rootSegment === undefined ? null : { rootSegment, segments };\n}\n\n/** The document node at the end of the leading segments, `$ref`s followed. */\nexport function leadingNode(pointer: RefPointer, refs: RefResolver): unknown {\n let node = refs.resolve(`#/${pointer.rootSegment}`);\n for (const segment of pointer.segments.slice(0, leadingSegmentsOf(pointer))) {\n node = isJsonObject(node) ? followRefs(node[segment], refs) : undefined;\n }\n return node;\n}\n\n/** The node at the whole pointer, without following a `$ref` at its end. */\nexport function pointerNode(pointer: RefPointer, refs: RefResolver): unknown {\n let node = refs.resolve(`#/${pointer.rootSegment}`);\n pointer.segments.forEach((segment, index) => {\n const child = isJsonObject(node) || Array.isArray(node) ? (node as never)[segment] : undefined;\n node = index === pointer.segments.length - 1 ? child : followRefs(child, refs);\n });\n return node;\n}\n\n/** Whether the leading segments name a component schema, so the walk starts inside a schema. */\nexport function startsInSchema(pointer: RefPointer): boolean {\n return pointer.rootSegment === \"components\" && pointer.segments[0] === \"schemas\";\n}\n\n/**\n * Whether the container at `index` is typed as its `schema`: a media type\n * (`content/<media type>`), a header (`headers/<name>`) or a component parameter.\n */\nexport function isTypedAsSchema(pointer: RefPointer, index: number): boolean {\n const owner = pointer.segments[index - 2];\n const isComponentParameter =\n pointer.rootSegment === \"components\" && index === 2 && owner === \"parameters\";\n return owner === \"content\" || owner === \"headers\" || isComponentParameter;\n}\n\n/**\n * Whether the segment at `index` is an operation's or path item's `parameters` list, indexed by\n * position next. The generated type groups parameters by `in` (`query`, `path`), so it has no\n * member `0`.\n */\nexport function isParameterList(pointer: RefPointer, index: number): boolean {\n const next = pointer.segments[index + 1] ?? \"\";\n return pointer.segments[index] === \"parameters\" && /^\\d+$/.test(next);\n}\n\n/**\n * Whether the segment at `index` names a response header that is an optional member: one the\n * response lists without `required: true`. A `$ref` header counts as required, as the generated\n * type has it; a component header (`components/headers/<name>`) is a member of its own.\n */\nexport function isOptionalHeader(pointer: RefPointer, index: number, headers: unknown): boolean {\n const isComponentHeader = pointer.rootSegment === \"components\" && index === 1;\n if (pointer.segments[index - 1] !== \"headers\" || isComponentHeader || !isJsonObject(headers)) {\n return false;\n }\n const header = headers[pointer.segments[index] as string];\n return isJsonObject(header) && header.$ref === undefined && header.required !== true;\n}\n\n/** A `requestBody` the operation does not mark `required` is an optional member. */\nexport function isOptionalRequestBody(container: unknown, refs: RefResolver): boolean {\n if (!isJsonObject(container) || container.requestBody === undefined) {\n return false;\n }\n const body = followRefs(container.requestBody, refs);\n return !(isJsonObject(body) && body.required === true);\n}\n"],"names":["parseRefPointer","isJsonObject","followRefs"],"mappings":";;;;;AAaA,MAAM,8BAAmC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,UAAU,CAAC,CAAA;AAO/D,SAAS,kBAAkB,OAAA,EAA6B;AAC7D,EAAA,OAAO,WAAA,CAAY,GAAA,CAAI,OAAA,CAAQ,WAAW,IAAI,CAAA,GAAI,CAAA;AACpD;AAEO,SAAS,aAAa,GAAA,EAAgC;AAC3D,EAAA,MAAM,CAAC,WAAA,EAAa,GAAG,QA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,EAAA,MAAM,IAAA,GAAOC,yBAAA,CAAW,SAAA,CAAU,WAAA,EAAa,IAAI,CAAA;AACnD,EAAA,OAAO,EAAED,2BAAA,CAAa,IAAI,CAAA,IAAK,KAAK,QAAA,KAAa,IAAA,CAAA;AACnD;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"pointer-walk.cjs","sources":["../../../../src/application/transform/ref-pointer/pointer-walk.ts"],"sourcesContent":["import { placeOf } from \"../../../domain/openapi/document-places.js\";\nimport { parseRefPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport { QUERYSTRING_LOCATION } from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport {\n childLocation,\n followLocated,\n followRefs,\n isJsonObject,\n type LocatedNode,\n} from \"./located-node.js\";\n\n/** The parts of a `$ref` pointer that both the original and the new types walk. */\n\nexport interface RefPointer {\n readonly rootSegment: string;\n /** The segments after the root: `#/components/schemas/A` gives `[\"schemas\", \"A\"]`. */\n readonly segments: readonly string[];\n}\n\n/** Roots whose generated type is keyed by one segment: the path or webhook name. */\nconst NAMED_ROOTS: ReadonlySet<string> = new Set([\"paths\", \"webhooks\"]);\n\n/**\n * How many segments after the root index the generated root type directly: one for `paths` and\n * `webhooks` (`paths[\"/a\"]`, so the path item's own `parameters/0` is walked), two otherwise\n * (`components[\"schemas\"][\"A\"]`).\n */\nexport function leadingSegmentsOf(pointer: RefPointer): number {\n return NAMED_ROOTS.has(pointer.rootSegment) ? 1 : 2;\n}\n\nexport function refPointerOf(ref: string): RefPointer | null {\n const [rootSegment, ...segments] = parseRefPointer(ref);\n return rootSegment === undefined ? null : { rootSegment, segments };\n}\n\n/** The document node at the end of the leading segments, `$ref`s followed, with its location. */\nexport function leadingLocated(pointer: RefPointer, refs: RefResolver): LocatedNode {\n let located: LocatedNode = {\n node: refs.resolve(`#/${pointer.rootSegment}`),\n location: childLocation(ROOT_POINTER, pointer.rootSegment),\n };\n for (const segment of pointer.segments.slice(0, leadingSegmentsOf(pointer))) {\n const { node, location } = located;\n const child = isJsonObject(node) ? node[segment] : undefined;\n located = followLocated({ node: child, location: childLocation(location, segment) }, refs);\n }\n return located;\n}\n\n/** The node at the whole pointer, without following a `$ref` at its end. */\nexport function pointerNode(pointer: RefPointer, refs: RefResolver): unknown {\n let node = refs.resolve(`#/${pointer.rootSegment}`);\n pointer.segments.forEach((segment, index) => {\n const child = isJsonObject(node) || Array.isArray(node) ? (node as never)[segment] : undefined;\n node = index === pointer.segments.length - 1 ? child : followRefs(child, refs);\n });\n return node;\n}\n\n/** Whether the leading segments name a component schema, so the walk starts inside a schema. */\nexport function startsInSchema(pointer: RefPointer): boolean {\n return pointer.rootSegment === \"components\" && pointer.segments[0] === \"schemas\";\n}\n\n/**\n * Whether the container at `index` is typed as its `schema`: a media type\n * (`content/<media type>`), a header (`headers/<name>`) or a component parameter.\n */\nexport function isTypedAsSchema(pointer: RefPointer, index: number): boolean {\n const owner = pointer.segments[index - 2];\n const isComponentParameter =\n pointer.rootSegment === \"components\" && index === 2 && owner === \"parameters\";\n return owner === \"content\" || owner === \"headers\" || isComponentParameter;\n}\n\n/**\n * How the generated type of a header or component parameter holds its `content` (header.ts,\n * parameter.ts): one member per media type, the type of the first media type, `string` (a\n * parameter without the `parameter-header-content` fix), or not at all (a `schema` wins).\n */\nexport type ContentForm = \"media-type-members\" | \"first-media-type\" | \"string\" | \"schema\";\n\n/**\n * The form of the `content` at `index` when it belongs to a header or a component parameter; null\n * for any other segment. An `in: querystring` parameter is typed by its `content` even next to a\n * `schema`.\n */\nexport function headerParameterContentForm(\n pointer: RefPointer,\n index: number,\n owner: unknown,\n options: SchemaOptions,\n): ContentForm | null {\n const isHeader = pointer.segments[index - 2] === \"headers\";\n const isComponentParameter =\n pointer.rootSegment === \"components\" && index === 2 && pointer.segments[0] === \"parameters\";\n const isOwnContent = pointer.segments[index] === \"content\" && (isHeader || isComponentParameter);\n if (!isOwnContent || !isJsonObject(owner)) {\n return null;\n }\n const isFixed = options.fixes.has(FIX.PARAMETER_HEADER_CONTENT);\n if (isHeader) {\n if (owner.schema) {\n return \"schema\";\n }\n return isFixed ? \"first-media-type\" : \"media-type-members\";\n }\n if (owner.in === QUERYSTRING_LOCATION) {\n return \"first-media-type\";\n }\n if (owner.schema !== undefined) {\n return \"schema\";\n }\n return isFixed ? \"first-media-type\" : \"string\";\n}\n\n/**\n * Whether the segment at `index` is an operation's or path item's `parameters` list, indexed by\n * position next. The generated type groups parameters by `in` (`query`, `path`), so it has no\n * member `0`.\n */\nexport function isParameterList(pointer: RefPointer, index: number): boolean {\n const next = pointer.segments[index + 1] ?? \"\";\n return pointer.segments[index] === \"parameters\" && /^\\d+$/.test(next);\n}\n\n/**\n * Whether the segment at `index` names a response header that is an optional member: one the\n * response lists without `required: true`. A `$ref` header counts as required, as the generated\n * type has it; a component header (`components/headers/<name>`) is a member of its own.\n */\nexport function isOptionalHeader(pointer: RefPointer, index: number, headers: unknown): boolean {\n const isComponentHeader = pointer.rootSegment === \"components\" && index === 1;\n if (pointer.segments[index - 1] !== \"headers\" || isComponentHeader || !isJsonObject(headers)) {\n return false;\n }\n const header = headers[pointer.segments[index] as string];\n return isJsonObject(header) && header.$ref === undefined && header.required !== true;\n}\n\n/**\n * Whether the segment at `index` names an operation that `--exclude-deprecated` leaves out: the\n * path item types it `never`, which has no member to index (`isIncludedOperation`).\n */\nexport function isExcludedOperation(\n pointer: RefPointer,\n index: number,\n pathItem: unknown,\n input: { readonly options: SchemaOptions; readonly refs: RefResolver },\n): boolean {\n const segments = [pointer.rootSegment, ...pointer.segments.slice(0, index + 1)];\n if (!input.options.excludeDeprecated || placeOf(segments) !== \"operation\") {\n return false;\n }\n const segment = pointer.segments[index] as string;\n const operation = isJsonObject(pathItem) ? followRefs(pathItem[segment], input.refs) : undefined;\n return isJsonObject(operation) && Boolean(operation.deprecated);\n}\n\n/** A `requestBody` the operation does not mark `required` is an optional member. */\nexport function isOptionalRequestBody(container: unknown, refs: RefResolver): boolean {\n if (!isJsonObject(container) || container.requestBody === undefined) {\n return false;\n }\n const body = followRefs(container.requestBody, refs);\n return !(isJsonObject(body) && body.required === true);\n}\n"],"names":["parseRefPointer","childLocation","ROOT_POINTER","isJsonObject","followLocated","followRefs","FIX","QUERYSTRING_LOCATION","placeOf"],"mappings":";;;;;;;;AAsBA,MAAM,8BAAmC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,UAAU,CAAC,CAAA;AAO/D,SAAS,kBAAkB,OAAA,EAA6B;AAC7D,EAAA,OAAO,WAAA,CAAY,GAAA,CAAI,OAAA,CAAQ,WAAW,IAAI,CAAA,GAAI,CAAA;AACpD;AAEO,SAAS,aAAa,GAAA,EAAgC;AAC3D,EAAA,MAAM,CAAC,WAAA,EAAa,GAAG,QAAQ,CAAA,GAAIA,4BAAgB,GAAG,CAAA;AACtD,EAAA,OAAO,WAAA,KAAgB,MAAA,GAAY,IAAA,GAAO,EAAE,aAAa,QAAA,EAAS;AACpE;AAGO,SAAS,cAAA,CAAe,SAAqB,IAAA,EAAgC;AAClF,EAAA,IAAI,OAAA,GAAuB;AAAA,IACzB,MAAM,IAAA,CAAK,OAAA,CAAQ,CAAA,EAAA,EAAK,OAAA,CAAQ,WAAW,CAAA,CAAE,CAAA;AAAA,IAC7C,QAAA,EAAUC,yBAAA,CAAcC,wBAAA,EAAc,OAAA,CAAQ,WAAW;AAAA,GAC3D;AACA,EAAA,KAAA,MAAW,OAAA,IAAW,QAAQ,QAAA,CAAS,KAAA,CAAM,GAAG,iBAAA,CAAkB,OAAO,CAAC,CAAA,EAAG;AAC3E,IAAA,MAAM,EAAE,IAAA,EAAM,QAAA,EAAS,GAAI,OAAA;AAC3B,IAAA,MAAM,QAAQC,wBAAA,CAAa,IAAI,CAAA,GAAI,IAAA,CAAK,OAAO,CAAA,GAAI,MAAA;AACnD,IAAA,OAAA,GAAUC,yBAAA,CAAc,EAAE,I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,CAAW,SAAA,CAAU,WAAA,EAAa,IAAI,CAAA;AACnD,EAAA,OAAO,EAAEF,wBAAA,CAAa,IAAI,CAAA,IAAK,KAAK,QAAA,KAAa,IAAA,CAAA;AACnD;;;;;;;;;;;;"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { placeOf } from '../../../domain/openapi/document-places.mjs';
|
|
2
|
+
import { parseRefPointer, ROOT_POINTER } from '../../../domain/openapi/json-pointer.mjs';
|
|
3
|
+
import { QUERYSTRING_LOCATION } from '../../../domain/openapi/parameter-object.mjs';
|
|
4
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
5
|
+
import { childLocation, isJsonObject, followLocated, followRefs } from './located-node.mjs';
|
|
3
6
|
|
|
4
7
|
const NAMED_ROOTS = /* @__PURE__ */ new Set(["paths", "webhooks"]);
|
|
5
8
|
function leadingSegmentsOf(pointer) {
|
|
@@ -9,12 +12,17 @@ function refPointerOf(ref) {
|
|
|
9
12
|
const [rootSegment, ...segments] = parseRefPointer(ref);
|
|
10
13
|
return rootSegment === void 0 ? null : { rootSegment, segments };
|
|
11
14
|
}
|
|
12
|
-
function
|
|
13
|
-
let
|
|
15
|
+
function leadingLocated(pointer, refs) {
|
|
16
|
+
let located = {
|
|
17
|
+
node: refs.resolve(`#/${pointer.rootSegment}`),
|
|
18
|
+
location: childLocation(ROOT_POINTER, pointer.rootSegment)
|
|
19
|
+
};
|
|
14
20
|
for (const segment of pointer.segments.slice(0, leadingSegmentsOf(pointer))) {
|
|
15
|
-
|
|
21
|
+
const { node, location } = located;
|
|
22
|
+
const child = isJsonObject(node) ? node[segment] : void 0;
|
|
23
|
+
located = followLocated({ node: child, location: childLocation(location, segment) }, refs);
|
|
16
24
|
}
|
|
17
|
-
return
|
|
25
|
+
return located;
|
|
18
26
|
}
|
|
19
27
|
function pointerNode(pointer, refs) {
|
|
20
28
|
let node = refs.resolve(`#/${pointer.rootSegment}`);
|
|
@@ -32,6 +40,28 @@ function isTypedAsSchema(pointer, index) {
|
|
|
32
40
|
const isComponentParameter = pointer.rootSegment === "components" && index === 2 && owner === "parameters";
|
|
33
41
|
return owner === "content" || owner === "headers" || isComponentParameter;
|
|
34
42
|
}
|
|
43
|
+
function headerParameterContentForm(pointer, index, owner, options) {
|
|
44
|
+
const isHeader = pointer.segments[index - 2] === "headers";
|
|
45
|
+
const isComponentParameter = pointer.rootSegment === "components" && index === 2 && pointer.segments[0] === "parameters";
|
|
46
|
+
const isOwnContent = pointer.segments[index] === "content" && (isHeader || isComponentParameter);
|
|
47
|
+
if (!isOwnContent || !isJsonObject(owner)) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const isFixed = options.fixes.has(FIX.PARAMETER_HEADER_CONTENT);
|
|
51
|
+
if (isHeader) {
|
|
52
|
+
if (owner.schema) {
|
|
53
|
+
return "schema";
|
|
54
|
+
}
|
|
55
|
+
return isFixed ? "first-media-type" : "media-type-members";
|
|
56
|
+
}
|
|
57
|
+
if (owner.in === QUERYSTRING_LOCATION) {
|
|
58
|
+
return "first-media-type";
|
|
59
|
+
}
|
|
60
|
+
if (owner.schema !== void 0) {
|
|
61
|
+
return "schema";
|
|
62
|
+
}
|
|
63
|
+
return isFixed ? "first-media-type" : "string";
|
|
64
|
+
}
|
|
35
65
|
function isParameterList(pointer, index) {
|
|
36
66
|
const next = pointer.segments[index + 1] ?? "";
|
|
37
67
|
return pointer.segments[index] === "parameters" && /^\d+$/.test(next);
|
|
@@ -44,6 +74,15 @@ function isOptionalHeader(pointer, index, headers) {
|
|
|
44
74
|
const header = headers[pointer.segments[index]];
|
|
45
75
|
return isJsonObject(header) && header.$ref === void 0 && header.required !== true;
|
|
46
76
|
}
|
|
77
|
+
function isExcludedOperation(pointer, index, pathItem, input) {
|
|
78
|
+
const segments = [pointer.rootSegment, ...pointer.segments.slice(0, index + 1)];
|
|
79
|
+
if (!input.options.excludeDeprecated || placeOf(segments) !== "operation") {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const segment = pointer.segments[index];
|
|
83
|
+
const operation = isJsonObject(pathItem) ? followRefs(pathItem[segment], input.refs) : void 0;
|
|
84
|
+
return isJsonObject(operation) && Boolean(operation.deprecated);
|
|
85
|
+
}
|
|
47
86
|
function isOptionalRequestBody(container, refs) {
|
|
48
87
|
if (!isJsonObject(container) || container.requestBody === void 0) {
|
|
49
88
|
return false;
|
|
@@ -52,5 +91,5 @@ function isOptionalRequestBody(container, refs) {
|
|
|
52
91
|
return !(isJsonObject(body) && body.required === true);
|
|
53
92
|
}
|
|
54
93
|
|
|
55
|
-
export { isOptionalHeader, isOptionalRequestBody, isParameterList, isTypedAsSchema,
|
|
94
|
+
export { headerParameterContentForm, isExcludedOperation, isOptionalHeader, isOptionalRequestBody, isParameterList, isTypedAsSchema, leadingLocated, leadingSegmentsOf, pointerNode, refPointerOf, startsInSchema };
|
|
56
95
|
//# sourceMappingURL=pointer-walk.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pointer-walk.mjs","sources":["../../../../src/application/transform/ref-pointer/pointer-walk.ts"],"sourcesContent":["import { parseRefPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport type { RefResolver } from \"../schema/schema-context.js\";\nimport { followRefs, isJsonObject } from \"./generated-shape.js\";\n\n/** The parts of a `$ref` pointer that both the original and the new types walk. */\n\nexport interface RefPointer {\n readonly rootSegment: string;\n /** The segments after the root: `#/components/schemas/A` gives `[\"schemas\", \"A\"]`. */\n readonly segments: readonly string[];\n}\n\n/** Roots whose generated type is keyed by one segment: the path or webhook name. */\nconst NAMED_ROOTS: ReadonlySet<string> = new Set([\"paths\", \"webhooks\"]);\n\n/**\n * How many segments after the root index the generated root type directly: one for `paths` and\n * `webhooks` (`paths[\"/a\"]`, so the path item's own `parameters/0` is walked), two otherwise\n * (`components[\"schemas\"][\"A\"]`).\n */\nexport function leadingSegmentsOf(pointer: RefPointer): number {\n return NAMED_ROOTS.has(pointer.rootSegment) ? 1 : 2;\n}\n\nexport function refPointerOf(ref: string): RefPointer | null {\n const [rootSegment, ...segments] = parseRefPointer(ref);\n return rootSegment === undefined ? null : { rootSegment, segments };\n}\n\n/** The document node at the end of the leading segments, `$ref`s followed. */\nexport function leadingNode(pointer: RefPointer, refs: RefResolver): unknown {\n let node = refs.resolve(`#/${pointer.rootSegment}`);\n for (const segment of pointer.segments.slice(0, leadingSegmentsOf(pointer))) {\n node = isJsonObject(node) ? followRefs(node[segment], refs) : undefined;\n }\n return node;\n}\n\n/** The node at the whole pointer, without following a `$ref` at its end. */\nexport function pointerNode(pointer: RefPointer, refs: RefResolver): unknown {\n let node = refs.resolve(`#/${pointer.rootSegment}`);\n pointer.segments.forEach((segment, index) => {\n const child = isJsonObject(node) || Array.isArray(node) ? (node as never)[segment] : undefined;\n node = index === pointer.segments.length - 1 ? child : followRefs(child, refs);\n });\n return node;\n}\n\n/** Whether the leading segments name a component schema, so the walk starts inside a schema. */\nexport function startsInSchema(pointer: RefPointer): boolean {\n return pointer.rootSegment === \"components\" && pointer.segments[0] === \"schemas\";\n}\n\n/**\n * Whether the container at `index` is typed as its `schema`: a media type\n * (`content/<media type>`), a header (`headers/<name>`) or a component parameter.\n */\nexport function isTypedAsSchema(pointer: RefPointer, index: number): boolean {\n const owner = pointer.segments[index - 2];\n const isComponentParameter =\n pointer.rootSegment === \"components\" && index === 2 && owner === \"parameters\";\n return owner === \"content\" || owner === \"headers\" || isComponentParameter;\n}\n\n/**\n * Whether the segment at `index` is an operation's or path item's `parameters` list, indexed by\n * position next. The generated type groups parameters by `in` (`query`, `path`), so it has no\n * member `0`.\n */\nexport function isParameterList(pointer: RefPointer, index: number): boolean {\n const next = pointer.segments[index + 1] ?? \"\";\n return pointer.segments[index] === \"parameters\" && /^\\d+$/.test(next);\n}\n\n/**\n * Whether the segment at `index` names a response header that is an optional member: one the\n * response lists without `required: true`. A `$ref` header counts as required, as the generated\n * type has it; a component header (`components/headers/<name>`) is a member of its own.\n */\nexport function isOptionalHeader(pointer: RefPointer, index: number, headers: unknown): boolean {\n const isComponentHeader = pointer.rootSegment === \"components\" && index === 1;\n if (pointer.segments[index - 1] !== \"headers\" || isComponentHeader || !isJsonObject(headers)) {\n return false;\n }\n const header = headers[pointer.segments[index] as string];\n return isJsonObject(header) && header.$ref === undefined && header.required !== true;\n}\n\n/** A `requestBody` the operation does not mark `required` is an optional member. */\nexport function isOptionalRequestBody(container: unknown, refs: RefResolver): boolean {\n if (!isJsonObject(container) || container.requestBody === undefined) {\n return false;\n }\n const body = followRefs(container.requestBody, refs);\n return !(isJsonObject(body) && body.required === true);\n}\n"],"names":[],"mappings":";;;AAaA,MAAM,8BAAmC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,UAAU,CAAC,CAAA;AAO/D,SAAS,kBAAkB,OAAA,EAA6B;AAC7D,EAAA,OAAO,WAAA,CAAY,GAAA,CAAI,OAAA,CAAQ,WAAW,IAAI,CAAA,GAAI,CAAA;AACpD;AAEO,SAAS,aAAa,GAAA,EAAgC;AAC3D,EAAA,MAAM,CAAC,WAAA,EAAa,GAAG,QAAQ,CAAA,GAAI,gBAAgB,GAAG,CAAA;AACtD,EAAA,OAAO,WAAA,KAAgB,MAAA,GAAY,IAAA,GAAO,EAAE,aAAa,QAAA,EAAS;AACpE;AAGO,SAAS,WAAA,CAAY,SAAqB,IAAA,EAA4B;AAC3E,EAAA,IAAI,OAAO,IAAA,CAAK,OAAA,CAAQ,CAAA,EAAA,EAAK,OAAA,CAAQ,WAAW,CAAA,CAAE,CAAA;AAClD,EAAA,KAAA,MAAW,OAAA,IAAW,QAAQ,QAAA,CAAS,KAAA,CAAM,GAAG,iBAAA,CAAkB,OAAO,CAAC,CAAA,EAAG;AAC3E,IAAA,IAAA,GAAO,YAAA,CAAa,IAAI,CAAA,GAAI,UAAA,CAAW,KAAK,OAAO,CAAA,EAAG,IAAI,CAAA,GAAI,MAAA;AAAA,EAChE;AACA,EAAA,OAAO,IAA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;AAOO,SAAS,gBAAA,CAAiB,OAAA,EAAqB,KAAA,EAAe,OAAA,EAA2B;AAC9F,EAAA,MAAM,iBAAA,GAAoB,OAAA,CAAQ,WAAA,KAAgB,YAAA,IAAgB,KAAA,KAAU,CAAA;AAC5E,EAAA,IAAI,OAAA,CAAQ,QAAA,CAAS,KAAA,GAAQ,CAAC,CAAA,KAAM,aAAa,iBAAA,IAAqB,CAAC,YAAA,CAAa,OAAO,CAAA,EAAG;AAC5F,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,OAAA,CAAQ,QAAA,CAAS,KAAK,CAAW,CAAA;AACxD,EAAA,OAAO,aAAa,MAAM,CAAA,IAAK,OAAO,IAAA,KAAS,MAAA,IAAa,OAAO,QAAA,KAAa,IAAA;AAClF;AAGO,SAAS,qBAAA,CAAsB,WAAoB,IAAA,EAA4B;AACpF,EAAA,IAAI,CAAC,YAAA,CAAa,SAAS,CAAA,IAAK,SAAA,CAAU,gBAAgB,MAAA,EAAW;AACnE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,MAAM,IAAA,GAAO,UAAA,CAAW,SAAA,CAAU,WAAA,EAAa,IAAI,CAAA;AACnD,EAAA,OAAO,EAAE,YAAA,CAAa,IAAI,CAAA,IAAK,KAAK,QAAA,KAAa,IAAA,CAAA;AACnD;;"}
|
|
1
|
+
{"version":3,"file":"pointer-walk.mjs","sources":["../../../../src/application/transform/ref-pointer/pointer-walk.ts"],"sourcesContent":["import { placeOf } from \"../../../domain/openapi/document-places.js\";\nimport { parseRefPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport { QUERYSTRING_LOCATION } from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport {\n childLocation,\n followLocated,\n followRefs,\n isJsonObject,\n type LocatedNode,\n} from \"./located-node.js\";\n\n/** The parts of a `$ref` pointer that both the original and the new types walk. */\n\nexport interface RefPointer {\n readonly rootSegment: string;\n /** The segments after the root: `#/components/schemas/A` gives `[\"schemas\", \"A\"]`. */\n readonly segments: readonly string[];\n}\n\n/** Roots whose generated type is keyed by one segment: the path or webhook name. */\nconst NAMED_ROOTS: ReadonlySet<string> = new Set([\"paths\", \"webhooks\"]);\n\n/**\n * How many segments after the root index the generated root type directly: one for `paths` and\n * `webhooks` (`paths[\"/a\"]`, so the path item's own `parameters/0` is walked), two otherwise\n * (`components[\"schemas\"][\"A\"]`).\n */\nexport function leadingSegmentsOf(pointer: RefPointer): number {\n return NAMED_ROOTS.has(pointer.rootSegment) ? 1 : 2;\n}\n\nexport function refPointerOf(ref: string): RefPointer | null {\n const [rootSegment, ...segments] = parseRefPointer(ref);\n return rootSegment === undefined ? null : { rootSegment, segments };\n}\n\n/** The document node at the end of the leading segments, `$ref`s followed, with its location. */\nexport function leadingLocated(pointer: RefPointer, refs: RefResolver): LocatedNode {\n let located: LocatedNode = {\n node: refs.resolve(`#/${pointer.rootSegment}`),\n location: childLocation(ROOT_POINTER, pointer.rootSegment),\n };\n for (const segment of pointer.segments.slice(0, leadingSegmentsOf(pointer))) {\n const { node, location } = located;\n const child = isJsonObject(node) ? node[segment] : undefined;\n located = followLocated({ node: child, location: childLocation(location, segment) }, refs);\n }\n return located;\n}\n\n/** The node at the whole pointer, without following a `$ref` at its end. */\nexport function pointerNode(pointer: RefPointer, refs: RefResolver): unknown {\n let node = refs.resolve(`#/${pointer.rootSegment}`);\n pointer.segments.forEach((segment, index) => {\n const child = isJsonObject(node) || Array.isArray(node) ? (node as never)[segment] : undefined;\n node = index === pointer.segments.length - 1 ? child : followRefs(child, refs);\n });\n return node;\n}\n\n/** Whether the leading segments name a component schema, so the walk starts inside a schema. */\nexport function startsInSchema(pointer: RefPointer): boolean {\n return pointer.rootSegment === \"components\" && pointer.segments[0] === \"schemas\";\n}\n\n/**\n * Whether the container at `index` is typed as its `schema`: a media type\n * (`content/<media type>`), a header (`headers/<name>`) or a component parameter.\n */\nexport function isTypedAsSchema(pointer: RefPointer, index: number): boolean {\n const owner = pointer.segments[index - 2];\n const isComponentParameter =\n pointer.rootSegment === \"components\" && index === 2 && owner === \"parameters\";\n return owner === \"content\" || owner === \"headers\" || isComponentParameter;\n}\n\n/**\n * How the generated type of a header or component parameter holds its `content` (header.ts,\n * parameter.ts): one member per media type, the type of the first media type, `string` (a\n * parameter without the `parameter-header-content` fix), or not at all (a `schema` wins).\n */\nexport type ContentForm = \"media-type-members\" | \"first-media-type\" | \"string\" | \"schema\";\n\n/**\n * The form of the `content` at `index` when it belongs to a header or a component parameter; null\n * for any other segment. An `in: querystring` parameter is typed by its `content` even next to a\n * `schema`.\n */\nexport function headerParameterContentForm(\n pointer: RefPointer,\n index: number,\n owner: unknown,\n options: SchemaOptions,\n): ContentForm | null {\n const isHeader = pointer.segments[index - 2] === \"headers\";\n const isComponentParameter =\n pointer.rootSegment === \"components\" && index === 2 && pointer.segments[0] === \"parameters\";\n const isOwnContent = pointer.segments[index] === \"content\" && (isHeader || isComponentParameter);\n if (!isOwnContent || !isJsonObject(owner)) {\n return null;\n }\n const isFixed = options.fixes.has(FIX.PARAMETER_HEADER_CONTENT);\n if (isHeader) {\n if (owner.schema) {\n return \"schema\";\n }\n return isFixed ? \"first-media-type\" : \"media-type-members\";\n }\n if (owner.in === QUERYSTRING_LOCATION) {\n return \"first-media-type\";\n }\n if (owner.schema !== undefined) {\n return \"schema\";\n }\n return isFixed ? \"first-media-type\" : \"string\";\n}\n\n/**\n * Whether the segment at `index` is an operation's or path item's `parameters` list, indexed by\n * position next. The generated type groups parameters by `in` (`query`, `path`), so it has no\n * member `0`.\n */\nexport function isParameterList(pointer: RefPointer, index: number): boolean {\n const next = pointer.segments[index + 1] ?? \"\";\n return pointer.segments[index] === \"parameters\" && /^\\d+$/.test(next);\n}\n\n/**\n * Whether the segment at `index` names a response header that is an optional member: one the\n * response lists without `required: true`. A `$ref` header counts as required, as the generated\n * type has it; a component header (`components/headers/<name>`) is a member of its own.\n */\nexport function isOptionalHeader(pointer: RefPointer, index: number, headers: unknown): boolean {\n const isComponentHeader = pointer.rootSegment === \"components\" && index === 1;\n if (pointer.segments[index - 1] !== \"headers\" || isComponentHeader || !isJsonObject(headers)) {\n return false;\n }\n const header = headers[pointer.segments[index] as string];\n return isJsonObject(header) && header.$ref === undefined && header.required !== true;\n}\n\n/**\n * Whether the segment at `index` names an operation that `--exclude-deprecated` leaves out: the\n * path item types it `never`, which has no member to index (`isIncludedOperation`).\n */\nexport function isExcludedOperation(\n pointer: RefPointer,\n index: number,\n pathItem: unknown,\n input: { readonly options: SchemaOptions; readonly refs: RefResolver },\n): boolean {\n const segments = [pointer.rootSegment, ...pointer.segments.slice(0, index + 1)];\n if (!input.options.excludeDeprecated || placeOf(segments) !== \"operation\") {\n return false;\n }\n const segment = pointer.segments[index] as string;\n const operation = isJsonObject(pathItem) ? followRefs(pathItem[segment], input.refs) : undefined;\n return isJsonObject(operation) && Boolean(operation.deprecated);\n}\n\n/** A `requestBody` the operation does not mark `required` is an optional member. */\nexport function isOptionalRequestBody(container: unknown, refs: RefResolver): boolean {\n if (!isJsonObject(container) || container.requestBody === undefined) {\n return false;\n }\n const body = followRefs(container.requestBody, refs);\n return !(isJsonObject(body) && body.required === true);\n}\n"],"names":[],"mappings":";;;;;;AAsBA,MAAM,8BAAmC,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,UAAU,CAAC,CAAA;AAO/D,SAAS,kBAAkB,OAAA,EAA6B;AAC7D,EAAA,OAAO,WAAA,CAAY,GAAA,CAAI,OAAA,CAAQ,WAAW,IAAI,CAAA,GAAI,CAAA;AACpD;AAEO,SAAS,aAAa,GAAA,EAAgC;AAC3D,EAAA,MAAM,CAAC,WAAA,EAAa,GAAG,QAAQ,CAAA,GAAI,gBAAgB,GAAG,CAAA;AACtD,EAAA,OAAO,WAAA,KAAgB,MAAA,GAAY,IAAA,GAAO,EAAE,aAAa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,CAAQ,QAAQ,MAAM,WAAA,EAAa;AACzE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,MAAM,OAAA,GAAU,OAAA,CAAQ,QAAA,CAAS,KAAK,CAAA;AACtC,EAAA,MAAM,SAAA,GAAY,YAAA,CAAa,QAAQ,CAAA,GAAI,UAAA,CAAW,SAAS,OAAO,CAAA,EAAG,KAAA,CAAM,IAAI,CAAA,GAAI,MAAA;AACvF,EAAA,OAAO,YAAA,CAAa,SAAS,CAAA,IAAK,OAAA,CAAQ,UAAU,UAAU,CAAA;AAChE;AAGO,SAAS,qBAAA,CAAsB,WAAoB,IAAA,EAA4B;AACpF,EAAA,IAAI,CAAC,YAAA,CAAa,SAAS,CAAA,IAAK,SAAA,CAAU,gBAAgB,MAAA,EAAW;AACnE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,MAAM,IAAA,GAAO,UAAA,CAAW,SAAA,CAAU,WAAA,EAAa,IAAI,CAAA;AACnD,EAAA,OAAO,EAAE,YAAA,CAAa,IAAI,CAAA,IAAK,KAAK,QAAA,KAAa,IAAA,CAAA;AACnD;;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const accessFlags = require('../schema/access-flags.cjs');
|
|
4
|
+
const inputLocation = require('../schema/input-location.cjs');
|
|
5
|
+
const locatedNode = require('./located-node.cjs');
|
|
6
|
+
|
|
7
|
+
function isNullableSchema(node) {
|
|
8
|
+
if (!locatedNode.isJsonObject(node)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return node.nullable === true || Array.isArray(node.type) && node.type.includes("null");
|
|
12
|
+
}
|
|
13
|
+
function isOptionalProperty(owner, key, options) {
|
|
14
|
+
const { node } = owner;
|
|
15
|
+
const required = Array.isArray(node.required) ? node.required : void 0;
|
|
16
|
+
const property = node.properties[key];
|
|
17
|
+
const hasDefault = locatedNode.isJsonObject(property) && property.default !== void 0;
|
|
18
|
+
const isDefaultRequired = hasDefault && options.defaultNonNullable && !inputLocation.isInputLocation(owner.location, options.fixes);
|
|
19
|
+
const isRequired = required?.includes(key) === true || required === void 0 && options.propertiesRequiredByDefault || isDefaultRequired;
|
|
20
|
+
return !isRequired;
|
|
21
|
+
}
|
|
22
|
+
function isExcludedProperty(property, options, refs) {
|
|
23
|
+
const resolved = locatedNode.followRefs(property, refs);
|
|
24
|
+
return options.excludeDeprecated && locatedNode.isJsonObject(resolved) && Boolean(resolved.deprecated);
|
|
25
|
+
}
|
|
26
|
+
function isMarkedProperty(value, options, refs) {
|
|
27
|
+
if (!options.readWriteMarkers || !locatedNode.isJsonObject(value)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const flags = accessFlags.propertyAccessFlags(value, { options, refs });
|
|
31
|
+
return flags.isReadOnly !== flags.isWriteOnly;
|
|
32
|
+
}
|
|
33
|
+
function schemaPresence(schema, refs) {
|
|
34
|
+
return isNullableSchema(locatedNode.followRefs(schema, refs)) ? "absent" : "present";
|
|
35
|
+
}
|
|
36
|
+
function propertyPresence(schema, key, options, refs) {
|
|
37
|
+
const owner = locatedNode.followLocated(schema, refs);
|
|
38
|
+
const { node } = owner;
|
|
39
|
+
const properties = locatedNode.isJsonObject(node) && locatedNode.isJsonObject(node.properties) ? node.properties : {};
|
|
40
|
+
if (!locatedNode.isJsonObject(node) || !Object.hasOwn(properties, key)) {
|
|
41
|
+
return "unknown";
|
|
42
|
+
}
|
|
43
|
+
return isOptionalProperty({ ...owner, node }, key, options) ? "absent" : schemaPresence(properties[key], refs);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.isExcludedProperty = isExcludedProperty;
|
|
47
|
+
exports.isMarkedProperty = isMarkedProperty;
|
|
48
|
+
exports.isNullableSchema = isNullableSchema;
|
|
49
|
+
exports.isOptionalProperty = isOptionalProperty;
|
|
50
|
+
exports.propertyPresence = propertyPresence;
|
|
51
|
+
exports.schemaPresence = schemaPresence;
|
|
52
|
+
//# sourceMappingURL=property-shape.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-shape.cjs","sources":["../../../../src/application/transform/ref-pointer/property-shape.ts"],"sourcesContent":["import type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { propertyAccessFlags } from \"../schema/access-flags.js\";\nimport { isInputLocation } from \"../schema/input-location.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport {\n followLocated,\n followRefs,\n isJsonObject,\n type JsonObject,\n type LocatedNode,\n} from \"./located-node.js\";\n\n/**\n * What the generated type of an object schema makes of one of its properties: optional, left\n * out, wrapped in a read or write marker, or a value that may be `undefined` or `null`.\n */\n\n/** `nullable: true` or a `type` list with `null`: the generated type includes `null`. */\nexport function isNullableSchema(node: unknown): boolean {\n if (!isJsonObject(node)) {\n return false;\n }\n return node.nullable === true || (Array.isArray(node.type) && node.type.includes(\"null\"));\n}\n\n/**\n * Whether the generated type has the property as optional, as `objectType` decides: a `default`\n * makes a property required except in an input location, where the client may leave it out.\n */\nexport function isOptionalProperty(\n owner: LocatedNode & { node: JsonObject },\n key: string,\n options: SchemaOptions,\n): boolean {\n const { node } = owner;\n const required = Array.isArray(node.required) ? node.required : undefined;\n const property = (node.properties as JsonObject)[key];\n const hasDefault = isJsonObject(property) && property.default !== undefined;\n const isDefaultRequired =\n hasDefault && options.defaultNonNullable && !isInputLocation(owner.location, options.fixes);\n const isRequired =\n required?.includes(key) === true ||\n (required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\n/**\n * Whether `--exclude-deprecated` leaves the property out: its object, or the one its `$ref`\n * names, is deprecated (`objectType`). The key is then not in the generated type at all.\n */\nexport function isExcludedProperty(\n property: unknown,\n options: SchemaOptions,\n refs: RefResolver,\n): boolean {\n const resolved = followRefs(property, refs);\n return options.excludeDeprecated && isJsonObject(resolved) && Boolean(resolved.deprecated);\n}\n\n/**\n * Whether `--read-write-markers` wraps the type of a property or `$defs` member: one that is only\n * `readOnly` or only `writeOnly` is `$Read<T>` or `$Write<T>` (object-type.ts).\n */\nexport function isMarkedProperty(value: unknown, options: SchemaOptions, refs: RefResolver) {\n if (!options.readWriteMarkers || !isJsonObject(value)) {\n return false;\n }\n const flags = propertyAccessFlags(value as Schema, { options, refs });\n return flags.isReadOnly !== flags.isWriteOnly;\n}\n\n/** Whether a value is there: `present`, `absent` (may be `undefined` or `null`) or `unknown`. */\nexport type Presence = \"present\" | \"absent\" | \"unknown\";\n\n/** The presence of a value of `schema` itself: `absent` when its type includes `null`. */\nexport function schemaPresence(schema: unknown, refs: RefResolver): Presence {\n return isNullableSchema(followRefs(schema, refs)) ? \"absent\" : \"present\";\n}\n\n/** The presence of property `key` of `schema`: optional or nullable is `absent`. */\nexport function propertyPresence(\n schema: LocatedNode,\n key: string,\n options: SchemaOptions,\n refs: RefResolver,\n): Presence {\n const owner = followLocated(schema, refs);\n const { node } = owner;\n const properties = isJsonObject(node) && isJsonObject(node.properties) ? node.properties : {};\n if (!isJsonObject(node) || !Object.hasOwn(properties, key)) {\n return \"unknown\";\n }\n return isOptionalProperty({ ...owner, node }, key, options)\n ? \"absent\"\n : schemaPresence(properties[key], refs);\n}\n"],"names":["isJsonObject","isInputLocation","followRefs","propertyAccessFlags","followLocated"],"mappings":";;;;;;AAkBO,SAAS,iBAAiB,IAAA,EAAwB;AACvD,EAAA,IAAI,CAACA,wBAAA,CAAa,IAAI,CAAA,EAAG;AACvB,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAA,CAAK,QAAA,KAAa,IAAA,IAAS,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA,IAAK,IAAA,CAAK,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA;AACzF;AAMO,SAAS,kBAAA,CACd,KAAA,EACA,GAAA,EACA,OAAA,EACS;AACT,EAAA,MAAM,EAAE,MAAK,GAAI,KAAA;AACjB,EAAA,MAAM,WAAW,KAAA,CAA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;AAGO,SAAS,gBAAA,CACd,MAAA,EACA,GAAA,EACA,OAAA,EACA,IAAA,EACU;AACV,EAAA,MAAM,KAAA,GAAQE,yBAAA,CAAc,MAAA,EAAQ,IAAI,CAAA;AACxC,EAAA,MAAM,EAAE,MAAK,GAAI,KAAA;AACjB,EAAA,MAAM,UAAA,GAAaJ,wBAAA,CAAa,IAAI,CAAA,IAAKA,wBAAA,CAAa,KAAK,UAAU,CAAA,GAAI,IAAA,CAAK,UAAA,GAAa,EAAC;AAC5F,EAAA,IAAI,CAACA,yBAAa,IAAI,CAAA,IAAK,CAAC,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY,GAAG,CAAA,EAAG;AAC1D,IAAA,OAAO,SAAA;AAAA,EACT;AACA,EAAA,OAAO,kBAAA,CAAmB,EAAE,GAAG,KAAA,EAAO,MAAK,EAAG,GAAA,EAAK,OAAO,CAAA,GACtD,QAAA,GACA,cAAA,CAAe,UAAA,CAAW,GAAG,GAAG,IAAI,CAAA;AAC1C;;;;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { propertyAccessFlags } from '../schema/access-flags.mjs';
|
|
2
|
+
import { isInputLocation } from '../schema/input-location.mjs';
|
|
3
|
+
import { followRefs, isJsonObject, followLocated } from './located-node.mjs';
|
|
4
|
+
|
|
5
|
+
function isNullableSchema(node) {
|
|
6
|
+
if (!isJsonObject(node)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return node.nullable === true || Array.isArray(node.type) && node.type.includes("null");
|
|
10
|
+
}
|
|
11
|
+
function isOptionalProperty(owner, key, options) {
|
|
12
|
+
const { node } = owner;
|
|
13
|
+
const required = Array.isArray(node.required) ? node.required : void 0;
|
|
14
|
+
const property = node.properties[key];
|
|
15
|
+
const hasDefault = isJsonObject(property) && property.default !== void 0;
|
|
16
|
+
const isDefaultRequired = hasDefault && options.defaultNonNullable && !isInputLocation(owner.location, options.fixes);
|
|
17
|
+
const isRequired = required?.includes(key) === true || required === void 0 && options.propertiesRequiredByDefault || isDefaultRequired;
|
|
18
|
+
return !isRequired;
|
|
19
|
+
}
|
|
20
|
+
function isExcludedProperty(property, options, refs) {
|
|
21
|
+
const resolved = followRefs(property, refs);
|
|
22
|
+
return options.excludeDeprecated && isJsonObject(resolved) && Boolean(resolved.deprecated);
|
|
23
|
+
}
|
|
24
|
+
function isMarkedProperty(value, options, refs) {
|
|
25
|
+
if (!options.readWriteMarkers || !isJsonObject(value)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const flags = propertyAccessFlags(value, { options, refs });
|
|
29
|
+
return flags.isReadOnly !== flags.isWriteOnly;
|
|
30
|
+
}
|
|
31
|
+
function schemaPresence(schema, refs) {
|
|
32
|
+
return isNullableSchema(followRefs(schema, refs)) ? "absent" : "present";
|
|
33
|
+
}
|
|
34
|
+
function propertyPresence(schema, key, options, refs) {
|
|
35
|
+
const owner = followLocated(schema, refs);
|
|
36
|
+
const { node } = owner;
|
|
37
|
+
const properties = isJsonObject(node) && isJsonObject(node.properties) ? node.properties : {};
|
|
38
|
+
if (!isJsonObject(node) || !Object.hasOwn(properties, key)) {
|
|
39
|
+
return "unknown";
|
|
40
|
+
}
|
|
41
|
+
return isOptionalProperty({ ...owner, node }, key, options) ? "absent" : schemaPresence(properties[key], refs);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { isExcludedProperty, isMarkedProperty, isNullableSchema, isOptionalProperty, propertyPresence, schemaPresence };
|
|
45
|
+
//# sourceMappingURL=property-shape.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-shape.mjs","sources":["../../../../src/application/transform/ref-pointer/property-shape.ts"],"sourcesContent":["import type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { propertyAccessFlags } from \"../schema/access-flags.js\";\nimport { isInputLocation } from \"../schema/input-location.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport {\n followLocated,\n followRefs,\n isJsonObject,\n type JsonObject,\n type LocatedNode,\n} from \"./located-node.js\";\n\n/**\n * What the generated type of an object schema makes of one of its properties: optional, left\n * out, wrapped in a read or write marker, or a value that may be `undefined` or `null`.\n */\n\n/** `nullable: true` or a `type` list with `null`: the generated type includes `null`. */\nexport function isNullableSchema(node: unknown): boolean {\n if (!isJsonObject(node)) {\n return false;\n }\n return node.nullable === true || (Array.isArray(node.type) && node.type.includes(\"null\"));\n}\n\n/**\n * Whether the generated type has the property as optional, as `objectType` decides: a `default`\n * makes a property required except in an input location, where the client may leave it out.\n */\nexport function isOptionalProperty(\n owner: LocatedNode & { node: JsonObject },\n key: string,\n options: SchemaOptions,\n): boolean {\n const { node } = owner;\n const required = Array.isArray(node.required) ? node.required : undefined;\n const property = (node.properties as JsonObject)[key];\n const hasDefault = isJsonObject(property) && property.default !== undefined;\n const isDefaultRequired =\n hasDefault && options.defaultNonNullable && !isInputLocation(owner.location, options.fixes);\n const isRequired =\n required?.includes(key) === true ||\n (required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\n/**\n * Whether `--exclude-deprecated` leaves the property out: its object, or the one its `$ref`\n * names, is deprecated (`objectType`). The key is then not in the generated type at all.\n */\nexport function isExcludedProperty(\n property: unknown,\n options: SchemaOptions,\n refs: RefResolver,\n): boolean {\n const resolved = followRefs(property, refs);\n return options.excludeDeprecated && isJsonObject(resolved) && Boolean(resolved.deprecated);\n}\n\n/**\n * Whether `--read-write-markers` wraps the type of a property or `$defs` member: one that is only\n * `readOnly` or only `writeOnly` is `$Read<T>` or `$Write<T>` (object-type.ts).\n */\nexport function isMarkedProperty(value: unknown, options: SchemaOptions, refs: RefResolver) {\n if (!options.readWriteMarkers || !isJsonObject(value)) {\n return false;\n }\n const flags = propertyAccessFlags(value as Schema, { options, refs });\n return flags.isReadOnly !== flags.isWriteOnly;\n}\n\n/** Whether a value is there: `present`, `absent` (may be `undefined` or `null`) or `unknown`. */\nexport type Presence = \"present\" | \"absent\" | \"unknown\";\n\n/** The presence of a value of `schema` itself: `absent` when its type includes `null`. */\nexport function schemaPresence(schema: unknown, refs: RefResolver): Presence {\n return isNullableSchema(followRefs(schema, refs)) ? \"absent\" : \"present\";\n}\n\n/** The presence of property `key` of `schema`: optional or nullable is `absent`. */\nexport function propertyPresence(\n schema: LocatedNode,\n key: string,\n options: SchemaOptions,\n refs: RefResolver,\n): Presence {\n const owner = followLocated(schema, refs);\n const { node } = owner;\n const properties = isJsonObject(node) && isJsonObject(node.properties) ? node.properties : {};\n if (!isJsonObject(node) || !Object.hasOwn(properties, key)) {\n return \"unknown\";\n }\n return isOptionalProperty({ ...owner, node }, key, options)\n ? \"absent\"\n : schemaPresence(properties[key], refs);\n}\n"],"names":[],"mappings":";;;;AAkBO,SAAS,iBAAiB,IAAA,EAAwB;AACvD,EAAA,IAAI,CAAC,YAAA,CAAa,IAAI,CAAA,EAAG;AACvB,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAA,CAAK,QAAA,KAAa,IAAA,IAAS,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA,IAAK,IAAA,CAAK,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA;AACzF;AAMO,SAAS,kBAAA,CACd,KAAA,EACA,GAAA,EACA,OAAA,EACS;AACT,EAAA,MAAM,EAAE,MAAK,GAAI,KAAA;AACjB,EAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,QAAQ,CAAA,GAAI,KAAK,QAAA,GAAW,MAAA;AAChE,EAAA,MAAM,QAAA,GAAY,IAAA,CAAK,UAAA,CAA0B,GAAG,CAAA;AACpD,EAAA,MAAM,UAAA,GAAa,YAAA,CAAa,QAAQ,CAAA,IAAK,SAAS,OAAA,KAAY,MAAA;AAClE,EAAA,MAAM,iBAAA,GACJ,cAAc,OAAA,CAAQ,kBAAA,IAAsB,CAAC,eAAA,CAAgB,KAAA,CAAM,QAAA,EAAU,OAAA,CAAQ,KAAK,C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,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY,GAAG,CAAA,EAAG;AAC1D,IAAA,OAAO,SAAA;AAAA,EACT;AACA,EAAA,OAAO,kBAAA,CAAmB,EAAE,GAAG,KAAA,EAAO,MAAK,EAAG,GAAA,EAAK,OAAO,CAAA,GACtD,QAAA,GACA,cAAA,CAAe,UAAA,CAAW,GAAG,GAAG,IAAI,CAAA;AAC1C;;"}
|
|
@@ -3,40 +3,56 @@
|
|
|
3
3
|
const constructors = require('../../../domain/ir/constructors.cjs');
|
|
4
4
|
const refType = require('../ref-type.cjs');
|
|
5
5
|
const generatedShape = require('./generated-shape.cjs');
|
|
6
|
+
const locatedNode = require('./located-node.cjs');
|
|
6
7
|
const pointerWalk = require('./pointer-walk.cjs');
|
|
8
|
+
const propertyShape = require('./property-shape.cjs');
|
|
7
9
|
|
|
8
10
|
const DEFS_KEYWORD = "$defs";
|
|
9
11
|
function present(walk) {
|
|
10
12
|
return walk.presence === "present" ? walk.type : constructors.irReference("NonNullable", [walk.type]);
|
|
11
13
|
}
|
|
12
14
|
function indexEntries(walk, key, keyword, refs) {
|
|
13
|
-
const owner =
|
|
14
|
-
const child =
|
|
15
|
+
const owner = locatedNode.followLocated(walk, refs);
|
|
16
|
+
const child = locatedNode.isJsonObject(owner.node) ? owner.node[keyword] : void 0;
|
|
15
17
|
return {
|
|
16
18
|
...walk,
|
|
17
19
|
type: constructors.irIndexedAccess(present(walk), constructors.irKeyword(key)),
|
|
18
20
|
node: child,
|
|
19
|
-
|
|
21
|
+
location: locatedNode.childLocation(owner.location, keyword),
|
|
22
|
+
presence: propertyShape.schemaPresence(child, refs)
|
|
20
23
|
};
|
|
21
24
|
}
|
|
22
25
|
function nameStep(walk, name, isLast, input) {
|
|
23
|
-
const owner =
|
|
24
|
-
const
|
|
26
|
+
const owner = locatedNode.followLocated(walk, input.refs);
|
|
27
|
+
const { node } = owner;
|
|
28
|
+
const properties = locatedNode.isJsonObject(node) && locatedNode.isJsonObject(node.properties) ? node.properties : {};
|
|
29
|
+
const value = properties[name];
|
|
30
|
+
const { options, refs } = input;
|
|
31
|
+
const isMarkedOnTheWay = !isLast && propertyShape.isMarkedProperty(value, options, refs);
|
|
32
|
+
if (propertyShape.isExcludedProperty(value, options, refs) || isMarkedOnTheWay) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
25
35
|
const type = walk.presence === "present" ? refType.indexKeyword(walk.type, name, isLast) : refType.indexBy(present(walk), name);
|
|
26
36
|
return {
|
|
27
37
|
...walk,
|
|
28
38
|
type,
|
|
29
|
-
node:
|
|
39
|
+
node: value,
|
|
40
|
+
location: locatedNode.childLocation(walk.namesLocation, name),
|
|
30
41
|
isName: false,
|
|
31
|
-
presence:
|
|
42
|
+
presence: propertyShape.propertyPresence(walk, name, input.options, input.refs)
|
|
32
43
|
};
|
|
33
44
|
}
|
|
34
45
|
function defsStep(walk, owner, isLast) {
|
|
35
|
-
const
|
|
46
|
+
const { node } = owner;
|
|
47
|
+
const defs = locatedNode.isJsonObject(node) && locatedNode.isJsonObject(node[DEFS_KEYWORD]) ? node[DEFS_KEYWORD] : {};
|
|
48
|
+
const namesLocation = locatedNode.childLocation(owner.location, DEFS_KEYWORD);
|
|
36
49
|
return {
|
|
37
50
|
...walk,
|
|
38
51
|
type: refType.indexKeyword(present(walk), DEFS_KEYWORD, isLast),
|
|
52
|
+
// A node of its own, not in the document: its properties are the definitions.
|
|
39
53
|
node: { properties: defs, required: Object.keys(defs) },
|
|
54
|
+
location: namesLocation,
|
|
55
|
+
namesLocation,
|
|
40
56
|
isName: true,
|
|
41
57
|
presence: "present"
|
|
42
58
|
};
|
|
@@ -47,19 +63,19 @@ const SHAPED_KEYWORDS = /* @__PURE__ */ new Set([
|
|
|
47
63
|
"additionalProperties"
|
|
48
64
|
]);
|
|
49
65
|
function hasKeywordMember(owner, segment) {
|
|
50
|
-
if (!SHAPED_KEYWORDS.has(segment) || !
|
|
66
|
+
if (!SHAPED_KEYWORDS.has(segment) || !locatedNode.isJsonObject(owner)) {
|
|
51
67
|
return true;
|
|
52
68
|
}
|
|
53
69
|
return segment === "items" ? generatedShape.isArrayShape(owner) : generatedShape.isObjectShape(owner);
|
|
54
70
|
}
|
|
55
71
|
function keywordStep(walk, segment, isLast, input) {
|
|
56
|
-
const owner =
|
|
57
|
-
if (!hasKeywordMember(owner, segment)) {
|
|
72
|
+
const owner = locatedNode.followLocated(walk, input.refs);
|
|
73
|
+
if (!hasKeywordMember(owner.node, segment)) {
|
|
58
74
|
return null;
|
|
59
75
|
}
|
|
60
76
|
switch (segment) {
|
|
61
77
|
case "properties":
|
|
62
|
-
return { ...walk, isName: true };
|
|
78
|
+
return { ...walk, isName: true, namesLocation: locatedNode.childLocation(owner.location, segment) };
|
|
63
79
|
case "items":
|
|
64
80
|
return indexEntries(walk, "number", "items", input.refs);
|
|
65
81
|
case "additionalProperties":
|
|
@@ -72,15 +88,56 @@ function keywordStep(walk, segment, isLast, input) {
|
|
|
72
88
|
}
|
|
73
89
|
function containerStep(walk, index, input) {
|
|
74
90
|
const segment = input.pointer.segments[index];
|
|
75
|
-
const owner =
|
|
91
|
+
const owner = locatedNode.followRefs(walk.node, input.refs);
|
|
76
92
|
const isOptional = segment === "requestBody" && pointerWalk.isOptionalRequestBody(owner, input.refs) || pointerWalk.isOptionalHeader(input.pointer, index, owner);
|
|
77
93
|
return {
|
|
78
94
|
...walk,
|
|
79
95
|
type: refType.indexBy(present(walk), segment),
|
|
80
|
-
node:
|
|
96
|
+
node: locatedNode.isJsonObject(owner) ? owner[segment] : void 0,
|
|
97
|
+
location: locatedNode.childLocation(locatedNode.followLocated(walk, input.refs).location, segment),
|
|
81
98
|
presence: isOptional ? "absent" : "present"
|
|
82
99
|
};
|
|
83
100
|
}
|
|
101
|
+
function contentStep(walk, form, isLast, refs) {
|
|
102
|
+
const isMapTyped = form === "media-type-members" || form === "first-media-type" && !isLast;
|
|
103
|
+
if (!isMapTyped) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const owner = locatedNode.followLocated(walk, refs);
|
|
107
|
+
return {
|
|
108
|
+
...walk,
|
|
109
|
+
node: locatedNode.isJsonObject(owner.node) ? owner.node.content : void 0,
|
|
110
|
+
location: locatedNode.childLocation(owner.location, "content"),
|
|
111
|
+
isFirstMediaType: form === "first-media-type"
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function firstMediaTypeStep(walk, segment) {
|
|
115
|
+
const content = locatedNode.isJsonObject(walk.node) ? walk.node : {};
|
|
116
|
+
if (Object.keys(content)[0] !== segment) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const location = locatedNode.childLocation(walk.location, segment);
|
|
120
|
+
return { ...walk, node: content[segment], location, isFirstMediaType: false };
|
|
121
|
+
}
|
|
122
|
+
function schemaStep(walk, refs) {
|
|
123
|
+
const owner = locatedNode.followLocated(walk, refs);
|
|
124
|
+
const schema = locatedNode.isJsonObject(owner.node) ? owner.node.schema : void 0;
|
|
125
|
+
const location = locatedNode.childLocation(owner.location, "schema");
|
|
126
|
+
const presence = walk.presence === "absent" ? "absent" : propertyShape.schemaPresence(schema, refs);
|
|
127
|
+
return { ...walk, node: schema, location, isSchema: true, presence };
|
|
128
|
+
}
|
|
129
|
+
function documentStep(walk, index, input) {
|
|
130
|
+
const owner = locatedNode.followRefs(walk.node, input.refs);
|
|
131
|
+
const form = pointerWalk.headerParameterContentForm(input.pointer, index, owner, input.options);
|
|
132
|
+
if (form !== null) {
|
|
133
|
+
const isLast = index === input.pointer.segments.length - 1;
|
|
134
|
+
return contentStep(walk, form, isLast, input.refs);
|
|
135
|
+
}
|
|
136
|
+
if (pointerWalk.isParameterList(input.pointer, index) || pointerWalk.isExcludedOperation(input.pointer, index, owner, input)) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return containerStep(walk, index, input);
|
|
140
|
+
}
|
|
84
141
|
function step(walk, index, input) {
|
|
85
142
|
const { segments } = input.pointer;
|
|
86
143
|
const segment = segments[index];
|
|
@@ -88,17 +145,17 @@ function step(walk, index, input) {
|
|
|
88
145
|
if (walk.isSchema) {
|
|
89
146
|
return walk.isName ? nameStep(walk, segment, isLast, input) : keywordStep(walk, segment, isLast, input);
|
|
90
147
|
}
|
|
148
|
+
if (walk.isFirstMediaType) {
|
|
149
|
+
return firstMediaTypeStep(walk, segment);
|
|
150
|
+
}
|
|
91
151
|
if (segment === "schema" && pointerWalk.isTypedAsSchema(input.pointer, index)) {
|
|
92
|
-
|
|
93
|
-
const schema = generatedShape.isJsonObject(owner) ? owner.schema : void 0;
|
|
94
|
-
const presence = walk.presence === "absent" ? "absent" : generatedShape.schemaPresence(schema, input.refs);
|
|
95
|
-
return { ...walk, node: schema, isSchema: true, presence };
|
|
152
|
+
return schemaStep(walk, input.refs);
|
|
96
153
|
}
|
|
97
|
-
return
|
|
154
|
+
return documentStep(walk, index, input);
|
|
98
155
|
}
|
|
99
156
|
function typedWalk(input) {
|
|
100
157
|
const { pointer } = input;
|
|
101
|
-
const node = pointerWalk.
|
|
158
|
+
const { node, location } = pointerWalk.leadingLocated(pointer, input.refs);
|
|
102
159
|
const isSchema = pointerWalk.startsInSchema(pointer);
|
|
103
160
|
let walk = {
|
|
104
161
|
type: refType.indexBy(
|
|
@@ -106,9 +163,10 @@ function typedWalk(input) {
|
|
|
106
163
|
...pointer.segments.slice(0, pointerWalk.leadingSegmentsOf(pointer))
|
|
107
164
|
),
|
|
108
165
|
node,
|
|
166
|
+
location,
|
|
109
167
|
isSchema,
|
|
110
168
|
isName: false,
|
|
111
|
-
presence: isSchema ?
|
|
169
|
+
presence: isSchema ? propertyShape.schemaPresence(node, input.refs) : "present"
|
|
112
170
|
};
|
|
113
171
|
for (let index = pointerWalk.leadingSegmentsOf(pointer); index < pointer.segments.length; index++) {
|
|
114
172
|
const next = step(walk, index, input);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-walk.cjs","sources":["../../../../src/application/transform/ref-pointer/typed-walk.ts"],"sourcesContent":["import { irIndexedAccess, irKeyword, irReference } from \"../../../domain/ir/constructors.js\";\nimport type { IrKeyword, IrType } from \"../../../domain/ir/nodes.js\";\nimport { indexBy, indexKeyword, rootType } from \"../ref-type.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport {\n followRefs,\n isArrayShape,\n isJsonObject,\n isObjectShape,\n type Presence,\n propertyPresence,\n schemaPresence,\n} from \"./generated-shape.js\";\nimport {\n isOptionalHeader,\n isOptionalRequestBody,\n isParameterList,\n isTypedAsSchema,\n leadingNode,\n leadingSegmentsOf,\n type RefPointer,\n startsInSchema,\n} from \"./pointer-walk.js\";\n\n/**\n * The type of a `$ref` pointer as the generated types have it: the `schema` of a media type,\n * header or component parameter is its type, `items` is indexed by `number`,\n * `additionalProperties` by `string`, and a value that may be `undefined` or `null` is wrapped in\n * `NonNullable` before it is indexed. The walk stops at a segment with no type of its own\n * (`allOf/0`, `definitions/A`, operation `parameters/0`): the caller types the target itself.\n */\n\nconst DEFS_KEYWORD = \"$defs\";\n\nexport interface TypedWalk {\n readonly type: IrType;\n /** The document node the type stands for (not followed through a `$ref`). */\n readonly node: unknown;\n readonly isSchema: boolean;\n /** The segment is a property or `$defs` name, not a keyword. */\n readonly isName: boolean;\n readonly presence: Presence;\n}\n\nexport interface TypedWalkInput {\n readonly pointer: RefPointer;\n readonly options: SchemaOptions;\n readonly refs: RefResolver;\n}\n\n/** The walk result: a type, or the index of the first segment that has no type. */\nexport type TypedWalkResult =\n | { readonly kind: \"typed\"; readonly walk: TypedWalk }\n | { readonly kind: \"untyped\"; readonly index: number };\n\nfunction present(walk: TypedWalk): IrType {\n return walk.presence === \"present\" ? walk.type : irReference(\"NonNullable\", [walk.type]);\n}\n\nfunction indexEntries(walk: TypedWalk, key: IrKeyword, keyword: string, refs: RefResolver) {\n const owner = followRefs(walk.node, refs);\n const child = isJsonObject(owner) ? owner[keyword] : undefined;\n return {\n ...walk,\n type: irIndexedAccess(present(walk), irKeyword(key)),\n node: child,\n presence: schemaPresence(child, refs),\n };\n}\n\nfunction nameStep(walk: TypedWalk, name: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followRefs(walk.node, input.refs);\n const properties = isJsonObject(owner) && isJsonObject(owner.properties) ? owner.properties : {};\n const type =\n walk.presence === \"present\"\n ? indexKeyword(walk.type, name, isLast)\n : indexBy(present(walk), name);\n return {\n ...walk,\n type,\n node: properties[name],\n isName: false,\n presence: propertyPresence(walk.node, name, input.options, input.refs),\n };\n}\n\n/** `$defs` is optional (`NonNullable` when more follows); its members are present. */\nfunction defsStep(walk: TypedWalk, owner: unknown, isLast: boolean): TypedWalk {\n const defs = isJsonObject(owner) && isJsonObject(owner[DEFS_KEYWORD]) ? owner[DEFS_KEYWORD] : {};\n return {\n ...walk,\n type: indexKeyword(present(walk), DEFS_KEYWORD, isLast),\n node: { properties: defs, required: Object.keys(defs) },\n isName: true,\n presence: \"present\",\n };\n}\n\nconst SHAPED_KEYWORDS: ReadonlySet<string> = new Set([\n \"properties\",\n \"items\",\n \"additionalProperties\",\n]);\n\n/**\n * Whether the keyword gives the owner's generated type a member: `items` only an array,\n * `properties` and `additionalProperties` only an object (`type: string` ignores them). A node\n * that is not in the document is indexed as the keyword says.\n */\nfunction hasKeywordMember(owner: unknown, segment: string): boolean {\n if (!SHAPED_KEYWORDS.has(segment) || !isJsonObject(owner)) {\n return true;\n }\n return segment === \"items\" ? isArrayShape(owner) : isObjectShape(owner);\n}\n\nfunction keywordStep(walk: TypedWalk, segment: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followRefs(walk.node, input.refs);\n if (!hasKeywordMember(owner, segment)) {\n return null;\n }\n switch (segment) {\n case \"properties\":\n return { ...walk, isName: true };\n case \"items\":\n return indexEntries(walk, \"number\", \"items\", input.refs);\n case \"additionalProperties\":\n return indexEntries(walk, \"string\", \"additionalProperties\", input.refs);\n case DEFS_KEYWORD:\n return defsStep(walk, owner, isLast);\n default:\n return null;\n }\n}\n\nfunction containerStep(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk {\n const segment = input.pointer.segments[index] as string;\n const owner = followRefs(walk.node, input.refs);\n const isOptional =\n (segment === \"requestBody\" && isOptionalRequestBody(owner, input.refs)) ||\n isOptionalHeader(input.pointer, index, owner);\n return {\n ...walk,\n type: indexBy(present(walk), segment),\n node: isJsonObject(owner) ? owner[segment] : undefined,\n presence: isOptional ? \"absent\" : \"present\",\n };\n}\n\nfunction step(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk | null {\n const { segments } = input.pointer;\n const segment = segments[index] as string;\n const isLast = index === segments.length - 1;\n if (walk.isSchema) {\n return walk.isName\n ? nameStep(walk, segment, isLast, input)\n : keywordStep(walk, segment, isLast, input);\n }\n if (segment === \"schema\" && isTypedAsSchema(input.pointer, index)) {\n const owner = followRefs(walk.node, input.refs);\n const schema = isJsonObject(owner) ? owner.schema : undefined;\n // The container's type is its schema's type: an optional header stays optional.\n const presence = walk.presence === \"absent\" ? \"absent\" : schemaPresence(schema, input.refs);\n return { ...walk, node: schema, isSchema: true, presence };\n }\n return isParameterList(input.pointer, index) ? null : containerStep(walk, index, input);\n}\n\n/** Walk the whole pointer; see the module comment. */\nexport function typedWalk(input: TypedWalkInput): TypedWalkResult {\n const { pointer } = input;\n const node = leadingNode(pointer, input.refs);\n const isSchema = startsInSchema(pointer);\n let walk: TypedWalk = {\n type: indexBy(\n rootType(pointer.rootSegment, false),\n ...pointer.segments.slice(0, leadingSegmentsOf(pointer)),\n ),\n node,\n isSchema,\n isName: false,\n presence: isSchema ? schemaPresence(node, input.refs) : \"present\",\n };\n for (let index = leadingSegmentsOf(pointer); index < pointer.segments.length; index++) {\n const next = step(walk, index, input);\n if (next === null) {\n return { kind: \"untyped\", index };\n }\n walk = next;\n }\n return { kind: \"typed\", walk };\n}\n"],"names":["irReference","followRefs","isJsonObject","irIndexedAccess","irKeyword","schemaPresence","indexKeyword","indexBy","propertyPresence","isArrayShape","isObjectShape","isOptionalRequestBody","isOptionalHe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;AACpB,EAAA,MAAM,IAAA,GAAOC,uBAAA,CAAY,OAAA,EAAS,KAAA,CAAM,IAAI,CAAA;AAC5C,EAAA,MAAM,QAAA,GAAWC,2BAAe,OAAO,CAAA;AACvC,EAAA,IAAI,IAAA,GAAkB;AAAA,IACpB,IAAA,EAAMT,eAAA;AAAA,MACJU,gBAAA,CAAS,OAAA,CAAQ,WAAA,EAAa,KAAK,CAAA;AAAA,MACnC,GAAG,OAAA,CAAQ,QAAA,CAAS,MAAM,CAAA,EAAGC,6BAAA,CAAkB,OAAO,CAAC;AAAA,KACzD;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA,EAAQ,KAAA;AAAA,IACR,UAAU,QAAA,GAAWb,6BAAA,CAAe,IAAA,EAAM,KAAA,CAAM,IAAI,CAAA,GAAI;AAAA,GAC1D;AACA,EAAA,KAAA,IAAS,KAAA,GAAQa,8BAAkB,OAAO,CAAA,EAAG,QAAQ,OAAA,CAAQ,QAAA,CAAS,QAAQ,KAAA,EAAA,EAAS;AACrF,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,IAAA,EAAM,KAAA,EAAO,KAAK,CAAA;AACpC,IAAA,IAAI,SAAS,IAAA,EAAM;AACjB,MAAA,OAAO,EAAE,IAAA,EAAM,SAAA,EAAW,KAAA,EAAM;AAAA,IAClC;AACA,IAAA,IAAA,GAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAK;AAC/B;;"}
|
|
1
|
+
{"version":3,"file":"typed-walk.cjs","sources":["../../../../src/application/transform/ref-pointer/typed-walk.ts"],"sourcesContent":["import { irIndexedAccess, irKeyword, irReference } from \"../../../domain/ir/constructors.js\";\nimport type { IrKeyword, IrType } from \"../../../domain/ir/nodes.js\";\nimport { indexBy, indexKeyword, rootType } from \"../ref-type.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport { isArrayShape, isObjectShape } from \"./generated-shape.js\";\nimport {\n childLocation,\n followLocated,\n followRefs,\n isJsonObject,\n type LocatedNode,\n} from \"./located-node.js\";\nimport {\n type ContentForm,\n headerParameterContentForm,\n isExcludedOperation,\n isOptionalHeader,\n isOptionalRequestBody,\n isParameterList,\n isTypedAsSchema,\n leadingLocated,\n leadingSegmentsOf,\n type RefPointer,\n startsInSchema,\n} from \"./pointer-walk.js\";\nimport {\n isExcludedProperty,\n isMarkedProperty,\n type Presence,\n propertyPresence,\n schemaPresence,\n} from \"./property-shape.js\";\n\n/**\n * The type of a `$ref` pointer as the generated types have it: the `schema` of a media type,\n * header or component parameter is its type, `items` is indexed by `number`,\n * `additionalProperties` by `string`, and a value that may be `undefined` or `null` is wrapped in\n * `NonNullable` before it is indexed. The walk stops at a segment with no type of its own\n * (`allOf/0`, `definitions/A`, operation `parameters/0`): the caller types the target itself.\n */\n\nconst DEFS_KEYWORD = \"$defs\";\n\nexport interface TypedWalk {\n readonly type: IrType;\n /** The document node the type stands for (not followed through a `$ref`). */\n readonly node: unknown;\n /** The node's JSON Pointer, where the generator writes its type (`LocatedNode`). */\n readonly location: string | undefined;\n readonly isSchema: boolean;\n /** The segment is a property or `$defs` name, not a keyword. */\n readonly isName: boolean;\n /** The location of the map of names (`properties` or `$defs`) when `isName`. */\n readonly namesLocation?: string | undefined;\n /**\n * The node is the `content` of a header or parameter typed as its first media type, so the\n * next segment must name that media type and adds no member.\n */\n readonly isFirstMediaType?: boolean;\n readonly presence: Presence;\n}\n\nexport interface TypedWalkInput {\n readonly pointer: RefPointer;\n readonly options: SchemaOptions;\n readonly refs: RefResolver;\n}\n\n/** The walk result: a type, or the index of the first segment that has no type. */\nexport type TypedWalkResult =\n | { readonly kind: \"typed\"; readonly walk: TypedWalk }\n | { readonly kind: \"untyped\"; readonly index: number };\n\nfunction present(walk: TypedWalk): IrType {\n return walk.presence === \"present\" ? walk.type : irReference(\"NonNullable\", [walk.type]);\n}\n\nfunction indexEntries(walk: TypedWalk, key: IrKeyword, keyword: string, refs: RefResolver) {\n const owner = followLocated(walk, refs);\n const child = isJsonObject(owner.node) ? owner.node[keyword] : undefined;\n return {\n ...walk,\n type: irIndexedAccess(present(walk), irKeyword(key)),\n node: child,\n location: childLocation(owner.location, keyword),\n presence: schemaPresence(child, refs),\n };\n}\n\n/**\n * A property `--exclude-deprecated` left out has no member to index, and the `$Read<T>` or\n * `$Write<T>` of a marked property has no member but the marker's: such a pointer is typed in\n * place.\n */\nfunction nameStep(walk: TypedWalk, name: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followLocated(walk, input.refs);\n const { node } = owner;\n const properties = isJsonObject(node) && isJsonObject(node.properties) ? node.properties : {};\n const value = properties[name];\n const { options, refs } = input;\n const isMarkedOnTheWay = !isLast && isMarkedProperty(value, options, refs);\n if (isExcludedProperty(value, options, refs) || isMarkedOnTheWay) {\n return null;\n }\n const type =\n walk.presence === \"present\"\n ? indexKeyword(walk.type, name, isLast)\n : indexBy(present(walk), name);\n return {\n ...walk,\n type,\n node: value,\n location: childLocation(walk.namesLocation, name),\n isName: false,\n presence: propertyPresence(walk, name, input.options, input.refs),\n };\n}\n\n/** `$defs` is optional (`NonNullable` when more follows); its members are present. */\nfunction defsStep(walk: TypedWalk, owner: LocatedNode, isLast: boolean): TypedWalk {\n const { node } = owner;\n const defs = isJsonObject(node) && isJsonObject(node[DEFS_KEYWORD]) ? node[DEFS_KEYWORD] : {};\n const namesLocation = childLocation(owner.location, DEFS_KEYWORD);\n return {\n ...walk,\n type: indexKeyword(present(walk), DEFS_KEYWORD, isLast),\n // A node of its own, not in the document: its properties are the definitions.\n node: { properties: defs, required: Object.keys(defs) },\n location: namesLocation,\n namesLocation,\n isName: true,\n presence: \"present\",\n };\n}\n\nconst SHAPED_KEYWORDS: ReadonlySet<string> = new Set([\n \"properties\",\n \"items\",\n \"additionalProperties\",\n]);\n\n/**\n * Whether the keyword gives the owner's generated type a member: `items` only an array,\n * `properties` and `additionalProperties` only an object (`type: string` ignores them). A node\n * that is not in the document is indexed as the keyword says.\n */\nfunction hasKeywordMember(owner: unknown, segment: string): boolean {\n if (!SHAPED_KEYWORDS.has(segment) || !isJsonObject(owner)) {\n return true;\n }\n return segment === \"items\" ? isArrayShape(owner) : isObjectShape(owner);\n}\n\nfunction keywordStep(walk: TypedWalk, segment: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followLocated(walk, input.refs);\n if (!hasKeywordMember(owner.node, segment)) {\n return null;\n }\n switch (segment) {\n case \"properties\":\n return { ...walk, isName: true, namesLocation: childLocation(owner.location, segment) };\n case \"items\":\n return indexEntries(walk, \"number\", \"items\", input.refs);\n case \"additionalProperties\":\n return indexEntries(walk, \"string\", \"additionalProperties\", input.refs);\n case DEFS_KEYWORD:\n return defsStep(walk, owner, isLast);\n default:\n return null;\n }\n}\n\nfunction containerStep(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk {\n const segment = input.pointer.segments[index] as string;\n const owner = followRefs(walk.node, input.refs);\n const isOptional =\n (segment === \"requestBody\" && isOptionalRequestBody(owner, input.refs)) ||\n isOptionalHeader(input.pointer, index, owner);\n return {\n ...walk,\n type: indexBy(present(walk), segment),\n node: isJsonObject(owner) ? owner[segment] : undefined,\n location: childLocation(followLocated(walk, input.refs).location, segment),\n presence: isOptional ? \"absent\" : \"present\",\n };\n}\n\n/**\n * The `content` of a header or parameter: no member of its own, since the type holds its media\n * types (or the first one's type). Untyped where the type is `string` or a `schema`'s, and as the\n * last segment of the first media type form, whose type is not the map's.\n */\nfunction contentStep(walk: TypedWalk, form: ContentForm, isLast: boolean, refs: RefResolver) {\n const isMapTyped = form === \"media-type-members\" || (form === \"first-media-type\" && !isLast);\n if (!isMapTyped) {\n return null;\n }\n const owner = followLocated(walk, refs);\n return {\n ...walk,\n node: isJsonObject(owner.node) ? owner.node.content : undefined,\n location: childLocation(owner.location, \"content\"),\n isFirstMediaType: form === \"first-media-type\",\n };\n}\n\n/** The first media type of such a `content` is the type itself; another one has no type. */\nfunction firstMediaTypeStep(walk: TypedWalk, segment: string): TypedWalk | null {\n const content = isJsonObject(walk.node) ? walk.node : {};\n if (Object.keys(content)[0] !== segment) {\n return null;\n }\n const location = childLocation(walk.location, segment);\n return { ...walk, node: content[segment], location, isFirstMediaType: false };\n}\n\nfunction schemaStep(walk: TypedWalk, refs: RefResolver): TypedWalk {\n const owner = followLocated(walk, refs);\n const schema = isJsonObject(owner.node) ? owner.node.schema : undefined;\n const location = childLocation(owner.location, \"schema\");\n // The container's type is its schema's type: an optional header stays optional.\n const presence = walk.presence === \"absent\" ? \"absent\" : schemaPresence(schema, refs);\n return { ...walk, node: schema, location, isSchema: true, presence };\n}\n\nfunction documentStep(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk | null {\n const owner = followRefs(walk.node, input.refs);\n const form = headerParameterContentForm(input.pointer, index, owner, input.options);\n if (form !== null) {\n const isLast = index === input.pointer.segments.length - 1;\n return contentStep(walk, form, isLast, input.refs);\n }\n if (\n isParameterList(input.pointer, index) ||\n isExcludedOperation(input.pointer, index, owner, input)\n ) {\n return null;\n }\n return containerStep(walk, index, input);\n}\n\nfunction step(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk | null {\n const { segments } = input.pointer;\n const segment = segments[index] as string;\n const isLast = index === segments.length - 1;\n if (walk.isSchema) {\n return walk.isName\n ? nameStep(walk, segment, isLast, input)\n : keywordStep(walk, segment, isLast, input);\n }\n if (walk.isFirstMediaType) {\n return firstMediaTypeStep(walk, segment);\n }\n if (segment === \"schema\" && isTypedAsSchema(input.pointer, index)) {\n return schemaStep(walk, input.refs);\n }\n return documentStep(walk, index, input);\n}\n\n/** Walk the whole pointer; see the module comment. */\nexport function typedWalk(input: TypedWalkInput): TypedWalkResult {\n const { pointer } = input;\n const { node, location } = leadingLocated(pointer, input.refs);\n const isSchema = startsInSchema(pointer);\n let walk: TypedWalk = {\n type: indexBy(\n rootType(pointer.rootSegment, false),\n ...pointer.segments.slice(0, leadingSegmentsOf(pointer)),\n ),\n node,\n location,\n isSchema,\n isName: false,\n presence: isSchema ? schemaPresence(node, input.refs) : \"present\",\n };\n for (let index = leadingSegmentsOf(pointer); index < pointer.segments.length; index++) {\n const next = step(walk, index, input);\n if (next === null) {\n return { kind: \"untyped\", index };\n }\n walk = next;\n }\n return { kind: \"typed\", walk };\n}\n"],"names":["irReference","followLocated","isJsonObject","irIndexedAccess","irKeyword","childLocation","schemaPresence","isMarkedProperty","isExcludedProperty","indexKeyword","indexBy","propertyPresence","isArrayShape","isObjectShape","followRefs","isOptionalRequestBody","isOptionalHeader","headerParameterContentForm","isParameterList","isExcludedOperation","isTypedAsSchema","leadingLocated","startsInSchema","rootType","leadingSegmentsOf"],"mappings":";;;;;;;;;AAyCA,MAAM,YAAA,GAAe,OAAA;AAgCrB,SAAS,QAAQ,IAAA,EAAyB;AACxC,EAAA,OAAO,IAAA,CAAK,QAAA,KAAa,SAAA,GAAY,IAAA,CAAK,IAAA,GAAOA,yBAAY,aAAA,EAAe,CAAC,IAAA,CAAK,IAAI,CAAC,CAAA;AACzF;AAEA,SAAS,YAAA,CAAa,IAAA,EAAiB,GAAA,EAAgB,OAAA,EAAiB,IAAA,EAAmB;AACzF,EAAA,MAAM,KAAA,GAAQC,yBAAA,CAAc,IAAA,EAAM,IAAI,CAAA;AACtC,EAAA,MAAM,KAAA,GAAQC,yBAAa,KAAA,CAAM,IAAI,IAAI,KAAA,CAAM,IAAA,CAAK,OAAO,CAAA,GAAI,MAAA;AAC/D,EAAA,OAAO;AAAA,IACL,GAAG,IAAA;AAAA,IACH,MAAMC,4BAAA,CAAgB,OAAA,CAAQ,IAAI,CAAA,EAAGC,sBAAA,CAAU,GAAG,CAAC,CAAA;AAAA,IACnD,IAAA,EAAM,KAAA;AAAA,IACN,QAAA,EAAUC,yBAAA,CAAc,KAAA,CAAM,QAAA,EAAU,OAAO,CAAA;AAAA,IAC/C,QAAA,EAAUC,4BAAA,CAAe,KAAA,EAAO,IAAI;AAAA,GACtC;AACF;AAOA,SAAS,QAAA,CAAS,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