GithubHelp home page GithubHelp logo

isabella232 / swagger-converter-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apigee-127/swagger-converter

0.0 0.0 0.0 1.03 MB

Converts Swagger documents from version 1.2 to 2.0

License: MIT License

JavaScript 100.00%

swagger-converter-1's Introduction

Swagger Converter

NPM version Build status Coverage Status Dependency status devDependency status

Join the chat at https://gitter.im/apigee-127/swagger-converter

Converts Swagger documents from version 1.x to version 2.0

Installation

Use npm

npm install swagger-converter --save

Usage

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(
  'http://test.com/api-docs',
  resourceListing,
);

console.log(JSON.stringify(apiDeclarations, null, 2));
/*
{
  "/pet": "http://test.com/api-docs/pet",
  "/user": "http://test.com/api-docs/user",
  "/store": "http://test.com/api-docs/store"
}
*/

Options

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

Development

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

License

MIT. See LICENSE

swagger-converter-1's People

Contributors

arkadianriver avatar bobvanderlinden avatar ceritium avatar gitter-badger avatar ivangoncharov avatar joepeding avatar mhardorf avatar mohsen1 avatar prabhatjha avatar rbren avatar shelbys avatar tandrup avatar utahdesignprocess avatar whitlockjc 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.