:link: Merge multiple swagger files into a swagger file, support JSON/YAML.
┌─┐┬ ┬┌─┐┌─┐┌─┐┌─┐┬─┐ ┌┬┐┌─┐┬─┐┌─┐┌─┐┬─┐
└─┐│││├─┤│ ┬│ ┬├┤ ├┬┘───│││├┤ ├┬┘│ ┬├┤ ├┬┘
└─┘└┴┘┴ ┴└─┘└─┘└─┘┴└─ ┴ ┴└─┘┴└─└─┘└─┘┴└─
Merge multiple related files from a input swagger file, Write to a output swagger file.
Support JSON/YAML.
.json
/.yaml
/.yml
).Includes a single-level of swagger file.
For yaml
example:
$ref: "./host.yaml"
parameters:
- $ref: "name.yaml"
- $ref: "./year.yaml"
- $ref: "age.yaml#/alex/son"
remote:
$ref: "https://raw.githubusercontent.com/WindomZ/swagger-merger/remote.yaml#/name"
responses:
$ref: "./responses.yaml#/post"
Includes a multi-level of swagger file.
$ref
, can be used side by side and not an arrayFor yaml
example:
paths:
$ref#pets: "./paths/pets.yaml"
$ref#pets-id: "./paths/pets-id.yaml"
paths-url:
$ref#paths: "https://raw.githubusercontent.com/WindomZ/swagger-merger/master/test/no_ext_json"
Output yaml
:
paths:
/pets:
hello: world
/pets/{id}:
good: bye
paths-url:
/pets:
hello: world
/pets/{id}:
good: bye
How to use?
$ swagger-merger -h
Usage: swagger-merger [-h] [-v] [-c] [-o file] <-i file | file>
Merge multiple swagger files into a swagger file, just support JSON/YAML.
Options:
-h, --help output usage information
-V, --version output the version number
-i, --input <file> input a main/entry JSON/YAML swagger file
-o, --output <file> output a merged JSON/YAML swagger file, default is `swagger.*`
-c, --compact compact JSON/YAML format string
--debug debug mode, such as print error tracks
Easy to use.
swagger-merger -i in.yaml # Merge in.yaml into swagger.yaml
swagger-merger -i in.yaml -o out.yaml # Merge in.yaml into out.yaml
swagger-merger -i in.yaml -o out.yaml -c # Merge in.yaml into out.yaml and compress it
swagger-merger -i in.yaml -o out.json # Merge in.yaml into out.json
swagger-merger -i in.json # Merge in.json into swagger.json
swagger-merger -i in.json -o out.json # Merge in.json into out.json
swagger-merger -i in.json -o out.json -c # Merge in.json into out.json and compress it
swagger-merger -i in.json -o out.yaml # Merge in.json into out.yaml
How to use?
npm install swagger-merger
#!/usr/bin/env node
const swaggerMerger = require('swagger-merger')
swaggerMerger.merge({
input: 'index.json',
output: 'swagger.json',
compact: false
}).catch(e => {
console.error(e)
})
npm install swagger-merger -g
It would be more helpful to see these examples.
Open the terminal, choose one of the following ways:
npm install
npm run test
yarn
yarn run test
swagger-merger (installed, go to each examples)
swagger-merger -i index.yaml
swagger-merger -i index.json
Then, these examples may help you:
Go to example/heroku-pets
swagger.json
is same as the expected heroku-pets.json
.swagger.yaml
is similar to the expected heroku-pets.yaml
.Go to example/echo
swagger.json
is same as the expected echo.json
.swagger.yaml
is similar to the expected echo.yaml
.Go to example/petstore_simple
swagger.json
is same as the expected petstore_simple.json
.swagger.yaml
is similar to the expected petstore_simple.yaml
.A way of using $ref instead of $ref#*, and better compatibility.
Go to example/petstore_domain
swagger.json
is same as the expected petstore_simple.json
.swagger.yaml
is similar to the expected petstore_simple.yaml
.Welcome to pull requests, report bugs, suggest ideas and discuss swagger-merger, i would love to hear what you think about swagger-merger on issues page.
If you like it then you can put a :star: on it.