@madkudu-core-tools/split
v1.2.0
Published
CLI tool to split OpenAPI specifications by tags or routes
Downloads
10
Maintainers
Readme
@madkudu-core-tools/split
A CLI tool to split OpenAPI specifications by tags or routes, extracting only the relevant paths and their referenced schemas.
Installation
npm install -g @madkudu-core-tools/splitUsage
Split by Tag
Extract all routes under a specific tag and their referenced schemas:
# Local files
mct-split openapi.yaml -t user-management
mct-split openapi.json -t orders
# Remote URLs
mct-split --remote https://api.example.com/openapi.json -t user-management
mct-split --remote https://raw.githubusercontent.com/user/repo/main/openapi.yaml -t orders
# Save to file
mct-split openapi.yaml -t user-management -o users-api.json
mct-split --remote https://api.example.com/openapi.json -t users -o users-api.jsonSplit by Route
Extract a specific route and its referenced schemas:
# Local files
mct-split openapi.yaml -r /users/{id}
mct-split openapi.json -r /orders
# Remote URLs
mct-split --remote https://api.example.com/openapi.json -r /users/{id}
mct-split --remote https://petstore.swagger.io/v2/swagger.json -r /pet/{petId}
# Save to file
mct-split openapi.yaml -r /users/{id} -o user-detail-api.json
mct-split --remote https://api.example.com/openapi.json -r /orders -o orders-api.jsonOptions
-t, --tag <tag>: Split by tag name-r, --route <route>: Split by route name-o, --output <path>: Output file path (if not specified, outputs to stdout)--remote <url>: Remote URL to fetch OpenAPI specification from-h, --help: Display help for command
Features
- ✅ Supports both YAML and JSON OpenAPI specifications
- ✅ Extracts routes by tag or specific route path
- ✅ Automatically includes all referenced schemas, responses, parameters, etc.
- ✅ Preserves OpenAPI structure and metadata
- ✅ Output to stdout or save to file
- ✅ Remote URL support for fetching specs from web
- ✅ TypeScript support
- ✅ Comprehensive test coverage
API
You can also use this package programmatically:
import { splitByTag, splitByRoute } from "@madkudu-core-tools/split";
// Split by tag
const userRoutes = await splitByTag("openapi.yaml", "users");
// Split by route
const specificRoute = await splitByRoute("openapi.yaml", "/users/{id}");Development
# Install dependencies
pnpm install
# Build the project
pnpm run build
# Run tests
pnpm test
# Run tests in watch mode
pnpm run test:watch
# Lint code
pnpm run lintLicense
MIT
