1.1.5 • Published 5 months ago

openapi-operation-splitter v1.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

OpenApi Operation Splitter

NodeJS codecov GitHub npm GitHub top language

Module and library that can use for splitting a given swagger/open-api file (YAML or JSON) by an operation.

Installation

npm i openapi-operation-splitter

Cli

$ node_modules/.bin/openapi-operation-splitter --inputFile=api-filename --targetFile=filename-with-extention --ignore path-to-ignore --operations=passedValue1 passedValue2

Options

ArgumentAliasTypeDescription
inputFilestringinput file (JSON or YAML)
targetFilestringoutput file (e.g. target.json or target.yaml
ignorestringoptional: path to ignore (e.g. api-internal)
operationsstring[]http operations to extract
helphbooleanoptional: Prints this usage guide

Library Usage

import { OpenApiOperationSplitter } from 'openapi-operation-splitter';

async function main() {
    const splitter = new OpenApiOperationSplitter();
    const api = await splitter.parse('inputFile.yml');
    const paths = splitter.getPathsObjectByOperation(api, "get");
    api.paths = paths;
    await splitter.saveApiToYaml(api, 'targetFile.yml');
}

main()

BTW

If your output is a JSON file you could beautify it with:

python -m json.tool target.json > target-beauty.json