oas 38.3.1 → 38.5.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 (53) hide show
  1. package/README.md +38 -4
  2. package/dist/analyzer/index.cjs +16 -16
  3. package/dist/analyzer/index.js +2 -2
  4. package/dist/{chunk-3ZXZMZXT.cjs → chunk-2F2OPV5M.cjs} +89 -75
  5. package/dist/chunk-2F2OPV5M.cjs.map +1 -0
  6. package/dist/{chunk-ANZIKNVX.js → chunk-6D7GWVEH.js} +2 -2
  7. package/dist/chunk-6DVSNS26.cjs +709 -0
  8. package/dist/chunk-6DVSNS26.cjs.map +1 -0
  9. package/dist/{chunk-7WBPPWYI.cjs → chunk-6GTPCWO5.cjs} +3 -3
  10. package/dist/{chunk-7WBPPWYI.cjs.map → chunk-6GTPCWO5.cjs.map} +1 -1
  11. package/dist/{chunk-LZNTJ4ZR.js → chunk-DYHV2B4Z.js} +4 -1
  12. package/dist/chunk-DYHV2B4Z.js.map +1 -0
  13. package/dist/{chunk-6HXOZ5GY.cjs → chunk-EARDDQSB.cjs} +5 -2
  14. package/dist/chunk-EARDDQSB.cjs.map +1 -0
  15. package/dist/chunk-MR33ELUC.js +709 -0
  16. package/dist/chunk-MR33ELUC.js.map +1 -0
  17. package/dist/{chunk-XXX6U72S.js → chunk-TU6UPWO6.js} +19 -5
  18. package/dist/chunk-TU6UPWO6.js.map +1 -0
  19. package/dist/extensions.cjs +4 -2
  20. package/dist/extensions.cjs.map +1 -1
  21. package/dist/extensions.d.cts +1 -1
  22. package/dist/extensions.d.ts +1 -1
  23. package/dist/extensions.js +3 -1
  24. package/dist/index-Borb1VXh.d.cts +174 -0
  25. package/dist/index-Br-eJMCh.d.ts +174 -0
  26. package/dist/index.cjs +60 -53
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +19 -1
  29. package/dist/index.d.ts +19 -1
  30. package/dist/index.js +14 -7
  31. package/dist/index.js.map +1 -1
  32. package/dist/operation/index.cjs +4 -4
  33. package/dist/operation/index.js +3 -3
  34. package/dist/pruner/index.cjs +87 -0
  35. package/dist/pruner/index.cjs.map +1 -0
  36. package/dist/pruner/index.d.cts +72 -0
  37. package/dist/pruner/index.d.ts +72 -0
  38. package/dist/pruner/index.js +87 -0
  39. package/dist/pruner/index.js.map +1 -0
  40. package/dist/reducer/index.cjs +40 -521
  41. package/dist/reducer/index.cjs.map +1 -1
  42. package/dist/reducer/index.d.cts +22 -108
  43. package/dist/reducer/index.d.ts +22 -108
  44. package/dist/reducer/index.js +38 -519
  45. package/dist/reducer/index.js.map +1 -1
  46. package/dist/utils.cjs +3 -3
  47. package/dist/utils.js +2 -2
  48. package/package.json +6 -2
  49. package/dist/chunk-3ZXZMZXT.cjs.map +0 -1
  50. package/dist/chunk-6HXOZ5GY.cjs.map +0 -1
  51. package/dist/chunk-LZNTJ4ZR.js.map +0 -1
  52. package/dist/chunk-XXX6U72S.js.map +0 -1
  53. /package/dist/{chunk-ANZIKNVX.js.map → chunk-6D7GWVEH.js.map} +0 -0
