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
|
@@ -15,7 +15,7 @@ const HASH_RE = /#/g;
|
|
|
15
15
|
function operationKeyOf(operationId) {
|
|
16
16
|
return operationId.replace(HASH_RE, "/");
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function isIncludedOperation(operation, context) {
|
|
19
19
|
if (!operation) {
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
@@ -41,7 +41,7 @@ function operationMember({ name, operation, path }, pathItem, location, context)
|
|
|
41
41
|
}
|
|
42
42
|
function methodMember(method, pathItem, location, context) {
|
|
43
43
|
const operation = pathItem[method];
|
|
44
|
-
if (!
|
|
44
|
+
if (!isIncludedOperation(operation, context)) {
|
|
45
45
|
const isReadonly = context.options.immutable;
|
|
46
46
|
return constructors.irProperty(propertyName.toPropertyName(method), constructors.irKeyword("never"), { isOptional: true, isReadonly });
|
|
47
47
|
}
|
|
@@ -50,7 +50,7 @@ function methodMember(method, pathItem, location, context) {
|
|
|
50
50
|
}
|
|
51
51
|
function additionalOperationsMember(pathItem, location, context) {
|
|
52
52
|
const entries = documentEntries.documentEntries(pathItem.additionalOperations ?? {}, context.options);
|
|
53
|
-
const members = entries.filter(([, operation]) =>
|
|
53
|
+
const members = entries.filter(([, operation]) => isIncludedOperation(operation, context)).map(([method, operation]) => {
|
|
54
54
|
const path = jsonPointer.appendPointer(location.path, [pathItemObject.ADDITIONAL_OPERATIONS_KEY, method]);
|
|
55
55
|
return operationMember({ name: method, operation, path }, pathItem, location, context);
|
|
56
56
|
});
|
|
@@ -74,6 +74,7 @@ function pathItemType(pathItem, location, context) {
|
|
|
74
74
|
return constructors.irObject(members);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
exports.isIncludedOperation = isIncludedOperation;
|
|
77
78
|
exports.operationKeyOf = operationKeyOf;
|
|
78
79
|
exports.pathItemType = pathItemType;
|
|
79
80
|
//# sourceMappingURL=path-item.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-item.cjs","sources":["../../../../src/application/transform/document/path-item.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport {\n ADDITIONAL_OPERATIONS_KEY,\n HTTP_METHODS,\n type OperationEntry,\n type PathItemMethod,\n type PathItemObject,\n QUERY_METHOD,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { operationMembers } from \"./operation.js\";\nimport { mergedParameters } from \"./parameter-entries.js\";\nimport { parametersMember } from \"./parameters.js\";\n\n/** Redocly reads `#` in an operation ID as a pointer, so it is replaced (upstream issue #1542). */\nconst HASH_RE = /#/g;\n\n/** The `operations` key an `operationId` asks for, before a repeated one gets a number. */\nexport function operationKeyOf(operationId: string): string {\n return operationId.replace(HASH_RE, \"/\");\n}\n\n/** Whether the method has an operation, not removed by `--exclude-deprecated`. */\
|
|
1
|
+
{"version":3,"file":"path-item.cjs","sources":["../../../../src/application/transform/document/path-item.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport {\n ADDITIONAL_OPERATIONS_KEY,\n HTTP_METHODS,\n type OperationEntry,\n type PathItemMethod,\n type PathItemObject,\n QUERY_METHOD,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { operationMembers } from \"./operation.js\";\nimport { mergedParameters } from \"./parameter-entries.js\";\nimport { parametersMember } from \"./parameters.js\";\n\n/** Redocly reads `#` in an operation ID as a pointer, so it is replaced (upstream issue #1542). */\nconst HASH_RE = /#/g;\n\n/** The `operations` key an `operationId` asks for, before a repeated one gets a number. */\nexport function operationKeyOf(operationId: string): string {\n return operationId.replace(HASH_RE, \"/\");\n}\n\n/** Whether the method has an operation, not removed by `--exclude-deprecated`. */\nexport function isIncludedOperation(\n operation: OperationEntry | undefined,\n context: TransformContext,\n): operation is OperationEntry {\n if (!operation) {\n return false;\n }\n const resolved =\n \"$ref\" in operation\n ? (context.refs.resolve(operation.$ref) as OperationObject | undefined)\n : operation;\n return !(context.options.excludeDeprecated && resolved?.deprecated);\n}\n\n/**\n * An operation with an `operationId` goes into the `operations` interface and is referenced from\n * the path item; others are written inline.\n */\nfunction operationType(\n pathItem: PathItemObject,\n operation: OperationObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const merged = { ...operation, parameters: mergedParameters(pathItem, operation, context.refs) };\n if (!operation.operationId) {\n return irObject(operationMembers(merged, location, context));\n }\n const operationId = context.footer.operationKey(operationKeyOf(operation.operationId));\n context.footer.addOperation(() =>\n irProperty(toPropertyName(operationId), irObject(operationMembers(merged, location, context)), {\n isReadonly: context.options.immutable,\n }),\n );\n return refType(appendPointer(ROOT_POINTER, [\"operations\", operationId]));\n}\n\n/** An included operation, the member name it gets and its location below the path item. */\ninterface DeclaredOperation {\n readonly name: string;\n readonly operation: OperationEntry;\n readonly path: string;\n}\n\nfunction operationMember(\n { name, operation, path }: DeclaredOperation,\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const type =\n \"$ref\" in operation\n ? refType(operation.$ref)\n : operationType(pathItem, operation, { ...location, path }, context);\n return documentMember(name, type, operation, { isReadonly: context.options.immutable });\n}\n\n/** A method member: the operation, or `?: never` when there is none or it is excluded. */\nfunction methodMember(\n method: PathItemMethod,\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const operation = pathItem[method];\n if (!isIncludedOperation(operation, context)) {\n const isReadonly = context.options.immutable;\n return irProperty(toPropertyName(method), irKeyword(\"never\"), { isOptional: true, isReadonly });\n }\n const path = appendPointer(location.path, [method]);\n return operationMember({ name: method, operation, path }, pathItem, location, context);\n}\n\n/**\n * `additionalOperations` (OpenAPI 3.2): the included operations keyed by their exact method name,\n * or null when the path item has none left.\n */\nfunction additionalOperationsMember(\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const entries = documentEntries(pathItem.additionalOperations ?? {}, context.options);\n const members = entries\n .filter(([, operation]) => isIncludedOperation(operation, context))\n .map(([method, operation]) => {\n const path = appendPointer(location.path, [ADDITIONAL_OPERATIONS_KEY, method]);\n return operationMember({ name: method, operation, path }, pathItem, location, context);\n });\n return members.length > 0\n ? irProperty(toPropertyName(ADDITIONAL_OPERATIONS_KEY), irObject(members), {\n isReadonly: context.options.immutable,\n })\n : null;\n}\n\n/**\n * A path item (OpenAPI 3.2 §4.8.9): its `parameters`, one member per HTTP method, then `query` and\n * `additionalOperations` when the path item declares them (ADR-020).\n */\nexport function pathItemType(\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const parametersLocation = { ...location, path: appendPointer(location.path, [\"parameters\"]) };\n const members: IrMember[] = [\n parametersMember(pathItem.parameters ?? [], parametersLocation, context),\n ...HTTP_METHODS.map((method) => methodMember(method, pathItem, location, context)),\n ];\n if (pathItem[QUERY_METHOD] !== undefined) {\n members.push(methodMember(QUERY_METHOD, pathItem, location, context));\n }\n const additionalOperations = additionalOperationsMember(pathItem, location, context);\n if (additionalOperations) {\n members.push(additionalOperations);\n }\n return irObject(members);\n}\n"],"names":["operation","mergedParameters","irObject","operationMembers","irProperty","toPropertyName","refType","appendPointer","ROO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,CAAaA,2BAAA,EAAc,QAAA,EAAU,QAAA,EAAU,OAAO,CAAC,CAAA;AAAA,EACtE;AACA,EAAA,MAAM,oBAAA,GAAuB,0BAAA,CAA2B,QAAA,EAAU,QAAA,EAAU,OAAO,CAAA;AACnF,EAAA,IAAI,oBAAA,EAAsB;AACxB,IAAA,OAAA,CAAQ,KAAK,oBAAoB,CAAA;AAAA,EACnC;AACA,EAAA,OAAOb,sBAAS,OAAO,CAAA;AACzB;;;;"}
|
|
@@ -13,7 +13,7 @@ const HASH_RE = /#/g;
|
|
|
13
13
|
function operationKeyOf(operationId) {
|
|
14
14
|
return operationId.replace(HASH_RE, "/");
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function isIncludedOperation(operation, context) {
|
|
17
17
|
if (!operation) {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
@@ -39,7 +39,7 @@ function operationMember({ name, operation, path }, pathItem, location, context)
|
|
|
39
39
|
}
|
|
40
40
|
function methodMember(method, pathItem, location, context) {
|
|
41
41
|
const operation = pathItem[method];
|
|
42
|
-
if (!
|
|
42
|
+
if (!isIncludedOperation(operation, context)) {
|
|
43
43
|
const isReadonly = context.options.immutable;
|
|
44
44
|
return irProperty(toPropertyName(method), irKeyword("never"), { isOptional: true, isReadonly });
|
|
45
45
|
}
|
|
@@ -48,7 +48,7 @@ function methodMember(method, pathItem, location, context) {
|
|
|
48
48
|
}
|
|
49
49
|
function additionalOperationsMember(pathItem, location, context) {
|
|
50
50
|
const entries = documentEntries(pathItem.additionalOperations ?? {}, context.options);
|
|
51
|
-
const members = entries.filter(([, operation]) =>
|
|
51
|
+
const members = entries.filter(([, operation]) => isIncludedOperation(operation, context)).map(([method, operation]) => {
|
|
52
52
|
const path = appendPointer(location.path, [ADDITIONAL_OPERATIONS_KEY, method]);
|
|
53
53
|
return operationMember({ name: method, operation, path }, pathItem, location, context);
|
|
54
54
|
});
|
|
@@ -72,5 +72,5 @@ function pathItemType(pathItem, location, context) {
|
|
|
72
72
|
return irObject(members);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
export { operationKeyOf, pathItemType };
|
|
75
|
+
export { isIncludedOperation, operationKeyOf, pathItemType };
|
|
76
76
|
//# sourceMappingURL=path-item.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-item.mjs","sources":["../../../../src/application/transform/document/path-item.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport {\n ADDITIONAL_OPERATIONS_KEY,\n HTTP_METHODS,\n type OperationEntry,\n type PathItemMethod,\n type PathItemObject,\n QUERY_METHOD,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { operationMembers } from \"./operation.js\";\nimport { mergedParameters } from \"./parameter-entries.js\";\nimport { parametersMember } from \"./parameters.js\";\n\n/** Redocly reads `#` in an operation ID as a pointer, so it is replaced (upstream issue #1542). */\nconst HASH_RE = /#/g;\n\n/** The `operations` key an `operationId` asks for, before a repeated one gets a number. */\nexport function operationKeyOf(operationId: string): string {\n return operationId.replace(HASH_RE, \"/\");\n}\n\n/** Whether the method has an operation, not removed by `--exclude-deprecated`. */\
|
|
1
|
+
{"version":3,"file":"path-item.mjs","sources":["../../../../src/application/transform/document/path-item.ts"],"sourcesContent":["import { irKeyword, irObject, irProperty } from \"../../../domain/ir/constructors.js\";\nimport type { IrMember, IrPropertySignature, IrType } from \"../../../domain/ir/nodes.js\";\nimport { toPropertyName } from \"../../../domain/ir/property-name.js\";\nimport { appendPointer, ROOT_POINTER } from \"../../../domain/openapi/json-pointer.js\";\nimport type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport {\n ADDITIONAL_OPERATIONS_KEY,\n HTTP_METHODS,\n type OperationEntry,\n type PathItemMethod,\n type PathItemObject,\n QUERY_METHOD,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport { refType } from \"../ref-type.js\";\nimport type { SchemaLocation } from \"../schema/schema-context.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { operationMembers } from \"./operation.js\";\nimport { mergedParameters } from \"./parameter-entries.js\";\nimport { parametersMember } from \"./parameters.js\";\n\n/** Redocly reads `#` in an operation ID as a pointer, so it is replaced (upstream issue #1542). */\nconst HASH_RE = /#/g;\n\n/** The `operations` key an `operationId` asks for, before a repeated one gets a number. */\nexport function operationKeyOf(operationId: string): string {\n return operationId.replace(HASH_RE, \"/\");\n}\n\n/** Whether the method has an operation, not removed by `--exclude-deprecated`. */\nexport function isIncludedOperation(\n operation: OperationEntry | undefined,\n context: TransformContext,\n): operation is OperationEntry {\n if (!operation) {\n return false;\n }\n const resolved =\n \"$ref\" in operation\n ? (context.refs.resolve(operation.$ref) as OperationObject | undefined)\n : operation;\n return !(context.options.excludeDeprecated && resolved?.deprecated);\n}\n\n/**\n * An operation with an `operationId` goes into the `operations` interface and is referenced from\n * the path item; others are written inline.\n */\nfunction operationType(\n pathItem: PathItemObject,\n operation: OperationObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const merged = { ...operation, parameters: mergedParameters(pathItem, operation, context.refs) };\n if (!operation.operationId) {\n return irObject(operationMembers(merged, location, context));\n }\n const operationId = context.footer.operationKey(operationKeyOf(operation.operationId));\n context.footer.addOperation(() =>\n irProperty(toPropertyName(operationId), irObject(operationMembers(merged, location, context)), {\n isReadonly: context.options.immutable,\n }),\n );\n return refType(appendPointer(ROOT_POINTER, [\"operations\", operationId]));\n}\n\n/** An included operation, the member name it gets and its location below the path item. */\ninterface DeclaredOperation {\n readonly name: string;\n readonly operation: OperationEntry;\n readonly path: string;\n}\n\nfunction operationMember(\n { name, operation, path }: DeclaredOperation,\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const type =\n \"$ref\" in operation\n ? refType(operation.$ref)\n : operationType(pathItem, operation, { ...location, path }, context);\n return documentMember(name, type, operation, { isReadonly: context.options.immutable });\n}\n\n/** A method member: the operation, or `?: never` when there is none or it is excluded. */\nfunction methodMember(\n method: PathItemMethod,\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature {\n const operation = pathItem[method];\n if (!isIncludedOperation(operation, context)) {\n const isReadonly = context.options.immutable;\n return irProperty(toPropertyName(method), irKeyword(\"never\"), { isOptional: true, isReadonly });\n }\n const path = appendPointer(location.path, [method]);\n return operationMember({ name: method, operation, path }, pathItem, location, context);\n}\n\n/**\n * `additionalOperations` (OpenAPI 3.2): the included operations keyed by their exact method name,\n * or null when the path item has none left.\n */\nfunction additionalOperationsMember(\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrPropertySignature | null {\n const entries = documentEntries(pathItem.additionalOperations ?? {}, context.options);\n const members = entries\n .filter(([, operation]) => isIncludedOperation(operation, context))\n .map(([method, operation]) => {\n const path = appendPointer(location.path, [ADDITIONAL_OPERATIONS_KEY, method]);\n return operationMember({ name: method, operation, path }, pathItem, location, context);\n });\n return members.length > 0\n ? irProperty(toPropertyName(ADDITIONAL_OPERATIONS_KEY), irObject(members), {\n isReadonly: context.options.immutable,\n })\n : null;\n}\n\n/**\n * A path item (OpenAPI 3.2 §4.8.9): its `parameters`, one member per HTTP method, then `query` and\n * `additionalOperations` when the path item declares them (ADR-020).\n */\nexport function pathItemType(\n pathItem: PathItemObject,\n location: SchemaLocation,\n context: TransformContext,\n): IrType {\n const parametersLocation = { ...location, path: appendPointer(location.path, [\"parameters\"]) };\n const members: IrMember[] = [\n parametersMember(pathItem.parameters ?? [], parametersLocation, context),\n ...HTTP_METHODS.map((method) => methodMember(method, pathItem, location, context)),\n ];\n if (pathItem[QUERY_METHOD] !== undefined) {\n members.push(methodMember(QUERY_METHOD, pathItem, location, context));\n }\n const additionalOperations = additionalOperationsMember(pathItem, location, context);\n if (additionalOperations) {\n members.push(additionalOperations);\n }\n return irObject(members);\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAuBA,MAAM,OAAA,GAAU,IAAA;AAGT,SAAS,eAAe,WAAA,EAA6B;AAC1D,EAAA,OAAO,WAAA,CAAY,OAAA,CAAQ,OAAA,EAAS,GAAG,CAAA;AACzC;AAGO,SAAS,mBAAA,CACd,WACA,OAAA,EAC6B;AAC7B,EAAA,IAAI,CAAC,SAAA,EAAW;AACd,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,MAAM,QAAA,GACJ,UAAU,SAAA,GACL,OAAA,CAAQ,KAAK,OAAA,CAAQ,SAAA,CAAU,IAAI,CAAA,GACpC,SAAA;AACN,EAAA,OAAO,EAAE,OAAA,CAAQ,OAAA,CAAQ,iBAAA,IAAqB,QAAA,EAAU,UAAA,CAAA;AAC1D;AAMA,SAAS,aAAA,CACP,QAAA,EACA,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,SAAA,EAAW,UAAA,EAAY,iBAAiB,QAAA,EAAU,SAAA,EAAW,OAAA,CAAQ,IAAI,CAAA,EAAE;AAC/F,EAAA,IAAI,CAAC,UAAU,WAAA,EAAa;AAC1B,IAAA,OAAO,QAAA,CAAS,gBAAA,CAAiB,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAC,CAAA;AAAA,EAC7D;AACA,EAAA,MAAM,cAAc,OAAA,CAAQ,MAAA,CAAO,aAAa,cAAA,CAAe,SAAA,CAAU,WAAW,CAAC,CAAA;AACrF,EAAA,OAAA,CAAQ,MA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AAA,EAAU,QAAA,EAAU,OAAO,CAAC;AAAA,GACnF;AACA,EAAA,IAAI,QAAA,CAAS,YAAY,CAAA,KAAM,MAAA,EAAW;AACxC,IAAA,OAAA,CAAQ,KAAK,YAAA,CAAa,YAAA,EAAc,QAAA,EAAU,QAAA,EAAU,OAAO,CAAC,CAAA;AAAA,EACtE;AACA,EAAA,MAAM,oBAAA,GAAuB,0BAAA,CAA2B,QAAA,EAAU,QAAA,EAAU,OAAO,CAAA;AACnF,EAAA,IAAI,oBAAA,EAAsB;AACxB,IAAA,OAAA,CAAQ,KAAK,oBAAoB,CAAA;AAAA,EACnC;AACA,EAAA,OAAO,SAAS,OAAO,CAAA;AACzB;;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const rawTextEscapes = require('../../../domain/ir/raw-text-escapes.cjs');
|
|
4
|
+
const pathItemObject = require('../../../domain/openapi/path-item-object.cjs');
|
|
5
|
+
const outputFixes = require('../../../domain/output-fixes.cjs');
|
|
6
|
+
const pathTemplateReplace = require('./path-template-replace.cjs');
|
|
7
|
+
|
|
8
|
+
const PATH_PARAMETER_RE = /\{[^{}]+\}/g;
|
|
9
|
+
const PLACEHOLDERS = /* @__PURE__ */ new Map([
|
|
10
|
+
["number", "number"],
|
|
11
|
+
["integer", "number"],
|
|
12
|
+
["boolean", "boolean"]
|
|
13
|
+
]);
|
|
14
|
+
const STRING_PLACEHOLDER = "string";
|
|
15
|
+
function resolvedParameter(parameter, context) {
|
|
16
|
+
return "$ref" in parameter && parameter.$ref ? context.refs.resolve(parameter.$ref) : parameter;
|
|
17
|
+
}
|
|
18
|
+
function addPathParameters(parameters, byName, context) {
|
|
19
|
+
for (const parameter of parameters) {
|
|
20
|
+
const resolved = resolvedParameter(parameter, context);
|
|
21
|
+
if (resolved && resolved.in === "path") {
|
|
22
|
+
byName.set(resolved.name, resolved);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function pathParameters(pathItem, context) {
|
|
27
|
+
const byName = /* @__PURE__ */ new Map();
|
|
28
|
+
addPathParameters(pathItem.parameters ?? [], byName, context);
|
|
29
|
+
for (const { operation: entry } of pathItemObject.pathItemOperations(pathItem)) {
|
|
30
|
+
const operation = entry.$ref ? context.refs.resolve(entry.$ref) : entry;
|
|
31
|
+
addPathParameters(operation?.parameters ?? [], byName, context);
|
|
32
|
+
}
|
|
33
|
+
return byName;
|
|
34
|
+
}
|
|
35
|
+
function splitTemplateParts(url, matches) {
|
|
36
|
+
return url.split(PATH_PARAMETER_RE).flatMap((text, index) => {
|
|
37
|
+
const type = matches[index]?.type;
|
|
38
|
+
const textPart = { kind: "text", text };
|
|
39
|
+
return type === void 0 ? [textPart] : [textPart, { kind: "placeholder", type }];
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function pathTemplateParts(url, pathItem, context) {
|
|
43
|
+
const found = url.match(PATH_PARAMETER_RE);
|
|
44
|
+
if (!found) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const parameters = pathParameters(pathItem, context);
|
|
48
|
+
const matches = found.map((match) => {
|
|
49
|
+
const schema = parameters.get(match.slice(1, -1))?.schema;
|
|
50
|
+
return { match, type: PLACEHOLDERS.get(schema?.type) ?? STRING_PLACEHOLDER };
|
|
51
|
+
});
|
|
52
|
+
return context.options.fixes.has(outputFixes.FIX.PATH_PARAM_TYPE_NAMES) ? splitTemplateParts(url, matches) : pathTemplateReplace.replacedTemplateParts(url, matches);
|
|
53
|
+
}
|
|
54
|
+
function templateText(parts) {
|
|
55
|
+
const text = parts.map(
|
|
56
|
+
(part) => part.kind === "text" ? rawTextEscapes.escapeTemplateText(part.text) : pathTemplateReplace.placeholderText(part.type)
|
|
57
|
+
).join("");
|
|
58
|
+
return `\`${text}\``;
|
|
59
|
+
}
|
|
60
|
+
const BOOLEAN_TEXTS = ["true", "false"];
|
|
61
|
+
const isBooleanPlaceholder = (part) => part.kind === "placeholder" && part.type === "boolean";
|
|
62
|
+
function booleanExpandedKeys(parts) {
|
|
63
|
+
const isBooleanOnly = parts.every((part) => part.kind === "text" || isBooleanPlaceholder(part));
|
|
64
|
+
if (!isBooleanOnly) {
|
|
65
|
+
return [[...parts]];
|
|
66
|
+
}
|
|
67
|
+
return parts.reduce(
|
|
68
|
+
(keys, part) => {
|
|
69
|
+
const choices = isBooleanPlaceholder(part) ? BOOLEAN_TEXTS.map((text) => ({ kind: "text", text })) : [part];
|
|
70
|
+
return keys.flatMap((key) => choices.map((choice) => [...key, choice]));
|
|
71
|
+
},
|
|
72
|
+
[[]]
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
function plainUrlOf(parts) {
|
|
76
|
+
const texts = parts.map((part) => part.kind === "text" ? part.text : null);
|
|
77
|
+
return texts.includes(null) ? null : texts.join("");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
exports.booleanExpandedKeys = booleanExpandedKeys;
|
|
81
|
+
exports.pathTemplateParts = pathTemplateParts;
|
|
82
|
+
exports.plainUrlOf = plainUrlOf;
|
|
83
|
+
exports.templateText = templateText;
|
|
84
|
+
//# sourceMappingURL=path-template-key.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-template-key.cjs","sources":["../../../../src/application/transform/document/path-template-key.ts"],"sourcesContent":["import { escapeTemplateText } from \"../../../domain/ir/raw-text-escapes.js\";\nimport type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport type {\n ParameterObject,\n ParameterOrReference,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport {\n type PathItemObject,\n pathItemOperations,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport type { ReferenceSchema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport type { PathKeyPart, PathPlaceholder } from \"./path-key-overlaps.js\";\nimport {\n type PathParameterMatch,\n placeholderText,\n replacedTemplateParts,\n} from \"./path-template-replace.js\";\n\n/** The `--path-params-as-types` key of a path: its URL with a placeholder per parameter. */\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_PARAMETER_RE = /\\{[^{}]+\\}/g;\n\n/** Placeholders by parameter schema type; anything else is a string placeholder. */\nconst PLACEHOLDERS: ReadonlyMap<unknown, PathPlaceholder> = new Map([\n [\"number\", \"number\"],\n [\"integer\", \"number\"],\n [\"boolean\", \"boolean\"],\n]);\nconst STRING_PLACEHOLDER: PathPlaceholder = \"string\";\n\nfunction resolvedParameter(\n parameter: ParameterOrReference,\n context: TransformContext,\n): ParameterObject | undefined {\n return \"$ref\" in parameter && parameter.$ref\n ? (context.refs.resolve(parameter.$ref) as ParameterObject | undefined)\n : (parameter as ParameterObject);\n}\n\nfunction addPathParameters(\n parameters: readonly ParameterOrReference[],\n byName: Map<string, ParameterObject>,\n context: TransformContext,\n): void {\n for (const parameter of parameters) {\n const resolved = resolvedParameter(parameter, context);\n if (resolved && resolved.in === \"path\") {\n byName.set(resolved.name, resolved);\n }\n }\n}\n\n/** Path parameters of the path item and of its operations; later definitions win. */\nfunction pathParameters(\n pathItem: PathItemObject,\n context: TransformContext,\n): Map<string, ParameterObject> {\n const byName = new Map<string, ParameterObject>();\n addPathParameters(pathItem.parameters ?? [], byName, context);\n for (const { operation: entry } of pathItemOperations(pathItem)) {\n const operation = (entry as ReferenceSchema).$ref\n ? (context.refs.resolve((entry as ReferenceSchema).$ref) as OperationObject | undefined)\n : (entry as OperationObject);\n addPathParameters(operation?.parameters ?? [], byName, context);\n }\n return byName;\n}\n\n/** Each `{name}` of the URL and its own placeholder, from the URL split at the matches. */\nfunction splitTemplateParts(url: string, matches: readonly PathParameterMatch[]): PathKeyPart[] {\n return url.split(PATH_PARAMETER_RE).flatMap((text, index): PathKeyPart[] => {\n const type = matches[index]?.type;\n const textPart: PathKeyPart = { kind: \"text\", text };\n return type === undefined ? [textPart] : [textPart, { kind: \"placeholder\", type }];\n });\n}\n\n/**\n * `--path-params-as-types`: the URL as template parts, each `{name}` replaced by a placeholder for\n * its parameter's type, the way the original replaces them unless the `path-param-type-names` fix\n * is on (see `replacedTemplateParts`). Null when the URL has no complete `{…}` placeholder.\n */\nexport function pathTemplateParts(\n url: string,\n pathItem: PathItemObject,\n context: TransformContext,\n): PathKeyPart[] | null {\n const found = url.match(PATH_PARAMETER_RE);\n if (!found) {\n return null;\n }\n const parameters = pathParameters(pathItem, context);\n const matches = found.map((match): PathParameterMatch => {\n const schema = parameters.get(match.slice(1, -1))?.schema as SchemaObject | undefined;\n return { match, type: PLACEHOLDERS.get(schema?.type) ?? STRING_PLACEHOLDER };\n });\n return context.options.fixes.has(FIX.PATH_PARAM_TYPE_NAMES)\n ? splitTemplateParts(url, matches)\n : replacedTemplateParts(url, matches);\n}\n\n/**\n * The template literal type of the parts. The original escaped only backticks: a backslash or\n * `${` in the URL could end the literal or open a placeholder, and add code to the generated file\n * (intentional fix). So the text parts are escaped.\n */\nexport function templateText(parts: readonly PathKeyPart[]): string {\n const text = parts\n .map((part) =>\n part.kind === \"text\" ? escapeTemplateText(part.text) : placeholderText(part.type),\n )\n .join(\"\");\n return `\\`${text}\\``;\n}\n\nconst BOOLEAN_TEXTS = [\"true\", \"false\"] as const;\n\nconst isBooleanPlaceholder = (part: PathKeyPart): boolean =>\n part.kind === \"placeholder\" && part.type === \"boolean\";\n\n/**\n * The keys of a template whose only placeholders are `${boolean}`, with each written as `true`\n * and as `false`. Such a template is a union of literals, and an index signature takes none\n * (TS1337), so the original's `` [path: `/flags/${boolean}`] `` did not compile. A path with n\n * boolean parameters gets 2ⁿ plain URLs (`/flags/true`), all with the same path item type. Next to\n * another placeholder the template is a pattern, a valid signature that admits the same URLs, so\n * those parts stay one key.\n */\nexport function booleanExpandedKeys(parts: readonly PathKeyPart[]): PathKeyPart[][] {\n const isBooleanOnly = parts.every((part) => part.kind === \"text\" || isBooleanPlaceholder(part));\n if (!isBooleanOnly) {\n return [[...parts]];\n }\n return parts.reduce<PathKeyPart[][]>(\n (keys, part) => {\n const choices: readonly PathKeyPart[] = isBooleanPlaceholder(part)\n ? BOOLEAN_TEXTS.map((text) => ({ kind: \"text\", text }))\n : [part];\n return keys.flatMap((key) => choices.map((choice) => [...key, choice]));\n },\n [[]],\n );\n}\n\n/** The URL of parts without placeholders; null when one is left. */\nexport function plainUrlOf(parts: readonly PathKeyPart[]): string | null {\n const texts = parts.map((part) => (part.kind === \"text\" ? part.text : null));\n return texts.includes(null) ? null : texts.join(\"\");\n}\n"],"names":["pathItemOperations","FIX","replacedTemplateParts","escapeTemplateText","placeholderText"],"mappings":";;;;;;;AAuBA,MAAM,iBAAA,GAAoB,aAAA;AAG1B,MAAM,YAAA,uBAA0D,GAAA,CAAI;AAAA,EAClE,CAAC,UAAU,QAAQ,CAAA;AAAA,EACnB,CAAC,WAAW,QAAQ,CAAA;AAAA,EACpB,CAAC,WAAW,SAAS;AACvB,CAAC,CAAA;AACD,MAAM,kBAAA,GAAsC,QAAA;AAE5C,SAAS,iBAAA,CACP,WACA,OAAA,EAC6B;AAC7B,EAAA,OAAO,MAAA,IAAU,aAAa,SAAA,CAAU,IAAA,GACnC,QAAQ,IAAA,CAAK,OAAA,CAAQ,SAAA,CAAU,IAAI,CAAA,GACnC,SAAA;AACP;AAEA,SAAS,iBAAA,CACP,UAAA,EACA,MAAA,EACA,OAAA,EACM;AACN,EAAA,KAAA,MAAW,aAAa,UAAA,EAAY;AAClC,IAAA,MAAM,QAAA,GAAW,iBAAA,CAAkB,SAAA,EAAW,OAAO,CAAA;AACrD,IAAA,IAAI,QAAA,IAAY,QAAA,CAAS,EAAA,KAAO,MAAA,EAAQ;AACtC,MAAA,MAAA,CAAO,GAAA,CAAI,QAAA,CAAS,IAAA,EAAM,QAAQ,CAAA;AAAA,IACpC;AAAA,EACF;AACF;AAGA,SAAS,cAAA,CACP,UACA,OAAA,EAC8B;AAC9B,EAAA,MAAM,MAAA,uBAAa,GA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,CAAqB,IAAI,CAAA,GAC7D,cAAc,GAAA,CAAI,CAAC,IAAA,MAAU,EAAE,MAAM,MAAA,EAAQ,IAAA,EAAK,CAAE,CAAA,GACpD,CAAC,IAAI,CAAA;AACT,MAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,CAAC,GAAA,KAAQ,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW,CAAC,GAAG,GAAA,EAAK,MAAM,CAAC,CAAC,CAAA;AAAA,IACxE,CAAA;AAAA,IACA,CAAC,EAAE;AAAA,GACL;AACF;AAGO,SAAS,WAAW,KAAA,EAA8C;AACvE,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,KAAU,KAAK,IAAA,KAAS,MAAA,GAAS,IAAA,CAAK,IAAA,GAAO,IAAK,CAAA;AAC3E,EAAA,OAAO,MAAM,QAAA,CAAS,IAAI,IAAI,IAAA,GAAO,KAAA,CAAM,KAAK,EAAE,CAAA;AACpD;;;;;"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { escapeTemplateText } from '../../../domain/ir/raw-text-escapes.mjs';
|
|
2
|
+
import { pathItemOperations } from '../../../domain/openapi/path-item-object.mjs';
|
|
3
|
+
import { FIX } from '../../../domain/output-fixes.mjs';
|
|
4
|
+
import { replacedTemplateParts, placeholderText } from './path-template-replace.mjs';
|
|
5
|
+
|
|
6
|
+
const PATH_PARAMETER_RE = /\{[^{}]+\}/g;
|
|
7
|
+
const PLACEHOLDERS = /* @__PURE__ */ new Map([
|
|
8
|
+
["number", "number"],
|
|
9
|
+
["integer", "number"],
|
|
10
|
+
["boolean", "boolean"]
|
|
11
|
+
]);
|
|
12
|
+
const STRING_PLACEHOLDER = "string";
|
|
13
|
+
function resolvedParameter(parameter, context) {
|
|
14
|
+
return "$ref" in parameter && parameter.$ref ? context.refs.resolve(parameter.$ref) : parameter;
|
|
15
|
+
}
|
|
16
|
+
function addPathParameters(parameters, byName, context) {
|
|
17
|
+
for (const parameter of parameters) {
|
|
18
|
+
const resolved = resolvedParameter(parameter, context);
|
|
19
|
+
if (resolved && resolved.in === "path") {
|
|
20
|
+
byName.set(resolved.name, resolved);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function pathParameters(pathItem, context) {
|
|
25
|
+
const byName = /* @__PURE__ */ new Map();
|
|
26
|
+
addPathParameters(pathItem.parameters ?? [], byName, context);
|
|
27
|
+
for (const { operation: entry } of pathItemOperations(pathItem)) {
|
|
28
|
+
const operation = entry.$ref ? context.refs.resolve(entry.$ref) : entry;
|
|
29
|
+
addPathParameters(operation?.parameters ?? [], byName, context);
|
|
30
|
+
}
|
|
31
|
+
return byName;
|
|
32
|
+
}
|
|
33
|
+
function splitTemplateParts(url, matches) {
|
|
34
|
+
return url.split(PATH_PARAMETER_RE).flatMap((text, index) => {
|
|
35
|
+
const type = matches[index]?.type;
|
|
36
|
+
const textPart = { kind: "text", text };
|
|
37
|
+
return type === void 0 ? [textPart] : [textPart, { kind: "placeholder", type }];
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function pathTemplateParts(url, pathItem, context) {
|
|
41
|
+
const found = url.match(PATH_PARAMETER_RE);
|
|
42
|
+
if (!found) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const parameters = pathParameters(pathItem, context);
|
|
46
|
+
const matches = found.map((match) => {
|
|
47
|
+
const schema = parameters.get(match.slice(1, -1))?.schema;
|
|
48
|
+
return { match, type: PLACEHOLDERS.get(schema?.type) ?? STRING_PLACEHOLDER };
|
|
49
|
+
});
|
|
50
|
+
return context.options.fixes.has(FIX.PATH_PARAM_TYPE_NAMES) ? splitTemplateParts(url, matches) : replacedTemplateParts(url, matches);
|
|
51
|
+
}
|
|
52
|
+
function templateText(parts) {
|
|
53
|
+
const text = parts.map(
|
|
54
|
+
(part) => part.kind === "text" ? escapeTemplateText(part.text) : placeholderText(part.type)
|
|
55
|
+
).join("");
|
|
56
|
+
return `\`${text}\``;
|
|
57
|
+
}
|
|
58
|
+
const BOOLEAN_TEXTS = ["true", "false"];
|
|
59
|
+
const isBooleanPlaceholder = (part) => part.kind === "placeholder" && part.type === "boolean";
|
|
60
|
+
function booleanExpandedKeys(parts) {
|
|
61
|
+
const isBooleanOnly = parts.every((part) => part.kind === "text" || isBooleanPlaceholder(part));
|
|
62
|
+
if (!isBooleanOnly) {
|
|
63
|
+
return [[...parts]];
|
|
64
|
+
}
|
|
65
|
+
return parts.reduce(
|
|
66
|
+
(keys, part) => {
|
|
67
|
+
const choices = isBooleanPlaceholder(part) ? BOOLEAN_TEXTS.map((text) => ({ kind: "text", text })) : [part];
|
|
68
|
+
return keys.flatMap((key) => choices.map((choice) => [...key, choice]));
|
|
69
|
+
},
|
|
70
|
+
[[]]
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
function plainUrlOf(parts) {
|
|
74
|
+
const texts = parts.map((part) => part.kind === "text" ? part.text : null);
|
|
75
|
+
return texts.includes(null) ? null : texts.join("");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { booleanExpandedKeys, pathTemplateParts, plainUrlOf, templateText };
|
|
79
|
+
//# sourceMappingURL=path-template-key.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-template-key.mjs","sources":["../../../../src/application/transform/document/path-template-key.ts"],"sourcesContent":["import { escapeTemplateText } from \"../../../domain/ir/raw-text-escapes.js\";\nimport type { OperationObject } from \"../../../domain/openapi/operation-object.js\";\nimport type {\n ParameterObject,\n ParameterOrReference,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport {\n type PathItemObject,\n pathItemOperations,\n} from \"../../../domain/openapi/path-item-object.js\";\nimport type { ReferenceSchema, SchemaObject } from \"../../../domain/openapi/schema-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport type { PathKeyPart, PathPlaceholder } from \"./path-key-overlaps.js\";\nimport {\n type PathParameterMatch,\n placeholderText,\n replacedTemplateParts,\n} from \"./path-template-replace.js\";\n\n/** The `--path-params-as-types` key of a path: its URL with a placeholder per parameter. */\n\n/** `[^{}]` keeps the scan linear: `[^}]` retried from every `{` of a long run of them. */\nconst PATH_PARAMETER_RE = /\\{[^{}]+\\}/g;\n\n/** Placeholders by parameter schema type; anything else is a string placeholder. */\nconst PLACEHOLDERS: ReadonlyMap<unknown, PathPlaceholder> = new Map([\n [\"number\", \"number\"],\n [\"integer\", \"number\"],\n [\"boolean\", \"boolean\"],\n]);\nconst STRING_PLACEHOLDER: PathPlaceholder = \"string\";\n\nfunction resolvedParameter(\n parameter: ParameterOrReference,\n context: TransformContext,\n): ParameterObject | undefined {\n return \"$ref\" in parameter && parameter.$ref\n ? (context.refs.resolve(parameter.$ref) as ParameterObject | undefined)\n : (parameter as ParameterObject);\n}\n\nfunction addPathParameters(\n parameters: readonly ParameterOrReference[],\n byName: Map<string, ParameterObject>,\n context: TransformContext,\n): void {\n for (const parameter of parameters) {\n const resolved = resolvedParameter(parameter, context);\n if (resolved && resolved.in === \"path\") {\n byName.set(resolved.name, resolved);\n }\n }\n}\n\n/** Path parameters of the path item and of its operations; later definitions win. */\nfunction pathParameters(\n pathItem: PathItemObject,\n context: TransformContext,\n): Map<string, ParameterObject> {\n const byName = new Map<string, ParameterObject>();\n addPathParameters(pathItem.parameters ?? [], byName, context);\n for (const { operation: entry } of pathItemOperations(pathItem)) {\n const operation = (entry as ReferenceSchema).$ref\n ? (context.refs.resolve((entry as ReferenceSchema).$ref) as OperationObject | undefined)\n : (entry as OperationObject);\n addPathParameters(operation?.parameters ?? [], byName, context);\n }\n return byName;\n}\n\n/** Each `{name}` of the URL and its own placeholder, from the URL split at the matches. */\nfunction splitTemplateParts(url: string, matches: readonly PathParameterMatch[]): PathKeyPart[] {\n return url.split(PATH_PARAMETER_RE).flatMap((text, index): PathKeyPart[] => {\n const type = matches[index]?.type;\n const textPart: PathKeyPart = { kind: \"text\", text };\n return type === undefined ? [textPart] : [textPart, { kind: \"placeholder\", type }];\n });\n}\n\n/**\n * `--path-params-as-types`: the URL as template parts, each `{name}` replaced by a placeholder for\n * its parameter's type, the way the original replaces them unless the `path-param-type-names` fix\n * is on (see `replacedTemplateParts`). Null when the URL has no complete `{…}` placeholder.\n */\nexport function pathTemplateParts(\n url: string,\n pathItem: PathItemObject,\n context: TransformContext,\n): PathKeyPart[] | null {\n const found = url.match(PATH_PARAMETER_RE);\n if (!found) {\n return null;\n }\n const parameters = pathParameters(pathItem, context);\n const matches = found.map((match): PathParameterMatch => {\n const schema = parameters.get(match.slice(1, -1))?.schema as SchemaObject | undefined;\n return { match, type: PLACEHOLDERS.get(schema?.type) ?? STRING_PLACEHOLDER };\n });\n return context.options.fixes.has(FIX.PATH_PARAM_TYPE_NAMES)\n ? splitTemplateParts(url, matches)\n : replacedTemplateParts(url, matches);\n}\n\n/**\n * The template literal type of the parts. The original escaped only backticks: a backslash or\n * `${` in the URL could end the literal or open a placeholder, and add code to the generated file\n * (intentional fix). So the text parts are escaped.\n */\nexport function templateText(parts: readonly PathKeyPart[]): string {\n const text = parts\n .map((part) =>\n part.kind === \"text\" ? escapeTemplateText(part.text) : placeholderText(part.type),\n )\n .join(\"\");\n return `\\`${text}\\``;\n}\n\nconst BOOLEAN_TEXTS = [\"true\", \"false\"] as const;\n\nconst isBooleanPlaceholder = (part: PathKeyPart): boolean =>\n part.kind === \"placeholder\" && part.type === \"boolean\";\n\n/**\n * The keys of a template whose only placeholders are `${boolean}`, with each written as `true`\n * and as `false`. Such a template is a union of literals, and an index signature takes none\n * (TS1337), so the original's `` [path: `/flags/${boolean}`] `` did not compile. A path with n\n * boolean parameters gets 2ⁿ plain URLs (`/flags/true`), all with the same path item type. Next to\n * another placeholder the template is a pattern, a valid signature that admits the same URLs, so\n * those parts stay one key.\n */\nexport function booleanExpandedKeys(parts: readonly PathKeyPart[]): PathKeyPart[][] {\n const isBooleanOnly = parts.every((part) => part.kind === \"text\" || isBooleanPlaceholder(part));\n if (!isBooleanOnly) {\n return [[...parts]];\n }\n return parts.reduce<PathKeyPart[][]>(\n (keys, part) => {\n const choices: readonly PathKeyPart[] = isBooleanPlaceholder(part)\n ? BOOLEAN_TEXTS.map((text) => ({ kind: \"text\", text }))\n : [part];\n return keys.flatMap((key) => choices.map((choice) => [...key, choice]));\n },\n [[]],\n );\n}\n\n/** The URL of parts without placeholders; null when one is left. */\nexport function plainUrlOf(parts: readonly PathKeyPart[]): string | null {\n const texts = parts.map((part) => (part.kind === \"text\" ? part.text : null));\n return texts.includes(null) ? null : texts.join(\"\");\n}\n"],"names":[],"mappings":";;;;;AAuBA,MAAM,iBAAA,GAAoB,aAAA;AAG1B,MAAM,YAAA,uBAA0D,GAAA,CAAI;AAAA,EAClE,CAAC,UAAU,QAAQ,CAAA;AAAA,EACnB,CAAC,WAAW,QAAQ,CAAA;AAAA,EACpB,CAAC,WAAW,SAAS;AACvB,CAAC,CAAA;AACD,MAAM,kBAAA,GAAsC,QAAA;AAE5C,SAAS,iBAAA,CACP,WACA,OAAA,EAC6B;AAC7B,EAAA,OAAO,MAAA,IAAU,aAAa,SAAA,CAAU,IAAA,GACnC,QAAQ,IAAA,CAAK,OAAA,CAAQ,SAAA,CAAU,IAAI,CAAA,GACnC,SAAA;AACP;AAEA,SAAS,iBAAA,CACP,UAAA,EACA,MAAA,EACA,OAAA,EACM;AACN,EAAA,KAAA,MAAW,aAAa,UAAA,EAAY;AAClC,IAAA,MAAM,QAAA,GAAW,iBAAA,CAAkB,SAAA,EAAW,OAAO,CAAA;AACrD,IAAA,IAAI,QAAA,IAAY,QAAA,CAAS,EAAA,KAAO,MAAA,EAAQ;AACtC,MAAA,MAAA,CAAO,GAAA,CAAI,QAAA,CAAS,IAAA,EAAM,QAAQ,CAAA;AAAA,IACpC;AAAA,EACF;AACF;AAGA,SAAS,cAAA,CACP,UACA,OAAA,EAC8B;AAC9B,EAAA,MAAM,MAAA,uBAAa,GAAA,EAA6B;AAChD,EA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D,cAAc,GAAA,CAAI,CAAC,IAAA,MAAU,EAAE,MAAM,MAAA,EAAQ,IAAA,EAAK,CAAE,CAAA,GACpD,CAAC,IAAI,CAAA;AACT,MAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,CAAC,GAAA,KAAQ,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW,CAAC,GAAG,GAAA,EAAK,MAAM,CAAC,CAAC,CAAA;AAAA,IACxE,CAAA;AAAA,IACA,CAAC,EAAE;AAAA,GACL;AACF;AAGO,SAAS,WAAW,KAAA,EAA8C;AACvE,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,KAAU,KAAK,IAAA,KAAS,MAAA,GAAS,IAAA,CAAK,IAAA,GAAO,IAAK,CAAA;AAC3E,EAAA,OAAO,MAAM,QAAA,CAAS,IAAI,IAAI,IAAA,GAAO,KAAA,CAAM,KAAK,EAAE,CAAA;AACpD;;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const constructors = require('../../../domain/ir/constructors.cjs');
|
|
4
|
+
const documentEntries = require('../document-entries.cjs');
|
|
5
|
+
const pathTemplateKey = require('./path-template-key.cjs');
|
|
6
|
+
const paths = require('./paths.cjs');
|
|
7
|
+
|
|
8
|
+
const PATHS_TYPE_NAME = "paths";
|
|
9
|
+
function templateIndexText(url, parts, takenUrls) {
|
|
10
|
+
const keys = pathTemplateKey.booleanExpandedKeys(parts).map(paths.pathKeyOf).filter((key) => paths.isUntakenKey(url, key, takenUrls));
|
|
11
|
+
const texts = keys.map(
|
|
12
|
+
(key) => key.kind === "literal" ? JSON.stringify(key.url) : pathTemplateKey.templateText(key.parts)
|
|
13
|
+
);
|
|
14
|
+
return texts.length === 0 ? void 0 : texts.join(" | ");
|
|
15
|
+
}
|
|
16
|
+
function unmatchedTemplateKeys(paths, context) {
|
|
17
|
+
const keys = /* @__PURE__ */ new Map();
|
|
18
|
+
if (!context.options.pathParamsAsTypes || typeof paths !== "object" || paths === null) {
|
|
19
|
+
return keys;
|
|
20
|
+
}
|
|
21
|
+
const takenUrls = new Set(Object.keys(paths));
|
|
22
|
+
for (const [url, pathItem] of documentEntries.documentEntries(paths, context.options)) {
|
|
23
|
+
if (!pathItem || typeof pathItem !== "object" || "$ref" in pathItem || !url.includes("{")) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const parts = pathTemplateKey.pathTemplateParts(url, pathItem, context);
|
|
27
|
+
const index = parts === null ? void 0 : templateIndexText(url, parts, takenUrls);
|
|
28
|
+
const isUnmatched = parts?.some(
|
|
29
|
+
(part) => part.kind === "placeholder" && part.type !== "string"
|
|
30
|
+
);
|
|
31
|
+
if (isUnmatched && index !== void 0) {
|
|
32
|
+
keys.set(url, index);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return keys;
|
|
36
|
+
}
|
|
37
|
+
function isNode(value) {
|
|
38
|
+
return typeof value === "object" && value !== null;
|
|
39
|
+
}
|
|
40
|
+
function pathsIndexUrl(node) {
|
|
41
|
+
const object = node.object;
|
|
42
|
+
const index = node.index;
|
|
43
|
+
const isPathsIndex = node.kind === "indexedAccess" && object?.kind === "reference" && object.name === PATHS_TYPE_NAME && object.typeArguments?.length === 0 && index?.kind === "stringLiteral";
|
|
44
|
+
return isPathsIndex ? index.value : void 0;
|
|
45
|
+
}
|
|
46
|
+
function rewrittenNode(value, keys) {
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
return value.map((item) => rewrittenNode(item, keys));
|
|
49
|
+
}
|
|
50
|
+
if (!isNode(value)) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
const template = keys.get(pathsIndexUrl(value) ?? "");
|
|
54
|
+
if (template !== void 0) {
|
|
55
|
+
return { ...value, index: constructors.irRaw(template) };
|
|
56
|
+
}
|
|
57
|
+
return Object.fromEntries(
|
|
58
|
+
Object.entries(value).map(([key, child]) => [
|
|
59
|
+
key,
|
|
60
|
+
key === "origin" ? child : rewrittenNode(child, keys)
|
|
61
|
+
])
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
function withTemplatePathRefs(declarations, keys) {
|
|
65
|
+
return keys.size === 0 ? [...declarations] : rewrittenNode(declarations, keys);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.unmatchedTemplateKeys = unmatchedTemplateKeys;
|
|
69
|
+
exports.withTemplatePathRefs = withTemplatePathRefs;
|
|
70
|
+
//# sourceMappingURL=path-template-refs.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-template-refs.cjs","sources":["../../../../src/application/transform/document/path-template-refs.ts"],"sourcesContent":["import { irRaw } from \"../../../domain/ir/constructors.js\";\nimport type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\nimport type { PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport type { PathKeyPart } from \"./path-key-overlaps.js\";\nimport { booleanExpandedKeys, pathTemplateParts, templateText } from \"./path-template-key.js\";\nimport { isUntakenKey, pathKeyOf } from \"./paths.js\";\n\n/**\n * `--path-params-as-types` and `$ref`s into a templated path. Such a path is an index signature\n * of `paths` (`` [path: `/pets/${number}`] ``), so `paths[\"/pets/{id}\"]`, the type of a `$ref`\n * to it, names no key: `{id}` is no number (TS2339). The reference indexes `paths` by the\n * template instead, which reaches the signature. With only `${string}` placeholders the URL\n * itself matches the template and the output compiles, so it stays as it is.\n */\n\nconst PATHS_TYPE_NAME = \"paths\";\n\n/**\n * The index of a templated path: the union of the keys it is written with. A `${boolean}` key the\n * document's own path took (`/flags/true` next to `/flags/{enabled}`) is left out, so the index\n * names only this path's members. Undefined when every key was taken: the path has no member.\n */\nfunction templateIndexText(url: string, parts: readonly PathKeyPart[], takenUrls: Set<string>) {\n const keys = booleanExpandedKeys(parts)\n .map(pathKeyOf)\n .filter((key) => isUntakenKey(url, key, takenUrls));\n const texts = keys.map((key) =>\n key.kind === \"literal\" ? JSON.stringify(key.url) : templateText(key.parts),\n );\n return texts.length === 0 ? undefined : texts.join(\" | \");\n}\n\n/** The index of each templated path whose URL does not match its keys, by URL. */\nexport function unmatchedTemplateKeys(\n paths: PathsObject | null | undefined,\n context: TransformContext,\n): ReadonlyMap<string, string> {\n const keys = new Map<string, string>();\n // A document may hold any value as `paths`; one that is no object has no paths.\n if (!context.options.pathParamsAsTypes || typeof paths !== \"object\" || paths === null) {\n return keys;\n }\n // The same walk as `pathMembers`, so a URL is taken by the same path as there.\n const takenUrls = new Set(Object.keys(paths));\n for (const [url, pathItem] of documentEntries(paths, context.options)) {\n if (!pathItem || typeof pathItem !== \"object\" || \"$ref\" in pathItem || !url.includes(\"{\")) {\n continue;\n }\n const parts = pathTemplateParts(url, pathItem, context);\n const index = parts === null ? undefined : templateIndexText(url, parts, takenUrls);\n const isUnmatched = parts?.some(\n (part) => part.kind === \"placeholder\" && part.type !== \"string\",\n );\n if (isUnmatched && index !== undefined) {\n keys.set(url, index);\n }\n }\n return keys;\n}\n\nfunction isNode(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null;\n}\n\n/** `paths[\"<url>\"]`: an index of the `paths` root by a string literal. */\nfunction pathsIndexUrl(node: Readonly<Record<string, unknown>>): string | undefined {\n const object = node.object as Readonly<Record<string, unknown>> | undefined;\n const index = node.index as Readonly<Record<string, unknown>> | undefined;\n const isPathsIndex =\n node.kind === \"indexedAccess\" &&\n object?.kind === \"reference\" &&\n object.name === PATHS_TYPE_NAME &&\n (object.typeArguments as readonly unknown[] | undefined)?.length === 0 &&\n index?.kind === \"stringLiteral\";\n return isPathsIndex ? (index.value as string) : undefined;\n}\n\nfunction rewrittenNode(value: unknown, keys: ReadonlyMap<string, string>): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => rewrittenNode(item, keys));\n }\n if (!isNode(value)) {\n return value;\n }\n const template = keys.get(pathsIndexUrl(value) ?? \"\");\n if (template !== undefined) {\n return { ...value, index: irRaw(template) };\n }\n // `origin` holds the compiler node a raw type was printed from; it is not IR.\n return Object.fromEntries(\n Object.entries(value).map(([key, child]) => [\n key,\n key === \"origin\" ? child : rewrittenNode(child, keys),\n ]),\n );\n}\n\n/** The declarations with each `paths[\"<url>\"]` of an unmatched template indexed by it. */\nexport function withTemplatePathRefs<T extends IrDeclaration>(\n declarations: readonly T[],\n keys: ReadonlyMap<string, string>,\n): T[] {\n return keys.size === 0 ? [...declarations] : (rewrittenNode(declarations, keys) as T[]);\n}\n"],"names":["booleanExpandedKeys","pathKeyOf","isUntakenKey","templateText","documentEntries","pathTemplateParts","irRaw"],"mappings":";;;;;;;AAiBA,MAAM,eAAA,GAAkB,OAAA;AAOxB,SAAS,iBAAA,CAAkB,GAAA,EAAa,KAAA,EAA+B,SAAA,EAAwB;AAC7F,EAAA,MAAM,IAAA,GAAOA,mCAAA,CAAoB,KAAK,CAAA,CACnC,IAAIC,eAAS,CAAA,CACb,MAAA,CAAO,CAAC,GAAA,KAAQC,kBAAA,CAAa,GAAA,EAAK,GAAA,EAAK,SAAS,CAAC,CAAA;AACpD,EAAA,MAAM,QAAQ,IAAA,CAAK,GAAA;AAAA,IAAI,CAAC,GAAA,KACtB,GAAA,CAAI,IAAA,KAAS,SAAA,GAAY,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA,GAAIC,4BAAA,CAAa,GAAA,CAAI,KAAK;AAAA,GAC3E;AACA,EAAA,OAAO,MAAM,MAAA,KAAW,CAAA,GAAI,MAAA,GAAY,KAAA,CAAM,KAAK,KAAK,CAAA;AAC1D;AAGO,SAAS,qBAAA,CACd,OACA,OAAA,EAC6B;AAC7B,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAoB;AAErC,EAAA,IAAI,CAAC,QAAQ,OAAA,CAAQ,iBAAA,IAAqB,OAAO,KAAA,KAAU,QAAA,IAAY,UAAU,IAAA,EAAM;AACrF,IAAA,OA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CAAA,IACrE,OAAO,IAAA,KAAS,eAAA;AAClB,EAAA,OAAO,YAAA,GAAgB,MAAM,KAAA,GAAmB,MAAA;AAClD;AAEA,SAAS,aAAA,CAAc,OAAgB,IAAA,EAA4C;AACjF,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,MAAM,GAAA,CAAI,CAAC,SAAS,aAAA,CAAc,IAAA,EAAM,IAAI,CAAC,CAAA;AAAA,EACtD;AACA,EAAA,IAAI,CAAC,MAAA,CAAO,KAAK,CAAA,EAAG;AAClB,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,MAAM,WAAW,IAAA,CAAK,GAAA,CAAI,aAAA,CAAc,KAAK,KAAK,EAAE,CAAA;AACpD,EAAA,IAAI,aAAa,MAAA,EAAW;AAC1B,IAAA,OAAO,EAAE,GAAG,KAAA,EAAO,KAAA,EAAOC,kBAAA,CAAM,QAAQ,CAAA,EAAE;AAAA,EAC5C;AAEA,EAAA,OAAO,MAAA,CAAO,WAAA;AAAA,IACZ,MAAA,CAAO,QAAQ,KAAK,CAAA,CAAE,IAAI,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM;AAAA,MAC1C,GAAA;AAAA,MACA,GAAA,KAAQ,QAAA,GAAW,KAAA,GAAQ,aAAA,CAAc,OAAO,IAAI;AAAA,KACrD;AAAA,GACH;AACF;AAGO,SAAS,oBAAA,CACd,cACA,IAAA,EACK;AACL,EAAA,OAAO,IAAA,CAAK,SAAS,CAAA,GAAI,CAAC,GAAG,YAAY,CAAA,GAAK,aAAA,CAAc,YAAA,EAAc,IAAI,CAAA;AAChF;;;"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { irRaw } from '../../../domain/ir/constructors.mjs';
|
|
2
|
+
import { documentEntries } from '../document-entries.mjs';
|
|
3
|
+
import { pathTemplateParts, booleanExpandedKeys, templateText } from './path-template-key.mjs';
|
|
4
|
+
import { pathKeyOf, isUntakenKey } from './paths.mjs';
|
|
5
|
+
|
|
6
|
+
const PATHS_TYPE_NAME = "paths";
|
|
7
|
+
function templateIndexText(url, parts, takenUrls) {
|
|
8
|
+
const keys = booleanExpandedKeys(parts).map(pathKeyOf).filter((key) => isUntakenKey(url, key, takenUrls));
|
|
9
|
+
const texts = keys.map(
|
|
10
|
+
(key) => key.kind === "literal" ? JSON.stringify(key.url) : templateText(key.parts)
|
|
11
|
+
);
|
|
12
|
+
return texts.length === 0 ? void 0 : texts.join(" | ");
|
|
13
|
+
}
|
|
14
|
+
function unmatchedTemplateKeys(paths, context) {
|
|
15
|
+
const keys = /* @__PURE__ */ new Map();
|
|
16
|
+
if (!context.options.pathParamsAsTypes || typeof paths !== "object" || paths === null) {
|
|
17
|
+
return keys;
|
|
18
|
+
}
|
|
19
|
+
const takenUrls = new Set(Object.keys(paths));
|
|
20
|
+
for (const [url, pathItem] of documentEntries(paths, context.options)) {
|
|
21
|
+
if (!pathItem || typeof pathItem !== "object" || "$ref" in pathItem || !url.includes("{")) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const parts = pathTemplateParts(url, pathItem, context);
|
|
25
|
+
const index = parts === null ? void 0 : templateIndexText(url, parts, takenUrls);
|
|
26
|
+
const isUnmatched = parts?.some(
|
|
27
|
+
(part) => part.kind === "placeholder" && part.type !== "string"
|
|
28
|
+
);
|
|
29
|
+
if (isUnmatched && index !== void 0) {
|
|
30
|
+
keys.set(url, index);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return keys;
|
|
34
|
+
}
|
|
35
|
+
function isNode(value) {
|
|
36
|
+
return typeof value === "object" && value !== null;
|
|
37
|
+
}
|
|
38
|
+
function pathsIndexUrl(node) {
|
|
39
|
+
const object = node.object;
|
|
40
|
+
const index = node.index;
|
|
41
|
+
const isPathsIndex = node.kind === "indexedAccess" && object?.kind === "reference" && object.name === PATHS_TYPE_NAME && object.typeArguments?.length === 0 && index?.kind === "stringLiteral";
|
|
42
|
+
return isPathsIndex ? index.value : void 0;
|
|
43
|
+
}
|
|
44
|
+
function rewrittenNode(value, keys) {
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
return value.map((item) => rewrittenNode(item, keys));
|
|
47
|
+
}
|
|
48
|
+
if (!isNode(value)) {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
const template = keys.get(pathsIndexUrl(value) ?? "");
|
|
52
|
+
if (template !== void 0) {
|
|
53
|
+
return { ...value, index: irRaw(template) };
|
|
54
|
+
}
|
|
55
|
+
return Object.fromEntries(
|
|
56
|
+
Object.entries(value).map(([key, child]) => [
|
|
57
|
+
key,
|
|
58
|
+
key === "origin" ? child : rewrittenNode(child, keys)
|
|
59
|
+
])
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
function withTemplatePathRefs(declarations, keys) {
|
|
63
|
+
return keys.size === 0 ? [...declarations] : rewrittenNode(declarations, keys);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { unmatchedTemplateKeys, withTemplatePathRefs };
|
|
67
|
+
//# sourceMappingURL=path-template-refs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-template-refs.mjs","sources":["../../../../src/application/transform/document/path-template-refs.ts"],"sourcesContent":["import { irRaw } from \"../../../domain/ir/constructors.js\";\nimport type { IrDeclaration } from \"../../../domain/ir/nodes.js\";\nimport type { PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport type { PathKeyPart } from \"./path-key-overlaps.js\";\nimport { booleanExpandedKeys, pathTemplateParts, templateText } from \"./path-template-key.js\";\nimport { isUntakenKey, pathKeyOf } from \"./paths.js\";\n\n/**\n * `--path-params-as-types` and `$ref`s into a templated path. Such a path is an index signature\n * of `paths` (`` [path: `/pets/${number}`] ``), so `paths[\"/pets/{id}\"]`, the type of a `$ref`\n * to it, names no key: `{id}` is no number (TS2339). The reference indexes `paths` by the\n * template instead, which reaches the signature. With only `${string}` placeholders the URL\n * itself matches the template and the output compiles, so it stays as it is.\n */\n\nconst PATHS_TYPE_NAME = \"paths\";\n\n/**\n * The index of a templated path: the union of the keys it is written with. A `${boolean}` key the\n * document's own path took (`/flags/true` next to `/flags/{enabled}`) is left out, so the index\n * names only this path's members. Undefined when every key was taken: the path has no member.\n */\nfunction templateIndexText(url: string, parts: readonly PathKeyPart[], takenUrls: Set<string>) {\n const keys = booleanExpandedKeys(parts)\n .map(pathKeyOf)\n .filter((key) => isUntakenKey(url, key, takenUrls));\n const texts = keys.map((key) =>\n key.kind === \"literal\" ? JSON.stringify(key.url) : templateText(key.parts),\n );\n return texts.length === 0 ? undefined : texts.join(\" | \");\n}\n\n/** The index of each templated path whose URL does not match its keys, by URL. */\nexport function unmatchedTemplateKeys(\n paths: PathsObject | null | undefined,\n context: TransformContext,\n): ReadonlyMap<string, string> {\n const keys = new Map<string, string>();\n // A document may hold any value as `paths`; one that is no object has no paths.\n if (!context.options.pathParamsAsTypes || typeof paths !== \"object\" || paths === null) {\n return keys;\n }\n // The same walk as `pathMembers`, so a URL is taken by the same path as there.\n const takenUrls = new Set(Object.keys(paths));\n for (const [url, pathItem] of documentEntries(paths, context.options)) {\n if (!pathItem || typeof pathItem !== \"object\" || \"$ref\" in pathItem || !url.includes(\"{\")) {\n continue;\n }\n const parts = pathTemplateParts(url, pathItem, context);\n const index = parts === null ? undefined : templateIndexText(url, parts, takenUrls);\n const isUnmatched = parts?.some(\n (part) => part.kind === \"placeholder\" && part.type !== \"string\",\n );\n if (isUnmatched && index !== undefined) {\n keys.set(url, index);\n }\n }\n return keys;\n}\n\nfunction isNode(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null;\n}\n\n/** `paths[\"<url>\"]`: an index of the `paths` root by a string literal. */\nfunction pathsIndexUrl(node: Readonly<Record<string, unknown>>): string | undefined {\n const object = node.object as Readonly<Record<string, unknown>> | undefined;\n const index = node.index as Readonly<Record<string, unknown>> | undefined;\n const isPathsIndex =\n node.kind === \"indexedAccess\" &&\n object?.kind === \"reference\" &&\n object.name === PATHS_TYPE_NAME &&\n (object.typeArguments as readonly unknown[] | undefined)?.length === 0 &&\n index?.kind === \"stringLiteral\";\n return isPathsIndex ? (index.value as string) : undefined;\n}\n\nfunction rewrittenNode(value: unknown, keys: ReadonlyMap<string, string>): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => rewrittenNode(item, keys));\n }\n if (!isNode(value)) {\n return value;\n }\n const template = keys.get(pathsIndexUrl(value) ?? \"\");\n if (template !== undefined) {\n return { ...value, index: irRaw(template) };\n }\n // `origin` holds the compiler node a raw type was printed from; it is not IR.\n return Object.fromEntries(\n Object.entries(value).map(([key, child]) => [\n key,\n key === \"origin\" ? child : rewrittenNode(child, keys),\n ]),\n );\n}\n\n/** The declarations with each `paths[\"<url>\"]` of an unmatched template indexed by it. */\nexport function withTemplatePathRefs<T extends IrDeclaration>(\n declarations: readonly T[],\n keys: ReadonlyMap<string, string>,\n): T[] {\n return keys.size === 0 ? [...declarations] : (rewrittenNode(declarations, keys) as T[]);\n}\n"],"names":[],"mappings":";;;;;AAiBA,MAAM,eAAA,GAAkB,OAAA;AAOxB,SAAS,iBAAA,CAAkB,GAAA,EAAa,KAAA,EAA+B,SAAA,EAAwB;AAC7F,EAAA,MAAM,IAAA,GAAO,mBAAA,CAAoB,KAAK,CAAA,CACnC,IAAI,SAAS,CAAA,CACb,MAAA,CAAO,CAAC,GAAA,KAAQ,YAAA,CAAa,GAAA,EAAK,GAAA,EAAK,SAAS,CAAC,CAAA;AACpD,EAAA,MAAM,QAAQ,IAAA,CAAK,GAAA;AAAA,IAAI,CAAC,GAAA,KACtB,GAAA,CAAI,IAAA,KAAS,SAAA,GAAY,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA,GAAI,YAAA,CAAa,GAAA,CAAI,KAAK;AAAA,GAC3E;AACA,EAAA,OAAO,MAAM,MAAA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AAC,GAAG,YAAY,CAAA,GAAK,aAAA,CAAc,YAAA,EAAc,IAAI,CAAA;AAChF;;"}
|
|
@@ -33,9 +33,10 @@ function pathItemEntries(pathItem) {
|
|
|
33
33
|
return METHODS.has(key) ? [[key, value]] : [];
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
const INCLUDES_EVERY_OPERATION = () => true;
|
|
37
|
+
function pathOperations(paths, isIncluded) {
|
|
37
38
|
return Object.entries(paths).flatMap(
|
|
38
|
-
([url, pathItem]) => pathItemEntries(pathItem).map(([method, operation]) => {
|
|
39
|
+
([url, pathItem]) => pathItemEntries(pathItem).filter(([, operation]) => isIncluded(operation)).map(([method, operation]) => {
|
|
39
40
|
const operationId = operation.operationId || void 0;
|
|
40
41
|
return { url, method, operationId };
|
|
41
42
|
})
|
|
@@ -57,17 +58,17 @@ function uniqueNames(operations) {
|
|
|
57
58
|
});
|
|
58
59
|
return numberedNames.withNumberedRepeats(named, (name, count) => `${name}${count}`);
|
|
59
60
|
}
|
|
60
|
-
function apiPathsEnum(paths) {
|
|
61
|
-
const operations = pathOperations(paths);
|
|
61
|
+
function apiPathsEnum(paths, isIncluded = INCLUDES_EVERY_OPERATION) {
|
|
62
|
+
const operations = pathOperations(paths, isIncluded);
|
|
62
63
|
const names = uniqueNames(operations);
|
|
63
64
|
return {
|
|
64
65
|
values: operations.map((operation) => operation.url),
|
|
65
66
|
metadata: names.map((name) => ({ name, description: void 0 }))
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
|
-
function apiPathsEnumDeclaration(paths) {
|
|
69
|
+
function apiPathsEnumDeclaration(paths, isIncluded = INCLUDES_EVERY_OPERATION) {
|
|
69
70
|
const naming = new enumNaming.EnumNaming();
|
|
70
|
-
return enumNaming.enumDeclaration(naming.enumName(API_PATHS_NAME), apiPathsEnum(paths), naming);
|
|
71
|
+
return enumNaming.enumDeclaration(naming.enumName(API_PATHS_NAME), apiPathsEnum(paths, isIncluded), naming);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
exports.API_PATHS_NAME = API_PATHS_NAME;
|