oas 38.3.0 → 38.4.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.
@@ -1,72 +1,34 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } function _optionalChainDelete(ops) { const result = _optionalChain(ops); return result == null ? true : result; } var _class;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkCOHEPMUPcjs = require('../chunk-COHEPMUP.cjs');
4
-
5
-
6
-
7
- var _chunk7WBPPWYIcjs = require('../chunk-7WBPPWYI.cjs');
3
+ var _chunkZ2WDQGCUcjs = require('../chunk-Z2WDQGCU.cjs');
4
+ require('../chunk-COHEPMUP.cjs');
5
+ require('../chunk-Y64TRECN.cjs');
6
+ require('../chunk-7WBPPWYI.cjs');
8
7
  require('../chunk-6HXOZ5GY.cjs');
9
-
10
-
11
-
12
- var _chunk7PWF3F2Wcjs = require('../chunk-7PWF3F2W.cjs');
8
+ require('../chunk-7PWF3F2W.cjs');
13
9
 
14
10
  // src/reducer/index.ts
15
- var _jsonpointer = require('jsonpointer'); var _jsonpointer2 = _interopRequireDefault(_jsonpointer);
16
- var OpenAPIReducer = (_class = class _OpenAPIReducer {
17
-
18
- /**
19
- * A collection of `$ref` pointers that are used within our reduced API definition. This is used
20
- * to ensure that all referenced schemas are retained in our resulting API definition. Not
21
- * retaining them would result in an invalid OpenAPI definition.
22
- */
23
- __init() {this.$refs = /* @__PURE__ */ new Set()}
24
- /**
25
- * A collection of OpenAPI tags that are used within our reduced API definition.
26
- */
27
- __init2() {this.usedTags = /* @__PURE__ */ new Set()}
28
- /**
29
- * A collection of OpenAPI paths and operations that are cross-referenced from any other paths
30
- * and operations that we are reducing. This collection is used in order to ensure that those
31
- * schemas are retained with our resulting API definition. Not retaining them would result in an
32
- * invalid OpenAPI definition.
33
- */
34
- __init3() {this.retainPathMethods = /* @__PURE__ */ new Set()}
35
- /**
36
- * A collection of OpenAPI webhook names and methods that are cross-referenced from any other
37
- * schemas. This collection, like `retainPathMethods`, is used in order to ensure that those
38
- * schemas are retained with our resulting API definition. Not retaining them would result in an
39
- * invalid OpenAPI definition.
40
- */
41
- __init4() {this.retainWebhookMethods = /* @__PURE__ */ new Set()}
42
- /**
43
- * An array of OpenAPI tags to reduce down to.
44
- */
45
- __init5() {this.tagsToReduceBy = []}
46
- /**
47
- * A collection of OpenAPI paths and operations to reduce down to.
48
- */
49
- __init6() {this.pathsToReduceBy = {}}
50
- /**
51
- * A collection of OpenAPI webhooks to reduce down to.
52
- */
53
- __init7() {this.webhooksToReduceBy = {}}
54
- __init8() {this.hasTagsToReduceBy = false}
55
- __init9() {this.hasPathsToReduceBy = false}
56
- __init10() {this.hasWebhooksToReduceBy = false}
57
- constructor(definition) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);_class.prototype.__init9.call(this);_class.prototype.__init10.call(this);
58
- this.definition = structuredClone(definition);
11
+ var OpenAPIReducer = class _OpenAPIReducer extends _chunkZ2WDQGCUcjs.OpenAPITransformer {
12
+ constructor(definition) {
13
+ super(definition, {
14
+ mode: "reduce"
15
+ });
59
16
  }
60
17
  /**
61
18
  * Initialize a new instance of the `OpenAPIReducer`. The reducer allows you to reduce an OpenAPI
62
19
  * definition down to only the information necessary to fulfill a specific set of tags, paths,
63
- * operations, and webhooks.
20
+ * operations, operation IDs, and webhooks.
64
21
  *
65
22
  * OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API
66
23
  * definitions, but also to compress a large API definition down to a manageable size containing
67
24
  * a specific set of items.
68
25
  *
69
- * All OpenAPI definitions reduced will still be fully functional and valid OpenAPI definitions.
26
+ * Tag and operation ID filters intersect with path, operation, and webhook filters. When they are
27
+ * combined, an operation must match every configured filter to be retained.
28
+ *
29
+ * Referenced Path Items are preserved intact rather than resolved. The complete dependency set
30
+ * of operations and Path Items retained transitively through cross-operation references is not
31
+ * expanded before paths and webhooks are transformed.
70
32
  *
71
33
  * @param definition An OpenAPI definition to reduce.
72
34
  */
@@ -74,12 +36,14 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
74
36
  return new _OpenAPIReducer(definition);
75
37
  }
76
38
  /**
77
- * Mark an OpenAPI tag to be included in our reduced API definition. Tag casing does not matter.
39
+ * Mark an OpenAPI tag to be included in our reduced API definition. When combined with an
40
+ * operation ID, path, operation, or webhook filter, this tag filter further narrows that
41
+ * selection. Tag casing does not matter.
78
42
  *
79
43
  * @param tag The tag to mark for reduction.
80
44
  */
81
45
  byTag(tag) {
82
- this.tagsToReduceBy.push(tag.toLowerCase());
46
+ this.selectTag(tag);
83
47
  return this;
84
48
  }
85
49
  /**
@@ -89,7 +53,7 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
89
53
  * @param path The path to mark for reduction.
90
54
  */
91
55
  byPath(path) {
92
- this.pathsToReduceBy[path.toLowerCase()] = "*";
56
+ this.selectPath(path);
93
57
  return this;
94
58
  }
95
59
  /**
@@ -103,481 +67,36 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
103
67
  *
104
68
  * @param path The path that the operation is a part of.
105
69
  * @param method The HTTP method of the operation to mark for reduction.
106
- *
107
70
  */
108
71
  byOperation(path, method) {
109
- const pathLC = path.toLowerCase();
110
- const methodLC = method.toLowerCase();
111
- if (this.pathsToReduceBy[pathLC] && Array.isArray(this.pathsToReduceBy[pathLC])) {
112
- this.pathsToReduceBy[pathLC].push(methodLC);
113
- } else {
114
- this.pathsToReduceBy[pathLC] = [methodLC];
115
- }
72
+ this.selectOperation(path, method);
116
73
  return this;
117
74
  }
118
- byWebhook(webhookName, method) {
119
- const nameLC = webhookName.toLowerCase();
120
- if (!method) {
121
- this.webhooksToReduceBy[nameLC] = "*";
122
- return this;
123
- }
124
- const methodLC = method.toLowerCase();
125
- if (this.webhooksToReduceBy[nameLC] && Array.isArray(this.webhooksToReduceBy[nameLC])) {
126
- this.webhooksToReduceBy[nameLC].push(methodLC);
127
- } else {
128
- this.webhooksToReduceBy[nameLC] = [methodLC];
129
- }
130
- return this;
131
- }
132
- /**
133
- * Reduce the current OpenAPI definition down to the configured filters.
134
- *
135
- */
136
- reduce() {
137
- if (!this.definition.openapi) {
138
- throw new Error("Sorry, only OpenAPI definitions are supported.");
139
- }
140
- this.hasPathsToReduceBy = Boolean(Object.keys(this.pathsToReduceBy).length);
141
- this.hasWebhooksToReduceBy = Boolean(Object.keys(this.webhooksToReduceBy).length);
142
- this.hasTagsToReduceBy = Boolean(this.tagsToReduceBy.length);
143
- if ("security" in this.definition) {
144
- Object.values(this.definition.security || {}).forEach((sec) => {
145
- Object.keys(sec).forEach((scheme) => {
146
- this.$refs.add(`#/components/securitySchemes/${scheme}`);
147
- });
148
- });
149
- }
150
- this.walkPaths();
151
- this.walkWebhooks();
152
- this.$refs.forEach(($ref) => {
153
- this.accumulateUsedRefs(this.definition, this.$refs, $ref);
154
- });
155
- this.$refs.forEach((ref) => {
156
- const usedPathRef = this.parsePathRef(ref);
157
- if (usedPathRef) {
158
- this.retainPathMethods.add(`${usedPathRef.path.toLowerCase()}|${usedPathRef.method.toLowerCase()}`);
159
- }
160
- const usedWebhookRef = this.parseWebhookRef(ref);
161
- if (usedWebhookRef) {
162
- this.retainWebhookMethods.add(`${usedWebhookRef.name.toLowerCase()}|${usedWebhookRef.method.toLowerCase()}`);
163
- }
164
- });
165
- this.reducePaths();
166
- this.reduceWebhooks();
167
- const hasPaths = Boolean(this.definition.paths && Object.keys(this.definition.paths).length);
168
- const hasWebhooks = Boolean(
169
- "webhooks" in this.definition && this.definition.webhooks && Object.keys(this.definition.webhooks).length
170
- );
171
- if (!hasPaths && !hasWebhooks) {
172
- throw new Error(
173
- "All paths and webhooks in the API definition were removed. Did you supply the right path, operation, or webhook to reduce by?"
174
- );
175
- }
176
- if ("components" in this.definition) {
177
- Object.keys(this.definition.components || {}).forEach((componentType) => {
178
- Object.keys(_optionalChain([this, 'access', _ => _.definition, 'access', _2 => _2.components, 'optionalAccess', _3 => _3[componentType]]) || {}).forEach((component) => {
179
- const refIsUsed = this.$refs.has(`#/components/${componentType}/${component}`) || Array.from(this.$refs).some((ref) => {
180
- return ref.startsWith(`#/components/${componentType}/${component}/`);
181
- });
182
- if (!refIsUsed) {
183
- _optionalChainDelete([this, 'access', _4 => _4.definition, 'access', _5 => _5.components, 'optionalAccess', _6 => _6[componentType], 'optionalAccess', _7 => delete _7[component]]);
184
- }
185
- });
186
- if (!Object.keys(_optionalChain([this, 'access', _8 => _8.definition, 'access', _9 => _9.components, 'optionalAccess', _10 => _10[componentType]]) || {}).length) {
187
- _optionalChainDelete([this, 'access', _11 => _11.definition, 'access', _12 => _12.components, 'optionalAccess', _13 => delete _13[componentType]]);
188
- }
189
- });
190
- if (!Object.keys(this.definition.components || {}).length) {
191
- delete this.definition.components;
192
- }
193
- }
194
- if ("tags" in this.definition) {
195
- this.definition.tags = (_nullishCoalesce(this.definition.tags, () => ( []))).filter((tag) => {
196
- return Boolean(tag) && this.usedTags.has(tag.name);
197
- });
198
- if (!_optionalChain([this, 'access', _14 => _14.definition, 'access', _15 => _15.tags, 'optionalAccess', _16 => _16.length])) {
199
- delete this.definition.tags;
200
- }
201
- }
202
- return this.definition;
203
- }
204
- /**
205
- * Recursively process a `$ref` pointer and accumulate any other `$ref` pointers that it or its
206
- * children use. This handles circular references by skipping `$ref` pointers we have already seen.
207
- * Additionally when a `$ref` points to `#/paths` we record the used path + method so we can
208
- * retain cross-operation references within the reduced definition.
209
- *
210
- * @param schema JSON Schema object to look for and accumulate any `$ref` pointers that it may have.
211
- * @param $refs Known set of `$ref` pointers.
212
- * @param $ref `$ref` pointer to fetch a schema from out of the supplied schema.
213
- */
214
- accumulateUsedRefs(schema, $refs, $ref) {
215
- const pathRef = this.parsePathRef($ref);
216
- if (pathRef) {
217
- this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);
218
- }
219
- const webhookRef = this.parseWebhookRef($ref);
220
- if (webhookRef) {
221
- this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);
222
- }
223
- let $refSchema;
224
- if (typeof $ref === "string") $refSchema = _jsonpointer2.default.get(schema, $ref.substring(1));
225
- if ($refSchema === void 0) {
226
- return;
227
- }
228
- this.queryForRefPointers($refSchema).forEach(({ value: currRef }) => {
229
- const foundRef = this.toRefString(currRef);
230
- if (!foundRef) {
231
- return;
232
- }
233
- if ($refs.has(foundRef)) {
234
- return;
235
- }
236
- $refs.add(foundRef);
237
- this.accumulateUsedRefs(schema, $refs, foundRef);
238
- });
239
- }
240
- /**
241
- * Query a JSON Schema object for any `$ref` pointers using JSONPath and return any pointers that
242
- * exist.
243
- *
244
- * @see {@link https://datatracker.ietf.org/doc/html/rfc9535}
245
- * @param schema JSON Schema object to look for any `$ref` pointers within it.
246
- */
247
- queryForRefPointers(schema) {
248
- return _chunkCOHEPMUPcjs.query.call(void 0, ["$..['$ref']"], schema);
249
- }
250
- /**
251
- * Normalize a value from a `jsonpath-plus` `$ref` query to a `$ref` pointer because JSONPath
252
- * queries may return the property value or the parent.
253
- *
254
- */
255
- toRefString(value) {
256
- if (typeof value === "string") {
257
- return value;
258
- } else if (value && typeof value === "object" && "$ref" in value && typeof value.$ref === "string") {
259
- return value.$ref;
260
- }
261
- return null;
262
- }
263
75
  /**
264
- * If the given `$ref` points into a path (e.g. `#/paths/~1anything/post/...`), return the path
265
- * and method so the reducer can ultimately retain cross-operation references.
76
+ * Mark an OpenAPI operation to be included in our reduced API definition by its operation ID.
77
+ * IDs are matched exactly. If an operation does not have an authored ID, the generated ID from
78
+ * `Operation.getOperationId()` can be used instead.
266
79
  *
267
- */
268
- parsePathRef($ref) {
269
- if (typeof $ref !== "string" || !$ref.startsWith("#/paths/")) {
270
- return null;
271
- }
272
- const match = $ref.match(/^#\/paths\/([^/]+)\/([^/]+)(?:\/|$)/);
273
- if (match) {
274
- const pathSegment = match[1];
275
- const method = match[2];
276
- if (pathSegment && method) {
277
- return { path: _chunk7WBPPWYIcjs.decodePointer.call(void 0, pathSegment), method };
278
- }
279
- }
280
- return null;
281
- }
282
- /**
283
- * If the given `$ref` points into webhooks (e.g. `#/webhooks/newBooking/post/...`), return the
284
- * webhook name and method so the reducer can retain cross-referenced webhook operations.
80
+ * Operation ID filters further narrow any tag, path, operation, or webhook filters.
285
81
  *
82
+ * @param operationId Operation ID to mark for reduction.
286
83
  */
287
- parseWebhookRef($ref) {
288
- if (typeof $ref !== "string" || !$ref.startsWith("#/webhooks/")) {
289
- return null;
290
- }
291
- const match = $ref.match(/^#\/webhooks\/([^/]+)\/([^/]+)(?:\/|$)/);
292
- if (match) {
293
- const webhookName = match[1];
294
- const method = match[2];
295
- if (webhookName && method) {
296
- return { name: _chunk7WBPPWYIcjs.decodePointer.call(void 0, webhookName), method };
297
- }
298
- }
299
- return null;
300
- }
301
- /**
302
- * Walk through the `paths` in our OpenAPI definition and reduce down any that we know we do not
303
- * want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced in
304
- * paths, webhooks, operations, and schemas that we _do_ want to keep.
305
- *
306
- */
307
- walkPaths() {
308
- if (!("paths" in this.definition) || !this.definition.paths) {
309
- return;
310
- }
311
- Object.keys(this.definition.paths).forEach((path) => {
312
- const pathLC = path.toLowerCase();
313
- if (this.hasWebhooksToReduceBy && !this.hasPathsToReduceBy) {
314
- _optionalChainDelete([this, 'access', _17 => _17.definition, 'access', _18 => _18.paths, 'optionalAccess', _19 => delete _19[path]]);
315
- return;
316
- }
317
- if (this.hasPathsToReduceBy) {
318
- if (!(pathLC in this.pathsToReduceBy)) {
319
- _optionalChainDelete([this, 'access', _20 => _20.definition, 'access', _21 => _21.paths, 'optionalAccess', _22 => delete _22[path]]);
320
- return;
321
- }
322
- }
323
- Object.keys(_optionalChain([this, 'access', _23 => _23.definition, 'access', _24 => _24.paths, 'optionalAccess', _25 => _25[path]]) || {}).forEach((method) => {
324
- if (method === "parameters" || !_chunk7WBPPWYIcjs.supportedMethods.includes(method.toLowerCase())) {
325
- return;
326
- }
327
- if (this.hasPathsToReduceBy) {
328
- if (this.pathsToReduceBy[pathLC] !== "*" && Array.isArray(this.pathsToReduceBy[pathLC]) && !this.pathsToReduceBy[pathLC].includes(method.toLowerCase())) {
329
- return;
330
- }
331
- }
332
- const operation = _optionalChain([this, 'access', _26 => _26.definition, 'access', _27 => _27.paths, 'optionalAccess', _28 => _28[path], 'optionalAccess', _29 => _29[method]]);
333
- if (!operation) {
334
- throw new Error(`Operation \`${method} ${path}\` not found`);
335
- }
336
- if (this.hasTagsToReduceBy) {
337
- if (!(operation.tags || []).filter((tag) => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {
338
- return;
339
- }
340
- }
341
- (operation.tags || []).forEach((tag) => {
342
- this.usedTags.add(tag);
343
- });
344
- const pathLevelParams = _optionalChain([this, 'access', _30 => _30.definition, 'access', _31 => _31.paths, 'optionalAccess', _32 => _32[path], 'optionalAccess', _33 => _33.parameters]);
345
- if (pathLevelParams) {
346
- this.queryForRefPointers(pathLevelParams).forEach(({ value: ref }) => {
347
- const refStr = this.toRefString(ref);
348
- if (!refStr) {
349
- return;
350
- }
351
- this.$refs.add(refStr);
352
- this.accumulateUsedRefs(this.definition, this.$refs, refStr);
353
- });
354
- }
355
- this.queryForRefPointers(operation).forEach(({ value: ref }) => {
356
- const refStr = this.toRefString(ref);
357
- if (!refStr) {
358
- return;
359
- }
360
- this.$refs.add(refStr);
361
- const pathRef = this.parsePathRef(refStr);
362
- if (pathRef) {
363
- this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);
364
- }
365
- this.accumulateUsedRefs(this.definition, this.$refs, refStr);
366
- });
367
- Object.values(operation.security || {}).forEach((sec) => {
368
- Object.keys(sec).forEach((scheme) => {
369
- this.$refs.add(`#/components/securitySchemes/${scheme}`);
370
- });
371
- });
372
- });
373
- });
374
- }
375
- /**
376
- * Walk through the `webhooks` in our OpenAPI definition and reduce down any that we know we do
377
- * not want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced
378
- * in paths, operations, and schemas that we _do_ want to keep.
379
- *
380
- */
381
- walkWebhooks() {
382
- if (!_chunk7PWF3F2Wcjs.isOpenAPI31.call(void 0, this.definition)) {
383
- return;
384
- } else if (!("webhooks" in this.definition) || !this.definition.webhooks) {
385
- return;
386
- }
387
- const definition = this.definition;
388
- Object.keys(definition.webhooks || {}).forEach((webhookName) => {
389
- const nameLC = webhookName.toLowerCase();
390
- if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {
391
- return;
392
- }
393
- const webhook = _optionalChain([definition, 'access', _34 => _34.webhooks, 'optionalAccess', _35 => _35[webhookName]]);
394
- if (!webhook || typeof webhook !== "object") {
395
- return;
396
- }
397
- Object.keys(webhook).forEach((method) => {
398
- if (method === "parameters" || !_chunk7WBPPWYIcjs.supportedMethods.includes(method.toLowerCase())) {
399
- return;
400
- }
401
- if (this.hasWebhooksToReduceBy) {
402
- const methodFilter = this.webhooksToReduceBy[nameLC];
403
- if (methodFilter !== "*" && Array.isArray(methodFilter) && !methodFilter.includes(method.toLowerCase())) {
404
- return;
405
- }
406
- }
407
- if (_chunk7PWF3F2Wcjs.isRef.call(void 0, webhook)) {
408
- return;
409
- }
410
- const operation = webhook[method];
411
- if (!operation) {
412
- return;
413
- }
414
- if (this.hasTagsToReduceBy) {
415
- if (!(operation.tags || []).filter((tag) => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {
416
- return;
417
- }
418
- }
419
- (operation.tags || []).forEach((tag) => {
420
- this.usedTags.add(tag);
421
- });
422
- if (webhook.parameters) {
423
- this.queryForRefPointers(webhook.parameters).forEach(({ value: ref }) => {
424
- const refStr = this.toRefString(ref);
425
- if (!refStr) {
426
- return;
427
- }
428
- this.$refs.add(refStr);
429
- this.accumulateUsedRefs(definition, this.$refs, refStr);
430
- });
431
- }
432
- this.queryForRefPointers(operation).forEach(({ value: ref }) => {
433
- const refStr = this.toRefString(ref);
434
- if (!refStr) {
435
- return;
436
- }
437
- this.$refs.add(refStr);
438
- const pathRef = this.parsePathRef(refStr);
439
- if (pathRef) {
440
- this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);
441
- }
442
- const webhookRef = this.parseWebhookRef(refStr);
443
- if (webhookRef) {
444
- this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);
445
- }
446
- this.accumulateUsedRefs(definition, this.$refs, refStr);
447
- });
448
- Object.values(operation.security || {}).forEach((sec) => {
449
- Object.keys(sec).forEach((scheme) => {
450
- this.$refs.add(`#/components/securitySchemes/${scheme}`);
451
- });
452
- });
453
- });
454
- });
84
+ byOperationId(operationId) {
85
+ this.selectOperationId(operationId);
86
+ return this;
455
87
  }
456
- /**
457
- * Prune back our `paths` object in the OpenAPI definition to only include paths that we want to
458
- * preserve.
459
- *
460
- */
461
- reducePaths() {
462
- if (!("paths" in this.definition) || !this.definition.paths) {
463
- return;
464
- }
465
- Object.keys(this.definition.paths).forEach((path) => {
466
- const pathLC = path.toLowerCase();
467
- if (this.hasPathsToReduceBy && !(pathLC in this.pathsToReduceBy)) {
468
- _optionalChainDelete([this, 'access', _36 => _36.definition, 'access', _37 => _37.paths, 'optionalAccess', _38 => delete _38[path]]);
469
- return;
470
- }
471
- Object.keys(_optionalChain([this, 'access', _39 => _39.definition, 'access', _40 => _40.paths, 'optionalAccess', _41 => _41[path]]) || {}).forEach((method) => {
472
- const methodLC = method.toLowerCase();
473
- if (method === "parameters" || !_chunk7WBPPWYIcjs.supportedMethods.includes(methodLC)) {
474
- return;
475
- }
476
- const retainedByRef = this.retainPathMethods.has(`${pathLC}|${methodLC}`) || Array.from(this.$refs).some((ref) => {
477
- const pathRef = this.parsePathRef(ref);
478
- return _optionalChain([pathRef, 'optionalAccess', _42 => _42.path, 'access', _43 => _43.toLowerCase, 'call', _44 => _44()]) === pathLC && _optionalChain([pathRef, 'optionalAccess', _45 => _45.method, 'access', _46 => _46.toLowerCase, 'call', _47 => _47()]) === methodLC;
479
- });
480
- if (methodLC !== "parameters") {
481
- if (this.hasPathsToReduceBy) {
482
- if (!retainedByRef && this.pathsToReduceBy[pathLC] !== "*" && Array.isArray(this.pathsToReduceBy[pathLC]) && !this.pathsToReduceBy[pathLC].includes(methodLC)) {
483
- _optionalChainDelete([this, 'access', _48 => _48.definition, 'access', _49 => _49.paths, 'optionalAccess', _50 => _50[path], 'optionalAccess', _51 => delete _51[method]]);
484
- return;
485
- }
486
- }
487
- }
488
- const operation = _optionalChain([this, 'access', _52 => _52.definition, 'access', _53 => _53.paths, 'optionalAccess', _54 => _54[path], 'optionalAccess', _55 => _55[method]]);
489
- if (!operation) {
490
- throw new Error(`Operation \`${method} ${path}\` not found`);
491
- }
492
- if (this.hasTagsToReduceBy) {
493
- if (!(operation.tags || []).filter((tag) => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {
494
- if (!retainedByRef) {
495
- _optionalChainDelete([this, 'access', _56 => _56.definition, 'access', _57 => _57.paths, 'optionalAccess', _58 => _58[path], 'optionalAccess', _59 => delete _59[method]]);
496
- }
497
- return;
498
- }
499
- }
500
- if ("tags" in operation) {
501
- _optionalChain([operation, 'access', _60 => _60.tags, 'optionalAccess', _61 => _61.forEach, 'call', _62 => _62((tag) => {
502
- this.usedTags.add(tag);
503
- })]);
504
- }
505
- if ("security" in operation) {
506
- Object.values(operation.security || {}).forEach((sec) => {
507
- Object.keys(sec).forEach((scheme) => {
508
- this.$refs.add(`#/components/securitySchemes/${scheme}`);
509
- });
510
- });
511
- }
512
- });
513
- if (!Object.keys(_optionalChain([this, 'access', _63 => _63.definition, 'access', _64 => _64.paths, 'optionalAccess', _65 => _65[path]]) || {}).length) {
514
- _optionalChainDelete([this, 'access', _66 => _66.definition, 'access', _67 => _67.paths, 'optionalAccess', _68 => delete _68[path]]);
515
- }
516
- });
517
- if (!Object.keys(this.definition.paths || {}).length) {
518
- if (!(this.definition.webhooks && Object.keys(this.definition.webhooks).length)) {
519
- throw new Error(
520
- "All paths in the API definition were removed. Did you supply the right path name to reduce by?"
521
- );
522
- }
523
- delete this.definition.paths;
524
- }
88
+ byWebhook(webhookName, method) {
89
+ this.selectWebhook(webhookName, method);
90
+ return this;
525
91
  }
526
92
  /**
527
- * Prune back our `webhooks` object in the OpenAPI definition to only include webhooks that we
528
- * want to preserve.
93
+ * Reduce the current OpenAPI definition down to the configured filters.
529
94
  *
530
95
  */
531
- reduceWebhooks() {
532
- if (!_chunk7PWF3F2Wcjs.isOpenAPI31.call(void 0, this.definition)) {
533
- return;
534
- } else if (!("webhooks" in this.definition) || !this.definition.webhooks) {
535
- return;
536
- }
537
- const definition = this.definition;
538
- Object.keys(definition.webhooks || {}).forEach((webhookName) => {
539
- const nameLC = webhookName.toLowerCase();
540
- if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {
541
- const retainedByRef = Array.from(this.retainWebhookMethods).some(
542
- (key) => key.startsWith(`${nameLC}|`) || key === `${nameLC}|`
543
- );
544
- if (!retainedByRef) {
545
- _optionalChainDelete([definition, 'access', _69 => _69.webhooks, 'optionalAccess', _70 => delete _70[webhookName]]);
546
- return;
547
- }
548
- }
549
- const webhook = _optionalChain([definition, 'access', _71 => _71.webhooks, 'optionalAccess', _72 => _72[webhookName]]);
550
- if (!webhook || typeof webhook !== "object") {
551
- return;
552
- }
553
- if (_chunk7PWF3F2Wcjs.isRef.call(void 0, webhook)) {
554
- return;
555
- }
556
- Object.keys(webhook).forEach((method) => {
557
- const methodLC = method.toLowerCase();
558
- if (method === "parameters" || !_chunk7WBPPWYIcjs.supportedMethods.includes(methodLC)) {
559
- return;
560
- }
561
- const retainedByRef = this.retainWebhookMethods.has(`${nameLC}|${methodLC}`);
562
- if (this.hasWebhooksToReduceBy && !retainedByRef) {
563
- const methodFilter = this.webhooksToReduceBy[nameLC];
564
- if (methodFilter !== "*" && Array.isArray(methodFilter) && !methodFilter.includes(methodLC)) {
565
- if (!_optionalChain([definition, 'access', _73 => _73.webhooks, 'optionalAccess', _74 => _74[webhookName]]) || _chunk7PWF3F2Wcjs.isRef.call(void 0, _optionalChain([definition, 'access', _75 => _75.webhooks, 'optionalAccess', _76 => _76[webhookName]]))) {
566
- return;
567
- }
568
- _optionalChainDelete([definition, 'access', _77 => _77.webhooks, 'optionalAccess', _78 => _78[webhookName], 'optionalAccess', _79 => delete _79[method]]);
569
- }
570
- }
571
- });
572
- if (!Object.keys(_optionalChain([definition, 'access', _80 => _80.webhooks, 'optionalAccess', _81 => _81[webhookName]]) || {}).length) {
573
- _optionalChainDelete([definition, 'access', _82 => _82.webhooks, 'optionalAccess', _83 => delete _83[webhookName]]);
574
- }
575
- });
576
- if (definition.webhooks && !Object.keys(definition.webhooks).length) {
577
- delete definition.webhooks;
578
- }
96
+ reduce() {
97
+ return this.transform();
579
98
  }
580
- }, _class);
99
+ };
581
100
 
582
101
 
583
102
  exports.OpenAPIReducer = OpenAPIReducer;