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

api-spec-transformer

v0.2.6

Published

This package helps to convert between different API specifications. Supports OAS (Swagger 2), RAML 0.8, RAML 1.0, and Postman collections.

Downloads

188

Readme

API Spec Transformer Build Status Coverage Status

This package helps to convert between different API specifications. It currently supports OAS (Swagger 2), RAML 0.8, RAML 1.0, and Postman collections.

This package is used in production @ https://stoplight.io. If you are using this package in production, please let us know and we will link you.

Note

A prior version of this library was available, but not published on NPM. If you are directly referencing the git URL in your package.json files, please update them to use the api-spec-transformer package name, instead of https://github.com/stoplightio/api-spec-converter. We will be re-naming the git repository to https://github.com/stoplightio/api-spec-transformer in the near future.

Installation

NodeJS or Browser

npm install --save api-spec-transformer

Usage

Convert RAML1.0 to OAS (Swagger), from a file.

var transformer = require('api-spec-transformer');

var ramlToSwagger = new transformer.Converter(transformer.Formats.RAML10, transformer.Formats.SWAGGER);

ramlToSwagger.loadFile('/source/raml.yaml', function(err) {
  if (err) {
    console.log(err.stack);
    return;
  }

  ramlToSwagger.convert('yaml')
    .then(function(convertedData) {
      // convertedData is swagger YAML string
    })
    .catch(function(err){
      console.log(err);
    });
});

Convert OAS (Swagger) to RAML1.0, from a URL.

var transformer = require('api-spec-transformer');

// Convert swagger to raml, from a url.

var swaggerToRaml = new transformer.Converter(transformer.Formats.SWAGGER, transformer.Formats.RAML10);

swaggerToRaml.loadFile('http://petstore.swagger.io/v2/swagger.json', function(err) {
  if (err) {
    console.log(err.stack);
    return;
  }

  swaggerToRaml.convert('yaml')
    .then(function(convertedData) {
      // convertedData is a raml YAML string
    })
    .catch(function(err){
      console.log(err);
    });
});

Convert unknown input to RAML1.0:

You can tell the converter to detect the input format automatically (by passing AUTO format), it will detect the right format for the input.

var transformer = require('api-spec-transformer');

var myConverter = new transformer.Converter(transformer.Formats.AUTO, transformer.Formats.RAML10);

swaggerToRaml.loadFile('http://petstore.swagger.io/v2/swagger.json', function(err) {
  // Will identify the input as swagger - the rest is the same as above.
});

Load a string:

var transformer = require('api-spec-transformer');

var swaggerToRaml = new transformer.Converter(transformer.Formats.SWAGGER, transformer.Formats.RAML10);

var mySwaggerString = '...';

swaggerToRaml.loadData(mySwaggerString)
  .then(function() {
    // Do the converstion, as in the first two examples.
  });

Supported Conversions

  • OAS (Swagger 2) -> RAML 0.8
  • OAS (Swagger 2) -> RAML 1.0
  • RAML 1.0 -> OAS (Swagger 2)
  • RAML 0.8 -> OAS (Swagger 2)
  • Postman -> OAS (Swagger 2) * Experimental
  • Postman -> RAML 0.8 * Experimental
  • Postman -> RAML 1.0 * Experimental

Development

Install dependencies:

npm install

Run tests:

npm test

Run eslint to check linting errors:

gulp lint

Contributing

Contributions are welcome! Please check the current issues to make sure what you are trying to do has not already been discussed.

  1. Fork.
  2. Make changes.
  3. Write tests.
  4. Send a pull request.