A command-line tool that produces a pruned OpenAPI specification containing only the tags, paths, and operations you specify — along with all transitively referenced components.
Useful for extracting focused API subsets from large, bundled OpenAPI documents.
cargo install --path .openapi-pruner --config config.yamlinput: bundled-spec.yaml
output: pruned-spec.yaml
# At least one of tags, paths, or operations is required
tags:
- Accounts
- Transactions
paths:
- /webhooks
operations:
- create-inquiry
# Optional: schemas to exclude from the output
exclude_schemas:
- InternalAuditLog| Field | Required | Description |
|---|---|---|
input |
Yes | Path to the input OpenAPI YAML file |
output |
Yes | Path to write the pruned output |
tags |
No* | Keep all operations tagged with any of these tags |
paths |
No* | Keep all operations under paths matching these prefixes |
operations |
No* | Keep specific operations by operationId |
exclude_schemas |
No | Remove these schemas from components (direct $refs are replaced with type: object) |
* At least one of tags, paths, or operations must be specified.
- Filter paths — Retains operations matching the configured tags, path prefixes, or operation IDs.
- Resolve references — Walks all
$ref,anyOf,oneOf, anddiscriminator.mappingentries in kept operations to collect seed references. - Transitive closure — Uses BFS to discover all components reachable from the seed set, skipping explicitly excluded schemas.
- Prune components — Removes unreferenced components (security schemes are always preserved).
- Strip excluded refs — Replaces remaining references to excluded schemas with
type: objectand filters them fromanyOf/oneOfarrays and discriminator mappings. - Prune tags — Keeps only top-level tag definitions still used by remaining operations.
- Reassemble — Outputs a valid OpenAPI document preserving
openapi,info,servers,security,tags,paths, andcomponents.