Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example #22

Closed
Tracked by #88
sumachaa opened this issue Jan 10, 2020 · 2 comments
Closed
Tracked by #88

Example #22

sumachaa opened this issue Jan 10, 2020 · 2 comments

Comments

@sumachaa
Copy link

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?

@VShingala
Copy link
Member

VShingala commented Jan 12, 2020

@sumachaa We will be updating README.md with better description in future release. For now you can follow this steps.

Using the converter as a NodeJS module

In order to use the convert 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. For now you can pass this as empty object.
*/

callback:

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

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

@VShingala
Copy link
Member

PR to update Readme here includes example and detailed usage. So closing this fo now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants