oas 31.1.2 → 32.1.0

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.
Files changed (70) hide show
  1. package/README.md +5 -0
  2. package/dist/analyzer/index.cjs +6 -7
  3. package/dist/analyzer/index.cjs.map +1 -1
  4. package/dist/analyzer/index.js +5 -6
  5. package/dist/analyzer/index.js.map +1 -1
  6. package/dist/{chunk-BRYRBTD7.cjs → chunk-4OCSFLJO.cjs} +537 -385
  7. package/dist/chunk-4OCSFLJO.cjs.map +1 -0
  8. package/dist/{chunk-HGVFNEKW.js → chunk-5245ZLBC.js} +476 -324
  9. package/dist/chunk-5245ZLBC.js.map +1 -0
  10. package/dist/{chunk-B5WP4BJM.cjs → chunk-7RDMAMMI.cjs} +511 -240
  11. package/dist/chunk-7RDMAMMI.cjs.map +1 -0
  12. package/dist/{chunk-LSH3X5NA.js → chunk-DVD6RE2D.js} +85 -48
  13. package/dist/chunk-DVD6RE2D.js.map +1 -0
  14. package/dist/{chunk-5EP6HY2E.js → chunk-HYH37HS2.js} +494 -223
  15. package/dist/chunk-HYH37HS2.js.map +1 -0
  16. package/dist/{chunk-7MARUOFZ.js → chunk-MNOEMVCF.js} +2 -2
  17. package/dist/chunk-MNOEMVCF.js.map +1 -0
  18. package/dist/{chunk-SYZDNSG6.cjs → chunk-WXNEGGLJ.cjs} +104 -67
  19. package/dist/chunk-WXNEGGLJ.cjs.map +1 -0
  20. package/dist/chunk-YPR7YTHM.cjs +24 -0
  21. package/dist/chunk-YPR7YTHM.cjs.map +1 -0
  22. package/dist/extensions.d.cts +3 -1
  23. package/dist/extensions.d.ts +3 -1
  24. package/dist/get-parameters-as-json-schema-BH81ZOnw.d.ts +36 -0
  25. package/dist/get-parameters-as-json-schema-DM1vWIEM.d.cts +36 -0
  26. package/dist/index.cjs +5 -6
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +947 -7
  29. package/dist/index.d.ts +946 -8
  30. package/dist/index.js +4 -5
  31. package/dist/operation/index.cjs +4 -5
  32. package/dist/operation/index.cjs.map +1 -1
  33. package/dist/operation/index.d.cts +3 -1
  34. package/dist/operation/index.d.ts +3 -1
  35. package/dist/operation/index.js +3 -4
  36. package/dist/reducer/index.cjs +16 -18
  37. package/dist/reducer/index.cjs.map +1 -1
  38. package/dist/reducer/index.js +4 -6
  39. package/dist/reducer/index.js.map +1 -1
  40. package/dist/types.cjs +2 -2
  41. package/dist/types.d.cts +9 -1
  42. package/dist/types.d.ts +9 -1
  43. package/dist/types.js +1 -1
  44. package/dist/utils.cjs +4 -4
  45. package/dist/utils.cjs.map +1 -1
  46. package/dist/utils.d.cts +17 -3
  47. package/dist/utils.d.ts +17 -3
  48. package/dist/utils.js +5 -5
  49. package/package.json +3 -6
  50. package/dist/chunk-5EP6HY2E.js.map +0 -1
  51. package/dist/chunk-7MARUOFZ.js.map +0 -1
  52. package/dist/chunk-B5WP4BJM.cjs.map +0 -1
  53. package/dist/chunk-BRYRBTD7.cjs.map +0 -1
  54. package/dist/chunk-HGVFNEKW.js.map +0 -1
  55. package/dist/chunk-LSH3X5NA.js.map +0 -1
  56. package/dist/chunk-O3GIPZLC.cjs +0 -9
  57. package/dist/chunk-O3GIPZLC.cjs.map +0 -1
  58. package/dist/chunk-SYZDNSG6.cjs.map +0 -1
  59. package/dist/chunk-VA3NKXX7.js +0 -9
  60. package/dist/chunk-VA3NKXX7.js.map +0 -1
  61. package/dist/chunk-VQBEI5WI.cjs +0 -24
  62. package/dist/chunk-VQBEI5WI.cjs.map +0 -1
  63. package/dist/extensions-9XckV6aO.d.cts +0 -899
  64. package/dist/extensions-gq53-7Ux.d.ts +0 -899
  65. package/dist/operation/lib/get-parameters-as-json-schema.cjs +0 -11
  66. package/dist/operation/lib/get-parameters-as-json-schema.cjs.map +0 -1
  67. package/dist/operation/lib/get-parameters-as-json-schema.d.cts +0 -4
  68. package/dist/operation/lib/get-parameters-as-json-schema.d.ts +0 -4
  69. package/dist/operation/lib/get-parameters-as-json-schema.js +0 -11
  70. package/dist/operation/lib/get-parameters-as-json-schema.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import {
2
2
  Oas
3
- } from "./chunk-LSH3X5NA.js";
4
- import "./chunk-HGVFNEKW.js";
5
- import "./chunk-VA3NKXX7.js";
6
- import "./chunk-5EP6HY2E.js";
3
+ } from "./chunk-DVD6RE2D.js";
4
+ import "./chunk-5245ZLBC.js";
5
+ import "./chunk-HYH37HS2.js";
7
6
  import "./chunk-S27IGTVG.js";
8
- import "./chunk-7MARUOFZ.js";
7
+ import "./chunk-MNOEMVCF.js";
9
8
  export {
10
9
  Oas as default
11
10
  };
@@ -2,14 +2,13 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkBRYRBTD7cjs = require('../chunk-BRYRBTD7.cjs');
6
- require('../chunk-O3GIPZLC.cjs');
7
- require('../chunk-B5WP4BJM.cjs');
5
+ var _chunk4OCSFLJOcjs = require('../chunk-4OCSFLJO.cjs');
6
+ require('../chunk-7RDMAMMI.cjs');
8
7
  require('../chunk-AYA3UT4L.cjs');
9
- require('../chunk-VQBEI5WI.cjs');
8
+ require('../chunk-YPR7YTHM.cjs');
10
9
 
11
10
 
12
11
 
13
12
 
14
- exports.Callback = _chunkBRYRBTD7cjs.Callback; exports.Operation = _chunkBRYRBTD7cjs.Operation; exports.Webhook = _chunkBRYRBTD7cjs.Webhook;
13
+ exports.Callback = _chunk4OCSFLJOcjs.Callback; exports.Operation = _chunk4OCSFLJOcjs.Operation; exports.Webhook = _chunk4OCSFLJOcjs.Webhook;
15
14
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/operation/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACA;AACF,4IAAC","file":"/Users/erunion/code/readme/oas/packages/oas/dist/operation/index.cjs"}
1
+ {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/operation/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACA;AACF,4IAAC","file":"/Users/erunion/code/readme/oas/packages/oas/dist/operation/index.cjs"}
@@ -1,4 +1,6 @@
1
- export { C as Callback, O as Operation, W as Webhook } from '../extensions-9XckV6aO.cjs';
1
+ export { C as Callback, O as Operation, W as Webhook } from '../index.cjs';
2
2
  import '../types.cjs';
3
+ import '../get-parameters-as-json-schema-DM1vWIEM.cjs';
4
+ import 'path-to-regexp';
3
5
  import 'json-schema';
4
6
  import 'openapi-types';
@@ -1,4 +1,6 @@
1
- export { C as Callback, O as Operation, W as Webhook } from '../extensions-gq53-7Ux.js';
1
+ export { C as Callback, O as Operation, W as Webhook } from '../index.js';
2
2
  import '../types.js';
3
+ import '../get-parameters-as-json-schema-BH81ZOnw.js';
4
+ import 'path-to-regexp';
3
5
  import 'json-schema';
4
6
  import 'openapi-types';
@@ -2,11 +2,10 @@ import {
2
2
  Callback,
3
3
  Operation,
4
4
  Webhook
5
- } from "../chunk-HGVFNEKW.js";
6
- import "../chunk-VA3NKXX7.js";
7
- import "../chunk-5EP6HY2E.js";
5
+ } from "../chunk-5245ZLBC.js";
6
+ import "../chunk-HYH37HS2.js";
8
7
  import "../chunk-S27IGTVG.js";
9
- import "../chunk-7MARUOFZ.js";
8
+ import "../chunk-MNOEMVCF.js";
10
9
  export {
11
10
  Callback,
12
11
  Operation,
@@ -3,15 +3,13 @@
3
3
  var _chunkW6GBV2JTcjs = require('../chunk-W6GBV2JT.cjs');
4
4
 
5
5
 
6
- var _chunkO3GIPZLCcjs = require('../chunk-O3GIPZLC.cjs');
7
6
 
8
-
9
- var _chunkB5WP4BJMcjs = require('../chunk-B5WP4BJM.cjs');
7
+ var _chunk7RDMAMMIcjs = require('../chunk-7RDMAMMI.cjs');
10
8
  require('../chunk-AYA3UT4L.cjs');
11
9
 
12
10
 
13
11
 
14
- var _chunkVQBEI5WIcjs = require('../chunk-VQBEI5WI.cjs');
12
+ var _chunkYPR7YTHMcjs = require('../chunk-YPR7YTHM.cjs');
15
13
 
16
14
  // src/reducer/index.ts
17
15
  var _jsonpointer = require('jsonpointer'); var _jsonpointer2 = _interopRequireDefault(_jsonpointer);
@@ -276,7 +274,7 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
276
274
  const pathSegment = match[1];
277
275
  const method = match[2];
278
276
  if (pathSegment && method) {
279
- return { path: _chunkB5WP4BJMcjs.decodePointer.call(void 0, pathSegment), method };
277
+ return { path: _chunk7RDMAMMIcjs.decodePointer.call(void 0, pathSegment), method };
280
278
  }
281
279
  }
282
280
  return null;
@@ -295,7 +293,7 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
295
293
  const webhookName = match[1];
296
294
  const method = match[2];
297
295
  if (webhookName && method) {
298
- return { name: _chunkB5WP4BJMcjs.decodePointer.call(void 0, webhookName), method };
296
+ return { name: _chunk7RDMAMMIcjs.decodePointer.call(void 0, webhookName), method };
299
297
  }
300
298
  }
301
299
  return null;
@@ -323,7 +321,7 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
323
321
  }
324
322
  }
