Giter Site home page Giter Site logo

swagger-merger's Introduction

┌─┐┬ ┬┌─┐┌─┐┌─┐┌─┐┬─┐   ┌┬┐┌─┐┬─┐┌─┐┌─┐┬─┐
└─┐│││├─┤│ ┬│ ┬├┤ ├┬┘───│││├┤ ├┬┘│ ┬├┤ ├┬┘
└─┘└┴┘┴ ┴└─┘└─┘└─┘┴└─   ┴ ┴└─┘┴└─└─┘└─┘┴└─

Greenkeeper badge Build Status Coverage Status Dependency Standard - JavaScript Style Guide License

Merge multiple swagger files into a swagger file, support JSON/YAML.

NPM

swagger-merger status

Features

  • Merge multiple swagger files into a swagger file.
  • $ref - A tag, include a single-level of swagger file.
  • $ref#* - A tag, include a multi-level of swagger file.
  • Support JSON/YAML swagger files(.json/.yaml/.yml).
  • CLI - Command line interface.

Usage

$ref

Includes a single-level of swagger file.

For 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"

$ref#*

Includes a multi-level of swagger file.

  • Non-standard, suggest you use it for yourself
  • Instead of $ref, can be used side by side and not an array

For example:

paths:
  $ref#pets: "./paths/pets.yaml"
  $ref#pets-id: "./paths/pets-id.yaml"
definitions:
  $ref#pets: "https://raw.githubusercontent.com/WindomZ/swagger-merger/pets.yaml"
  $ref#error: "https://raw.githubusercontent.com/WindomZ/swagger-merger/error.yaml"

CLI

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

Install

npm install swagger-merger -g

Examples

It would be more helpful to see these examples.

Open the terminal, choose one of the following ways:

  • npm

    npm install
    npm run test
  • yarn

    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:

  • Official swagger example
  • No modification

Go to example/heroku-pets

  1. The output swagger.json is same as the expected heroku-pets.json.
  2. The output swagger.yaml is similar to the expected heroku-pets.yaml.
  • Base on official swagger example
  • Modify to support for $ref tags

Go to example/echo

  1. The output swagger.json is same as the expected echo.json.
  2. The output swagger.yaml is similar to the expected echo.yaml.
  • Base on official swagger example
  • Modify to support for $ref#* tags

Go to example/petstore_simple

  1. The output swagger.json is same as the expected petstore_simple.json.
  2. The output swagger.yaml is similar to the expected petstore_simple.yaml.

A way of using $ref instead of $ref#*, and better compatibility.

  • Same as petstore_simple
  • Modify to support for $ref tags
  • Modify to support for multiple levels schema

Go to example/petstore_domain

  1. The output swagger.json is same as the expected petstore_simple.json.
  2. The output swagger.yaml is similar to the expected petstore_simple.yaml.

Contributing

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 ⭐ on it.

License

MIT

swagger-merger's People

Contributors

brinley avatar greenkeeper[bot] avatar mfcollins3 avatar windomz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.