oas 31.0.0 → 31.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -324,9 +324,6 @@ console.log(OpenAPIReducer.init(petstore).byOperation('/pet', 'post').reduce());
324
324
  console.log(OpenAPIReducer.init(petstore).byPath('/pet').reduce());
325
325
  ```
326
326
 
327
- > [!NOTE]
328
- > Note that this does not yet support OpenAPI 3.1+ definitions that contain webhooks.
329
-
330
327
  ## FAQ
331
328
 
332
329
  #### Can I create an OpenAPI definition with this?
@@ -8,7 +8,10 @@ var _chunkO3GIPZLCcjs = require('../chunk-O3GIPZLC.cjs');
8
8
 
9
9
  var _chunkB5WP4BJMcjs = require('../chunk-B5WP4BJM.cjs');
10
10
  require('../chunk-AYA3UT4L.cjs');
11
- require('../chunk-VQBEI5WI.cjs');
11
+
12
+
13
+
14
+ var _chunkVQBEI5WIcjs = require('../chunk-VQBEI5WI.cjs');
12
15
 
13
16
  // src/reducer/index.ts
14
17
  var _jsonpointer = require('jsonpointer'); var _jsonpointer2 = _interopRequireDefault(_jsonpointer);
@@ -31,21 +34,35 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
31
34
  * invalid OpenAPI definition.
32
35
  */
33
36
  __init3() {this.retainPathMethods = /* @__PURE__ */ new Set()}
37
+ /**
38
+ * A collection of OpenAPI webhook names and methods that are cross-referenced from any other
39
+ * schemas. This collection, like `retainPathMethods`, is used in order to ensure that those
40
+ * schemas are retained with our resulting API definition. Not retaining them would result in an
41
+ * invalid OpenAPI definition.
42
+ */
43
+ __init4() {this.retainWebhookMethods = /* @__PURE__ */ new Set()}
34
44
  /**
35
45
  * An array of OpenAPI tags to reduce down to.
36
46
  */
37
- __init4() {this.tagsToReduceBy = []}
47
+ __init5() {this.tagsToReduceBy = []}
38
48
  /**
39
49
  * A collection of OpenAPI paths and operations to reduce down to.
40
50
  */
41
- __init5() {this.pathsToReduceBy = {}}
42
- 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);
51
+ __init6() {this.pathsToReduceBy = {}}
52
+ /**
53
+ * A collection of OpenAPI webhooks to reduce down to.
54
+ */
55
+ __init7() {this.webhooksToReduceBy = {}}
56
+ __init8() {this.hasTagsToReduceBy = false}
57
+ __init9() {this.hasPathsToReduceBy = false}
58
+ __init10() {this.hasWebhooksToReduceBy = false}
59
+ 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);
43
60
  this.definition = structuredClone(definition);
44
61
  }
45
62
  /**
46
63
  * Initialize a new instance of the `OpenAPIReducer`. The reducer allows you to reduce an OpenAPI
47
64
  * definition down to only the information necessary to fulfill a specific set of tags, paths,
48
- * and operations.
65
+ * operations, and webhooks.
49
66
  *
50
67
  * OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API
51
68
  * definitions, but also to compress a large API definition down to a manageable size containing
@@ -53,8 +70,6 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
53
70
  *
54
71
  * All OpenAPI definitions reduced will still be fully functional and valid OpenAPI definitions.
55
72
  *
56
- * Note that this does not yet support OpenAPI 3.1+ definitions that contain webhooks.
57
- *
58
73
  * @param definition An OpenAPI definition to reduce.
59
74
  */
60
75
  static init(definition) {
@@ -102,6 +117,20 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
102
117
  }
103
118
  return this;
104
119
  }
120
+ byWebhook(webhookName, method) {
121
+ const nameLC = webhookName.toLowerCase();
122
+ if (!method) {
123
+ this.webhooksToReduceBy[nameLC] = "*";
124
+ return this;
125
+ }
126
+ const methodLC = method.toLowerCase();
127
+ if (this.webhooksToReduceBy[nameLC] && Array.isArray(this.webhooksToReduceBy[nameLC])) {
128
+ this.webhooksToReduceBy[nameLC].push(methodLC);
129
+ } else {
130
+ this.webhooksToReduceBy[nameLC] = [methodLC];
131
+ }
132
+ return this;
133
+ }
105
134
  /**
106
135
  * Reduce the current OpenAPI definition down to the configured filters.
107
136
  *
@@ -110,13 +139,9 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
110
139
  if (!this.definition.openapi) {
111
140
  throw new Error("Sorry, only OpenAPI definitions are supported.");
112
141
  }
113
- if (!this.definition.openapi.startsWith("3.0")) {
114
- if ("webhooks" in this.definition) {
115
- return this.definition;
116
- }
117
- }
118
- const hasPathsToReduceBy = Boolean(Object.keys(this.pathsToReduceBy).length);
119
- const hasTagsToReduceBy = Boolean(this.tagsToReduceBy.length);
142
+ this.hasPathsToReduceBy = Boolean(Object.keys(this.pathsToReduceBy).length);
143
+ this.hasWebhooksToReduceBy = Boolean(Object.keys(this.webhooksToReduceBy).length);
144
+ this.hasTagsToReduceBy = Boolean(this.tagsToReduceBy.length);
120
145
  if ("security" in this.definition) {
121
146
  Object.values(this.definition.security || {}).forEach((sec) => {
122
147
  Object.keys(sec).forEach((scheme) => {
@@ -124,134 +149,44 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
124
149
  });
125
150
  });
126
151
  }
127
- if ("paths" in this.definition) {
128
- Object.keys(this.definition.paths || {}).forEach((path) => {
129
- const pathLC = path.toLowerCase();
130
- if (hasPathsToReduceBy) {
131
- if (!(pathLC in this.pathsToReduceBy)) {
132
- _optionalChainDelete([this, 'access', _ => _.definition, 'access', _2 => _2.paths, 'optionalAccess', _3 => delete _3[path]]);
133
- return;
134
- }
135
- }
136
- Object.keys(_optionalChain([this, 'access', _4 => _4.definition, 'access', _5 => _5.paths, 'optionalAccess', _6 => _6[path]]) || {}).forEach((method) => {
137
- if (method === "parameters" || !_chunkO3GIPZLCcjs.supportedMethods.includes(method.toLowerCase())) {
138
- return;
139
- }
140
- if (hasPathsToReduceBy) {
141
- if (this.pathsToReduceBy[pathLC] !== "*" && Array.isArray(this.pathsToReduceBy[pathLC]) && !this.pathsToReduceBy[pathLC].includes(method.toLowerCase())) {
142
- return;
143
- }
144
- }
145
- const operation = _optionalChain([this, 'access', _7 => _7.definition, 'access', _8 => _8.paths, 'optionalAccess', _9 => _9[path], 'optionalAccess', _10 => _10[method]]);
146
- if (!operation) {
147
- throw new Error(`Operation \`${method} ${path}\` not found`);
148
- }
149
- if (hasTagsToReduceBy) {
150
- if (!(operation.tags || []).filter((tag) => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {
151
- return;
152
- }
153
- }
154
- (operation.tags || []).forEach((tag) => {
155
- this.usedTags.add(tag);
156
- });
157
- this.queryForRefPointers(operation).forEach(({ value: ref }) => {
158
- const refStr = this.toRefString(ref);
159
- if (!refStr) {
160
- return;
161
- }
162
- this.$refs.add(refStr);
163
- const pathRef = this.parsePathRef(refStr);
164
- if (pathRef) {
165
- this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);
166
- }
167
- this.accumulateUsedRefs(this.definition, this.$refs, refStr);
168
- });
169
- Object.values(operation.security || {}).forEach((sec) => {
170
- Object.keys(sec).forEach((scheme) => {
171
- this.$refs.add(`#/components/securitySchemes/${scheme}`);
172
- });
173
- });
174
- });
175
- });
176
- this.$refs.forEach(($ref) => {
177
- this.accumulateUsedRefs(this.definition, this.$refs, $ref);
178
- });
179
- this.$refs.forEach((ref) => {
180
- const usedPathRef = this.parsePathRef(ref);
181
- if (usedPathRef) {
182
- this.retainPathMethods.add(`${usedPathRef.path.toLowerCase()}|${usedPathRef.method.toLowerCase()}`);
183
- }
184
- });
185
- Object.keys(this.definition.paths || {}).forEach((path) => {
186
- const pathLC = path.toLowerCase();
187
- if (hasPathsToReduceBy && !(pathLC in this.pathsToReduceBy)) {
188
- _optionalChainDelete([this, 'access', _11 => _11.definition, 'access', _12 => _12.paths, 'optionalAccess', _13 => delete _13[path]]);
189
- return;
190
- }
191
- Object.keys(_optionalChain([this, 'access', _14 => _14.definition, 'access', _15 => _15.paths, 'optionalAccess', _16 => _16[path]]) || {}).forEach((method) => {
192
- const methodLC = method.toLowerCase();
193
- if (method === "parameters" || !_chunkO3GIPZLCcjs.supportedMethods.includes(methodLC)) {
194
- return;
195
- }
196
- const retainedByRef = this.retainPathMethods.has(`${pathLC}|${methodLC}`) || Array.from(this.$refs).some((ref) => {
197
- const pathRef = this.parsePathRef(ref);
198
- return _optionalChain([pathRef, 'optionalAccess', _17 => _17.path, 'access', _18 => _18.toLowerCase, 'call', _19 => _19()]) === pathLC && _optionalChain([pathRef, 'optionalAccess', _20 => _20.method, 'access', _21 => _21.toLowerCase, 'call', _22 => _22()]) === methodLC;
199
- });
200
- if (methodLC !== "parameters") {
201
- if (hasPathsToReduceBy) {
202
- if (!retainedByRef && this.pathsToReduceBy[pathLC] !== "*" && Array.isArray(this.pathsToReduceBy[pathLC]) && !this.pathsToReduceBy[pathLC].includes(methodLC)) {
203
- _optionalChainDelete([this, 'access', _23 => _23.definition, 'access', _24 => _24.paths, 'optionalAccess', _25 => _25[path], 'optionalAccess', _26 => delete _26[method]]);
204
- return;
205
- }
206
- }
207
- }
208
- const operation = _optionalChain([this, 'access', _27 => _27.definition, 'access', _28 => _28.paths, 'optionalAccess', _29 => _29[path], 'optionalAccess', _30 => _30[method]]);
209
- if (!operation) {
210
- throw new Error(`Operation \`${method} ${path}\` not found`);
211
- }
212
- if (hasTagsToReduceBy) {
213
- if (!(operation.tags || []).filter((tag) => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {
214
- if (!retainedByRef) {
215
- _optionalChainDelete([this, 'access', _31 => _31.definition, 'access', _32 => _32.paths, 'optionalAccess', _33 => _33[path], 'optionalAccess', _34 => delete _34[method]]);
216
- }
217
- return;
218
- }
219
- }
220
- if ("tags" in operation) {
221
- _optionalChain([operation, 'access', _35 => _35.tags, 'optionalAccess', _36 => _36.forEach, 'call', _37 => _37((tag) => {
222
- this.usedTags.add(tag);
223
- })]);
224
- }
225
- if ("security" in operation) {
226
- Object.values(operation.security || {}).forEach((sec) => {
227
- Object.keys(sec).forEach((scheme) => {
228
- this.$refs.add(`#/components/securitySchemes/${scheme}`);
229
- });
230
- });
231
- }
232
- });
233
- if (!Object.keys(_optionalChain([this, 'access', _38 => _38.definition, 'access', _39 => _39.paths, 'optionalAccess', _40 => _40[path]]) || {}).length) {
234
- _optionalChainDelete([this, 'access', _41 => _41.definition, 'access', _42 => _42.paths, 'optionalAccess', _43 => delete _43[path]]);
235
- }
236
- });
237
- if (!Object.keys(this.definition.paths || {}).length) {
238
- throw new Error(
239
- "All paths in the API definition were removed. Did you supply the right path name to reduce by?"
240
- );
152
+ this.walkPaths();
153
+ this.walkWebhooks();
154
+ this.$refs.forEach(($ref) => {
155
+ this.accumulateUsedRefs(this.definition, this.$refs, $ref);
156
+ });
157
+ this.$refs.forEach((ref) => {
158
+ const usedPathRef = this.parsePathRef(ref);
159
+ if (usedPathRef) {
160
+ this.retainPathMethods.add(`${usedPathRef.path.toLowerCase()}|${usedPathRef.method.toLowerCase()}`);
161
+ }
162
+ const usedWebhookRef = this.parseWebhookRef(ref);
163
+ if (usedWebhookRef) {
164
+ this.retainWebhookMethods.add(`${usedWebhookRef.name.toLowerCase()}|${usedWebhookRef.method.toLowerCase()}`);
241
165
  }
166
+ });
167
+ this.reducePaths();
168
+ this.reduceWebhooks();
169
+ const hasPaths = Boolean(this.definition.paths && Object.keys(this.definition.paths).length);
170
+ const hasWebhooks = Boolean(
171
+ "webhooks" in this.definition && this.definition.webhooks && Object.keys(this.definition.webhooks).length
172
+ );
173
+ if (!hasPaths && !hasWebhooks) {
174
+ throw new Error(
175
+ "All paths and webhooks in the API definition were removed. Did you supply the right path, operation, or webhook to reduce by?"
176
+ );
242
177
  }
243
178
  if ("components" in this.definition) {
244
179
  Object.keys(this.definition.components || {}).forEach((componentType) => {
245
- Object.keys(_optionalChain([this, 'access', _44 => _44.definition, 'access', _45 => _45.components, 'optionalAccess', _46 => _46[componentType]]) || {}).forEach((component) => {
180
+ Object.keys(_optionalChain([this, 'access', _ => _.definition, 'access', _2 => _2.components, 'optionalAccess', _3 => _3[componentType]]) || {}).forEach((component) => {
246
181
  const refIsUsed = this.$refs.has(`#/components/${componentType}/${component}`) || Array.from(this.$refs).some((ref) => {
247
182
  return ref.startsWith(`#/components/${componentType}/${component}/`);
248
183
  });
249
184
  if (!refIsUsed) {
250
- _optionalChainDelete([this, 'access', _47 => _47.definition, 'access', _48 => _48.components, 'optionalAccess', _49 => _49[componentType], 'optionalAccess', _50 => delete _50[component]]);
185
+ _optionalChainDelete([this, 'access', _4 => _4.definition, 'access', _5 => _5.components, 'optionalAccess', _6 => _6[componentType], 'optionalAccess', _7 => delete _7[component]]);
251
186
  }
252
187
  });
253
- if (!Object.keys(_optionalChain([this, 'access', _51 => _51.definition, 'access', _52 => _52.components, 'optionalAccess', _53 => _53[componentType]]) || {}).length) {
254
- _optionalChainDelete([this, 'access', _54 => _54.definition, 'access', _55 => _55.components, 'optionalAccess', _56 => delete _56[componentType]]);
188
+ if (!Object.keys(_optionalChain([this, 'access', _8 => _8.definition, 'access', _9 => _9.components, 'optionalAccess', _10 => _10[componentType]]) || {}).length) {
189
+ _optionalChainDelete([this, 'access', _11 => _11.definition, 'access', _12 => _12.components, 'optionalAccess', _13 => delete _13[componentType]]);
255
190
  }
256
191
  });
257
192
  if (!Object.keys(this.definition.components || {}).length) {
@@ -262,7 +197,7 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
262
197
  this.definition.tags = (_nullishCoalesce(this.definition.tags, () => ( []))).filter((tag) => {
263
198
  return Boolean(tag) && this.usedTags.has(tag.name);
264
199
  });
265
- if (!_optionalChain([this, 'access', _57 => _57.definition, 'access', _58 => _58.tags, 'optionalAccess', _59 => _59.length])) {
200
+ if (!_optionalChain([this, 'access', _14 => _14.definition, 'access', _15 => _15.tags, 'optionalAccess', _16 => _16.length])) {
266
201
  delete this.definition.tags;
267
202
  }
268
203
  }
@@ -283,6 +218,10 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
283
218
  if (pathRef) {
284
219
  this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);
285
220
  }
221
+ const webhookRef = this.parseWebhookRef($ref);
222
+ if (webhookRef) {
223
+ this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);
224
+ }
286
225
  let $refSchema;
287
226
  if (typeof $ref === "string") $refSchema = _jsonpointer2.default.get(schema, $ref.substring(1));
288
227
  if ($refSchema === void 0) {
@@ -324,8 +263,8 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
324
263
  return null;
325
264
  }
326
265
  /**
327
- * If the given `$ref` points into a path (e.g. `#/paths/~1anything/post/...`), return the path and
328
- * method so the reducer can ultimately retain cross-operation references.
266
+ * If the given `$ref` points into a path (e.g. `#/paths/~1anything/post/...`), return the path
267
+ * and method so the reducer can ultimately retain cross-operation references.
329
268
  *
330
269
  */
331
270
  parsePathRef($ref) {
@@ -342,6 +281,283 @@ var OpenAPIReducer = (_class = class _OpenAPIReducer {
342
281
  }
343
282
  return null;
344
283
  }
284
+ /**
285
+ * If the given `$ref` points into webhooks (e.g. `#/webhooks/newBooking/post/...`), return the
286
+ * webhook name and method so the reducer can retain cross-referenced webhook operations.
287
+ *
288
+ */
289
+ parseWebhookRef($ref) {
290
+ if (typeof $ref !== "string" || !$ref.startsWith("#/webhooks/")) {
291
+ return null;
292
+ }
293
+ const match = $ref.match(/^#\/webhooks\/([^/]+)\/([^/]+)(?:\/|$)/);
294
+ if (match) {
295
+ const webhookName = match[1];
296
+ const method = match[2];
297
+ if (webhookName && method) {
298
+ return { name: _chunkB5WP4BJMcjs.decodePointer.call(void 0, webhookName), method };
299
+ }
300
+ }
301
+ return null;
302
+ }
303
+ /**
304
+ * Walk through the `paths` in our OpenAPI definition and reduce down any that we know we do not
305
+ * want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced in
306
+ * paths, webhooks, operations, and schemas that we _do_ want to keep.
307
+ *
308
+ */
309
+ walkPaths() {
310
+ if (!("paths" in this.definition) || !this.definition.paths) {
311
+ return;
312
+ }
313
+ Object.keys(this.definition.paths).forEach((path) => {
314
+ const pathLC = path.toLowerCase();
315
+ if (this.hasWebhooksToReduceBy && !this.hasPathsToReduceBy) {
316
+ _optionalChainDelete([this, 'access', _17 => _17.definition, 'access', _18 => _18.paths, 'optionalAccess', _19 => delete _19[path]]);
317
+ return;
318
+ }
319
+ if (this.hasPathsToReduceBy) {
320
+ if (!(pathLC in this.pathsToReduceBy)) {
321
+ _optionalChainDelete([this, 'access', _20 => _20.definition, 'access', _21 => _21.paths, 'optionalAccess', _22 => delete _22[path]]);
322
+ return;
323
+ }
324
+ }
325
+ 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())) {
327
+ return;
328
+ }
329
+ if (this.hasPathsToReduceBy) {
330
+ if (this.pathsToReduceBy[pathLC] !== "*" && Array.isArray(this.pathsToReduceBy[pathLC]) && !this.pathsToReduceBy[pathLC].includes(method.toLowerCase())) {
331
+ return;
332
+ }
333
+ }
334
+ const operation = _optionalChain([this, 'access', _26 => _26.definition, 'access', _27 => _27.paths, 'optionalAccess', _28 => _28[path], 'optionalAccess', _29 => _29[method]]);
335
+ if (!operation) {
336
+ throw new Error(`Operation \`${method} ${path}\` not found`);
337
+ }
338
+ if (this.hasTagsToReduceBy) {
339
+ if (!(operation.tags || []).filter((tag) => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {
340
+ return;
341
+ }
342
+ }
343
+ (operation.tags || []).forEach((tag) => {
344
+ this.usedTags.add(tag);
345
+ });
346
+ this.queryForRefPointers(operation).forEach(({ value: ref }) => {
347
+ const refStr = this.toRefString(ref);
348
+ if (!refStr) {
349
+ return;
350
+ }
351
+ this.$refs.add(refStr);
352
+ const pathRef = this.parsePathRef(refStr);
353
+ if (pathRef) {
354
+ this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);
355
+ }
356
+ this.accumulateUsedRefs(this.definition, this.$refs, refStr);
357
+ });
358
+ Object.values(operation.security || {}).forEach((sec) => {
359
+ Object.keys(sec).forEach((scheme) => {
360
+ this.$refs.add(`#/components/securitySchemes/${scheme}`);
361
+ });
362
+ });
363
+ });
364
+ });
365
+ }
366
+ /**
367
+ * Walk through the `webhooks` in our OpenAPI definition and reduce down any that we know we do
368
+ * not want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced
369
+ * in paths, operations, and schemas that we _do_ want to keep.
370
+ *
371
+ */
372
+ walkWebhooks() {
373
+ if (!_chunkVQBEI5WIcjs.isOpenAPI31.call(void 0, this.definition)) {
374
+ return;
375
+ } else if (!("webhooks" in this.definition) || !this.definition.webhooks) {
376
+ return;
377
+ }
378
+ const definition = this.definition;
379
+ Object.keys(definition.webhooks || {}).forEach((webhookName) => {
380
+ const nameLC = webhookName.toLowerCase();
381
+ if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {
382
+ return;
383
+ }
384
+ const webhook = _optionalChain([definition, 'access', _30 => _30.webhooks, 'optionalAccess', _31 => _31[webhookName]]);
385
+ if (!webhook || typeof webhook !== "object") {
386
+ return;
387
+ }
388
+ Object.keys(webhook).forEach((method) => {
389
+ if (method === "parameters" || !_chunkO3GIPZLCcjs.supportedMethods.includes(method.toLowerCase())) {
390
+ return;
391
+ }
392
+ if (this.hasWebhooksToReduceBy) {
393
+ const methodFilter = this.webhooksToReduceBy[nameLC];
394
+ if (methodFilter !== "*" && Array.isArray(methodFilter) && !methodFilter.includes(method.toLowerCase())) {
395
+ return;
396
+ }
397
+ }
398
+ if (_chunkVQBEI5WIcjs.isRef.call(void 0, webhook)) {
399
+ return;
400
+ }
401
+ const operation = webhook[method];
402
+ if (!operation) {
403
+ return;
404
+ }
405
+ if (this.hasTagsToReduceBy) {
406
+ if (!(operation.tags || []).filter((tag) => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {
407
+ return;
408
+ }
409
+ }
410
+ (operation.tags || []).forEach((tag) => {
411
+ this.usedTags.add(tag);
412
+ });
413
+ this.queryForRefPointers(operation).forEach(({ value: ref }) => {
414
+ const refStr = this.toRefString(ref);
415
+ if (!refStr) {
416
+ return;
417
+ }
418
+ this.$refs.add(refStr);
419
+ const pathRef = this.parsePathRef(refStr);
420
+ if (pathRef) {
421
+ this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);
422
+ }
423
+ const webhookRef = this.parseWebhookRef(refStr);
424
+ if (webhookRef) {
425
+ this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);
426
+ }
427
+ this.accumulateUsedRefs(definition, this.$refs, refStr);
428
+ });
429
+ Object.values(operation.security || {}).forEach((sec) => {
430
+ Object.keys(sec).forEach((scheme) => {
431
+ this.$refs.add(`#/components/securitySchemes/${scheme}`);
432
+ });
433
+ });
434
+ });
435
+ });
436
+ }
437
+ /**
438
+ * Prune back our `paths` object in the OpenAPI definition to only include paths that we want to
439
+ * preserve.
440
+ *
441
+ */
442
+ reducePaths() {
443
+ if (!("paths" in this.definition) || !this.definition.paths) {
444
+ return;
445
+ }
446
+ Object.keys(this.definition.paths).forEach((path) => {
447
+ const pathLC = path.toLowerCase();
448
+ if (this.hasPathsToReduceBy && !(pathLC in this.pathsToReduceBy)) {
449
+ _optionalChainDelete([this, 'access', _32 => _32.definition, 'access', _33 => _33.paths, 'optionalAccess', _34 => delete _34[path]]);
450
+ return;
451
+ }
452
+ Object.keys(_optionalChain([this, 'access', _35 => _35.definition, 'access', _36 => _36.paths, 'optionalAccess', _37 => _37[path]]) || {}).forEach((method) => {
453
+ const methodLC = method.toLowerCase();
454
+ if (method === "parameters" || !_chunkO3GIPZLCcjs.supportedMethods.includes(methodLC)) {
455
+ return;
456
+ }
457
+ const retainedByRef = this.retainPathMethods.has(`${pathLC}|${methodLC}`) || Array.from(this.$refs).some((ref) => {
458
+ const pathRef = this.parsePathRef(ref);
459
+ return _optionalChain([pathRef, 'optionalAccess', _38 => _38.path, 'access', _39 => _39.toLowerCase, 'call', _40 => _40()]) === pathLC && _optionalChain([pathRef, 'optionalAccess', _41 => _41.method, 'access', _42 => _42.toLowerCase, 'call', _43 => _43()]) === methodLC;
460
+ });
461
+ if (methodLC !== "parameters") {
462
+ if (this.hasPathsToReduceBy) {
463
+ if (!retainedByRef && this.pathsToReduceBy[pathLC] !== "*" && Array.isArray(this.pathsToReduceBy[pathLC]) && !this.pathsToReduceBy[pathLC].includes(methodLC)) {
464
+ _optionalChainDelete([this, 'access', _44 => _44.definition, 'access', _45 => _45.paths, 'optionalAccess', _46 => _46[path], 'optionalAccess', _47 => delete _47[method]]);
465
+ return;
466
+ }
467
+ }
468
+ }
469
+ const operation = _optionalChain([this, 'access', _48 => _48.definition, 'access', _49 => _49.paths, 'optionalAccess', _50 => _50[path], 'optionalAccess', _51 => _51[method]]);
470
+ if (!operation) {
471
+ throw new Error(`Operation \`${method} ${path}\` not found`);
472
+ }
473
+ if (this.hasTagsToReduceBy) {
474
+ if (!(operation.tags || []).filter((tag) => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {
475
+ if (!retainedByRef) {
476
+ _optionalChainDelete([this, 'access', _52 => _52.definition, 'access', _53 => _53.paths, 'optionalAccess', _54 => _54[path], 'optionalAccess', _55 => delete _55[method]]);
477
+ }
478
+ return;
479
+ }
480
+ }
481
+ if ("tags" in operation) {
482
+ _optionalChain([operation, 'access', _56 => _56.tags, 'optionalAccess', _57 => _57.forEach, 'call', _58 => _58((tag) => {
483
+ this.usedTags.add(tag);
484
+ })]);
485
+ }
486
+ if ("security" in operation) {
487
+ Object.values(operation.security || {}).forEach((sec) => {
488
+ Object.keys(sec).forEach((scheme) => {
489
+ this.$refs.add(`#/components/securitySchemes/${scheme}`);
490
+ });
491
+ });
492
+ }
493
+ });
494
+ if (!Object.keys(_optionalChain([this, 'access', _59 => _59.definition, 'access', _60 => _60.paths, 'optionalAccess', _61 => _61[path]]) || {}).length) {
495
+ _optionalChainDelete([this, 'access', _62 => _62.definition, 'access', _63 => _63.paths, 'optionalAccess', _64 => delete _64[path]]);
496
+ }
497
+ });
498
+ if (!Object.keys(this.definition.paths || {}).length) {
499
+ if (!(this.definition.webhooks && Object.keys(this.definition.webhooks).length)) {
500
+ throw new Error(
501
+ "All paths in the API definition were removed. Did you supply the right path name to reduce by?"
502
+ );
503
+ }
504
+ delete this.definition.paths;
505
+ }
506
+ }
507
+ /**
508
+ * Prune back our `webhooks` object in the OpenAPI definition to only include webhooks that we
509
+ * want to preserve.
510
+ *
511
+ */
512
+ reduceWebhooks() {
513
+ if (!_chunkVQBEI5WIcjs.isOpenAPI31.call(void 0, this.definition)) {
514
+ return;
515
+ } else if (!("webhooks" in this.definition) || !this.definition.webhooks) {
516
+ return;
517
+ }
518
+ const definition = this.definition;
519
+ Object.keys(definition.webhooks || {}).forEach((webhookName) => {
520
+ const nameLC = webhookName.toLowerCase();
521
+ if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {
522
+ const retainedByRef = Array.from(this.retainWebhookMethods).some(
523
+ (key) => key.startsWith(`${nameLC}|`) || key === `${nameLC}|`
524
+ );
525
+ if (!retainedByRef) {
526
+ _optionalChainDelete([definition, 'access', _65 => _65.webhooks, 'optionalAccess', _66 => delete _66[webhookName]]);
527
+ return;
528
+ }
529
+ }
530
+ const webhook = _optionalChain([definition, 'access', _67 => _67.webhooks, 'optionalAccess', _68 => _68[webhookName]]);
531
+ if (!webhook || typeof webhook !== "object") {
532
+ return;
533
+ }
534
+ if (_chunkVQBEI5WIcjs.isRef.call(void 0, webhook)) {
535
+ return;
536
+ }
537
+ Object.keys(webhook).forEach((method) => {
538
+ const methodLC = method.toLowerCase();
539
+ if (method === "parameters" || !_chunkO3GIPZLCcjs.supportedMethods.includes(methodLC)) {
540
+ return;
541
+ }
542
+ const retainedByRef = this.retainWebhookMethods.has(`${nameLC}|${methodLC}`);
543
+ if (this.hasWebhooksToReduceBy && !retainedByRef) {
544
+ const methodFilter = this.webhooksToReduceBy[nameLC];
545
+ 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]]))) {
547
+ return;
548
+ }
549
+ _optionalChainDelete([definition, 'access', _71 => _71.webhooks, 'optionalAccess', _72 => _72[webhookName], 'optionalAccess', _73 => delete _73[method]]);
550
+ }
551
+ }
552
+ });
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]]);
555
+ }
556
+ });
557
+ if (definition.webhooks && !Object.keys(definition.webhooks).length) {
558
+ delete definition.webhooks;
559
+ }
560
+ }
345
561
  }, _class);
346
562
 
347
563