Skip to content

gavinnewcomer/openapi-pruner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openapi-pruner

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.

Installation

cargo install --path .

Usage

openapi-pruner --config config.yaml

Config file

input: 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.

How it works

  1. Filter paths — Retains operations matching the configured tags, path prefixes, or operation IDs.
  2. Resolve references — Walks all $ref, anyOf, oneOf, and discriminator.mapping entries in kept operations to collect seed references.
  3. Transitive closure — Uses BFS to discover all components reachable from the seed set, skipping explicitly excluded schemas.
  4. Prune components — Removes unreferenced components (security schemes are always preserved).
  5. Strip excluded refs — Replaces remaining references to excluded schemas with type: object and filters them from anyOf/oneOf arrays and discriminator mappings.
  6. Prune tags — Keeps only top-level tag definitions still used by remaining operations.
  7. Reassemble — Outputs a valid OpenAPI document preserving openapi, info, servers, security, tags, paths, and components.

About

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.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages