Project Description
Ever wanted to share only a small part of your massive 100+ endpoint API without dumping the whole spec?
openapi-subset is a command-line tool that extracts exactly the endpoints and HTTP methods you care about from an OpenAPI (Swagger) specification, and automatically prunes unused components — giving you a clean, minimal spec to share or document.
Key features:
- Subset by specific paths or HTTP methods, or use regex to match multiple endpoints.
- Automatically prunes unused components (schemas, responses, parameters, etc.) for you.
- Generates a minimal, focused OpenAPI spec tailored to your needs — perfect for sharing or documentation.
Installation
Build and install locally using Cargo:
Make sure ~/.cargo/bin is in your PATH so you can run the tool from anywhere:
Usage
Extract specific paths and methods from an OpenAPI spec:
Use a regular expression to match multiple paths:
You can use the --path, --path-regex, and --method flags individually or in combination to precisely control which parts of the OpenAPI spec are included in the output.
--pathselects specific API paths by exact match. You can specify this flag multiple times to include multiple paths.--path-regexselects API paths matching a regular expression.--methodfilters the HTTP methods (e.g., GET, POST) within the selected paths.
When combined, the tool extracts only the specified methods within the selected paths or path patterns.
Examples
Extract multiple specific paths:
Filter paths by regex and methods together:
Keep all paths but prune components by filtering methods only:
See openapi-subset --help for all options.
Rebuilding
After making changes, rebuild the tool:
Or reinstall:
Contributing
- Fork the repository and clone it.
- Create a new branch for your changes.
- Commit your changes with a descriptive message.
- Push the branch to your fork.
- Open a pull request.
Running Tests
This repository includes integration tests that use the Petstore OpenAPI example to validate path and method filtering as well as component pruning. To run the tests, use:
Tests will fail if any changes break existing functionality, helping ensure the tool remains reliable.