package/README.md CHANGED
@@ -310,12 +310,13 @@ console.log(await analyzer(petstore, ['polymorphism', 'xml]));
310
310
 
311
311
  #### Reducer
312
312
 
313
- > [!WARNING]
314
- > This API is still very experimental and should not be used in production environments!
313
+ The `OpenAPIReducer` utility, located in `oas/reducer`, can be used to reduce an OpenAPI definition down to only the information necessary to fulfill a specific set of tags, paths, operations, operation IDs, or webhooks.
315
314
 
316
- The `OpenAPIReducer` utility, located in `oas/reducer`, can be used to reduce an OpenAPI definition down to only the information necessary to fulfill a specific set of tags, paths, or operations.
315
+ OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API definitions, but also to compress a large API definition down to a manageable size containing a specific set of items.
317
316
 
318
- OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API definitions, but also to compress a large API definition down to a manageable size containing a specific set of items. All OpenAPI definitions reduced will still be fully functional and valid OpenAPI definitions.
317
+ Tag and operation ID filters intersect with path, operation, and webhook filters. When they are combined, an operation is retained only when it matches every configured filter. Multiple operation IDs are alternatives within the operation ID filter.
318
+
319
+ Operation IDs are matched exactly. For operations without an authored `operationId`, use the generated value returned by `Operation.getOperationId()`.
319
320
 
320
321
  ```ts
321
322
  import petstore from '@readme/oas-examples/3.0/json/petstore.json' with { type: 'json' };
@@ -328,12 +329,45 @@ console.log(OpenAPIReducer.init(petstore).byTag('Store').reduce());
328
329
  // Reduces the `petstore` down to only the `POST /pet` operation.
329
330
  console.log(OpenAPIReducer.init(petstore).byOperation('/pet', 'post').reduce());
330
331
 
332
+ // Reduces the `petstore` down to the operation with this exact operation ID.
333
+ console.log(OpenAPIReducer.init(petstore).byOperationId('addPet').reduce());
334
+
331
335
  // You can also select all of the methods of a given path by using the `*`
332
336
  // wildcard. The resulting reduced API definition here will contain `POST /pet`
333
337
  // and `PUT /put`.
334
338
  console.log(OpenAPIReducer.init(petstore).byPath('/pet').reduce());
335
339
  ```
336
340
 
341
+ #### Pruner
342
+
343
+ The `OpenAPIPruner` utility, located in `oas/pruner`, can be used to remove a specific set of tags, paths, operations, operation IDs, or webhooks from an OpenAPI definition. Components and tags that are no longer reachable from the remaining definition are also removed.
344
+
345
+ Unlike `oas/reducer`, which selects the content to retain, the pruner is useful when you know which content to remove.
346
+
347
+ Pruner filters are additive. Combining tag, operation ID, and location filters removes operations that match any filter.
348
+
349
+ Operation IDs are matched exactly. For operations without an authored `operationId`, use the generated value returned by `Operation.getOperationId()`.
350
+
351
+ ```ts
352
+ import petstore from '@readme/oas-examples/3.0/json/petstore.json' with { type: 'json' };
353
+ import { OpenAPIPruner } from 'oas/pruner';
354
+
355
+ // Removes every operation in the `store` tag.
356
+ console.log(OpenAPIPruner.init(petstore).removeTag('store').prune());
357
+
358
+ // Removes only the `POST /pet` operation while retaining other operations on
359
+ // the same path.
360
+ console.log(OpenAPIPruner.init(petstore).removeOperation('/pet', 'post').prune());
361
+
362
+ // Removes the operation with this exact operation ID.
363
+ console.log(OpenAPIPruner.init(petstore).removeOperationId('addPet').prune());
364
+
365
+ // Removes an entire path and all of its operations.
366
+ console.log(OpenAPIPruner.init(petstore).removePath('/pet').prune());
367
+ ```
368
+
369
+ Referenced Path Items in paths and webhooks are retained intact for operation-level removals because they cannot be partially transformed without rewriting their shared target. Removing an entire referenced path or webhook removes the Path Item and any components that are no longer reachable when it is not used elsewhere. The pruner rejects removals that would break a `$ref` from a surviving operation.
370
+
337
371
  ## FAQ
338
372
 
339
373
  #### Can I create an OpenAPI definition with this?
@@ -7,8 +7,8 @@ var _chunkCOHEPMUPcjs = require('../chunk-COHEPMUP.cjs');
7
7
 
8
8
 
9
9
 
10
- var _chunk7WBPPWYIcjs = require('../chunk-7WBPPWYI.cjs');
11
- require('../chunk-6HXOZ5GY.cjs');
10
+ var _chunk6GTPCWO5cjs = require('../chunk-6GTPCWO5.cjs');
11
+ require('../chunk-EARDDQSB.cjs');
12
12
 
13
13
 
14
14
  var _chunk7PWF3F2Wcjs = require('../chunk-7PWF3F2W.cjs');
@@ -127,14 +127,14 @@ function accumulateReachableRefs(definition, seeds) {
127
127
  reachable.add(ref);
128
128
  let resolved;
129
129
  try {
130
- resolved = _jsonpointer2.default.get(definition, _chunk7WBPPWYIcjs.toPointer.call(void 0, ref));
130
+ resolved = _jsonpointer2.default.get(definition, _chunk6GTPCWO5cjs.toPointer.call(void 0, ref));
131
131
  } catch (e) {
132
132
  continue;
133
133
  }
134
134
  if (resolved === void 0) {
135
135
  continue;
136
136
  }
137
- _chunk7WBPPWYIcjs.collectRefsInSchema.call(void 0, resolved).forEach((nestedRef) => {
137
+ _chunk6GTPCWO5cjs.collectRefsInSchema.call(void 0, resolved).forEach((nestedRef) => {
138
138
  if (!reachable.has(nestedRef)) {
139
139
  queue.push(nestedRef);
140
140
  }
@@ -144,7 +144,7 @@ function accumulateReachableRefs(definition, seeds) {
144
144
  }
145
145
  function buildAnchors(rootPointer, extraPointers, reachableRefs) {
146
146
  const anchors = [rootPointer, ...extraPointers];
147
- reachableRefs.forEach((ref) => anchors.push(_chunk7WBPPWYIcjs.toPointer.call(void 0, ref)));
147
+ reachableRefs.forEach((ref) => anchors.push(_chunk6GTPCWO5cjs.toPointer.call(void 0, ref)));
148
148
  return { anchors, anchorPrefixes: anchors.map((anchor) => `${anchor}/`) };
149
149
  }
150
150
  function collectSecuritySchemeRefs(security) {
@@ -168,16 +168,16 @@ function computeOperationScope(definition, path, method) {
168
168
  }
169
169
  const pathItem = definition.paths[pathKey] || {};
170
170
  const methodKey = resolveKey(Object.keys(pathItem), method);
171
- if (!methodKey || !_chunk7WBPPWYIcjs.supportedMethods.includes(methodKey.toLowerCase())) {
171
+ if (!methodKey || !_chunk6GTPCWO5cjs.supportedMethods.includes(methodKey.toLowerCase())) {
172
172
  throw new Error(`Operation \`${method} ${path}\` not found.`);
173
173
  }
174
174
  const operation = pathItem[methodKey];
175
- const rootPointer = `/paths/${_chunk7WBPPWYIcjs.encodePointer.call(void 0, pathKey)}/${methodKey}`;
175
+ const rootPointer = `/paths/${_chunk6GTPCWO5cjs.encodePointer.call(void 0, pathKey)}/${methodKey}`;
176
176
  const extraPointers = [];
177
- const seeds = new Set(_chunk7WBPPWYIcjs.collectRefsInSchema.call(void 0, operation));
177
+ const seeds = new Set(_chunk6GTPCWO5cjs.collectRefsInSchema.call(void 0, operation));
178
178
  if (pathItem.parameters) {
179
- extraPointers.push(`/paths/${_chunk7WBPPWYIcjs.encodePointer.call(void 0, pathKey)}/parameters`);
180
- _chunk7WBPPWYIcjs.collectRefsInSchema.call(void 0, pathItem.parameters).forEach((ref) => seeds.add(ref));
179
+ extraPointers.push(`/paths/${_chunk6GTPCWO5cjs.encodePointer.call(void 0, pathKey)}/parameters`);
180
+ _chunk6GTPCWO5cjs.collectRefsInSchema.call(void 0, pathItem.parameters).forEach((ref) => seeds.add(ref));
181
181
  }
182
182
  const security = "security" in operation ? operation.security : definition.security;
183
183
  collectSecuritySchemeRefs(security).forEach((ref) => seeds.add(ref));
@@ -192,16 +192,16 @@ function computeWebhookScope(definition, webhookName, method) {
192
192
  }
193
193
  const webhook = webhooks2[webhookKey] || {};
194
194
  const methodKey = resolveKey(Object.keys(webhook), method);
195
- if (!methodKey || !_chunk7WBPPWYIcjs.supportedMethods.includes(methodKey.toLowerCase())) {
195
+ if (!methodKey || !_chunk6GTPCWO5cjs.supportedMethods.includes(methodKey.toLowerCase())) {
196
196
  throw new Error(`Webhook operation \`${method} ${webhookName}\` not found.`);
197
197
  }
198
198
  const operation = webhook[methodKey];
199
- const rootPointer = `/webhooks/${_chunk7WBPPWYIcjs.encodePointer.call(void 0, webhookKey)}/${methodKey}`;
199
+ const rootPointer = `/webhooks/${_chunk6GTPCWO5cjs.encodePointer.call(void 0, webhookKey)}/${methodKey}`;
200
200
  const extraPointers = [];
201
- const seeds = new Set(_chunk7WBPPWYIcjs.collectRefsInSchema.call(void 0, operation));
201
+ const seeds = new Set(_chunk6GTPCWO5cjs.collectRefsInSchema.call(void 0, operation));
202
202
  if (webhook.parameters) {
203
- extraPointers.push(`/webhooks/${_chunk7WBPPWYIcjs.encodePointer.call(void 0, webhookKey)}/parameters`);
204
- _chunk7WBPPWYIcjs.collectRefsInSchema.call(void 0, webhook.parameters).forEach((ref) => seeds.add(ref));
203
+ extraPointers.push(`/webhooks/${_chunk6GTPCWO5cjs.encodePointer.call(void 0, webhookKey)}/parameters`);
204
+ _chunk6GTPCWO5cjs.collectRefsInSchema.call(void 0, webhook.parameters).forEach((ref) => seeds.add(ref));
205
205
  }
206
206
  const security = "security" in operation ? operation.security : definition.security;
207
207
  collectSecuritySchemeRefs(security).forEach((ref) => seeds.add(ref));
@@ -392,7 +392,7 @@ async function buildAnalysis(definition, query2, scope) {
392
392
  }
393
393
  if (!query2 || query2.includes("circularRefs")) {
394
394
  const { circularRefs: dereferencedCircularRefs } = await dereferenceOasShared(definition);
395
- const circularRefs = (scope ? dereferencedCircularRefs.filter((ref) => isPointerInScope(_chunk7WBPPWYIcjs.toPointer.call(void 0, ref), scope)) : [...dereferencedCircularRefs]).toSorted();
395
+ const circularRefs = (scope ? dereferencedCircularRefs.filter((ref) => isPointerInScope(_chunk6GTPCWO5cjs.toPointer.call(void 0, ref), scope)) : [...dereferencedCircularRefs]).toSorted();
396
396
  analysis.circularRefs = {
397
397
  present: !!circularRefs.length,
398
398
  locations: circularRefs
@@ -7,8 +7,8 @@ import {
7
7
  encodePointer,
8
8
  supportedMethods,
9
9
  toPointer
10
- } from "../chunk-ANZIKNVX.js";
11
- import "../chunk-LZNTJ4ZR.js";
10
+ } from "../chunk-6D7GWVEH.js";
11
+ import "../chunk-DYHV2B4Z.js";
12
12
  import {
13
13
  isOpenAPI31
14
14
  } from "../chunk-XG4HGNCN.js";