Generates a valid OpenAPI spec from source spec. Various options for filtering out parts of the spec you don't want.
Project description
Filter OpenAPI Specifications
A command-line tool to filter and modify OpenAPI specification files. This tool is designed to help you tailor OpenAPI specifications for specific use cases by filtering out APIs and other information you do not need. A compliant OpenAPI specification is always produced.
Features
- Filter Out Paths by Tags: Keep only the API paths that are associated with a specific set of tags. Allows you to remove large groups of API that are organized by tag.
- Filter Endpoints: For any endpoints/paths left after filtering by tag, you can precisely control which endpoints (and which HTTP methods for those endpoints) are included in the final specification.
- Remove Unreferenced Schemas: Clean up your OpenAPI document by removing any schemas that are no longer referenced after filtering.
- Remove
x-oaiMetaProperties: Strip outx-oaiMetaproperties, which are often specific to internal tooling and not needed for public consumption. - Filter Top-Level Tags: Ensure the top-level
tagsarray only contains tags that are present in the filtered paths.
Installation
This project uses Python and its dependencies are listed in pyproject.toml. You can install the dependencies using pip:
pip install pyyaml pydantic
Configuration
The tool's behavior is controlled by a JSON configuration file. You can create your own config.json based on the provided config.example.json.
Here's an overview of the configuration options:
-
allowedTags: An array of strings representing the tags to keep. Any path that does not have at least one of these tags will be removed."allowedTags": [ "Chat", "Completions" ]
-
pathFilters: An object where each key is a path in the OpenAPI specification (e.g.,/chat/completions). The value is an object with anallowedMethodsarray, specifying which HTTP methods to keep (e.g.,"POST"). An emptyallowedMethodsarray will cause the entire path to be removed."pathFilters": { "/chat/completions": { "allowedMethods": [ "POST" ] }, "/chat/completions/{completion_id}": { "allowedMethods": [] } }
-
options: An object to control additional features.removeXOaiMeta: Set totrueto remove allx-oaiMetafields from the specification.removeUnreferencedSchemas: Set totrueto automatically remove any schemas incomponents/schemasthat are not referenced by any of the remaining endpoints.
"options": { "removeXOaiMeta": true, "removeUnreferencedSchemas": true }
Usage
The tool is run from the command line and accepts the following arguments:
input_file: (Required) The path to the input OpenAPI YAML file.-cor--config: (Required) The path to yourconfig.jsonfile.-oor--output: (Optional) The path to the output file. If not provided, the modified YAML will be printed to standard output.-vor--verbose: (Optional) Enable verbose logging.
Example
python -m filter_openapi.main openai.yaml --config config.json --output openapi_filtered.yaml
This command will:
- Read the
openai.yamlfile. - Apply the transformations defined in
config.json. - Write the resulting specification to
openapi_prepared.yaml.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file filter_openapi-0.1.0.tar.gz.
File metadata
- Download URL: filter_openapi-0.1.0.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ccfc93973b6e3378648b5659e199e240957316d1041fe3d418f5e36a833b6ab
|
|
| MD5 |
cbac99d09f0d64d1ac368c840204c4f5
|
|
| BLAKE2b-256 |
2c5fcd5c857d5c48bbe3d9100b518278ee501e73c6fcc6dfb0a3782c0390b407
|
File details
Details for the file filter_openapi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: filter_openapi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
737441f08a1d7bea35f0fd5c165eb74b33b11a3710f40a3c3ed3594416820fb1
|
|
| MD5 |
da53f3228fc46fe75ecc0fa507ff9992
|
|
| BLAKE2b-256 |
1ad37e6e9d9b90fbd7798a97c7a6fa23201a4d9285fc8ee18f86ae3c23fea89b
|