Code Monkey home page Code Monkey logo

raml1-to-postman's Introduction


Manage all of your organization's APIs in Postman, with the industry's most complete API development environment.

Supercharge your API workflow.
Modern software is built on APIs. Postman helps you develop APIs faster.

RAML 1.0 to Postman Collection Converter   Build Status

This module is used to convert RAML 1.0 API schema to Postman Collection v2.

Contents

  1. Getting Started
  2. Using the converter as a NodeJS module
    1. Convert Function
    2. Options
    3. ConversionResult
    4. Sample usage
    5. Validate function
  3. Notes
  4. Resources

Getting Started

To use the converter as a Node module, you need to have a copy of the NodeJS runtime (>= v6). The easiest way to do this is through npm. If you have NodeJS installed you have npm installed as well.

$ npm install raml1-to-postman

Using the converter as a NodeJS module

In order to use the converter in your node application, you need to import the package using require.

var Converter = require('raml1-to-postman')

The converter provides the following functions:

Convert

The convert function takes in your RAML 1.0 specification and converts it to a Postman collection.

Signature: convert (data, options, callback);

data:

{ type: 'file', data: 'filepath' }
OR
{ type: 'string', data: '<entire RAML 1.0 Specification string>' }
OR
{ type: 'folder', data: [Array of Objects with fileName property and file-path as it's value] }

options:

{
  collapseFolders: true,
  requestParametersResolution: 'schema',
  exampleParametersResolution: 'example'
}
/*
All three properties are optional. Defaults will be used for no options provided. Check the options section below for possible values for each option..
*/

callback:

function (err, result) {
  /*
  result = {
    result: true,
    output: [
      {
        type: 'collection',
        data: {..collection object..}
      }
    ]
  }
  */
}

Options:

  • 'collapseFolders'(boolean): Determines whether the importer should attempt to collapse redundant folders into one. Folders are redundant if they have only one child element, and don't have any folder-level data to persist. Default: true
  • 'requestParametersResolution'(string): Determines how request parameters (query parameters, path parameters, headers, or the request body) should be generated. Setting this to schema will cause the importer to use the parameter's schema as an indicator; example will cause the example (if provided) to be picked up. Default: schema
  • 'exampleParametersResolution'(string): Determines how response parameters (query parameters, path parameters, headers, or the request body) should be generated. Setting this to schema will cause the importer to use the parameter's schema as an indicator; example will cause the example (if provided) to be picked up. Default: exapmle

ConversionResult

  • result - Flag responsible for providing a status whether the conversion was successful or not

  • reason - Provides the reason for an unsuccessful conversion, defined only if result: false

  • output - Contains an array of Postman objects, each one with a type and data. The only type currently supported is collection.

Sample Usage:

var fs = require('fs'),

Converter = require('raml1-to-postman'),
ramlSpec = fs.readFileSync('sample-spec.raml', {encoding: 'UTF8'});

Converter.convert({ type: 'string', data: ramlSpec },
  {}, (err, conversionResult) => {
    if (!conversionResult.result) {
      console.log('Could not convert', conversionResult.reason);
    }
    else {
      console.log('The collection object is: ', conversionResult.output[0].data);
    }
  }
);

Validate Function

The validate function is meant to ensure that the data that is being passed to the convert function is a valid RAML 1.0 Spec.

The validate function is synchronous and returns a status object which conforms to the following schema

Validation object schema

{
  type: 'object',
  properties: {
    result: { type: 'boolean'},
    reason: { type: 'string' }
  },
  required: ['result']
}
Validation object explanation
  • result - true if the data looks like RAML 1.0 and can be passed to the convert function

  • reason - Provides a reason for an unsuccessful validation of the specification

Notes

This version of converter does not handle the following yet:

  • Libraries, Overlays and Extensions.
  • Annotations.

Resources

raml1-to-postman's People

Contributors

abhijitkane avatar shreys7 avatar umeshp7 avatar vshingala avatar web-flow avatar webholik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raml1-to-postman's Issues

RAML directive to set "Inherit auth from parent" in postman after importing schema?

In postman, you can set authentication on the collection level (and other levels). The issue is if a collection is created by importing RAML, each imported endpoint in the collection (created from a RAML schema) has to set the "Inherit auth from parent".

Is there some directive in RAML that cause this to be set? The securedBy attribute is set to basic & endpoints do show as needing authentication settings. But it's tedious to set then in a large collection imported from RAML.

Basically I'd like basic auth to be set in one place after creating a collection from RAML in API. I can't figure out the right magic to do it however.

Maybe this is a feature request (or just unfamiliarity with postman ;))?

Example

Is there an example of how we can use this. We have a raml folder (with #%RAML 1.0).
How can we this code to convert those to postman collection?

Valid RAML 1.0 will not import using Postman >11.0.12

I have some RAML 1.0 spec that has imported fine in for a while. In BOTH of the 11.1.x builds, the import started failing importing, with popup saying it failed. Tired cut-and-pasting the RAML and using a file.

There is no logs or some specific indicator what might be wrong. The same RAML validates using raml2html -v and via the webapi-parser code. e.g.

const wap = require('webapi-parser').WebApiParser
const fs = require("fs")
async function main () {
  const raml = fs.readFileSync(`${__dirname}/ros-rest-tool.raml`, "utf-8")  
  const model = await wap.raml10.parse(raml)
  const report = await wap.raml10.validate(model)
  console.log('Validation errors:', report.toString())
}
main()

Validation errors: Model: http://a.ml/amf/default_document
Profile: RAML 1.0
Conforms? true
Number of results: 0

I tried using some JS code with postmanlabs/raml1-to-postman – I don't normally to it this way but it does NOT work either. This generates a seemingly valid JSON file – but the generate Postman JSON is valid AFAIK, but it fails to import in Postman App. e.g.

var fs = require('fs'),
Converter = require('raml1-to-postman'),
ramlSpec = fs.readFileSync('ros-rest-tool.raml', {encoding: 'UTF8'});
Converter.convert({ type: 'string', data: ramlSpec },
  {}, (err, conversionResult) => {
    if (!conversionResult.result) {
      console.log('Could not convert', conversionResult.reason);
      process.exit(1)
    }
    else {
      console.log(JSON.stringify(conversionResult.output[0]));
    }
  }
)

Anyway tried a few things, but something broke in newer Postman versions, specifically 11.1.x. The last version that worked is 11.0.12. Postman has worked with this scheme for a while (9.x, 10.x, and 11.0.12), so it being a postman error was NOT my right thought. ;). So... I think something broken between those builds on your side.

Attached the problematic RAML file. Renamed to .txt to it can be attached

ros-rest-tool.raml.txt

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.