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
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const schemaTransform = require('../schema/schema-transform.cjs');
|
|
4
|
+
const typeCombinators = require('../type-combinators.cjs');
|
|
5
|
+
|
|
6
|
+
function refOf(value) {
|
|
7
|
+
const ref = value?.$ref;
|
|
8
|
+
return typeof ref === "string" ? ref : void 0;
|
|
9
|
+
}
|
|
10
|
+
function declaredSchema(schema, ref, context) {
|
|
11
|
+
let declared = { schema, path: ref };
|
|
12
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13
|
+
for (let next = refOf(schema); next !== void 0 && !seen.has(next); ) {
|
|
14
|
+
seen.add(next);
|
|
15
|
+
declared = { schema: context.refs.resolve(next), path: next };
|
|
16
|
+
next = refOf(declared.schema);
|
|
17
|
+
}
|
|
18
|
+
return declared;
|
|
19
|
+
}
|
|
20
|
+
function declaredObjectType(entry, context) {
|
|
21
|
+
const { original, resolved } = entry;
|
|
22
|
+
const schemaRef = refOf(resolved.schema);
|
|
23
|
+
if (schemaRef !== void 0) {
|
|
24
|
+
const { schema, path } = declaredSchema(resolved.schema, schemaRef, context);
|
|
25
|
+
return schemaTransform.transformSchema(schema, { path, schema }, context);
|
|
26
|
+
}
|
|
27
|
+
const parameterRef = refOf(original);
|
|
28
|
+
return parameterRef === void 0 ? null : schemaTransform.transformSchema(resolved.schema, { path: parameterRef, schema: resolved }, context);
|
|
29
|
+
}
|
|
30
|
+
function isIndexSignature(member) {
|
|
31
|
+
return member.kind === "indexSignature";
|
|
32
|
+
}
|
|
33
|
+
function hasIndexSignature(type) {
|
|
34
|
+
switch (type.kind) {
|
|
35
|
+
case "object":
|
|
36
|
+
return type.members.some(isIndexSignature);
|
|
37
|
+
case "union":
|
|
38
|
+
case "intersection":
|
|
39
|
+
return type.types.some(hasIndexSignature);
|
|
40
|
+
default:
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function widenedMember(member, values) {
|
|
45
|
+
const isUnknown = member.type.kind === "keyword" && member.type.keyword === "unknown";
|
|
46
|
+
return isIndexSignature(member) && !isUnknown ? { ...member, type: typeCombinators.unionOf([member.type, ...values]) } : member;
|
|
47
|
+
}
|
|
48
|
+
function withIndexValues(type, values) {
|
|
49
|
+
switch (type.kind) {
|
|
50
|
+
case "object":
|
|
51
|
+
return { ...type, members: type.members.map((member) => widenedMember(member, values)) };
|
|
52
|
+
case "union":
|
|
53
|
+
case "intersection":
|
|
54
|
+
return { ...type, types: type.types.map((member) => withIndexValues(member, values)) };
|
|
55
|
+
default:
|
|
56
|
+
return type;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.declaredObjectType = declaredObjectType;
|
|
61
|
+
exports.hasIndexSignature = hasIndexSignature;
|
|
62
|
+
exports.withIndexValues = withIndexValues;
|
|
63
|
+
//# sourceMappingURL=exploded-query-values.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exploded-query-values.cjs","sources":["../../../../src/application/transform/document/exploded-query-values.ts"],"sourcesContent":["import type { IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { ResolvedEntry } from \"./parameter-entries.js\";\n\n/**\n * `exploded-query-objects` and index signatures. The keys of an exploded object are keys of\n * `query`, next to the other parameters. TypeScript checks an index signature against every key\n * of a value, so `{ page?: number } & { [key: string]: string }` admits no `page`, and no value\n * with another parameter at all. An index signature of an exploded object therefore also takes\n * the value types of the other keys of `query`: those keys carry their own values.\n */\n\nfunction refOf(value: unknown): string | undefined {\n const ref = (value as { $ref?: unknown } | undefined)?.$ref;\n return typeof ref === \"string\" ? ref : undefined;\n}\n\n/** A schema `$ref` chain followed to its end, with the pointer where that schema is declared. */\nfunction declaredSchema(schema: Schema | undefined, ref: string, context: TransformContext) {\n let declared = { schema, path: ref };\n const seen = new Set<string>();\n for (let next = refOf(schema); next !== undefined && !seen.has(next); ) {\n seen.add(next);\n declared = { schema: context.refs.resolve(next) as Schema | undefined, path: next };\n next = refOf(declared.schema);\n }\n return declared;\n}\n\n/**\n * The type of an exploded parameter whose own type is a reference (its `$ref`, or the `$ref` of\n * its schema), written out where its schema is declared: the index signature of a referenced type\n * cannot be changed. The location is the one `components` types it at, so the enums it declares\n * are the ones the reference names. Null when no `$ref` is involved.\n */\nexport function declaredObjectType(entry: ResolvedEntry, context: TransformContext): IrType | null {\n const { original, resolved } = entry;\n const schemaRef = refOf(resolved.schema);\n if (schemaRef !== undefined) {\n const { schema, path } = declaredSchema(resolved.schema, schemaRef, context);\n return transformSchema(schema, { path, schema }, context);\n }\n const parameterRef = refOf(original);\n return parameterRef === undefined\n ? null\n : transformSchema(resolved.schema, { path: parameterRef, schema: resolved }, context);\n}\n\nfunction isIndexSignature(member: IrMember): boolean {\n return member.kind === \"indexSignature\";\n}\n\n/** Whether the type has an index signature in its objects, through unions and intersections. */\nexport function hasIndexSignature(type: IrType): boolean {\n switch (type.kind) {\n case \"object\":\n return type.members.some(isIndexSignature);\n case \"union\":\n case \"intersection\":\n return type.types.some(hasIndexSignature);\n default:\n return false;\n }\n}\n\nfunction widenedMember(member: IrMember, values: readonly IrType[]): IrMember {\n // `unknown` takes every value already.\n const isUnknown = member.type.kind === \"keyword\" && member.type.keyword === \"unknown\";\n return isIndexSignature(member) && !isUnknown\n ? { ...member, type: unionOf([member.type, ...values]) }\n : member;\n}\n\n/** The type with the values added to each index signature of its objects. */\nexport function withIndexValues(type: IrType, values: readonly IrType[]): IrType {\n switch (type.kind) {\n case \"object\":\n return { ...type, members: type.members.map((member) => widenedMember(member, values)) };\n case \"union\":\n case \"intersection\":\n return { ...type, types: type.types.map((member) => withIndexValues(member, values)) };\n default:\n return type;\n }\n}\n"],"names":["transformSchema","unionOf"],"mappings":";;;;;AAeA,SAAS,MAAM,KAAA,EAAoC;AACjD,EAAA,MAAM,MAAO,KAAA,EAA0C,IAAA;AACvD,EAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,GAAW,GAAA,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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { transformSchema } from '../schema/schema-transform.mjs';
|
|
2
|
+
import { unionOf } from '../type-combinators.mjs';
|
|
3
|
+
|
|
4
|
+
function refOf(value) {
|
|
5
|
+
const ref = value?.$ref;
|
|
6
|
+
return typeof ref === "string" ? ref : void 0;
|
|
7
|
+
}
|
|
8
|
+
function declaredSchema(schema, ref, context) {
|
|
9
|
+
let declared = { schema, path: ref };
|
|
10
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11
|
+
for (let next = refOf(schema); next !== void 0 && !seen.has(next); ) {
|
|
12
|
+
seen.add(next);
|
|
13
|
+
declared = { schema: context.refs.resolve(next), path: next };
|
|
14
|
+
next = refOf(declared.schema);
|
|
15
|
+
}
|
|
16
|
+
return declared;
|
|
17
|
+
}
|
|
18
|
+
function declaredObjectType(entry, context) {
|
|
19
|
+
const { original, resolved } = entry;
|
|
20
|
+
const schemaRef = refOf(resolved.schema);
|
|
21
|
+
if (schemaRef !== void 0) {
|
|
22
|
+
const { schema, path } = declaredSchema(resolved.schema, schemaRef, context);
|
|
23
|
+
return transformSchema(schema, { path, schema }, context);
|
|
24
|
+
}
|
|
25
|
+
const parameterRef = refOf(original);
|
|
26
|
+
return parameterRef === void 0 ? null : transformSchema(resolved.schema, { path: parameterRef, schema: resolved }, context);
|
|
27
|
+
}
|
|
28
|
+
function isIndexSignature(member) {
|
|
29
|
+
return member.kind === "indexSignature";
|
|
30
|
+
}
|
|
31
|
+
function hasIndexSignature(type) {
|
|
32
|
+
switch (type.kind) {
|
|
33
|
+
case "object":
|
|
34
|
+
return type.members.some(isIndexSignature);
|
|
35
|
+
case "union":
|
|
36
|
+
case "intersection":
|
|
37
|
+
return type.types.some(hasIndexSignature);
|
|
38
|
+
default:
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function widenedMember(member, values) {
|
|
43
|
+
const isUnknown = member.type.kind === "keyword" && member.type.keyword === "unknown";
|
|
44
|
+
return isIndexSignature(member) && !isUnknown ? { ...member, type: unionOf([member.type, ...values]) } : member;
|
|
45
|
+
}
|
|
46
|
+
function withIndexValues(type, values) {
|
|
47
|
+
switch (type.kind) {
|
|
48
|
+
case "object":
|
|
49
|
+
return { ...type, members: type.members.map((member) => widenedMember(member, values)) };
|
|
50
|
+
case "union":
|
|
51
|
+
case "intersection":
|
|
52
|
+
return { ...type, types: type.types.map((member) => withIndexValues(member, values)) };
|
|
53
|
+
default:
|
|
54
|
+
return type;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { declaredObjectType, hasIndexSignature, withIndexValues };
|
|
59
|
+
//# sourceMappingURL=exploded-query-values.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exploded-query-values.mjs","sources":["../../../../src/application/transform/document/exploded-query-values.ts"],"sourcesContent":["import type { IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { ResolvedEntry } from \"./parameter-entries.js\";\n\n/**\n * `exploded-query-objects` and index signatures. The keys of an exploded object are keys of\n * `query`, next to the other parameters. TypeScript checks an index signature against every key\n * of a value, so `{ page?: number } & { [key: string]: string }` admits no `page`, and no value\n * with another parameter at all. An index signature of an exploded object therefore also takes\n * the value types of the other keys of `query`: those keys carry their own values.\n */\n\nfunction refOf(value: unknown): string | undefined {\n const ref = (value as { $ref?: unknown } | undefined)?.$ref;\n return typeof ref === \"string\" ? ref : undefined;\n}\n\n/** A schema `$ref` chain followed to its end, with the pointer where that schema is declared. */\nfunction declaredSchema(schema: Schema | undefined, ref: string, context: TransformContext) {\n let declared = { schema, path: ref };\n const seen = new Set<string>();\n for (let next = refOf(schema); next !== undefined && !seen.has(next); ) {\n seen.add(next);\n declared = { schema: context.refs.resolve(next) as Schema | undefined, path: next };\n next = refOf(declared.schema);\n }\n return declared;\n}\n\n/**\n * The type of an exploded parameter whose own type is a reference (its `$ref`, or the `$ref` of\n * its schema), written out where its schema is declared: the index signature of a referenced type\n * cannot be changed. The location is the one `components` types it at, so the enums it declares\n * are the ones the reference names. Null when no `$ref` is involved.\n */\nexport function declaredObjectType(entry: ResolvedEntry, context: TransformContext): IrType | null {\n const { original, resolved } = entry;\n const schemaRef = refOf(resolved.schema);\n if (schemaRef !== undefined) {\n const { schema, path } = declaredSchema(resolved.schema, schemaRef, context);\n return transformSchema(schema, { path, schema }, context);\n }\n const parameterRef = refOf(original);\n return parameterRef === undefined\n ? null\n : transformSchema(resolved.schema, { path: parameterRef, schema: resolved }, context);\n}\n\nfunction isIndexSignature(member: IrMember): boolean {\n return member.kind === \"indexSignature\";\n}\n\n/** Whether the type has an index signature in its objects, through unions and intersections. */\nexport function hasIndexSignature(type: IrType): boolean {\n switch (type.kind) {\n case \"object\":\n return type.members.some(isIndexSignature);\n case \"union\":\n case \"intersection\":\n return type.types.some(hasIndexSignature);\n default:\n return false;\n }\n}\n\nfunction widenedMember(member: IrMember, values: readonly IrType[]): IrMember {\n // `unknown` takes every value already.\n const isUnknown = member.type.kind === \"keyword\" && member.type.keyword === \"unknown\";\n return isIndexSignature(member) && !isUnknown\n ? { ...member, type: unionOf([member.type, ...values]) }\n : member;\n}\n\n/** The type with the values added to each index signature of its objects. */\nexport function withIndexValues(type: IrType, values: readonly IrType[]): IrType {\n switch (type.kind) {\n case \"object\":\n return { ...type, members: type.members.map((member) => widenedMember(member, values)) };\n case \"union\":\n case \"intersection\":\n return { ...type, types: type.types.map((member) => withIndexValues(member, values)) };\n default:\n return type;\n }\n}\n"],"names":[],"mappings":";;;AAeA,SAAS,MAAM,KAAA,EAAoC;AACjD,EAAA,MAAM,MAAO,KAAA,EAA0C,IAAA;AACvD,EAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,GAAW,GAAA,GAAM,MAAA;AACzC;AAGA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
2
|
|
|
3
3
|
const constructors = require('../../../domain/ir/constructors.cjs');
|
|
4
4
|
const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
|
|
5
|
+
const outputFixes = require('../../../domain/output-fixes.cjs');
|
|
5
6
|
const documentEntries = require('../document-entries.cjs');
|
|
6
7
|
const schemaTransform = require('../schema/schema-transform.cjs');
|
|
7
8
|
const sharedTypes = require('../shared-types.cjs');
|
|
8
9
|
const documentMember = require('./document-member.cjs');
|
|
9
|
-
const mediaType = require('./media-type.cjs');
|
|
10
|
+
const mediaType$1 = require('./media-type.cjs');
|
|
10
11
|
|
|
11
12
|
function headerType(header, location, context) {
|
|
12
13
|
if (header.schema) {
|
|
@@ -15,13 +16,20 @@ function headerType(header, location, context) {
|
|
|
15
16
|
if (!header.content) {
|
|
16
17
|
return sharedTypes.UNKNOWN_TYPE;
|
|
17
18
|
}
|
|
19
|
+
if (context.options.fixes.has(outputFixes.FIX.PARAMETER_HEADER_CONTENT)) {
|
|
20
|
+
const first = Object.entries(header.content)[0];
|
|
21
|
+
return first === void 0 ? sharedTypes.UNKNOWN_TYPE : mediaType(...first, location, context);
|
|
22
|
+
}
|
|
18
23
|
const members = documentEntries.documentEntries(header.content, context.options).map(([contentType, entry]) => {
|
|
19
|
-
const
|
|
20
|
-
const type = mediaType.contentEntryType(entry, { ...location, path }, context);
|
|
24
|
+
const type = mediaType(contentType, entry, location, context);
|
|
21
25
|
return documentMember.documentMember(contentType, type, entry, { isReadonly: context.options.immutable });
|
|
22
26
|
});
|
|
23
27
|
return constructors.irObject(members);
|
|
24
28
|
}
|
|
29
|
+
function mediaType(contentType, entry, location, context) {
|
|
30
|
+
const path = `${location.path ?? "#"}/${jsonPointer.escapePointerSegment(contentType)}`;
|
|
31
|
+
return mediaType$1.contentEntryType(entry, { ...location, path }, context);
|
|
32
|
+
}
|
|
25
33
|
|
|
26
34
|
exports.headerType = headerType;
|
|
27
35
|
//# sourceMappingURL=header.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"header.cjs","sources":["../../../../src/application/transform/document/header.ts"],"sourcesContent":["import { irObject } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { HeaderObject } from \"../../../domain/openapi/header-object.js\";\nimport { escapePointerSegment } from \"../../../domain/openapi/json-pointer.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A header's type (OpenAPI 3.1 §4.8.21): its schema, else an object with one property per media\n * type
|
|
1
|
+
{"version":3,"file":"header.cjs","sources":["../../../../src/application/transform/document/header.ts"],"sourcesContent":["import { irObject } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { HeaderObject } from \"../../../domain/openapi/header-object.js\";\nimport { escapePointerSegment } from \"../../../domain/openapi/json-pointer.js\";\nimport type { ContentMap } from \"../../../domain/openapi/media-type-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A header's type (OpenAPI 3.1 §4.8.21): its schema, else the type of its `content`, else\n * `unknown`. `content` holds one media type whose schema describes the value; the original typed\n * it as an object with one property per media type, which the `parameter-header-content` fix\n * replaces by the media type's type, as for a parameter.\n */\nexport function headerType(\n header: HeaderObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (header.schema) {\n return transformSchema(header.schema, location, context);\n }\n if (!header.content) {\n return UNKNOWN_TYPE;\n }\n if (context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT)) {\n // The first media type in document order, as for a parameter: `--alphabetize` sorts only\n // the members it writes.\n const first = Object.entries(header.content)[0];\n return first === undefined ? UNKNOWN_TYPE : mediaType(...first, location, context);\n }\n const members = documentEntries(header.content, context.options).map(([contentType, entry]) => {\n const type = mediaType(contentType, entry, location, context);\n return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n\n/** The type of one media type of a header, at the path the original gave it. */\nfunction mediaType(\n contentType: string,\n entry: ContentMap[string],\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n // Unlike other content maps, the original joins this path by hand: a missing path is `#`.\n const path = `${location.path ?? \"#\"}/${escapePointerSegment(contentType)}`;\n return contentEntryType(entry, { ...location, path }, context);\n}\n"],"names":["transformSchema","UNKNOWN_TYPE","FIX","documentEntries","documentMember","irObject","escapePointerSegment","contentEntryType"],"mappings":";;;;;;;;;;;AAmBO,SAAS,UAAA,CACd,MAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,OAAO,MAAA,EAAQ;AACjB,IAAA,OAAOA,+BAAA,CAAgB,MAAA,CAAO,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AAAA,EACzD;AACA,EAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,IAAA,OAAOC,wBAAA;AAAA,EACT;AACA,EAAA,IAAI,QAAQ,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAIC,eAAA,CAAI,wBAAwB,CAAA,EAAG;AAG3D,IAAA,MAAM,QAAQ,MAAA,CAAO,OAAA,CAAQ,MAAA,CAAO,OAAO,EAAE,CAAC,CAAA;AAC9C,IAAA,OAAO,UAAU,MAAA,GAAYD,wBAAA,GAAe,UAAU,GAAG,KAAA,EAAO,UAAU,OAAO,CAAA;AAAA,EACnF;AACA,EAAA,MAAM,OAAA,GAAUE,+BAAA,CAAgB,MAAA,CAAO,OAAA,EAAS,OAAA,CAAQ,OAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,WAAA,EAAa,KAAK,CAAA,KAAM;AAC7F,IAAA,MAAM,IAAA,GAAO,SAAA,CAAU,WAAA,EAAa,KAAA,EAAO,UAAU,OAAO,CAAA;AAC5D,IAAA,OAAOC,6BAAA,CAAe,aAAa,IAAA,EAAM,KAAA,EAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EAC3F,CAAC,CAAA;AACD,EAAA,OAAOC,sBAAS,OAAO,CAAA;AACzB;AAGA,SAAS,SAAA,CACP,WAAA,EACA,KAAA,EACA,QAAA,EACA,OAAA,EACQ;AAER,EAAA,MAAM,IAAA,GAAO,GAAG,QAAA,CAAS,IAAA,IAAQ,GAAG,CAAA,CAAA,EAAIC,gCAAA,CAAqB,WAAW,CAAC,CAAA,CAAA;AACzE,EAAA,OAAOC,6BAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AAC/D;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { irObject } from '../../../domain/ir/constructors.mjs';
|
|
2
2
|
import { escapePointerSegment } from '../../../domain/openapi/json-pointer.mjs';
|
|
3
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
3
4
|
import { documentEntries } from '../document-entries.mjs';
|
|
4
5
|
import { transformSchema } from '../schema/schema-transform.mjs';
|
|
5
6
|
import { UNKNOWN_TYPE } from '../shared-types.mjs';
|
|
@@ -13,13 +14,20 @@ function headerType(header, location, context) {
|
|
|
13
14
|
if (!header.content) {
|
|
14
15
|
return UNKNOWN_TYPE;
|
|
15
16
|
}
|
|
17
|
+
if (context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT)) {
|
|
18
|
+
const first = Object.entries(header.content)[0];
|
|
19
|
+
return first === void 0 ? UNKNOWN_TYPE : mediaType(...first, location, context);
|
|
20
|
+
}
|
|
16
21
|
const members = documentEntries(header.content, context.options).map(([contentType, entry]) => {
|
|
17
|
-
const
|
|
18
|
-
const type = contentEntryType(entry, { ...location, path }, context);
|
|
22
|
+
const type = mediaType(contentType, entry, location, context);
|
|
19
23
|
return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });
|
|
20
24
|
});
|
|
21
25
|
return irObject(members);
|
|
22
26
|
}
|
|
27
|
+
function mediaType(contentType, entry, location, context) {
|
|
28
|
+
const path = `${location.path ?? "#"}/${escapePointerSegment(contentType)}`;
|
|
29
|
+
return contentEntryType(entry, { ...location, path }, context);
|
|
30
|
+
}
|
|
23
31
|
|
|
24
32
|
export { headerType };
|
|
25
33
|
//# sourceMappingURL=header.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"header.mjs","sources":["../../../../src/application/transform/document/header.ts"],"sourcesContent":["import { irObject } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { HeaderObject } from \"../../../domain/openapi/header-object.js\";\nimport { escapePointerSegment } from \"../../../domain/openapi/json-pointer.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A header's type (OpenAPI 3.1 §4.8.21): its schema, else an object with one property per media\n * type
|
|
1
|
+
{"version":3,"file":"header.mjs","sources":["../../../../src/application/transform/document/header.ts"],"sourcesContent":["import { irObject } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { HeaderObject } from \"../../../domain/openapi/header-object.js\";\nimport { escapePointerSegment } from \"../../../domain/openapi/json-pointer.js\";\nimport type { ContentMap } from \"../../../domain/openapi/media-type-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A header's type (OpenAPI 3.1 §4.8.21): its schema, else the type of its `content`, else\n * `unknown`. `content` holds one media type whose schema describes the value; the original typed\n * it as an object with one property per media type, which the `parameter-header-content` fix\n * replaces by the media type's type, as for a parameter.\n */\nexport function headerType(\n header: HeaderObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (header.schema) {\n return transformSchema(header.schema, location, context);\n }\n if (!header.content) {\n return UNKNOWN_TYPE;\n }\n if (context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT)) {\n // The first media type in document order, as for a parameter: `--alphabetize` sorts only\n // the members it writes.\n const first = Object.entries(header.content)[0];\n return first === undefined ? UNKNOWN_TYPE : mediaType(...first, location, context);\n }\n const members = documentEntries(header.content, context.options).map(([contentType, entry]) => {\n const type = mediaType(contentType, entry, location, context);\n return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n\n/** The type of one media type of a header, at the path the original gave it. */\nfunction mediaType(\n contentType: string,\n entry: ContentMap[string],\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n // Unlike other content maps, the original joins this path by hand: a missing path is `#`.\n const path = `${location.path ?? \"#\"}/${escapePointerSegment(contentType)}`;\n return contentEntryType(entry, { ...location, path }, context);\n}\n"],"names":[],"mappings":";;;;;;;;;AAmBO,SAAS,UAAA,CACd,MAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,OAAO,MAAA,EAAQ;AACjB,IAAA,OAAO,eAAA,CAAgB,MAAA,CAAO,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AAAA,EACzD;AACA,EAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,IAAA,OAAO,YAAA;AAAA,EACT;AACA,EAAA,IAAI,QAAQ,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAI,GAAA,CAAI,wBAAwB,CAAA,EAAG;AAG3D,IAAA,MAAM,QAAQ,MAAA,CAAO,OAAA,CAAQ,MAAA,CAAO,OAAO,EAAE,CAAC,CAAA;AAC9C,IAAA,OAAO,UAAU,MAAA,GAAY,YAAA,GAAe,UAAU,GAAG,KAAA,EAAO,UAAU,OAAO,CAAA;AAAA,EACnF;AACA,EAAA,MAAM,OAAA,GAAU,eAAA,CAAgB,MAAA,CAAO,OAAA,EAAS,OAAA,CAAQ,OAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,WAAA,EAAa,KAAK,CAAA,KAAM;AAC7F,IAAA,MAAM,IAAA,GAAO,SAAA,CAAU,WAAA,EAAa,KAAA,EAAO,UAAU,OAAO,CAAA;AAC5D,IAAA,OAAO,cAAA,CAAe,aAAa,IAAA,EAAM,KAAA,EAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EAC3F,CAAC,CAAA;AACD,EAAA,OAAO,SAAS,OAAO,CAAA;AACzB;AAGA,SAAS,SAAA,CACP,WAAA,EACA,KAAA,EACA,QAAA,EACA,OAAA,EACQ;AAER,EAAA,MAAM,IAAA,GAAO,GAAG,QAAA,CAAS,IAAA,IAAQ,GAAG,CAAA,CAAA,EAAI,oBAAA,CAAqB,WAAW,CAAC,CAAA,CAAA;AACzE,EAAA,OAAO,iBAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AAC/D;;"}
|
|
@@ -20,7 +20,7 @@ function isTypedByContent(parameter, context) {
|
|
|
20
20
|
return true;
|
|
21
21
|
}
|
|
22
22
|
const hasContent = parameter.schema === void 0 && parameter.content !== void 0;
|
|
23
|
-
return hasContent && context.options.fixes.has(outputFixes.FIX.
|
|
23
|
+
return hasContent && context.options.fixes.has(outputFixes.FIX.PARAMETER_HEADER_CONTENT);
|
|
24
24
|
}
|
|
25
25
|
function parameterType(parameter, location, context) {
|
|
26
26
|
if (isTypedByContent(parameter, context)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameter.cjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ParameterObject,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A parameter typed by the schema of its one `content` media type. An `in: querystring` parameter\n * (OpenAPI 3.2) is the whole query string (ADR-020); without a media type it is `string`, the\n * query string as text. With the `parameter-content` fix, any other parameter with `content`\n * (OpenAPI 3.0 and later, for a JSON value in a query parameter) is typed the same way.\n */\nfunction contentParameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const [mediaType, entry] = Object.entries(parameter.content ?? {})[0] ?? [];\n if (mediaType === undefined || entry === undefined) {\n return irKeyword(\"string\");\n }\n const path = appendPointer(location.path, [\"content\", mediaType]);\n return contentEntryType(entry, { ...location, path }, context);\n}\n\nfunction isTypedByContent(parameter: ParameterObject, context: SchemaContext): boolean {\n if (parameter.in === QUERYSTRING_LOCATION) {\n return true;\n }\n const hasContent = parameter.schema === undefined && parameter.content !== undefined;\n return hasContent && context.options.fixes.has(FIX.
|
|
1
|
+
{"version":3,"file":"parameter.cjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ParameterObject,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A parameter typed by the schema of its one `content` media type. An `in: querystring` parameter\n * (OpenAPI 3.2) is the whole query string (ADR-020); without a media type it is `string`, the\n * query string as text. With the `parameter-header-content` fix, any other parameter with `content`\n * (OpenAPI 3.0 and later, for a JSON value in a query parameter) is typed the same way.\n */\nfunction contentParameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const [mediaType, entry] = Object.entries(parameter.content ?? {})[0] ?? [];\n if (mediaType === undefined || entry === undefined) {\n return irKeyword(\"string\");\n }\n const path = appendPointer(location.path, [\"content\", mediaType]);\n return contentEntryType(entry, { ...location, path }, context);\n}\n\nfunction isTypedByContent(parameter: ParameterObject, context: SchemaContext): boolean {\n if (parameter.in === QUERYSTRING_LOCATION) {\n return true;\n }\n const hasContent = parameter.schema === undefined && parameter.content !== undefined;\n return hasContent && context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT);\n}\n\n/**\n * A parameter's type (OpenAPI 3.2 §4.8.12). Without a schema it is `string`, not `unknown`:\n * query, path, header and cookie values all arrive as text. `content` is read for\n * `in: querystring`, and with the `parameter-header-content` fix for every parameter; without\n * the fix other parameters with `content` keep the original's `string`.\n */\nexport function parameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (isTypedByContent(parameter, context)) {\n return contentParameterType(parameter, location, context);\n }\n return parameter.schema\n ? transformSchema(parameter.schema, location, context)\n : irKeyword(\"string\");\n}\n"],"names":["mediaType","irKeyword","appendPointer","contentEntryType","QUERYSTRING_LOCATION","FIX","transformSchema"],"mappings":";;;;;;;;;AAkBA,SAAS,oBAAA,CACP,SAAA,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const hasContent = parameter.schema === void 0 && parameter.content !== void 0;
|
|
21
|
-
return hasContent && context.options.fixes.has(FIX.
|
|
21
|
+
return hasContent && context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT);
|
|
22
22
|
}
|
|
23
23
|
function parameterType(parameter, location, context) {
|
|
24
24
|
if (isTypedByContent(parameter, context)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameter.mjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ParameterObject,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A parameter typed by the schema of its one `content` media type. An `in: querystring` parameter\n * (OpenAPI 3.2) is the whole query string (ADR-020); without a media type it is `string`, the\n * query string as text. With the `parameter-content` fix, any other parameter with `content`\n * (OpenAPI 3.0 and later, for a JSON value in a query parameter) is typed the same way.\n */\nfunction contentParameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const [mediaType, entry] = Object.entries(parameter.content ?? {})[0] ?? [];\n if (mediaType === undefined || entry === undefined) {\n return irKeyword(\"string\");\n }\n const path = appendPointer(location.path, [\"content\", mediaType]);\n return contentEntryType(entry, { ...location, path }, context);\n}\n\nfunction isTypedByContent(parameter: ParameterObject, context: SchemaContext): boolean {\n if (parameter.in === QUERYSTRING_LOCATION) {\n return true;\n }\n const hasContent = parameter.schema === undefined && parameter.content !== undefined;\n return hasContent && context.options.fixes.has(FIX.
|
|
1
|
+
{"version":3,"file":"parameter.mjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ParameterObject,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A parameter typed by the schema of its one `content` media type. An `in: querystring` parameter\n * (OpenAPI 3.2) is the whole query string (ADR-020); without a media type it is `string`, the\n * query string as text. With the `parameter-header-content` fix, any other parameter with `content`\n * (OpenAPI 3.0 and later, for a JSON value in a query parameter) is typed the same way.\n */\nfunction contentParameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const [mediaType, entry] = Object.entries(parameter.content ?? {})[0] ?? [];\n if (mediaType === undefined || entry === undefined) {\n return irKeyword(\"string\");\n }\n const path = appendPointer(location.path, [\"content\", mediaType]);\n return contentEntryType(entry, { ...location, path }, context);\n}\n\nfunction isTypedByContent(parameter: ParameterObject, context: SchemaContext): boolean {\n if (parameter.in === QUERYSTRING_LOCATION) {\n return true;\n }\n const hasContent = parameter.schema === undefined && parameter.content !== undefined;\n return hasContent && context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT);\n}\n\n/**\n * A parameter's type (OpenAPI 3.2 §4.8.12). Without a schema it is `string`, not `unknown`:\n * query, path, header and cookie values all arrive as text. `content` is read for\n * `in: querystring`, and with the `parameter-header-content` fix for every parameter; without\n * the fix other parameters with `content` keep the original's `string`.\n */\nexport function parameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (isTypedByContent(parameter, context)) {\n return contentParameterType(parameter, location, context);\n }\n return parameter.schema\n ? transformSchema(parameter.schema, location, context)\n : irKeyword(\"string\");\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.cjs');
|
|
|
5
5
|
const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
|
|
6
6
|
const parameterObject = require('../../../domain/openapi/parameter-object.cjs');
|
|
7
7
|
const outputFixes = require('../../../domain/output-fixes.cjs');
|
|
8
|
+
const declaredValueTypes = require('../declared-value-types.cjs');
|
|
8
9
|
const schemaComment = require('../schema-comment.cjs');
|
|
9
10
|
const explodedQuery = require('./exploded-query.cjs');
|
|
11
|
+
const explodedQueryValues = require('./exploded-query-values.cjs');
|
|
10
12
|
const parameter = require('./parameter.cjs');
|
|
11
13
|
const parameterEntries = require('./parameter-entries.cjs');
|
|
12
14
|
const referencedParameter = require('./referenced-parameter.cjs');
|
|
@@ -67,9 +69,25 @@ function querystringMember(entries, location, context) {
|
|
|
67
69
|
function isExplodedEntry(entry, context) {
|
|
68
70
|
return context.options.fixes.has(outputFixes.FIX.EXPLODED_QUERY_OBJECTS) && explodedQuery.isExplodedQueryObject(entry.resolved, context.refs);
|
|
69
71
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
function explodedObjectType({ entry, type }, hasOtherKeys, context) {
|
|
73
|
+
if (!hasOtherKeys) {
|
|
74
|
+
return type;
|
|
75
|
+
}
|
|
76
|
+
const declared = explodedQueryValues.declaredObjectType(entry, context);
|
|
77
|
+
return declared !== null && explodedQueryValues.hasIndexSignature(declared) ? declared : type;
|
|
78
|
+
}
|
|
79
|
+
function explodedParts(exploded, members, context) {
|
|
80
|
+
const hasOtherKeys = members.length > 0 || exploded.length > 1;
|
|
81
|
+
const types = exploded.map((part) => explodedObjectType(part, hasOtherKeys, context));
|
|
82
|
+
const others = (index) => [
|
|
83
|
+
...members.length > 0 ? [constructors.irObject(members)] : [],
|
|
84
|
+
...types.filter((_type, other) => other !== index)
|
|
85
|
+
];
|
|
86
|
+
return types.map((type, index) => {
|
|
87
|
+
const values = others(index).flatMap((other) => declaredValueTypes.declaredValueTypes(other, context.footer));
|
|
88
|
+
const widened = explodedQueryValues.withIndexValues(type, values);
|
|
89
|
+
return exploded[index]?.entry.resolved.required ? widened : constructors.irReference("Partial", [widened]);
|
|
90
|
+
});
|
|
73
91
|
}
|
|
74
92
|
function locationParts(entries, location, context) {
|
|
75
93
|
const members = [];
|
|
@@ -77,7 +95,7 @@ function locationParts(entries, location, context) {
|
|
|
77
95
|
let isOptional = true;
|
|
78
96
|
for (const entry of entries) {
|
|
79
97
|
if (isExplodedEntry(entry, context)) {
|
|
80
|
-
exploded.push(
|
|
98
|
+
exploded.push({ entry, type: entryType(entry, location, context) });
|
|
81
99
|
isOptional &&= !entry.resolved.required;
|
|
82
100
|
continue;
|
|
83
101
|
}
|
|
@@ -85,7 +103,7 @@ function locationParts(entries, location, context) {
|
|
|
85
103
|
members.push(member);
|
|
86
104
|
isOptional &&= member.isOptional;
|
|
87
105
|
}
|
|
88
|
-
return { members, exploded, isOptional };
|
|
106
|
+
return { members, exploded: explodedParts(exploded, members, context), isOptional };
|
|
89
107
|
}
|
|
90
108
|
function locationType({ members, exploded }) {
|
|
91
109
|
const types = [...members.length > 0 ? [constructors.irObject(members)] : [], ...exploded];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameters.cjs","sources":["../../../../src/application/transform/document/parameters.ts"],"sourcesContent":["import {\n irIntersection,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertyName, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n PARAMETER_LOCATIONS,\n type ParameterLocation,\n type ParameterObject,\n type ParameterOrReference,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { isExplodedQueryObject } from \"./exploded-query.js\";\nimport { parameterType } from \"./parameter.js\";\nimport {\n type ParameterEntry,\n parameterEntries,\n type ResolvedEntry,\n resolveParameter,\n} from \"./parameter-entries.js\";\nimport { referencedParameterType } from \"./referenced-parameter.js\";\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_TEMPLATE_RE = /\\{([^{}]+)\\}/g;\n\n/** Required string parameters for every `{name}` in a path template. */\nfunction pathTemplateParameters(path: string): ParameterObject[] {\n return (path.match(PATH_TEMPLATE_RE) ?? []).map((match) => ({\n name: match.slice(1, -1),\n in: \"path\",\n required: true,\n schema: { type: \"string\" },\n }));\n}\n\n/** `--generate-path-params`: add the path template parameters the list does not define. */\nfunction withPathTemplateParameters(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): ParameterOrReference[] {\n const result = [...parameters];\n if (!context.options.generatePathParams || !location.path) {\n return result;\n }\n for (const parameter of pathTemplateParameters(location.path)) {\n const isDefined = result.some((candidate) => {\n const resolved = resolveParameter(candidate, context.refs);\n return resolved?.in === \"path\" && resolved.name === parameter.name;\n });\n if (!isDefined) {\n result.push(parameter);\n }\n }\n return result;\n}\n\n/** The original quotes a name that is not text (a missing name prints as `\"undefined\"`). */\nfunction parameterName(name: unknown): IrPropertyName {\n return typeof name === \"string\" || typeof name === \"number\"\n ? toPropertyName(name)\n : { kind: \"string\", value: String(name) };\n}\n\nfunction entryType(\n { original, resolved }: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const path = appendPointer(location.path, [\"parameters\", resolved.in, resolved.name]);\n return \"$ref\" in original\n ? referencedParameterType(original.$ref, resolved, context)\n : parameterType(resolved, { ...location, path }, context);\n}\n\nfunction parameterMember(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const { resolved } = entry;\n const property = irProperty(parameterName(resolved.name), entryType(entry, location, context), {\n isOptional: resolved.in !== \"path\" && !resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, resolved);\n}\n\n/**\n * The `query` member typed by an `in: querystring` parameter (OpenAPI 3.2, ADR-020): the parameter\n * is the whole query string. Null when there is none, or when `in: query` parameters sit next to\n * it, which 3.2 does not allow; those keep their types, and a warning names the parameter.\n */\nfunction querystringMember(\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const querystring = entries.find(\n (entry): entry is ResolvedEntry => entry.resolved?.in === QUERYSTRING_LOCATION,\n );\n if (!querystring || entries.some((entry) => entry.resolved?.in === \"query\")) {\n return null;\n }\n const property = irProperty(toPropertyName(\"query\"), entryType(querystring, location, context), {\n isOptional: !querystring.resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, querystring.resolved);\n}\n\n/** With `exploded-query-objects`, whether the parameter's object keys are keys of `query`. */\nfunction isExplodedEntry(entry: ResolvedEntry, context: TransformContext): boolean {\n return (\n context.options.fixes.has(FIX.EXPLODED_QUERY_OBJECTS) &&\n isExplodedQueryObject(entry.resolved, context.refs)\n );\n}\n\n/**\n * An exploded object parameter's part of `query`: its object type. A parameter that may be left\n * out sends none of its keys then, so they are optional: `Partial<…>`.\n */\nfunction explodedPart(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const type = entryType(entry, location, context);\n return entry.resolved.required ? type : irReference(\"Partial\", [type]);\n}\n\n/** A location's parameters as members, and the object types of its exploded parameters. */\ninterface LocationParts {\n readonly members: readonly IrPropertySignature[];\n readonly exploded: readonly IrType[];\n readonly isOptional: boolean;\n}\n\n/** Each parameter in document order, so the declarations they add keep their order. */\nfunction locationParts(\n entries: readonly ResolvedEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): LocationParts {\n const members: IrPropertySignature[] = [];\n const exploded: IrType[] = [];\n let isOptional = true;\n for (const entry of entries) {\n if (isExplodedEntry(entry, context)) {\n exploded.push(explodedPart(entry, location, context));\n isOptional &&= !entry.resolved.required;\n continue;\n }\n const member = parameterMember(entry, location, context);\n members.push(member);\n isOptional &&= member.isOptional;\n }\n return { members, exploded, isOptional };\n}\n\n/** The members' object, intersected with the exploded parameters' types; `never` for none. */\nfunction locationType({ members, exploded }: LocationParts): IrType {\n const types = [...(members.length > 0 ? [irObject(members)] : []), ...exploded];\n const [first] = types;\n if (first === undefined) {\n return irKeyword(\"never\");\n }\n return types.length === 1 ? first : irIntersection(types);\n}\n\n/** One location's parameters; optional when all of them are, and `never` when there are none. */\nfunction locationMember(\n parameterIn: ParameterLocation,\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const located = entries.filter(\n (entry): entry is ResolvedEntry => entry.resolved?.in === parameterIn,\n );\n const parts = locationParts(located, location, context);\n return irProperty(toPropertyName(parameterIn), locationType(parts), {\n isOptional: parts.isOptional,\n isReadonly: context.options.immutable,\n });\n}\n\n/**\n * The `parameters` property of an operation or path item: one member per location, each an object\n * of that location's parameters. `location.path` is the path template for\n * `--generate-path-params`.\n */\nexport function parametersMember(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const entries = parameterEntries(\n withPathTemplateParameters(parameters, location, context),\n context,\n );\n const querystring = querystringMember(entries, location, context);\n const members = PARAMETER_LOCATIONS.map((parameterIn) =>\n parameterIn === \"query\" && querystring\n ? querystring\n : locationMember(parameterIn, entries, location, context),\n );\n return irProperty(toPropertyName(\"parameters\"), irObject(members), {\n isReadonly: context.options.immutable,\n });\n}\n"],"names":["resolveParameter","toPropertyName","appendPointer","referencedParameterType","parameterType","irProperty","withSchemaComment","QUERYSTRING_LOCATION","FIX","isExplodedQueryObject","irReference","irObject","irKeyword","irIntersection","parameterEntries","PARAMETER_LOCATIONS"],"mappings":";;;;;;;;;;;;;AAgCA,MAAM,gBAAA,GAAmB,eAAA;AAGzB,SAAS,uBAAuB,IAAA,EAAiC;AAC/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O,CAAA;AAAA,IACxD;AAAA,GACF;AACA,EAAA,MAAM,WAAA,GAAc,iBAAA,CAAkB,OAAA,EAAS,QAAA,EAAU,OAAO,CAAA;AAChE,EAAA,MAAM,UAAUC,mCAAA,CAAoB,GAAA;AAAA,IAAI,CAAC,WAAA,KACvC,WAAA,KAAgB,OAAA,IAAW,WAAA,GACvB,cACA,cAAA,CAAe,WAAA,EAAa,OAAA,EAAS,QAAA,EAAU,OAAO;AAAA,GAC5D;AACA,EAAA,OAAOV,wBAAWJ,2BAAA,CAAe,YAAY,CAAA,EAAGU,qBAAA,CAAS,OAAO,CAAA,EAAG;AAAA,IACjE,UAAA,EAAY,QAAQ,OAAA,CAAQ;AAAA,GAC7B,CAAA;AACH;;"}
|
|
1
|
+
{"version":3,"file":"parameters.cjs","sources":["../../../../src/application/transform/document/parameters.ts"],"sourcesContent":["import {\n irIntersection,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertyName, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n PARAMETER_LOCATIONS,\n type ParameterLocation,\n type ParameterObject,\n type ParameterOrReference,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { declaredValueTypes } from \"../declared-value-types.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { isExplodedQueryObject } from \"./exploded-query.js\";\nimport { declaredObjectType, hasIndexSignature, withIndexValues } from \"./exploded-query-values.js\";\nimport { parameterType } from \"./parameter.js\";\nimport {\n type ParameterEntry,\n parameterEntries,\n type ResolvedEntry,\n resolveParameter,\n} from \"./parameter-entries.js\";\nimport { referencedParameterType } from \"./referenced-parameter.js\";\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_TEMPLATE_RE = /\\{([^{}]+)\\}/g;\n\n/** Required string parameters for every `{name}` in a path template. */\nfunction pathTemplateParameters(path: string): ParameterObject[] {\n return (path.match(PATH_TEMPLATE_RE) ?? []).map((match) => ({\n name: match.slice(1, -1),\n in: \"path\",\n required: true,\n schema: { type: \"string\" },\n }));\n}\n\n/** `--generate-path-params`: add the path template parameters the list does not define. */\nfunction withPathTemplateParameters(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): ParameterOrReference[] {\n const result = [...parameters];\n if (!context.options.generatePathParams || !location.path) {\n return result;\n }\n for (const parameter of pathTemplateParameters(location.path)) {\n const isDefined = result.some((candidate) => {\n const resolved = resolveParameter(candidate, context.refs);\n return resolved?.in === \"path\" && resolved.name === parameter.name;\n });\n if (!isDefined) {\n result.push(parameter);\n }\n }\n return result;\n}\n\n/** The original quotes a name that is not text (a missing name prints as `\"undefined\"`). */\nfunction parameterName(name: unknown): IrPropertyName {\n return typeof name === \"string\" || typeof name === \"number\"\n ? toPropertyName(name)\n : { kind: \"string\", value: String(name) };\n}\n\nfunction entryType(\n { original, resolved }: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const path = appendPointer(location.path, [\"parameters\", resolved.in, resolved.name]);\n return \"$ref\" in original\n ? referencedParameterType(original.$ref, resolved, context)\n : parameterType(resolved, { ...location, path }, context);\n}\n\nfunction parameterMember(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const { resolved } = entry;\n const property = irProperty(parameterName(resolved.name), entryType(entry, location, context), {\n isOptional: resolved.in !== \"path\" && !resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, resolved);\n}\n\n/**\n * The `query` member typed by an `in: querystring` parameter (OpenAPI 3.2, ADR-020): the parameter\n * is the whole query string. Null when there is none, or when `in: query` parameters sit next to\n * it, which 3.2 does not allow; those keep their types, and a warning names the parameter.\n */\nfunction querystringMember(\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const querystring = entries.find(\n (entry): entry is ResolvedEntry => entry.resolved?.in === QUERYSTRING_LOCATION,\n );\n if (!querystring || entries.some((entry) => entry.resolved?.in === \"query\")) {\n return null;\n }\n const property = irProperty(toPropertyName(\"query\"), entryType(querystring, location, context), {\n isOptional: !querystring.resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, querystring.resolved);\n}\n\n/** With `exploded-query-objects`, whether the parameter's object keys are keys of `query`. */\nfunction isExplodedEntry(entry: ResolvedEntry, context: TransformContext): boolean {\n return (\n context.options.fixes.has(FIX.EXPLODED_QUERY_OBJECTS) &&\n isExplodedQueryObject(entry.resolved, context.refs)\n );\n}\n\n/** An exploded object parameter with its type, typed in document order. */\ninterface ExplodedEntry {\n readonly entry: ResolvedEntry;\n readonly type: IrType;\n}\n\n/**\n * The object type of an exploded parameter, written out when it is a reference to a type with an\n * index signature and `query` has other keys, which that signature must then admit. Without\n * other keys the reference is kept.\n */\nfunction explodedObjectType(\n { entry, type }: ExplodedEntry,\n hasOtherKeys: boolean,\n context: TransformContext,\n): IrType {\n if (!hasOtherKeys) {\n return type;\n }\n const declared = declaredObjectType(entry, context);\n return declared !== null && hasIndexSignature(declared) ? declared : type;\n}\n\n/**\n * The exploded object parameters' parts of `query`: their object types, each index signature\n * widened by the value types of the other keys (see `exploded-query-values.ts`). A parameter that\n * may be left out sends none of its keys then, so they are optional: `Partial<…>`.\n */\nfunction explodedParts(\n exploded: readonly ExplodedEntry[],\n members: readonly IrPropertySignature[],\n context: TransformContext,\n): IrType[] {\n const hasOtherKeys = members.length > 0 || exploded.length > 1;\n const types = exploded.map((part) => explodedObjectType(part, hasOtherKeys, context));\n const others = (index: number) => [\n ...(members.length > 0 ? [irObject(members)] : []),\n ...types.filter((_type, other) => other !== index),\n ];\n return types.map((type, index) => {\n const values = others(index).flatMap((other) => declaredValueTypes(other, context.footer));\n const widened = withIndexValues(type, values);\n return exploded[index]?.entry.resolved.required ? widened : irReference(\"Partial\", [widened]);\n });\n}\n\n/** A location's parameters as members, and the object types of its exploded parameters. */\ninterface LocationParts {\n readonly members: readonly IrPropertySignature[];\n readonly exploded: readonly IrType[];\n readonly isOptional: boolean;\n}\n\n/** Each parameter in document order, so the declarations they add keep their order. */\nfunction locationParts(\n entries: readonly ResolvedEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): LocationParts {\n const members: IrPropertySignature[] = [];\n const exploded: ExplodedEntry[] = [];\n let isOptional = true;\n for (const entry of entries) {\n if (isExplodedEntry(entry, context)) {\n exploded.push({ entry, type: entryType(entry, location, context) });\n isOptional &&= !entry.resolved.required;\n continue;\n }\n const member = parameterMember(entry, location, context);\n members.push(member);\n isOptional &&= member.isOptional;\n }\n return { members, exploded: explodedParts(exploded, members, context), isOptional };\n}\n\n/** The members' object, intersected with the exploded parameters' types; `never` for none. */\nfunction locationType({ members, exploded }: LocationParts): IrType {\n const types = [...(members.length > 0 ? [irObject(members)] : []), ...exploded];\n const [first] = types;\n if (first === undefined) {\n return irKeyword(\"never\");\n }\n return types.length === 1 ? first : irIntersection(types);\n}\n\n/** One location's parameters; optional when all of them are, and `never` when there are none. */\nfunction locationMember(\n parameterIn: ParameterLocation,\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const located = entries.filter(\n (entry): entry is ResolvedEntry => entry.resolved?.in === parameterIn,\n );\n const parts = locationParts(located, location, context);\n return irProperty(toPropertyName(parameterIn), locationType(parts), {\n isOptional: parts.isOptional,\n isReadonly: context.options.immutable,\n });\n}\n\n/**\n * The `parameters` property of an operation or path item: one member per location, each an object\n * of that location's parameters. `location.path` is the path template for\n * `--generate-path-params`.\n */\nexport function parametersMember(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const entries = parameterEntries(\n withPathTemplateParameters(parameters, location, context),\n context,\n );\n const querystring = querystringMember(entries, location, context);\n const members = PARAMETER_LOCATIONS.map((parameterIn) =>\n parameterIn === \"query\" && querystring\n ? querystring\n : locationMember(parameterIn, entries, location, context),\n );\n return irProperty(toPropertyName(\"parameters\"), irObject(members), {\n isReadonly: context.options.immutable,\n });\n}\n"],"names":["resolveParameter","toPropertyName","appendPointer","referencedParameterType","parameterType","irProperty","withSchemaComment","QUERYSTRING_LOCATION","FIX","isExplodedQueryObject","declaredObjectType","hasIndexSignature","irObject","declaredValueTypes","withIndexValues","irReference","irKeyword","irIntersection","parameterEntries","PARAMETER_LOCATIONS"],"mappings":";;;;;;;;;;;;;;;AAkCA,MAAM,gBAAA,GAAmB,eAAA;AAGzB,SAAS,uBAAuB,IAAA,EAAiC;AAC/D,EAAA,OAAA,CAAQ,IAAA,CAAK,MAAM,gBAAgB,CAAA,IAAK,EAAC,EAAG,GAAA,CAAI,CAAC,KAAA,MAAW;AAAA,IAC1D,IAAA,EAAM,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,IACvB,EAAA,EAAI,MAAA;AAAA,IACJ,QAAA,EAAU,IAAA;AAAA,IACV,MAAA,EAAQ,EAAE,IAAA,EAAM,QAAA;AAAS,GAC3B,CAAE,CAAA;AACJ;AAGA,SAAS,0BAAA,CACP,UAAA,EACA,QAAA,EACA,OAAA,EACwB;AACxB,EAAA,MAAM,MAAA,GAAS,CAAC,GAAG,UAAU,CAAA;AAC7B,EAAA,IAAI,CAAC,OAAA,CAAQ,OAAA,CAAQ,kBAAA,IAAsB,CAAC,SAAS,IAAA,EAAM;AACzD,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,KAAA,MAAW,SAAA,IAAa,sBAAA,CAAuB,QAAA,CAAS,IAAI,CAAA,EAAG;AAC7D,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,CAAC,SAAA,KAAc;AAC3C,MA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CAAc,OAAA,EAAS,QAAA,EAAU,OAAO,CAAA;AACtD,EAAA,OAAOZ,wBAAWJ,2BAAA,CAAe,WAAW,CAAA,EAAG,YAAA,CAAa,KAAK,CAAA,EAAG;AAAA,IAClE,YAAY,KAAA,CAAM,UAAA;AAAA,IAClB,UAAA,EAAY,QAAQ,OAAA,CAAQ;AAAA,GAC7B,CAAA;AACH;AAOO,SAAS,gBAAA,CACd,UAAA,EACA,QAAA,EACA,OAAA,EACqB;AACrB,EAAA,MAAM,OAAA,GAAUiB,iCAAA;AAAA,IACd,0BAAA,CAA2B,UAAA,EAAY,QAAA,EAAU,OAAO,CAAA;AAAA,IACxD;AAAA,GACF;AACA,EAAA,MAAM,WAAA,GAAc,iBAAA,CAAkB,OAAA,EAAS,QAAA,EAAU,OAAO,CAAA;AAChE,EAAA,MAAM,UAAUC,mCAAA,CAAoB,GAAA;AAAA,IAAI,CAAC,WAAA,KACvC,WAAA,KAAgB,OAAA,IAAW,WAAA,GACvB,cACA,cAAA,CAAe,WAAA,EAAa,OAAA,EAAS,QAAA,EAAU,OAAO;AAAA,GAC5D;AACA,EAAA,OAAOd,wBAAWJ,2BAAA,CAAe,YAAY,CAAA,EAAGW,qBAAA,CAAS,OAAO,CAAA,EAAG;AAAA,IACjE,UAAA,EAAY,QAAQ,OAAA,CAAQ;AAAA,GAC7B,CAAA;AACH;;"}
|
|
@@ -3,8 +3,10 @@ import { toPropertyName } from '../../../domain/ir/property-name.mjs';
|
|
|
3
3
|
import { appendPointer } from '../../../domain/openapi/json-pointer.mjs';
|
|
4
4
|
import { PARAMETER_LOCATIONS, QUERYSTRING_LOCATION } from '../../../domain/openapi/parameter-object.mjs';
|
|
5
5
|
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
6
|
+
import { declaredValueTypes } from '../declared-value-types.mjs';
|
|
6
7
|
import { withSchemaComment } from '../schema-comment.mjs';
|
|
7
8
|
import { isExplodedQueryObject } from './exploded-query.mjs';
|
|
9
|
+
import { withIndexValues, declaredObjectType, hasIndexSignature } from './exploded-query-values.mjs';
|
|
8
10
|
import { parameterType } from './parameter.mjs';
|
|
9
11
|
import { parameterEntries, resolveParameter } from './parameter-entries.mjs';
|
|
10
12
|
import { referencedParameterType } from './referenced-parameter.mjs';
|
|
@@ -65,9 +67,25 @@ function querystringMember(entries, location, context) {
|
|
|
65
67
|
function isExplodedEntry(entry, context) {
|
|
66
68
|
return context.options.fixes.has(FIX.EXPLODED_QUERY_OBJECTS) && isExplodedQueryObject(entry.resolved, context.refs);
|
|
67
69
|
}
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
function explodedObjectType({ entry, type }, hasOtherKeys, context) {
|
|
71
|
+
if (!hasOtherKeys) {
|
|
72
|
+
return type;
|
|
73
|
+
}
|
|
74
|
+
const declared = declaredObjectType(entry, context);
|
|
75
|
+
return declared !== null && hasIndexSignature(declared) ? declared : type;
|
|
76
|
+
}
|
|
77
|
+
function explodedParts(exploded, members, context) {
|
|
78
|
+
const hasOtherKeys = members.length > 0 || exploded.length > 1;
|
|
79
|
+
const types = exploded.map((part) => explodedObjectType(part, hasOtherKeys, context));
|
|
80
|
+
const others = (index) => [
|
|
81
|
+
...members.length > 0 ? [irObject(members)] : [],
|
|
82
|
+
...types.filter((_type, other) => other !== index)
|
|
83
|
+
];
|
|
84
|
+
return types.map((type, index) => {
|
|
85
|
+
const values = others(index).flatMap((other) => declaredValueTypes(other, context.footer));
|
|
86
|
+
const widened = withIndexValues(type, values);
|
|
87
|
+
return exploded[index]?.entry.resolved.required ? widened : irReference("Partial", [widened]);
|
|
88
|
+
});
|
|
71
89
|
}
|
|
72
90
|
function locationParts(entries, location, context) {
|
|
73
91
|
const members = [];
|
|
@@ -75,7 +93,7 @@ function locationParts(entries, location, context) {
|
|
|
75
93
|
let isOptional = true;
|
|
76
94
|
for (const entry of entries) {
|
|
77
95
|
if (isExplodedEntry(entry, context)) {
|
|
78
|
-
exploded.push(
|
|
96
|
+
exploded.push({ entry, type: entryType(entry, location, context) });
|
|
79
97
|
isOptional &&= !entry.resolved.required;
|
|
80
98
|
continue;
|
|
81
99
|
}
|
|
@@ -83,7 +101,7 @@ function locationParts(entries, location, context) {
|
|
|
83
101
|
members.push(member);
|
|
84
102
|
isOptional &&= member.isOptional;
|
|
85
103
|
}
|
|
86
|
-
return { members, exploded, isOptional };
|
|
104
|
+
return { members, exploded: explodedParts(exploded, members, context), isOptional };
|
|
87
105
|
}
|
|
88
106
|
function locationType({ members, exploded }) {
|
|
89
107
|
const types = [...members.length > 0 ? [irObject(members)] : [], ...exploded];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameters.mjs","sources":["../../../../src/application/transform/document/parameters.ts"],"sourcesContent":["import {\n irIntersection,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertyName, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n PARAMETER_LOCATIONS,\n type ParameterLocation,\n type ParameterObject,\n type ParameterOrReference,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { isExplodedQueryObject } from \"./exploded-query.js\";\nimport { parameterType } from \"./parameter.js\";\nimport {\n type ParameterEntry,\n parameterEntries,\n type ResolvedEntry,\n resolveParameter,\n} from \"./parameter-entries.js\";\nimport { referencedParameterType } from \"./referenced-parameter.js\";\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_TEMPLATE_RE = /\\{([^{}]+)\\}/g;\n\n/** Required string parameters for every `{name}` in a path template. */\nfunction pathTemplateParameters(path: string): ParameterObject[] {\n return (path.match(PATH_TEMPLATE_RE) ?? []).map((match) => ({\n name: match.slice(1, -1),\n in: \"path\",\n required: true,\n schema: { type: \"string\" },\n }));\n}\n\n/** `--generate-path-params`: add the path template parameters the list does not define. */\nfunction withPathTemplateParameters(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): ParameterOrReference[] {\n const result = [...parameters];\n if (!context.options.generatePathParams || !location.path) {\n return result;\n }\n for (const parameter of pathTemplateParameters(location.path)) {\n const isDefined = result.some((candidate) => {\n const resolved = resolveParameter(candidate, context.refs);\n return resolved?.in === \"path\" && resolved.name === parameter.name;\n });\n if (!isDefined) {\n result.push(parameter);\n }\n }\n return result;\n}\n\n/** The original quotes a name that is not text (a missing name prints as `\"undefined\"`). */\nfunction parameterName(name: unknown): IrPropertyName {\n return typeof name === \"string\" || typeof name === \"number\"\n ? toPropertyName(name)\n : { kind: \"string\", value: String(name) };\n}\n\nfunction entryType(\n { original, resolved }: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const path = appendPointer(location.path, [\"parameters\", resolved.in, resolved.name]);\n return \"$ref\" in original\n ? referencedParameterType(original.$ref, resolved, context)\n : parameterType(resolved, { ...location, path }, context);\n}\n\nfunction parameterMember(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const { resolved } = entry;\n const property = irProperty(parameterName(resolved.name), entryType(entry, location, context), {\n isOptional: resolved.in !== \"path\" && !resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, resolved);\n}\n\n/**\n * The `query` member typed by an `in: querystring` parameter (OpenAPI 3.2, ADR-020): the parameter\n * is the whole query string. Null when there is none, or when `in: query` parameters sit next to\n * it, which 3.2 does not allow; those keep their types, and a warning names the parameter.\n */\nfunction querystringMember(\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const querystring = entries.find(\n (entry): entry is ResolvedEntry => entry.resolved?.in === QUERYSTRING_LOCATION,\n );\n if (!querystring || entries.some((entry) => entry.resolved?.in === \"query\")) {\n return null;\n }\n const property = irProperty(toPropertyName(\"query\"), entryType(querystring, location, context), {\n isOptional: !querystring.resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, querystring.resolved);\n}\n\n/** With `exploded-query-objects`, whether the parameter's object keys are keys of `query`. */\nfunction isExplodedEntry(entry: ResolvedEntry, context: TransformContext): boolean {\n return (\n context.options.fixes.has(FIX.EXPLODED_QUERY_OBJECTS) &&\n isExplodedQueryObject(entry.resolved, context.refs)\n );\n}\n\n/**\n * An exploded object parameter's part of `query`: its object type. A parameter that may be left\n * out sends none of its keys then, so they are optional: `Partial<…>`.\n */\nfunction explodedPart(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const type = entryType(entry, location, context);\n return entry.resolved.required ? type : irReference(\"Partial\", [type]);\n}\n\n/** A location's parameters as members, and the object types of its exploded parameters. */\ninterface LocationParts {\n readonly members: readonly IrPropertySignature[];\n readonly exploded: readonly IrType[];\n readonly isOptional: boolean;\n}\n\n/** Each parameter in document order, so the declarations they add keep their order. */\nfunction locationParts(\n entries: readonly ResolvedEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): LocationParts {\n const members: IrPropertySignature[] = [];\n const exploded: IrType[] = [];\n let isOptional = true;\n for (const entry of entries) {\n if (isExplodedEntry(entry, context)) {\n exploded.push(explodedPart(entry, location, context));\n isOptional &&= !entry.resolved.required;\n continue;\n }\n const member = parameterMember(entry, location, context);\n members.push(member);\n isOptional &&= member.isOptional;\n }\n return { members, exploded, isOptional };\n}\n\n/** The members' object, intersected with the exploded parameters' types; `never` for none. */\nfunction locationType({ members, exploded }: LocationParts): IrType {\n const types = [...(members.length > 0 ? [irObject(members)] : []), ...exploded];\n const [first] = types;\n if (first === undefined) {\n return irKeyword(\"never\");\n }\n return types.length === 1 ? first : irIntersection(types);\n}\n\n/** One location's parameters; optional when all of them are, and `never` when there are none. */\nfunction locationMember(\n parameterIn: ParameterLocation,\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const located = entries.filter(\n (entry): entry is ResolvedEntry => entry.resolved?.in === parameterIn,\n );\n const parts = locationParts(located, location, context);\n return irProperty(toPropertyName(parameterIn), locationType(parts), {\n isOptional: parts.isOptional,\n isReadonly: context.options.immutable,\n });\n}\n\n/**\n * The `parameters` property of an operation or path item: one member per location, each an object\n * of that location's parameters. `location.path` is the path template for\n * `--generate-path-params`.\n */\nexport function parametersMember(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const entries = parameterEntries(\n withPathTemplateParameters(parameters, location, context),\n context,\n );\n const querystring = querystringMember(entries, location, context);\n const members = PARAMETER_LOCATIONS.map((parameterIn) =>\n parameterIn === \"query\" && querystring\n ? querystring\n : locationMember(parameterIn, entries, location, context),\n );\n return irProperty(toPropertyName(\"parameters\"), irObject(members), {\n isReadonly: context.options.immutable,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAgCA,MAAM,gBAAA,GAAmB,eAAA;AAGzB,SAAS,uBAAuB,IAAA,EAAiC;AAC/D,EAAA,OAAA,CAAQ,IAAA,CAAK,MAAM,gBAAgB,CAAA,IAAK,EAAC,EAAG,GAAA,CAAI,CAAC,KAAA,MAAW;AAAA,IAC1D,IAAA,EAAM,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,IACvB,EAAA,EAAI,MAAA;AAAA,IACJ,QAAA,EAAU,IAAA;AAAA,IACV,MAAA,EAAQ,EAAE,IAAA,EAAM,QAAA;AAAS,GAC3B,CAAE,CAAA;AACJ;AAGA,SAAS,0BAAA,CACP,UAAA,EACA,QAAA,EACA,OAAA,EACwB;AACxB,EAAA,MAAM,MAAA,GAAS,CAAC,GAAG,UAAU,CAAA;AAC7B,EAAA,IAAI,CAAC,OAAA,CAAQ,OAAA,CAAQ,kB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esContent":["import {\n irIntersection,\n irKeyword,\n irObject,\n irProperty,\n irReference,\n} from \"../../../domain/ir/constructors.js\";\nimport type { IrPropertyName, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n PARAMETER_LOCATIONS,\n type ParameterLocation,\n type ParameterObject,\n type ParameterOrReference,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { declaredValueTypes } from \"../declared-value-types.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport { withSchemaComment } from \"../schema-comment.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { isExplodedQueryObject } from \"./exploded-query.js\";\nimport { declaredObjectType, hasIndexSignature, withIndexValues } from \"./exploded-query-values.js\";\nimport { parameterType } from \"./parameter.js\";\nimport {\n type ParameterEntry,\n parameterEntries,\n type ResolvedEntry,\n resolveParameter,\n} from \"./parameter-entries.js\";\nimport { referencedParameterType } from \"./referenced-parameter.js\";\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_TEMPLATE_RE = /\\{([^{}]+)\\}/g;\n\n/** Required string parameters for every `{name}` in a path template. */\nfunction pathTemplateParameters(path: string): ParameterObject[] {\n return (path.match(PATH_TEMPLATE_RE) ?? []).map((match) => ({\n name: match.slice(1, -1),\n in: \"path\",\n required: true,\n schema: { type: \"string\" },\n }));\n}\n\n/** `--generate-path-params`: add the path template parameters the list does not define. */\nfunction withPathTemplateParameters(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): ParameterOrReference[] {\n const result = [...parameters];\n if (!context.options.generatePathParams || !location.path) {\n return result;\n }\n for (const parameter of pathTemplateParameters(location.path)) {\n const isDefined = result.some((candidate) => {\n const resolved = resolveParameter(candidate, context.refs);\n return resolved?.in === \"path\" && resolved.name === parameter.name;\n });\n if (!isDefined) {\n result.push(parameter);\n }\n }\n return result;\n}\n\n/** The original quotes a name that is not text (a missing name prints as `\"undefined\"`). */\nfunction parameterName(name: unknown): IrPropertyName {\n return typeof name === \"string\" || typeof name === \"number\"\n ? toPropertyName(name)\n : { kind: \"string\", value: String(name) };\n}\n\nfunction entryType(\n { original, resolved }: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const path = appendPointer(location.path, [\"parameters\", resolved.in, resolved.name]);\n return \"$ref\" in original\n ? referencedParameterType(original.$ref, resolved, context)\n : parameterType(resolved, { ...location, path }, context);\n}\n\nfunction parameterMember(\n entry: ResolvedEntry,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const { resolved } = entry;\n const property = irProperty(parameterName(resolved.name), entryType(entry, location, context), {\n isOptional: resolved.in !== \"path\" && !resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, resolved);\n}\n\n/**\n * The `query` member typed by an `in: querystring` parameter (OpenAPI 3.2, ADR-020): the parameter\n * is the whole query string. Null when there is none, or when `in: query` parameters sit next to\n * it, which 3.2 does not allow; those keep their types, and a warning names the parameter.\n */\nfunction querystringMember(\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const querystring = entries.find(\n (entry): entry is ResolvedEntry => entry.resolved?.in === QUERYSTRING_LOCATION,\n );\n if (!querystring || entries.some((entry) => entry.resolved?.in === \"query\")) {\n return null;\n }\n const property = irProperty(toPropertyName(\"query\"), entryType(querystring, location, context), {\n isOptional: !querystring.resolved.required,\n isReadonly: context.options.immutable,\n });\n return withSchemaComment(property, querystring.resolved);\n}\n\n/** With `exploded-query-objects`, whether the parameter's object keys are keys of `query`. */\nfunction isExplodedEntry(entry: ResolvedEntry, context: TransformContext): boolean {\n return (\n context.options.fixes.has(FIX.EXPLODED_QUERY_OBJECTS) &&\n isExplodedQueryObject(entry.resolved, context.refs)\n );\n}\n\n/** An exploded object parameter with its type, typed in document order. */\ninterface ExplodedEntry {\n readonly entry: ResolvedEntry;\n readonly type: IrType;\n}\n\n/**\n * The object type of an exploded parameter, written out when it is a reference to a type with an\n * index signature and `query` has other keys, which that signature must then admit. Without\n * other keys the reference is kept.\n */\nfunction explodedObjectType(\n { entry, type }: ExplodedEntry,\n hasOtherKeys: boolean,\n context: TransformContext,\n): IrType {\n if (!hasOtherKeys) {\n return type;\n }\n const declared = declaredObjectType(entry, context);\n return declared !== null && hasIndexSignature(declared) ? declared : type;\n}\n\n/**\n * The exploded object parameters' parts of `query`: their object types, each index signature\n * widened by the value types of the other keys (see `exploded-query-values.ts`). A parameter that\n * may be left out sends none of its keys then, so they are optional: `Partial<…>`.\n */\nfunction explodedParts(\n exploded: readonly ExplodedEntry[],\n members: readonly IrPropertySignature[],\n context: TransformContext,\n): IrType[] {\n const hasOtherKeys = members.length > 0 || exploded.length > 1;\n const types = exploded.map((part) => explodedObjectType(part, hasOtherKeys, context));\n const others = (index: number) => [\n ...(members.length > 0 ? [irObject(members)] : []),\n ...types.filter((_type, other) => other !== index),\n ];\n return types.map((type, index) => {\n const values = others(index).flatMap((other) => declaredValueTypes(other, context.footer));\n const widened = withIndexValues(type, values);\n return exploded[index]?.entry.resolved.required ? widened : irReference(\"Partial\", [widened]);\n });\n}\n\n/** A location's parameters as members, and the object types of its exploded parameters. */\ninterface LocationParts {\n readonly members: readonly IrPropertySignature[];\n readonly exploded: readonly IrType[];\n readonly isOptional: boolean;\n}\n\n/** Each parameter in document order, so the declarations they add keep their order. */\nfunction locationParts(\n entries: readonly ResolvedEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): LocationParts {\n const members: IrPropertySignature[] = [];\n const exploded: ExplodedEntry[] = [];\n let isOptional = true;\n for (const entry of entries) {\n if (isExplodedEntry(entry, context)) {\n exploded.push({ entry, type: entryType(entry, location, context) });\n isOptional &&= !entry.resolved.required;\n continue;\n }\n const member = parameterMember(entry, location, context);\n members.push(member);\n isOptional &&= member.isOptional;\n }\n return { members, exploded: explodedParts(exploded, members, context), isOptional };\n}\n\n/** The members' object, intersected with the exploded parameters' types; `never` for none. */\nfunction locationType({ members, exploded }: LocationParts): IrType {\n const types = [...(members.length > 0 ? [irObject(members)] : []), ...exploded];\n const [first] = types;\n if (first === undefined) {\n return irKeyword(\"never\");\n }\n return types.length === 1 ? first : irIntersection(types);\n}\n\n/** One location's parameters; optional when all of them are, and `never` when there are none. */\nfunction locationMember(\n parameterIn: ParameterLocation,\n entries: readonly ParameterEntry[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const located = entries.filter(\n (entry): entry is ResolvedEntry => entry.resolved?.in === parameterIn,\n );\n const parts = locationParts(located, location, context);\n return irProperty(toPropertyName(parameterIn), locationType(parts), {\n isOptional: parts.isOptional,\n isReadonly: context.options.immutable,\n });\n}\n\n/**\n * The `parameters` property of an operation or path item: one member per location, each an object\n * of that location's parameters. `location.path` is the path template for\n * `--generate-path-params`.\n */\nexport function parametersMember(\n parameters: readonly ParameterOrReference[],\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const entries = parameterEntries(\n withPathTemplateParameters(parameters, location, context),\n context,\n );\n const querystring = querystringMember(entries, location, context);\n const members = PARAMETER_LOCATIONS.map((parameterIn) =>\n parameterIn === \"query\" && querystring\n ? querystring\n : locationMember(parameterIn, entries, location, context),\n );\n return irProperty(toPropertyName(\"parameters\"), irObject(members), {\n isReadonly: context.options.immutable,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAkCA,MAAM,gBAAA,GAAmB,eAAA;AAGzB,SAAS,uBAAuB,IAAA,EAAiC;AAC/D,EAAA,OAAA,CAAQ,IAAA,CAAK,MAAM,gBAAgB,CAAA,IAAK,EAAC,EAAG,GAAA,CAAI,CAAC,KAAA,MAAW;AAAA,IAC1D,IAAA,EAAM,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,IACvB,EAAA,EA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