325
323
  Object.keys(_optionalChain([this, 'access', _23 => _23.definition, 'access', _24 => _24.paths, 'optionalAccess', _25 => _25[path]]) || {}).forEach((method) => {
326
- if (method === "parameters" || !_chunkO3GIPZLCcjs.supportedMethods.includes(method.toLowerCase())) {
324
+ if (method === "parameters" || !_chunk7RDMAMMIcjs.supportedMethods.includes(method.toLowerCase())) {
327
325
  return;
328
326
  }
329
327
  if (this.hasPathsToReduceBy) {
@@ -370,7 +368,7 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
370
368
  *
371
369
  */
372
370
  walkWebhooks() {
373
- if (!_chunkVQBEI5WIcjs.isOpenAPI31.call(void 0, this.definition)) {
371
+ if (!_chunkYPR7YTHMcjs.isOpenAPI31.call(void 0, this.definition)) {
374
372
  return;
375
373
  } else if (!("webhooks" in this.definition) || !this.definition.webhooks) {
376
374
  return;
@@ -386,7 +384,7 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
386
384
  return;
387
385
  }
388
386
  Object.keys(webhook).forEach((method) => {
389
- if (method === "parameters" || !_chunkO3GIPZLCcjs.supportedMethods.includes(method.toLowerCase())) {
387
+ if (method === "parameters" || !_chunk7RDMAMMIcjs.supportedMethods.includes(method.toLowerCase())) {
390
388
  return;
391
389
  }
392
390
  if (this.hasWebhooksToReduceBy) {
@@ -395,7 +393,7 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
395
393
  return;
396
394
  }
397
395
  }
398
- if (_chunkVQBEI5WIcjs.isRef.call(void 0, webhook)) {
396
+ if (_chunkYPR7YTHMcjs.isRef.call(void 0, webhook)) {
399
397
  return;
400
398
  }
401
399
  const operation = webhook[method];
@@ -451,7 +449,7 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
451
449
  }
452
450
  Object.keys(_optionalChain([this, 'access', _35 => _35.definition, 'access', _36 => _36.paths, 'optionalAccess', _37 => _37[path]]) || {}).forEach((method) => {
453
451
  const methodLC = method.toLowerCase();
454
- if (method === "parameters" || !_chunkO3GIPZLCcjs.supportedMethods.includes(methodLC)) {
452
+ if (method === "parameters" || !_chunk7RDMAMMIcjs.supportedMethods.includes(methodLC)) {
455
453
  return;
456
454
  }
457
455
  const retainedByRef = this.retainPathMethods.has(`${pathLC}|${methodLC}`) || Array.from(this.$refs).some((ref) => {
@@ -510,7 +508,7 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
510
508
  *
511
509
  */
512
510
  reduceWebhooks() {
513
- if (!_chunkVQBEI5WIcjs.isOpenAPI31.call(void 0, this.definition)) {
511
+ if (!_chunkYPR7YTHMcjs.isOpenAPI31.call(void 0, this.definition)) {
514
512
  return;
515
513
  } else if (!("webhooks" in this.definition) || !this.definition.webhooks) {
516
514
  return;
@@ -531,27 +529,27 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
531
529
  if (!webhook || typeof webhook !== "object") {
532
530
  return;
533
531
  }
534
- if (_chunkVQBEI5WIcjs.isRef.call(void 0, webhook)) {
532
+ if (_chunkYPR7YTHMcjs.isRef.call(void 0, webhook)) {
535
533
  return;
536
534
  }
537
535
  Object.keys(webhook).forEach((method) => {
538
536
  const methodLC = method.toLowerCase();
539
- if (method === "parameters" || !_chunkO3GIPZLCcjs.supportedMethods.includes(methodLC)) {
537
+ if (method === "parameters" || !_chunk7RDMAMMIcjs.supportedMethods.includes(methodLC)) {
540
538
  return;
541
539
  }
542
540
  const retainedByRef = this.retainWebhookMethods.has(`${nameLC}|${methodLC}`);
543
541
  if (this.hasWebhooksToReduceBy && !retainedByRef) {
544
542
  const methodFilter = this.webhooksToReduceBy[nameLC];
545
543
  if (methodFilter !== "*" && Array.isArray(methodFilter) && !methodFilter.includes(methodLC)) {
546
- if (_chunkVQBEI5WIcjs.isRef.call(void 0, _optionalChain([definition, 'access', _69 => _69.webhooks, 'optionalAccess', _70 => _70[webhookName]]))) {
544
+ if (!_optionalChain([definition, 'access', _69 => _69.webhooks, 'optionalAccess', _70 => _70[webhookName]]) || _chunkYPR7YTHMcjs.isRef.call(void 0, _optionalChain([definition, 'access', _71 => _71.webhooks, 'optionalAccess', _72 => _72[webhookName]]))) {
547
545
  return;
548
546
  }
549
- _optionalChainDelete([definition, 'access', _71 => _71.webhooks, 'optionalAccess', _72 => _72[webhookName], 'optionalAccess', _73 => delete _73[method]]);
547
+ _optionalChainDelete([definition, 'access', _73 => _73.webhooks, 'optionalAccess', _74 => _74[webhookName], 'optionalAccess', _75 => delete _75[method]]);
550
548
  }
551
549
  }
552
550
  });
553
- if (!Object.keys(_optionalChain([definition, 'access', _74 => _74.webhooks, 'optionalAccess', _75 => _75[webhookName]]) || {}).length) {
554
- _optionalChainDelete([definition, 'access', _76 => _76.webhooks, 'optionalAccess', _77 => delete _77[webhookName]]);
551
+ if (!Object.keys(_optionalChain([definition, 'access', _76 => _76.webhooks, 'optionalAccess', _77 => _77[webhookName]]) || {}).length) {
552
+ _optionalChainDelete([definition, 'access', _78 => _78.webhooks, 'optionalAccess', _79 => delete _79[webhookName]]);
555
553
  }
556
554
  });
557
555
  if (definition.webhooks && !Object.keys(definition.webhooks).length) {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/reducer/index.cjs","../../src/reducer/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B;AACE;AACF,yDAA8B;AAC9B;AACE;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B;AACA;ACZA,oGAAwB;AAOjB,IAAM,eAAA,YAAN,MAAM,gBAAe;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAOA,MAAA,kBAAqB,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA,kBAK7B,SAAA,kBAAwB,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAQhC,kBAAA,kBAAgD,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAQxD,qBAAA,kBAAmD,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA,kBAK3D,eAAA,EAA2B,CAAC,EAAA;AAAA;AAAA;AAAA;AAAA,kBAK5B,gBAAA,EAAkD,CAAC,EAAA;AAAA;AAAA;AAAA;AAAA,kBAKnD,mBAAA,EAAqD,CAAC,EAAA;AAAA,kBAEtD,kBAAA,EAA6B,MAAA;AAAA,kBAC7B,mBAAA,EAA8B,MAAA;AAAA,mBAC9B,sBAAA,EAAiC,MAAA;AAAA,EAEjC,WAAA,CAAY,UAAA,EAAyB;AAC3C,IAAA,I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AA;AACD,IAAA;AAE0D,IAAA;AACvC,MAAA;AACpB,IAAA;AACF,EAAA;AACF;AD9LgE;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/reducer/index.cjs","sourcesContent":[null,"import type { OpenAPIV3_1 } from 'openapi-types';\nimport type { ComponentsObject, HttpMethods, OASDocument, OperationObject, TagObject } from '../types.js';\n\nimport jsonPointer from 'jsonpointer';\n\nimport { query } from '../analyzer/util.js';\nimport { decodePointer } from '../lib/refs.js';\nimport { isOpenAPI31, isRef } from '../types.js';\nimport { supportedMethods } from '../utils.js';\n\nexport class OpenAPIReducer {\n private definition: OASDocument;\n\n /**\n * A collection of `$ref` pointers that are used within our reduced API definition. This is used\n * to ensure that all referenced schemas are retained in our resulting API definition. Not\n * retaining them would result in an invalid OpenAPI definition.\n */\n private $refs: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI tags that are used within our reduced API definition.\n */\n private usedTags: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI paths and operations that are cross-referenced from any other paths\n * and operations that we are reducing. This collection is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainPathMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * A collection of OpenAPI webhook names and methods that are cross-referenced from any other\n * schemas. This collection, like `retainPathMethods`, is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainWebhookMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * An array of OpenAPI tags to reduce down to.\n */\n private tagsToReduceBy: string[] = [];\n\n /**\n * A collection of OpenAPI paths and operations to reduce down to.\n */\n private pathsToReduceBy: Record<string, '*' | string[]> = {};\n\n /**\n * A collection of OpenAPI webhooks to reduce down to.\n */\n private webhooksToReduceBy: Record<string, '*' | string[]> = {};\n\n private hasTagsToReduceBy: boolean = false;\n private hasPathsToReduceBy: boolean = false;\n private hasWebhooksToReduceBy: boolean = false;\n\n private constructor(definition: OASDocument) {\n this.definition = structuredClone(definition);\n }\n\n /**\n * Initialize a new instance of the `OpenAPIReducer`. The reducer allows you to reduce an OpenAPI\n * definition down to only the information necessary to fulfill a specific set of tags, paths,\n * operations, and webhooks.\n *\n * OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API\n * definitions, but also to compress a large API definition down to a manageable size containing\n * a specific set of items.\n *\n * All OpenAPI definitions reduced will still be fully functional and valid OpenAPI definitions.\n *\n * @param definition An OpenAPI definition to reduce.\n */\n static init(definition: OASDocument): OpenAPIReducer {\n return new OpenAPIReducer(definition);\n }\n\n /**\n * Mark an OpenAPI tag to be included in our reduced API definition. Tag casing does not matter.\n *\n * @param tag The tag to mark for reduction.\n */\n byTag(tag: string): OpenAPIReducer {\n this.tagsToReduceBy.push(tag.toLowerCase());\n return this;\n }\n\n /**\n * Mark an entire OpenAPI path, and all methods that it contains, to be included in your reduced\n * API definition. Path casing does not matter.\n *\n * @param path The path to mark for reduction.\n */\n byPath(path: string): OpenAPIReducer {\n this.pathsToReduceBy[path.toLowerCase()] = '*';\n return this;\n }\n\n /**\n * Mark a single OpenAPI operation to be included in your reduced API definition. If the path\n * that this operation is a part of utilizes common parameters, those will be automatically\n * included. Path and method casing does not matter.\n *\n * Note that if you previously called `.byPath()` to reduce an entire path down, calling\n * `.byOperation()` will override that to just reduce this specific method (or this plus\n * subsequent calls to `.byOperation()`).\n *\n * @param path The path that the operation is a part of.\n * @param method The HTTP method of the operation to mark for reduction.\n *\n */\n byOperation(path: string, method: string): OpenAPIReducer {\n const pathLC = path.toLowerCase(); // Casing should not matter.\n const methodLC = method.toLowerCase();\n\n if (this.pathsToReduceBy[pathLC] && Array.isArray(this.pathsToReduceBy[pathLC])) {\n this.pathsToReduceBy[pathLC].push(methodLC);\n } else {\n this.pathsToReduceBy[pathLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Mark an OpenAPI webhook (and all of its operations) to be included in your reduced API\n * definition. Casing does not matter.\n *\n * @param webhookName The webhook name to mark for reduction.\n */\n byWebhook(webhookName: string): OpenAPIReducer;\n\n /**\n * Mark a single OpenAPI webhook operation to be included in your reduced API definition.\n * Casing does not matter.\n *\n * @param webhookName The webhook name that the operation belongs to.\n * @param method The HTTP method of the webhook operation to mark for reduction.\n */\n byWebhook(webhookName: string, method: string): OpenAPIReducer;\n\n byWebhook(webhookName: string, method?: string): OpenAPIReducer {\n const nameLC = webhookName.toLowerCase();\n if (!method) {\n this.webhooksToReduceBy[nameLC] = '*';\n return this;\n }\n\n const methodLC = method.toLowerCase();\n if (this.webhooksToReduceBy[nameLC] && Array.isArray(this.webhooksToReduceBy[nameLC])) {\n this.webhooksToReduceBy[nameLC].push(methodLC);\n } else {\n this.webhooksToReduceBy[nameLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Reduce the current OpenAPI definition down to the configured filters.\n *\n */\n reduce(): OASDocument {\n if (!this.definition.openapi) {\n throw new Error('Sorry, only OpenAPI definitions are supported.');\n }\n\n this.hasPathsToReduceBy = Boolean(Object.keys(this.pathsToReduceBy).length);\n this.hasWebhooksToReduceBy = Boolean(Object.keys(this.webhooksToReduceBy).length);\n this.hasTagsToReduceBy = Boolean(this.tagsToReduceBy.length);\n\n // Retain any root-level security definitions, regardless if they're used or not on our reduced\n // operations.\n if ('security' in this.definition) {\n Object.values(this.definition.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n\n this.walkPaths();\n this.walkWebhooks();\n\n // Recursively accumulate any components that are in use.\n this.$refs.forEach($ref => {\n this.accumulateUsedRefs(this.definition, this.$refs, $ref);\n });\n\n this.$refs.forEach(ref => {\n const usedPathRef = this.parsePathRef(ref);\n if (usedPathRef) {\n this.retainPathMethods.add(`${usedPathRef.path.toLowerCase()}|${usedPathRef.method.toLowerCase()}`);\n }\n\n const usedWebhookRef = this.parseWebhookRef(ref);\n if (usedWebhookRef) {\n this.retainWebhookMethods.add(`${usedWebhookRef.name.toLowerCase()}|${usedWebhookRef.method.toLowerCase()}`);\n }\n });\n\n this.reducePaths();\n this.reduceWebhooks();\n\n // Require at least one path or one webhook in the result.\n const hasPaths = Boolean(this.definition.paths && Object.keys(this.definition.paths).length);\n const hasWebhooks = Boolean(\n 'webhooks' in this.definition && this.definition.webhooks && Object.keys(this.definition.webhooks).length,\n );\n\n if (!hasPaths && !hasWebhooks) {\n throw new Error(\n 'All paths and webhooks in the API definition were removed. Did you supply the right path, operation, or webhook to reduce by?',\n );\n }\n\n // Remove any unused components.\n if ('components' in this.definition) {\n Object.keys(this.definition.components || {}).forEach(componentType => {\n Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).forEach(component => {\n // If our `$ref` either is a full, or deep match, then we should preserve it.\n const refIsUsed =\n this.$refs.has(`#/components/${componentType}/${component}`) ||\n Array.from(this.$refs).some(ref => {\n // Because you can have a `$ref` like `#/components/examples/event-min/value`, which\n // would be accumulated via our `$refs` query, we want to make sure we account for them.\n // If we don't look for these then we'll end up removing them from the overall reduced\n // definition, resulting in data loss and schema corruption.\n return ref.startsWith(`#/components/${componentType}/${component}/`);\n });\n\n if (!refIsUsed) {\n delete this.definition.components?.[componentType as keyof ComponentsObject]?.[component];\n }\n });\n\n // If this component group is now empty, delete it.\n if (!Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).length) {\n delete this.definition.components?.[componentType as keyof ComponentsObject];\n }\n });\n\n // If this path no longer has any components, delete it.\n if (!Object.keys(this.definition.components || {}).length) {\n delete this.definition.components;\n }\n }\n\n // Remove any unused tags.\n if ('tags' in this.definition) {\n this.definition.tags = (this.definition.tags ?? []).filter((tag): tag is TagObject => {\n return Boolean(tag) && this.usedTags.has(tag.name);\n });\n\n if (!this.definition.tags?.length) {\n delete this.definition.tags;\n }\n }\n\n return this.definition;\n }\n\n /**\n * Recursively process a `$ref` pointer and accumulate any other `$ref` pointers that it or its\n * children use. This handles circular references by skipping `$ref` pointers we have already seen.\n * Additionally when a `$ref` points to `#/paths` we record the used path + method so we can\n * retain cross-operation references within the reduced definition.\n *\n * @param schema JSON Schema object to look for and accumulate any `$ref` pointers that it may have.\n * @param $refs Known set of `$ref` pointers.\n * @param $ref `$ref` pointer to fetch a schema from out of the supplied schema.\n */\n private accumulateUsedRefs(schema: Record<string, unknown>, $refs: Set<string>, $ref: string): void {\n // Record `$ref` pointers aimed at `#/paths` so we can retain any cross-operation references.\n const pathRef = this.parsePathRef($ref);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef($ref);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n let $refSchema: unknown;\n if (typeof $ref === 'string') $refSchema = jsonPointer.get(schema, $ref.substring(1));\n if ($refSchema === undefined) {\n // If the schema we have wasn't fully dereferenced or bundled for whatever reason and this\n // `$ref` that we have doesn't exist here we shouldn't try to search for more `$ref` pointers\n // in a schema that doesn't exist.\n return;\n }\n\n this.queryForRefPointers($refSchema).forEach(({ value: currRef }) => {\n // Because it's possible to have a schema property named `$ref` that is not a `$ref` pointer,\n // which our JSONPath query would pick up as a false positive, we want to exclude that from\n // `$ref` matching as it's not a reference pointer.\n const foundRef = this.toRefString(currRef);\n if (!foundRef) {\n return;\n }\n\n // If we've already processed this `$ref` then don't send us into an infinite loop of processing\n // circular references.\n if ($refs.has(foundRef)) {\n return;\n }\n\n $refs.add(foundRef);\n this.accumulateUsedRefs(schema, $refs, foundRef);\n });\n }\n\n /**\n * Query a JSON Schema object for any `$ref` pointers using JSONPath and return any pointers that\n * exist.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc9535}\n * @param schema JSON Schema object to look for any `$ref` pointers within it.\n */\n private queryForRefPointers(schema: any) {\n return query([\"$..['$ref']\"], schema);\n }\n\n /**\n * Normalize a value from a `jsonpath-plus` `$ref` query to a `$ref` pointer because JSONPath\n * queries may return the property value or the parent.\n *\n */\n private toRefString(value: unknown): string | null {\n if (typeof value === 'string') {\n return value;\n } else if (value && typeof value === 'object' && '$ref' in value && typeof value.$ref === 'string') {\n return value.$ref;\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into a path (e.g. `#/paths/~1anything/post/...`), return the path\n * and method so the reducer can ultimately retain cross-operation references.\n *\n */\n private parsePathRef($ref: string): { path: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/paths/')) {\n return null;\n }\n\n // Extract path segment and method: `#/paths/<pathSegment>/<method>/...`\n const match = $ref.match(/^#\\/paths\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const pathSegment = match[1];\n const method = match[2];\n if (pathSegment && method) {\n return { path: decodePointer(pathSegment), method };\n }\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into webhooks (e.g. `#/webhooks/newBooking/post/...`), return the\n * webhook name and method so the reducer can retain cross-referenced webhook operations.\n *\n */\n private parseWebhookRef($ref: string): { name: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/webhooks/')) {\n return null;\n }\n\n // Extract path segment and method: `#/webhooks/<webhookName>/<method>/...`\n const match = $ref.match(/^#\\/webhooks\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const webhookName = match[1];\n const method = match[2];\n if (webhookName && method) {\n return { name: decodePointer(webhookName), method };\n }\n }\n\n return null;\n }\n\n /**\n * Walk through the `paths` in our OpenAPI definition and reduce down any that we know we do not\n * want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced in\n * paths, webhooks, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkPaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n // When only webhooks were requested (no path/operation filter), remove all paths.\n if (this.hasWebhooksToReduceBy && !this.hasPathsToReduceBy) {\n delete this.definition.paths?.[path];\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n if (!(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n // If we have paths we want to reduce but this isn't part of our filter set, then ignore.\n // We'll remove it later.\n if (\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(method.toLowerCase())\n ) {\n return;\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods] as OperationObject;\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n if (this.hasTagsToReduceBy) {\n // If this endpoint either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n\n // If this operation has a cross-operation `$ref` pointer then we need to track it so\n // it's retained.\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n // Re-run through any `$ref` pointers that we found within this operation and search for\n // any `$ref` pointers that they also may be using.\n this.accumulateUsedRefs(this.definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Walk through the `webhooks` in our OpenAPI definition and reduce down any that we know we do\n * not want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced\n * in paths, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkWebhooks() {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n return;\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasWebhooksToReduceBy) {\n // If we have webhooks we want to reduce but this isn't part of our filter set, then\n // ignore. We'll remove it later.\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(method.toLowerCase())) {\n return;\n }\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n const operation = webhook[method as HttpMethods] as OperationObject;\n if (!operation) {\n return;\n }\n\n if (this.hasTagsToReduceBy) {\n // If this operation either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef(refStr);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n this.accumulateUsedRefs(definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Prune back our `paths` object in the OpenAPI definition to only include paths that we want to\n * preserve.\n *\n */\n private reducePaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n if (this.hasPathsToReduceBy && !(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n const methodLC = method.toLowerCase();\n\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef =\n this.retainPathMethods.has(`${pathLC}|${methodLC}`) ||\n Array.from(this.$refs).some(ref => {\n const pathRef = this.parsePathRef(ref);\n return pathRef?.path.toLowerCase() === pathLC && pathRef?.method.toLowerCase() === methodLC;\n });\n\n if (methodLC !== 'parameters') {\n // If we're reducing paths and this operation isn't part of our filter set, and it's\n // not a cross-referenced operation that we want to retain, then we should prune it.\n if (this.hasPathsToReduceBy) {\n if (\n !retainedByRef &&\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(methodLC)\n ) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n return;\n }\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods];\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n // If we're reducing by tags and this operation doesn't live in one of those, remove it.\n if (this.hasTagsToReduceBy) {\n // If this operation doesn't have any tags that we want to preserve, and it isn't\n // cross-referenced from an operation we _do_ want to preserve, then remove it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n if (!retainedByRef) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n }\n\n return;\n }\n }\n\n // Accumulate a list of used tags so we can filter out any ones that we don't need later.\n if ('tags' in operation) {\n operation.tags?.forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n }\n\n // Accumulate any used operation-level security schemas that we need to retain.\n if ('security' in operation) {\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n });\n\n // If this path no longer has any methods, delete it.\n if (!Object.keys(this.definition.paths?.[path] || {}).length) {\n delete this.definition.paths?.[path];\n }\n });\n\n // If we don't have any more paths after cleanup, and we don't have any webhooks, then throw\n // an error because an OpenAPI definition must have at least one path.\n if (!Object.keys(this.definition.paths || {}).length) {\n if (!(this.definition.webhooks && Object.keys(this.definition.webhooks).length)) {\n throw new Error(\n 'All paths in the API definition were removed. Did you supply the right path name to reduce by?',\n );\n }\n\n delete this.definition.paths;\n }\n }\n\n /**\n * Prune back our `webhooks` object in the OpenAPI definition to only include webhooks that we\n * want to preserve.\n *\n */\n private reduceWebhooks(): void {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n const retainedByRef = Array.from(this.retainWebhookMethods).some(\n key => key.startsWith(`${nameLC}|`) || key === `${nameLC}|`,\n );\n\n if (!retainedByRef) {\n delete definition.webhooks?.[webhookName];\n return;\n }\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n const methodLC = method.toLowerCase();\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef = this.retainWebhookMethods.has(`${nameLC}|${methodLC}`);\n if (this.hasWebhooksToReduceBy && !retainedByRef) {\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(methodLC)) {\n /**\n * If this webhook path item is a `$ref` then ignore and retain it.\n * @fixme we should better support reducing this.\n */\n if (isRef(definition.webhooks?.[webhookName])) {\n return;\n }\n\n delete definition.webhooks?.[webhookName]?.[method as HttpMethods];\n }\n }\n });\n\n if (!Object.keys(definition.webhooks?.[webhookName] || {}).length) {\n delete definition.webhooks?.[webhookName];\n }\n });\n\n if (definition.webhooks && !Object.keys(definition.webhooks).length) {\n delete definition.webhooks;\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/reducer/index.cjs","../../src/reducer/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B;AACA;ACVA,oGAAwB;AAOjB,IAAM,eAAA,YAAN,MAAM,gBAAe;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAOA,MAAA,kBAAqB,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA,kBAK7B,SAAA,kBAAwB,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAQhC,kBAAA,kBAAgD,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AA;AACc,UAAA;AACpD,QAAA;AAEoB,QAAA;AACsB,UAAA;AACxC,UAAA;AACF,QAAA;AACF,MAAA;AAEiD,MAAA;AACJ,MAAA;AAC3C,QAAA;AACF,MAAA;AAMoB,MAAA;AAClB,QAAA;AACF,MAAA;AAEuC,MAAA;AACD,QAAA;AACa,QAAA;AAC/C,UAAA;AACF,QAAA;AAEuD,QAAA;AACL,QAAA;AACG,UAAA;AACG,UAAA;AAKH,YAAA;AAC/C,cAAA;AACF,YAAA;AAEiE,YAAA;AACnE,UAAA;AACF,QAAA;AACD,MAAA;AAEwD,MAAA;AACf,QAAA;AAC1C,MAAA;AACD,IAAA;AAE0D,IAAA;AACvC,MAAA;AACpB,IAAA;AACF,EAAA;AACF;ADhMgE;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/reducer/index.cjs","sourcesContent":[null,"import type { OpenAPIV3_1 } from 'openapi-types';\nimport type { ComponentsObject, HttpMethods, OASDocument, OperationObject, TagObject } from '../types.js';\n\nimport jsonPointer from 'jsonpointer';\n\nimport { query } from '../analyzer/util.js';\nimport { decodePointer } from '../lib/refs.js';\nimport { isOpenAPI31, isRef } from '../types.js';\nimport { supportedMethods } from '../utils.js';\n\nexport class OpenAPIReducer {\n private definition: OASDocument;\n\n /**\n * A collection of `$ref` pointers that are used within our reduced API definition. This is used\n * to ensure that all referenced schemas are retained in our resulting API definition. Not\n * retaining them would result in an invalid OpenAPI definition.\n */\n private $refs: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI tags that are used within our reduced API definition.\n */\n private usedTags: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI paths and operations that are cross-referenced from any other paths\n * and operations that we are reducing. This collection is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainPathMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * A collection of OpenAPI webhook names and methods that are cross-referenced from any other\n * schemas. This collection, like `retainPathMethods`, is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainWebhookMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * An array of OpenAPI tags to reduce down to.\n */\n private tagsToReduceBy: string[] = [];\n\n /**\n * A collection of OpenAPI paths and operations to reduce down to.\n */\n private pathsToReduceBy: Record<string, '*' | string[]> = {};\n\n /**\n * A collection of OpenAPI webhooks to reduce down to.\n */\n private webhooksToReduceBy: Record<string, '*' | string[]> = {};\n\n private hasTagsToReduceBy: boolean = false;\n private hasPathsToReduceBy: boolean = false;\n private hasWebhooksToReduceBy: boolean = false;\n\n private constructor(definition: OASDocument) {\n this.definition = structuredClone(definition);\n }\n\n /**\n * Initialize a new instance of the `OpenAPIReducer`. The reducer allows you to reduce an OpenAPI\n * definition down to only the information necessary to fulfill a specific set of tags, paths,\n * operations, and webhooks.\n *\n * OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API\n * definitions, but also to compress a large API definition down to a manageable size containing\n * a specific set of items.\n *\n * All OpenAPI definitions reduced will still be fully functional and valid OpenAPI definitions.\n *\n * @param definition An OpenAPI definition to reduce.\n */\n static init(definition: OASDocument): OpenAPIReducer {\n return new OpenAPIReducer(definition);\n }\n\n /**\n * Mark an OpenAPI tag to be included in our reduced API definition. Tag casing does not matter.\n *\n * @param tag The tag to mark for reduction.\n */\n byTag(tag: string): OpenAPIReducer {\n this.tagsToReduceBy.push(tag.toLowerCase());\n return this;\n }\n\n /**\n * Mark an entire OpenAPI path, and all methods that it contains, to be included in your reduced\n * API definition. Path casing does not matter.\n *\n * @param path The path to mark for reduction.\n */\n byPath(path: string): OpenAPIReducer {\n this.pathsToReduceBy[path.toLowerCase()] = '*';\n return this;\n }\n\n /**\n * Mark a single OpenAPI operation to be included in your reduced API definition. If the path\n * that this operation is a part of utilizes common parameters, those will be automatically\n * included. Path and method casing does not matter.\n *\n * Note that if you previously called `.byPath()` to reduce an entire path down, calling\n * `.byOperation()` will override that to just reduce this specific method (or this plus\n * subsequent calls to `.byOperation()`).\n *\n * @param path The path that the operation is a part of.\n * @param method The HTTP method of the operation to mark for reduction.\n *\n */\n byOperation(path: string, method: string): OpenAPIReducer {\n const pathLC = path.toLowerCase(); // Casing should not matter.\n const methodLC = method.toLowerCase();\n\n if (this.pathsToReduceBy[pathLC] && Array.isArray(this.pathsToReduceBy[pathLC])) {\n this.pathsToReduceBy[pathLC].push(methodLC);\n } else {\n this.pathsToReduceBy[pathLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Mark an OpenAPI webhook (and all of its operations) to be included in your reduced API\n * definition. Casing does not matter.\n *\n * @param webhookName The webhook name to mark for reduction.\n */\n byWebhook(webhookName: string): OpenAPIReducer;\n\n /**\n * Mark a single OpenAPI webhook operation to be included in your reduced API definition.\n * Casing does not matter.\n *\n * @param webhookName The webhook name that the operation belongs to.\n * @param method The HTTP method of the webhook operation to mark for reduction.\n */\n byWebhook(webhookName: string, method: string): OpenAPIReducer;\n\n byWebhook(webhookName: string, method?: string): OpenAPIReducer {\n const nameLC = webhookName.toLowerCase();\n if (!method) {\n this.webhooksToReduceBy[nameLC] = '*';\n return this;\n }\n\n const methodLC = method.toLowerCase();\n if (this.webhooksToReduceBy[nameLC] && Array.isArray(this.webhooksToReduceBy[nameLC])) {\n this.webhooksToReduceBy[nameLC].push(methodLC);\n } else {\n this.webhooksToReduceBy[nameLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Reduce the current OpenAPI definition down to the configured filters.\n *\n */\n reduce(): OASDocument {\n if (!this.definition.openapi) {\n throw new Error('Sorry, only OpenAPI definitions are supported.');\n }\n\n this.hasPathsToReduceBy = Boolean(Object.keys(this.pathsToReduceBy).length);\n this.hasWebhooksToReduceBy = Boolean(Object.keys(this.webhooksToReduceBy).length);\n this.hasTagsToReduceBy = Boolean(this.tagsToReduceBy.length);\n\n // Retain any root-level security definitions, regardless if they're used or not on our reduced\n // operations.\n if ('security' in this.definition) {\n Object.values(this.definition.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n\n this.walkPaths();\n this.walkWebhooks();\n\n // Recursively accumulate any components that are in use.\n this.$refs.forEach($ref => {\n this.accumulateUsedRefs(this.definition, this.$refs, $ref);\n });\n\n this.$refs.forEach(ref => {\n const usedPathRef = this.parsePathRef(ref);\n if (usedPathRef) {\n this.retainPathMethods.add(`${usedPathRef.path.toLowerCase()}|${usedPathRef.method.toLowerCase()}`);\n }\n\n const usedWebhookRef = this.parseWebhookRef(ref);\n if (usedWebhookRef) {\n this.retainWebhookMethods.add(`${usedWebhookRef.name.toLowerCase()}|${usedWebhookRef.method.toLowerCase()}`);\n }\n });\n\n this.reducePaths();\n this.reduceWebhooks();\n\n // Require at least one path or one webhook in the result.\n const hasPaths = Boolean(this.definition.paths && Object.keys(this.definition.paths).length);\n const hasWebhooks = Boolean(\n 'webhooks' in this.definition && this.definition.webhooks && Object.keys(this.definition.webhooks).length,\n );\n\n if (!hasPaths && !hasWebhooks) {\n throw new Error(\n 'All paths and webhooks in the API definition were removed. Did you supply the right path, operation, or webhook to reduce by?',\n );\n }\n\n // Remove any unused components.\n if ('components' in this.definition) {\n Object.keys(this.definition.components || {}).forEach(componentType => {\n Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).forEach(component => {\n // If our `$ref` either is a full, or deep match, then we should preserve it.\n const refIsUsed =\n this.$refs.has(`#/components/${componentType}/${component}`) ||\n Array.from(this.$refs).some(ref => {\n // Because you can have a `$ref` like `#/components/examples/event-min/value`, which\n // would be accumulated via our `$refs` query, we want to make sure we account for them.\n // If we don't look for these then we'll end up removing them from the overall reduced\n // definition, resulting in data loss and schema corruption.\n return ref.startsWith(`#/components/${componentType}/${component}/`);\n });\n\n if (!refIsUsed) {\n delete this.definition.components?.[componentType as keyof ComponentsObject]?.[component];\n }\n });\n\n // If this component group is now empty, delete it.\n if (!Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).length) {\n delete this.definition.components?.[componentType as keyof ComponentsObject];\n }\n });\n\n // If this path no longer has any components, delete it.\n if (!Object.keys(this.definition.components || {}).length) {\n delete this.definition.components;\n }\n }\n\n // Remove any unused tags.\n if ('tags' in this.definition) {\n this.definition.tags = (this.definition.tags ?? []).filter((tag): tag is TagObject => {\n return Boolean(tag) && this.usedTags.has(tag.name);\n });\n\n if (!this.definition.tags?.length) {\n delete this.definition.tags;\n }\n }\n\n return this.definition;\n }\n\n /**\n * Recursively process a `$ref` pointer and accumulate any other `$ref` pointers that it or its\n * children use. This handles circular references by skipping `$ref` pointers we have already seen.\n * Additionally when a `$ref` points to `#/paths` we record the used path + method so we can\n * retain cross-operation references within the reduced definition.\n *\n * @param schema JSON Schema object to look for and accumulate any `$ref` pointers that it may have.\n * @param $refs Known set of `$ref` pointers.\n * @param $ref `$ref` pointer to fetch a schema from out of the supplied schema.\n */\n private accumulateUsedRefs(schema: Record<string, unknown>, $refs: Set<string>, $ref: string): void {\n // Record `$ref` pointers aimed at `#/paths` so we can retain any cross-operation references.\n const pathRef = this.parsePathRef($ref);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef($ref);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n let $refSchema: unknown;\n if (typeof $ref === 'string') $refSchema = jsonPointer.get(schema, $ref.substring(1));\n if ($refSchema === undefined) {\n // If the schema we have wasn't fully dereferenced or bundled for whatever reason and this\n // `$ref` that we have doesn't exist here we shouldn't try to search for more `$ref` pointers\n // in a schema that doesn't exist.\n return;\n }\n\n this.queryForRefPointers($refSchema).forEach(({ value: currRef }) => {\n // Because it's possible to have a schema property named `$ref` that is not a `$ref` pointer,\n // which our JSONPath query would pick up as a false positive, we want to exclude that from\n // `$ref` matching as it's not a reference pointer.\n const foundRef = this.toRefString(currRef);\n if (!foundRef) {\n return;\n }\n\n // If we've already processed this `$ref` then don't send us into an infinite loop of processing\n // circular references.\n if ($refs.has(foundRef)) {\n return;\n }\n\n $refs.add(foundRef);\n this.accumulateUsedRefs(schema, $refs, foundRef);\n });\n }\n\n /**\n * Query a JSON Schema object for any `$ref` pointers using JSONPath and return any pointers that\n * exist.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc9535}\n * @param schema JSON Schema object to look for any `$ref` pointers within it.\n */\n private queryForRefPointers(schema: any) {\n return query([\"$..['$ref']\"], schema);\n }\n\n /**\n * Normalize a value from a `jsonpath-plus` `$ref` query to a `$ref` pointer because JSONPath\n * queries may return the property value or the parent.\n *\n */\n private toRefString(value: unknown): string | null {\n if (typeof value === 'string') {\n return value;\n } else if (value && typeof value === 'object' && '$ref' in value && typeof value.$ref === 'string') {\n return value.$ref;\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into a path (e.g. `#/paths/~1anything/post/...`), return the path\n * and method so the reducer can ultimately retain cross-operation references.\n *\n */\n private parsePathRef($ref: string): { path: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/paths/')) {\n return null;\n }\n\n // Extract path segment and method: `#/paths/<pathSegment>/<method>/...`\n const match = $ref.match(/^#\\/paths\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const pathSegment = match[1];\n const method = match[2];\n if (pathSegment && method) {\n return { path: decodePointer(pathSegment), method };\n }\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into webhooks (e.g. `#/webhooks/newBooking/post/...`), return the\n * webhook name and method so the reducer can retain cross-referenced webhook operations.\n *\n */\n private parseWebhookRef($ref: string): { name: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/webhooks/')) {\n return null;\n }\n\n // Extract path segment and method: `#/webhooks/<webhookName>/<method>/...`\n const match = $ref.match(/^#\\/webhooks\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const webhookName = match[1];\n const method = match[2];\n if (webhookName && method) {\n return { name: decodePointer(webhookName), method };\n }\n }\n\n return null;\n }\n\n /**\n * Walk through the `paths` in our OpenAPI definition and reduce down any that we know we do not\n * want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced in\n * paths, webhooks, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkPaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n // When only webhooks were requested (no path/operation filter), remove all paths.\n if (this.hasWebhooksToReduceBy && !this.hasPathsToReduceBy) {\n delete this.definition.paths?.[path];\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n if (!(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n // If we have paths we want to reduce but this isn't part of our filter set, then ignore.\n // We'll remove it later.\n if (\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(method.toLowerCase())\n ) {\n return;\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods] as OperationObject;\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n if (this.hasTagsToReduceBy) {\n // If this endpoint either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n\n // If this operation has a cross-operation `$ref` pointer then we need to track it so\n // it's retained.\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n // Re-run through any `$ref` pointers that we found within this operation and search for\n // any `$ref` pointers that they also may be using.\n this.accumulateUsedRefs(this.definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Walk through the `webhooks` in our OpenAPI definition and reduce down any that we know we do\n * not want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced\n * in paths, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkWebhooks() {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n return;\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasWebhooksToReduceBy) {\n // If we have webhooks we want to reduce but this isn't part of our filter set, then\n // ignore. We'll remove it later.\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(method.toLowerCase())) {\n return;\n }\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n const operation = webhook[method as HttpMethods] as OperationObject;\n if (!operation) {\n return;\n }\n\n if (this.hasTagsToReduceBy) {\n // If this operation either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef(refStr);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n this.accumulateUsedRefs(definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Prune back our `paths` object in the OpenAPI definition to only include paths that we want to\n * preserve.\n *\n */\n private reducePaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n if (this.hasPathsToReduceBy && !(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n const methodLC = method.toLowerCase();\n\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef =\n this.retainPathMethods.has(`${pathLC}|${methodLC}`) ||\n Array.from(this.$refs).some(ref => {\n const pathRef = this.parsePathRef(ref);\n return pathRef?.path.toLowerCase() === pathLC && pathRef?.method.toLowerCase() === methodLC;\n });\n\n if (methodLC !== 'parameters') {\n // If we're reducing paths and this operation isn't part of our filter set, and it's\n // not a cross-referenced operation that we want to retain, then we should prune it.\n if (this.hasPathsToReduceBy) {\n if (\n !retainedByRef &&\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(methodLC)\n ) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n return;\n }\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods];\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n // If we're reducing by tags and this operation doesn't live in one of those, remove it.\n if (this.hasTagsToReduceBy) {\n // If this operation doesn't have any tags that we want to preserve, and it isn't\n // cross-referenced from an operation we _do_ want to preserve, then remove it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n if (!retainedByRef) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n }\n\n return;\n }\n }\n\n // Accumulate a list of used tags so we can filter out any ones that we don't need later.\n if ('tags' in operation) {\n operation.tags?.forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n }\n\n // Accumulate any used operation-level security schemas that we need to retain.\n if ('security' in operation) {\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n });\n\n // If this path no longer has any methods, delete it.\n if (!Object.keys(this.definition.paths?.[path] || {}).length) {\n delete this.definition.paths?.[path];\n }\n });\n\n // If we don't have any more paths after cleanup, and we don't have any webhooks, then throw\n // an error because an OpenAPI definition must have at least one path.\n if (!Object.keys(this.definition.paths || {}).length) {\n if (!(this.definition.webhooks && Object.keys(this.definition.webhooks).length)) {\n throw new Error(\n 'All paths in the API definition were removed. Did you supply the right path name to reduce by?',\n );\n }\n\n delete this.definition.paths;\n }\n }\n\n /**\n * Prune back our `webhooks` object in the OpenAPI definition to only include webhooks that we\n * want to preserve.\n *\n */\n private reduceWebhooks(): void {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n const retainedByRef = Array.from(this.retainWebhookMethods).some(\n key => key.startsWith(`${nameLC}|`) || key === `${nameLC}|`,\n );\n\n if (!retainedByRef) {\n delete definition.webhooks?.[webhookName];\n return;\n }\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n const methodLC = method.toLowerCase();\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef = this.retainWebhookMethods.has(`${nameLC}|${methodLC}`);\n if (this.hasWebhooksToReduceBy && !retainedByRef) {\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(methodLC)) {\n /**\n * If this webhook path item is a `$ref` then ignore and retain it.\n * @fixme we should better support reducing this.\n */\n if (!definition.webhooks?.[webhookName] || isRef(definition.webhooks?.[webhookName])) {\n return;\n }\n\n delete definition.webhooks?.[webhookName]?.[method as HttpMethods];\n }\n }\n });\n\n if (!Object.keys(definition.webhooks?.[webhookName] || {}).length) {\n delete definition.webhooks?.[webhookName];\n }\n });\n\n if (definition.webhooks && !Object.keys(definition.webhooks).length) {\n delete definition.webhooks;\n }\n }\n}\n"]}
@@ -2,16 +2,14 @@ import {
2
2
  query
3
3
  } from "../chunk-CKC36IL7.js";
4
4
  import {
5
+ decodePointer,
5
6
  supportedMethods
6
- } from "../chunk-VA3NKXX7.js";
7
- import {
8
- decodePointer
9
- } from "../chunk-5EP6HY2E.js";
7
+ } from "../chunk-HYH37HS2.js";
10
8
  import "../chunk-S27IGTVG.js";
11
9
  import {
12
10
  isOpenAPI31,
13
11
  isRef
14
- } from "../chunk-7MARUOFZ.js";
12
+ } from "../chunk-MNOEMVCF.js";
15
13
 
16
14
  // src/reducer/index.ts
17
15
  import jsonPointer from "jsonpointer";
@@ -543,7 +541,7 @@ var OpenAPIReducer = class _OpenAPIReducer {
543
541
  if (this.hasWebhooksToReduceBy && !retainedByRef) {
544
542
  const methodFilter = this.webhooksToReduceBy[nameLC];
545
543
  if (methodFilter !== "*" && Array.isArray(methodFilter) && !methodFilter.includes(methodLC)) {
546
- if (isRef(definition.webhooks?.[webhookName])) {
544
+ if (!definition.webhooks?.[webhookName] || isRef(definition.webhooks?.[webhookName])) {
547
545
  return;
548
546
  }
549
547
  delete definition.webhooks?.[webhookName]?.[method];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/reducer/index.ts"],"sourcesContent":["import type { OpenAPIV3_1 } from 'openapi-types';\nimport type { ComponentsObject, HttpMethods, OASDocument, OperationObject, TagObject } from '../types.js';\n\nimport jsonPointer from 'jsonpointer';\n\nimport { query } from '../analyzer/util.js';\nimport { decodePointer } from '../lib/refs.js';\nimport { isOpenAPI31, isRef } from '../types.js';\nimport { supportedMethods } from '../utils.js';\n\nexport class OpenAPIReducer {\n private definition: OASDocument;\n\n /**\n * A collection of `$ref` pointers that are used within our reduced API definition. This is used\n * to ensure that all referenced schemas are retained in our resulting API definition. Not\n * retaining them would result in an invalid OpenAPI definition.\n */\n private $refs: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI tags that are used within our reduced API definition.\n */\n private usedTags: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI paths and operations that are cross-referenced from any other paths\n * and operations that we are reducing. This collection is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainPathMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * A collection of OpenAPI webhook names and methods that are cross-referenced from any other\n * schemas. This collection, like `retainPathMethods`, is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainWebhookMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * An array of OpenAPI tags to reduce down to.\n */\n private tagsToReduceBy: string[] = [];\n\n /**\n * A collection of OpenAPI paths and operations to reduce down to.\n */\n private pathsToReduceBy: Record<string, '*' | string[]> = {};\n\n /**\n * A collection of OpenAPI webhooks to reduce down to.\n */\n private webhooksToReduceBy: Record<string, '*' | string[]> = {};\n\n private hasTagsToReduceBy: boolean = false;\n private hasPathsToReduceBy: boolean = false;\n private hasWebhooksToReduceBy: boolean = false;\n\n private constructor(definition: OASDocument) {\n this.definition = structuredClone(definition);\n }\n\n /**\n * Initialize a new instance of the `OpenAPIReducer`. The reducer allows you to reduce an OpenAPI\n * definition down to only the information necessary to fulfill a specific set of tags, paths,\n * operations, and webhooks.\n *\n * OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API\n * definitions, but also to compress a large API definition down to a manageable size containing\n * a specific set of items.\n *\n * All OpenAPI definitions reduced will still be fully functional and valid OpenAPI definitions.\n *\n * @param definition An OpenAPI definition to reduce.\n */\n static init(definition: OASDocument): OpenAPIReducer {\n return new OpenAPIReducer(definition);\n }\n\n /**\n * Mark an OpenAPI tag to be included in our reduced API definition. Tag casing does not matter.\n *\n * @param tag The tag to mark for reduction.\n */\n byTag(tag: string): OpenAPIReducer {\n this.tagsToReduceBy.push(tag.toLowerCase());\n return this;\n }\n\n /**\n * Mark an entire OpenAPI path, and all methods that it contains, to be included in your reduced\n * API definition. Path casing does not matter.\n *\n * @param path The path to mark for reduction.\n */\n byPath(path: string): OpenAPIReducer {\n this.pathsToReduceBy[path.toLowerCase()] = '*';\n return this;\n }\n\n /**\n * Mark a single OpenAPI operation to be included in your reduced API definition. If the path\n * that this operation is a part of utilizes common parameters, those will be automatically\n * included. Path and method casing does not matter.\n *\n * Note that if you previously called `.byPath()` to reduce an entire path down, calling\n * `.byOperation()` will override that to just reduce this specific method (or this plus\n * subsequent calls to `.byOperation()`).\n *\n * @param path The path that the operation is a part of.\n * @param method The HTTP method of the operation to mark for reduction.\n *\n */\n byOperation(path: string, method: string): OpenAPIReducer {\n const pathLC = path.toLowerCase(); // Casing should not matter.\n const methodLC = method.toLowerCase();\n\n if (this.pathsToReduceBy[pathLC] && Array.isArray(this.pathsToReduceBy[pathLC])) {\n this.pathsToReduceBy[pathLC].push(methodLC);\n } else {\n this.pathsToReduceBy[pathLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Mark an OpenAPI webhook (and all of its operations) to be included in your reduced API\n * definition. Casing does not matter.\n *\n * @param webhookName The webhook name to mark for reduction.\n */\n byWebhook(webhookName: string): OpenAPIReducer;\n\n /**\n * Mark a single OpenAPI webhook operation to be included in your reduced API definition.\n * Casing does not matter.\n *\n * @param webhookName The webhook name that the operation belongs to.\n * @param method The HTTP method of the webhook operation to mark for reduction.\n */\n byWebhook(webhookName: string, method: string): OpenAPIReducer;\n\n byWebhook(webhookName: string, method?: string): OpenAPIReducer {\n const nameLC = webhookName.toLowerCase();\n if (!method) {\n this.webhooksToReduceBy[nameLC] = '*';\n return this;\n }\n\n const methodLC = method.toLowerCase();\n if (this.webhooksToReduceBy[nameLC] && Array.isArray(this.webhooksToReduceBy[nameLC])) {\n this.webhooksToReduceBy[nameLC].push(methodLC);\n } else {\n this.webhooksToReduceBy[nameLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Reduce the current OpenAPI definition down to the configured filters.\n *\n */\n reduce(): OASDocument {\n if (!this.definition.openapi) {\n throw new Error('Sorry, only OpenAPI definitions are supported.');\n }\n\n this.hasPathsToReduceBy = Boolean(Object.keys(this.pathsToReduceBy).length);\n this.hasWebhooksToReduceBy = Boolean(Object.keys(this.webhooksToReduceBy).length);\n this.hasTagsToReduceBy = Boolean(this.tagsToReduceBy.length);\n\n // Retain any root-level security definitions, regardless if they're used or not on our reduced\n // operations.\n if ('security' in this.definition) {\n Object.values(this.definition.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n\n this.walkPaths();\n this.walkWebhooks();\n\n // Recursively accumulate any components that are in use.\n this.$refs.forEach($ref => {\n this.accumulateUsedRefs(this.definition, this.$refs, $ref);\n });\n\n this.$refs.forEach(ref => {\n const usedPathRef = this.parsePathRef(ref);\n if (usedPathRef) {\n this.retainPathMethods.add(`${usedPathRef.path.toLowerCase()}|${usedPathRef.method.toLowerCase()}`);\n }\n\n const usedWebhookRef = this.parseWebhookRef(ref);\n if (usedWebhookRef) {\n this.retainWebhookMethods.add(`${usedWebhookRef.name.toLowerCase()}|${usedWebhookRef.method.toLowerCase()}`);\n }\n });\n\n this.reducePaths();\n this.reduceWebhooks();\n\n // Require at least one path or one webhook in the result.\n const hasPaths = Boolean(this.definition.paths && Object.keys(this.definition.paths).length);\n const hasWebhooks = Boolean(\n 'webhooks' in this.definition && this.definition.webhooks && Object.keys(this.definition.webhooks).length,\n );\n\n if (!hasPaths && !hasWebhooks) {\n throw new Error(\n 'All paths and webhooks in the API definition were removed. Did you supply the right path, operation, or webhook to reduce by?',\n );\n }\n\n // Remove any unused components.\n if ('components' in this.definition) {\n Object.keys(this.definition.components || {}).forEach(componentType => {\n Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).forEach(component => {\n // If our `$ref` either is a full, or deep match, then we should preserve it.\n const refIsUsed =\n this.$refs.has(`#/components/${componentType}/${component}`) ||\n Array.from(this.$refs).some(ref => {\n // Because you can have a `$ref` like `#/components/examples/event-min/value`, which\n // would be accumulated via our `$refs` query, we want to make sure we account for them.\n // If we don't look for these then we'll end up removing them from the overall reduced\n // definition, resulting in data loss and schema corruption.\n return ref.startsWith(`#/components/${componentType}/${component}/`);\n });\n\n if (!refIsUsed) {\n delete this.definition.components?.[componentType as keyof ComponentsObject]?.[component];\n }\n });\n\n // If this component group is now empty, delete it.\n if (!Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).length) {\n delete this.definition.components?.[componentType as keyof ComponentsObject];\n }\n });\n\n // If this path no longer has any components, delete it.\n if (!Object.keys(this.definition.components || {}).length) {\n delete this.definition.components;\n }\n }\n\n // Remove any unused tags.\n if ('tags' in this.definition) {\n this.definition.tags = (this.definition.tags ?? []).filter((tag): tag is TagObject => {\n return Boolean(tag) && this.usedTags.has(tag.name);\n });\n\n if (!this.definition.tags?.length) {\n delete this.definition.tags;\n }\n }\n\n return this.definition;\n }\n\n /**\n * Recursively process a `$ref` pointer and accumulate any other `$ref` pointers that it or its\n * children use. This handles circular references by skipping `$ref` pointers we have already seen.\n * Additionally when a `$ref` points to `#/paths` we record the used path + method so we can\n * retain cross-operation references within the reduced definition.\n *\n * @param schema JSON Schema object to look for and accumulate any `$ref` pointers that it may have.\n * @param $refs Known set of `$ref` pointers.\n * @param $ref `$ref` pointer to fetch a schema from out of the supplied schema.\n */\n private accumulateUsedRefs(schema: Record<string, unknown>, $refs: Set<string>, $ref: string): void {\n // Record `$ref` pointers aimed at `#/paths` so we can retain any cross-operation references.\n const pathRef = this.parsePathRef($ref);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef($ref);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n let $refSchema: unknown;\n if (typeof $ref === 'string') $refSchema = jsonPointer.get(schema, $ref.substring(1));\n if ($refSchema === undefined) {\n // If the schema we have wasn't fully dereferenced or bundled for whatever reason and this\n // `$ref` that we have doesn't exist here we shouldn't try to search for more `$ref` pointers\n // in a schema that doesn't exist.\n return;\n }\n\n this.queryForRefPointers($refSchema).forEach(({ value: currRef }) => {\n // Because it's possible to have a schema property named `$ref` that is not a `$ref` pointer,\n // which our JSONPath query would pick up as a false positive, we want to exclude that from\n // `$ref` matching as it's not a reference pointer.\n const foundRef = this.toRefString(currRef);\n if (!foundRef) {\n return;\n }\n\n // If we've already processed this `$ref` then don't send us into an infinite loop of processing\n // circular references.\n if ($refs.has(foundRef)) {\n return;\n }\n\n $refs.add(foundRef);\n this.accumulateUsedRefs(schema, $refs, foundRef);\n });\n }\n\n /**\n * Query a JSON Schema object for any `$ref` pointers using JSONPath and return any pointers that\n * exist.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc9535}\n * @param schema JSON Schema object to look for any `$ref` pointers within it.\n */\n private queryForRefPointers(schema: any) {\n return query([\"$..['$ref']\"], schema);\n }\n\n /**\n * Normalize a value from a `jsonpath-plus` `$ref` query to a `$ref` pointer because JSONPath\n * queries may return the property value or the parent.\n *\n */\n private toRefString(value: unknown): string | null {\n if (typeof value === 'string') {\n return value;\n } else if (value && typeof value === 'object' && '$ref' in value && typeof value.$ref === 'string') {\n return value.$ref;\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into a path (e.g. `#/paths/~1anything/post/...`), return the path\n * and method so the reducer can ultimately retain cross-operation references.\n *\n */\n private parsePathRef($ref: string): { path: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/paths/')) {\n return null;\n }\n\n // Extract path segment and method: `#/paths/<pathSegment>/<method>/...`\n const match = $ref.match(/^#\\/paths\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const pathSegment = match[1];\n const method = match[2];\n if (pathSegment && method) {\n return { path: decodePointer(pathSegment), method };\n }\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into webhooks (e.g. `#/webhooks/newBooking/post/...`), return the\n * webhook name and method so the reducer can retain cross-referenced webhook operations.\n *\n */\n private parseWebhookRef($ref: string): { name: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/webhooks/')) {\n return null;\n }\n\n // Extract path segment and method: `#/webhooks/<webhookName>/<method>/...`\n const match = $ref.match(/^#\\/webhooks\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const webhookName = match[1];\n const method = match[2];\n if (webhookName && method) {\n return { name: decodePointer(webhookName), method };\n }\n }\n\n return null;\n }\n\n /**\n * Walk through the `paths` in our OpenAPI definition and reduce down any that we know we do not\n * want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced in\n * paths, webhooks, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkPaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n // When only webhooks were requested (no path/operation filter), remove all paths.\n if (this.hasWebhooksToReduceBy && !this.hasPathsToReduceBy) {\n delete this.definition.paths?.[path];\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n if (!(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n // If we have paths we want to reduce but this isn't part of our filter set, then ignore.\n // We'll remove it later.\n if (\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(method.toLowerCase())\n ) {\n return;\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods] as OperationObject;\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n if (this.hasTagsToReduceBy) {\n // If this endpoint either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n\n // If this operation has a cross-operation `$ref` pointer then we need to track it so\n // it's retained.\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n // Re-run through any `$ref` pointers that we found within this operation and search for\n // any `$ref` pointers that they also may be using.\n this.accumulateUsedRefs(this.definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Walk through the `webhooks` in our OpenAPI definition and reduce down any that we know we do\n * not want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced\n * in paths, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkWebhooks() {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n return;\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasWebhooksToReduceBy) {\n // If we have webhooks we want to reduce but this isn't part of our filter set, then\n // ignore. We'll remove it later.\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(method.toLowerCase())) {\n return;\n }\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n const operation = webhook[method as HttpMethods] as OperationObject;\n if (!operation) {\n return;\n }\n\n if (this.hasTagsToReduceBy) {\n // If this operation either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef(refStr);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n this.accumulateUsedRefs(definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Prune back our `paths` object in the OpenAPI definition to only include paths that we want to\n * preserve.\n *\n */\n private reducePaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n if (this.hasPathsToReduceBy && !(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n const methodLC = method.toLowerCase();\n\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef =\n this.retainPathMethods.has(`${pathLC}|${methodLC}`) ||\n Array.from(this.$refs).some(ref => {\n const pathRef = this.parsePathRef(ref);\n return pathRef?.path.toLowerCase() === pathLC && pathRef?.method.toLowerCase() === methodLC;\n });\n\n if (methodLC !== 'parameters') {\n // If we're reducing paths and this operation isn't part of our filter set, and it's\n // not a cross-referenced operation that we want to retain, then we should prune it.\n if (this.hasPathsToReduceBy) {\n if (\n !retainedByRef &&\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(methodLC)\n ) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n return;\n }\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods];\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n // If we're reducing by tags and this operation doesn't live in one of those, remove it.\n if (this.hasTagsToReduceBy) {\n // If this operation doesn't have any tags that we want to preserve, and it isn't\n // cross-referenced from an operation we _do_ want to preserve, then remove it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n if (!retainedByRef) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n }\n\n return;\n }\n }\n\n // Accumulate a list of used tags so we can filter out any ones that we don't need later.\n if ('tags' in operation) {\n operation.tags?.forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n }\n\n // Accumulate any used operation-level security schemas that we need to retain.\n if ('security' in operation) {\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n });\n\n // If this path no longer has any methods, delete it.\n if (!Object.keys(this.definition.paths?.[path] || {}).length) {\n delete this.definition.paths?.[path];\n }\n });\n\n // If we don't have any more paths after cleanup, and we don't have any webhooks, then throw\n // an error because an OpenAPI definition must have at least one path.\n if (!Object.keys(this.definition.paths || {}).length) {\n if (!(this.definition.webhooks && Object.keys(this.definition.webhooks).length)) {\n throw new Error(\n 'All paths in the API definition were removed. Did you supply the right path name to reduce by?',\n );\n }\n\n delete this.definition.paths;\n }\n }\n\n /**\n * Prune back our `webhooks` object in the OpenAPI definition to only include webhooks that we\n * want to preserve.\n *\n */\n private reduceWebhooks(): void {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n const retainedByRef = Array.from(this.retainWebhookMethods).some(\n key => key.startsWith(`${nameLC}|`) || key === `${nameLC}|`,\n );\n\n if (!retainedByRef) {\n delete definition.webhooks?.[webhookName];\n return;\n }\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n const methodLC = method.toLowerCase();\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef = this.retainWebhookMethods.has(`${nameLC}|${methodLC}`);\n if (this.hasWebhooksToReduceBy && !retainedByRef) {\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(methodLC)) {\n /**\n * If this webhook path item is a `$ref` then ignore and retain it.\n * @fixme we should better support reducing this.\n */\n if (isRef(definition.webhooks?.[webhookName])) {\n return;\n }\n\n delete definition.webhooks?.[webhookName]?.[method as HttpMethods];\n }\n }\n });\n\n if (!Object.keys(definition.webhooks?.[webhookName] || {}).length) {\n delete definition.webhooks?.[webhookName];\n }\n });\n\n if (definition.webhooks && !Object.keys(definition.webhooks).length) {\n delete definition.webhooks;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAGA,OAAO,iBAAiB;AAOjB,IAAM,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AED,UAAI,CAAC,OAAO,KAAK,WAAW,WAAW,WAAW,KAAK,CAAC,CAAC,EAAE,QAAQ;AACjE,eAAO,WAAW,WAAW,WAAW;AAAA,MAC1C;AAAA,IACF,CAAC;AAED,QAAI,WAAW,YAAY,CAAC,OAAO,KAAK,WAAW,QAAQ,EAAE,QAAQ;AACnE,aAAO,WAAW;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/reducer/index.ts"],"sourcesContent":["import type { OpenAPIV3_1 } from 'openapi-types';\nimport type { ComponentsObject, HttpMethods, OASDocument, OperationObject, TagObject } from '../types.js';\n\nimport jsonPointer from 'jsonpointer';\n\nimport { query } from '../analyzer/util.js';\nimport { decodePointer } from '../lib/refs.js';\nimport { isOpenAPI31, isRef } from '../types.js';\nimport { supportedMethods } from '../utils.js';\n\nexport class OpenAPIReducer {\n private definition: OASDocument;\n\n /**\n * A collection of `$ref` pointers that are used within our reduced API definition. This is used\n * to ensure that all referenced schemas are retained in our resulting API definition. Not\n * retaining them would result in an invalid OpenAPI definition.\n */\n private $refs: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI tags that are used within our reduced API definition.\n */\n private usedTags: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI paths and operations that are cross-referenced from any other paths\n * and operations that we are reducing. This collection is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainPathMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * A collection of OpenAPI webhook names and methods that are cross-referenced from any other\n * schemas. This collection, like `retainPathMethods`, is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainWebhookMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * An array of OpenAPI tags to reduce down to.\n */\n private tagsToReduceBy: string[] = [];\n\n /**\n * A collection of OpenAPI paths and operations to reduce down to.\n */\n private pathsToReduceBy: Record<string, '*' | string[]> = {};\n\n /**\n * A collection of OpenAPI webhooks to reduce down to.\n */\n private webhooksToReduceBy: Record<string, '*' | string[]> = {};\n\n private hasTagsToReduceBy: boolean = false;\n private hasPathsToReduceBy: boolean = false;\n private hasWebhooksToReduceBy: boolean = false;\n\n private constructor(definition: OASDocument) {\n this.definition = structuredClone(definition);\n }\n\n /**\n * Initialize a new instance of the `OpenAPIReducer`. The reducer allows you to reduce an OpenAPI\n * definition down to only the information necessary to fulfill a specific set of tags, paths,\n * operations, and webhooks.\n *\n * OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API\n * definitions, but also to compress a large API definition down to a manageable size containing\n * a specific set of items.\n *\n * All OpenAPI definitions reduced will still be fully functional and valid OpenAPI definitions.\n *\n * @param definition An OpenAPI definition to reduce.\n */\n static init(definition: OASDocument): OpenAPIReducer {\n return new OpenAPIReducer(definition);\n }\n\n /**\n * Mark an OpenAPI tag to be included in our reduced API definition. Tag casing does not matter.\n *\n * @param tag The tag to mark for reduction.\n */\n byTag(tag: string): OpenAPIReducer {\n this.tagsToReduceBy.push(tag.toLowerCase());\n return this;\n }\n\n /**\n * Mark an entire OpenAPI path, and all methods that it contains, to be included in your reduced\n * API definition. Path casing does not matter.\n *\n * @param path The path to mark for reduction.\n */\n byPath(path: string): OpenAPIReducer {\n this.pathsToReduceBy[path.toLowerCase()] = '*';\n return this;\n }\n\n /**\n * Mark a single OpenAPI operation to be included in your reduced API definition. If the path\n * that this operation is a part of utilizes common parameters, those will be automatically\n * included. Path and method casing does not matter.\n *\n * Note that if you previously called `.byPath()` to reduce an entire path down, calling\n * `.byOperation()` will override that to just reduce this specific method (or this plus\n * subsequent calls to `.byOperation()`).\n *\n * @param path The path that the operation is a part of.\n * @param method The HTTP method of the operation to mark for reduction.\n *\n */\n byOperation(path: string, method: string): OpenAPIReducer {\n const pathLC = path.toLowerCase(); // Casing should not matter.\n const methodLC = method.toLowerCase();\n\n if (this.pathsToReduceBy[pathLC] && Array.isArray(this.pathsToReduceBy[pathLC])) {\n this.pathsToReduceBy[pathLC].push(methodLC);\n } else {\n this.pathsToReduceBy[pathLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Mark an OpenAPI webhook (and all of its operations) to be included in your reduced API\n * definition. Casing does not matter.\n *\n * @param webhookName The webhook name to mark for reduction.\n */\n byWebhook(webhookName: string): OpenAPIReducer;\n\n /**\n * Mark a single OpenAPI webhook operation to be included in your reduced API definition.\n * Casing does not matter.\n *\n * @param webhookName The webhook name that the operation belongs to.\n * @param method The HTTP method of the webhook operation to mark for reduction.\n */\n byWebhook(webhookName: string, method: string): OpenAPIReducer;\n\n byWebhook(webhookName: string, method?: string): OpenAPIReducer {\n const nameLC = webhookName.toLowerCase();\n if (!method) {\n this.webhooksToReduceBy[nameLC] = '*';\n return this;\n }\n\n const methodLC = method.toLowerCase();\n if (this.webhooksToReduceBy[nameLC] && Array.isArray(this.webhooksToReduceBy[nameLC])) {\n this.webhooksToReduceBy[nameLC].push(methodLC);\n } else {\n this.webhooksToReduceBy[nameLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Reduce the current OpenAPI definition down to the configured filters.\n *\n */\n reduce(): OASDocument {\n if (!this.definition.openapi) {\n throw new Error('Sorry, only OpenAPI definitions are supported.');\n }\n\n this.hasPathsToReduceBy = Boolean(Object.keys(this.pathsToReduceBy).length);\n this.hasWebhooksToReduceBy = Boolean(Object.keys(this.webhooksToReduceBy).length);\n this.hasTagsToReduceBy = Boolean(this.tagsToReduceBy.length);\n\n // Retain any root-level security definitions, regardless if they're used or not on our reduced\n // operations.\n if ('security' in this.definition) {\n Object.values(this.definition.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n\n this.walkPaths();\n this.walkWebhooks();\n\n // Recursively accumulate any components that are in use.\n this.$refs.forEach($ref => {\n this.accumulateUsedRefs(this.definition, this.$refs, $ref);\n });\n\n this.$refs.forEach(ref => {\n const usedPathRef = this.parsePathRef(ref);\n if (usedPathRef) {\n this.retainPathMethods.add(`${usedPathRef.path.toLowerCase()}|${usedPathRef.method.toLowerCase()}`);\n }\n\n const usedWebhookRef = this.parseWebhookRef(ref);\n if (usedWebhookRef) {\n this.retainWebhookMethods.add(`${usedWebhookRef.name.toLowerCase()}|${usedWebhookRef.method.toLowerCase()}`);\n }\n });\n\n this.reducePaths();\n this.reduceWebhooks();\n\n // Require at least one path or one webhook in the result.\n const hasPaths = Boolean(this.definition.paths && Object.keys(this.definition.paths).length);\n const hasWebhooks = Boolean(\n 'webhooks' in this.definition && this.definition.webhooks && Object.keys(this.definition.webhooks).length,\n );\n\n if (!hasPaths && !hasWebhooks) {\n throw new Error(\n 'All paths and webhooks in the API definition were removed. Did you supply the right path, operation, or webhook to reduce by?',\n );\n }\n\n // Remove any unused components.\n if ('components' in this.definition) {\n Object.keys(this.definition.components || {}).forEach(componentType => {\n Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).forEach(component => {\n // If our `$ref` either is a full, or deep match, then we should preserve it.\n const refIsUsed =\n this.$refs.has(`#/components/${componentType}/${component}`) ||\n Array.from(this.$refs).some(ref => {\n // Because you can have a `$ref` like `#/components/examples/event-min/value`, which\n // would be accumulated via our `$refs` query, we want to make sure we account for them.\n // If we don't look for these then we'll end up removing them from the overall reduced\n // definition, resulting in data loss and schema corruption.\n return ref.startsWith(`#/components/${componentType}/${component}/`);\n });\n\n if (!refIsUsed) {\n delete this.definition.components?.[componentType as keyof ComponentsObject]?.[component];\n }\n });\n\n // If this component group is now empty, delete it.\n if (!Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).length) {\n delete this.definition.components?.[componentType as keyof ComponentsObject];\n }\n });\n\n // If this path no longer has any components, delete it.\n if (!Object.keys(this.definition.components || {}).length) {\n delete this.definition.components;\n }\n }\n\n // Remove any unused tags.\n if ('tags' in this.definition) {\n this.definition.tags = (this.definition.tags ?? []).filter((tag): tag is TagObject => {\n return Boolean(tag) && this.usedTags.has(tag.name);\n });\n\n if (!this.definition.tags?.length) {\n delete this.definition.tags;\n }\n }\n\n return this.definition;\n }\n\n /**\n * Recursively process a `$ref` pointer and accumulate any other `$ref` pointers that it or its\n * children use. This handles circular references by skipping `$ref` pointers we have already seen.\n * Additionally when a `$ref` points to `#/paths` we record the used path + method so we can\n * retain cross-operation references within the reduced definition.\n *\n * @param schema JSON Schema object to look for and accumulate any `$ref` pointers that it may have.\n * @param $refs Known set of `$ref` pointers.\n * @param $ref `$ref` pointer to fetch a schema from out of the supplied schema.\n */\n private accumulateUsedRefs(schema: Record<string, unknown>, $refs: Set<string>, $ref: string): void {\n // Record `$ref` pointers aimed at `#/paths` so we can retain any cross-operation references.\n const pathRef = this.parsePathRef($ref);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef($ref);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n let $refSchema: unknown;\n if (typeof $ref === 'string') $refSchema = jsonPointer.get(schema, $ref.substring(1));\n if ($refSchema === undefined) {\n // If the schema we have wasn't fully dereferenced or bundled for whatever reason and this\n // `$ref` that we have doesn't exist here we shouldn't try to search for more `$ref` pointers\n // in a schema that doesn't exist.\n return;\n }\n\n this.queryForRefPointers($refSchema).forEach(({ value: currRef }) => {\n // Because it's possible to have a schema property named `$ref` that is not a `$ref` pointer,\n // which our JSONPath query would pick up as a false positive, we want to exclude that from\n // `$ref` matching as it's not a reference pointer.\n const foundRef = this.toRefString(currRef);\n if (!foundRef) {\n return;\n }\n\n // If we've already processed this `$ref` then don't send us into an infinite loop of processing\n // circular references.\n if ($refs.has(foundRef)) {\n return;\n }\n\n $refs.add(foundRef);\n this.accumulateUsedRefs(schema, $refs, foundRef);\n });\n }\n\n /**\n * Query a JSON Schema object for any `$ref` pointers using JSONPath and return any pointers that\n * exist.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc9535}\n * @param schema JSON Schema object to look for any `$ref` pointers within it.\n */\n private queryForRefPointers(schema: any) {\n return query([\"$..['$ref']\"], schema);\n }\n\n /**\n * Normalize a value from a `jsonpath-plus` `$ref` query to a `$ref` pointer because JSONPath\n * queries may return the property value or the parent.\n *\n */\n private toRefString(value: unknown): string | null {\n if (typeof value === 'string') {\n return value;\n } else if (value && typeof value === 'object' && '$ref' in value && typeof value.$ref === 'string') {\n return value.$ref;\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into a path (e.g. `#/paths/~1anything/post/...`), return the path\n * and method so the reducer can ultimately retain cross-operation references.\n *\n */\n private parsePathRef($ref: string): { path: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/paths/')) {\n return null;\n }\n\n // Extract path segment and method: `#/paths/<pathSegment>/<method>/...`\n const match = $ref.match(/^#\\/paths\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const pathSegment = match[1];\n const method = match[2];\n if (pathSegment && method) {\n return { path: decodePointer(pathSegment), method };\n }\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into webhooks (e.g. `#/webhooks/newBooking/post/...`), return the\n * webhook name and method so the reducer can retain cross-referenced webhook operations.\n *\n */\n private parseWebhookRef($ref: string): { name: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/webhooks/')) {\n return null;\n }\n\n // Extract path segment and method: `#/webhooks/<webhookName>/<method>/...`\n const match = $ref.match(/^#\\/webhooks\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const webhookName = match[1];\n const method = match[2];\n if (webhookName && method) {\n return { name: decodePointer(webhookName), method };\n }\n }\n\n return null;\n }\n\n /**\n * Walk through the `paths` in our OpenAPI definition and reduce down any that we know we do not\n * want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced in\n * paths, webhooks, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkPaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n // When only webhooks were requested (no path/operation filter), remove all paths.\n if (this.hasWebhooksToReduceBy && !this.hasPathsToReduceBy) {\n delete this.definition.paths?.[path];\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n if (!(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n // If we have paths we want to reduce but this isn't part of our filter set, then ignore.\n // We'll remove it later.\n if (\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(method.toLowerCase())\n ) {\n return;\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods] as OperationObject;\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n if (this.hasTagsToReduceBy) {\n // If this endpoint either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n\n // If this operation has a cross-operation `$ref` pointer then we need to track it so\n // it's retained.\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n // Re-run through any `$ref` pointers that we found within this operation and search for\n // any `$ref` pointers that they also may be using.\n this.accumulateUsedRefs(this.definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Walk through the `webhooks` in our OpenAPI definition and reduce down any that we know we do\n * not want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced\n * in paths, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkWebhooks() {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n return;\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasWebhooksToReduceBy) {\n // If we have webhooks we want to reduce but this isn't part of our filter set, then\n // ignore. We'll remove it later.\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(method.toLowerCase())) {\n return;\n }\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n const operation = webhook[method as HttpMethods] as OperationObject;\n if (!operation) {\n return;\n }\n\n if (this.hasTagsToReduceBy) {\n // If this operation either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef(refStr);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n this.accumulateUsedRefs(definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Prune back our `paths` object in the OpenAPI definition to only include paths that we want to\n * preserve.\n *\n */\n private reducePaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n if (this.hasPathsToReduceBy && !(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n const methodLC = method.toLowerCase();\n\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef =\n this.retainPathMethods.has(`${pathLC}|${methodLC}`) ||\n Array.from(this.$refs).some(ref => {\n const pathRef = this.parsePathRef(ref);\n return pathRef?.path.toLowerCase() === pathLC && pathRef?.method.toLowerCase() === methodLC;\n });\n\n if (methodLC !== 'parameters') {\n // If we're reducing paths and this operation isn't part of our filter set, and it's\n // not a cross-referenced operation that we want to retain, then we should prune it.\n if (this.hasPathsToReduceBy) {\n if (\n !retainedByRef &&\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(methodLC)\n ) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n return;\n }\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods];\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n // If we're reducing by tags and this operation doesn't live in one of those, remove it.\n if (this.hasTagsToReduceBy) {\n // If this operation doesn't have any tags that we want to preserve, and it isn't\n // cross-referenced from an operation we _do_ want to preserve, then remove it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n if (!retainedByRef) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n }\n\n return;\n }\n }\n\n // Accumulate a list of used tags so we can filter out any ones that we don't need later.\n if ('tags' in operation) {\n operation.tags?.forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n }\n\n // Accumulate any used operation-level security schemas that we need to retain.\n if ('security' in operation) {\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n });\n\n // If this path no longer has any methods, delete it.\n if (!Object.keys(this.definition.paths?.[path] || {}).length) {\n delete this.definition.paths?.[path];\n }\n });\n\n // If we don't have any more paths after cleanup, and we don't have any webhooks, then throw\n // an error because an OpenAPI definition must have at least one path.\n if (!Object.keys(this.definition.paths || {}).length) {\n if (!(this.definition.webhooks && Object.keys(this.definition.webhooks).length)) {\n throw new Error(\n 'All paths in the API definition were removed. Did you supply the right path name to reduce by?',\n );\n }\n\n delete this.definition.paths;\n }\n }\n\n /**\n * Prune back our `webhooks` object in the OpenAPI definition to only include webhooks that we\n * want to preserve.\n *\n */\n private reduceWebhooks(): void {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n const retainedByRef = Array.from(this.retainWebhookMethods).some(\n key => key.startsWith(`${nameLC}|`) || key === `${nameLC}|`,\n );\n\n if (!retainedByRef) {\n delete definition.webhooks?.[webhookName];\n return;\n }\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n const methodLC = method.toLowerCase();\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef = this.retainWebhookMethods.has(`${nameLC}|${methodLC}`);\n if (this.hasWebhooksToReduceBy && !retainedByRef) {\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(methodLC)) {\n /**\n * If this webhook path item is a `$ref` then ignore and retain it.\n * @fixme we should better support reducing this.\n */\n if (!definition.webhooks?.[webhookName] || isRef(definition.webhooks?.[webhookName])) {\n return;\n }\n\n delete definition.webhooks?.[webhookName]?.[method as HttpMethods];\n }\n }\n });\n\n if (!Object.keys(definition.webhooks?.[webhookName] || {}).length) {\n delete definition.webhooks?.[webhookName];\n }\n });\n\n if (definition.webhooks && !Object.keys(definition.webhooks).length) {\n delete definition.webhooks;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAGA,OAAO,iBAAiB;AAOjB,IAAM,iBAAN,MAAM,gBAAe;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAqB,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA,EAK7B,WAAwB,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQhC,oBAAgD,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQxD,uBAAmD,oBAAI,IAAI;AAAA;AAAA;AAAA;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