npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

swagger-merger

v1.5.4

Published

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

Downloads

60,985

Readme

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

Greenkeeper badge Node.js(≥12.22) CI Coverage Status Standard - JavaScript Style Guide License

Merge multiple related files from a input swagger file, Write to a output swagger file.

Support JSON/YAML.

NPM

swagger-merger status

Features

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

Usage

$ref

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"

$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 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

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

Module

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)
})

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:

heroku-pets

  • 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.

echo

  • 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.

petstore_simple

  • 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.

petstore_domain

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 :star: on it.

License

MIT