Skip to content
Branch: master
Go to file

Latest commit


Failed to load latest commit information.
Latest commit message
Commit time

Swagger Converter

NPM version Build status Coverage Status Dependency status devDependency status

Join the chat at

Converts Swagger documents from version 1.x to version 2.0


Use npm

npm install swagger-converter --save


It's recommended to use command line tools like swagger-tools or swagger-spec-converter for converting your spec. This module will not handle validation and if your spec is not valid can produce invalid spec.

convert function

convert accept accept following arguments:

  • resourceListing(required) is Swagger 1.x entry point file.
  • apiDeclarations(required) is a map with paths from resourceListing as keys and resources as values
  • options(optional) - See options for the full list of options
var swaggerConverter = require('swagger-converter');

var resourceListing = require('/path/to/petstore/index.json');

var apiDeclarations = {
  '/pet': require('/path/to/petstore/pet.json'),
  '/user': require('/path/to/petstore/user.json'),
  '/store': require('/path/to/petstore/store.json')

var swagger2Document = swaggerConverter.convert(resourceListing, apiDeclarations);

console.log(JSON.stringify(swagger2Document, null, 2));
listApiDeclarations function

listApiDeclarations function accept following arguments:

  • sourceUrl(required) - source URL for root Swagger 1.x document
  • resourceListing(required) - root Swagger 1.x document
var swaggerConverter = require('swagger-converter');

var resourceListing = require('/path/to/petstore/index.json');

var apiDeclarations = swaggerConverter.listApiDeclarations('', resourceListing);

console.log(JSON.stringify(apiDeclarations, null, 2));
  "/pet": "",
  "/user": "",
  "/store": ""
In browser

Install via Bower

bower install --save swagger-converter

Include the browser.js script in your HTML

  <script src="/path/to/swagger-converter/browser.js"></script>

Use the script

var swagger2Document = SwaggerConverter.convert(resourceListing, apiDeclarations);


  • collectionFormat[string] - assigned to every array parameter.
  • buildTagsFromPaths[bool] - ignore resourcePath and buid tags from resource path. Default: false.


Install dependencies with npm install command and use npm test to run the test. Tests will fail if you break coding style.

Building for browser

Just run this command to make a new browser.js

npm run build



You can’t perform that action at this time.