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.
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?