0.0.2 • Published 3 years ago

postman-collection-code-generators v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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.

postman-collection-code-generators

This library converts Postman Collection into client SDK of the chosen language.

Every sdk generator has two identifiers: language and variant.

  • language of sdk generator is the language in which client SDK is generated.
  • variant of sdk generator is the main library name which is used in the generated SDK.
LanguageVariant
NodejsRequest

Table of contents

Getting Started

To get started on your local machine.

$ git clone https://github.com/postmanlabs/postman-code-generators.git

Prerequisite

To run any of the postman-collection-code-generators, ensure that you have NodeJS >= v12. A copy of the NodeJS installable can be downloaded here

Usage

Using postman-collection-code-generators as a Library

There are three functions that are exposed in postman-collection-code-generators: getLanguageList, getSDKOptions & generate.

getLanguageList

let sdkgen = require('pathToSdkgen');

console.log(sdkgen.getLanguageList());
// [ 
//   {
//     name: 'nodejs-request',
//     language: 'nodejs',
//     variant: 'request'
//   } 
//   ...
// ]

getSDKOptions

General Options

This function takes in two optional parameters and returns an Array.

  • language - language key from the language list returned from getLanguageList function
  • variant - variant key provided by getLanguageList function

A typical option has the following properties:

  • name - Display name
  • id - unique ID of the option
  • type - Data type of the option. (Allowed data types: boolean, string)
  • default - Default value. The value that is used if this option is not specified while creating SDK snippet.
  • availableOptions - List of available options.
  • required - Boolean to denote if its a required option
  • description - User-friendly description.
let sdkgen = require('pathToSdkgen');

console.log(sdkgen.getSDKOptions());
// [
//   {
//     name: 'SDK Language',
//     id: 'language',
//     availableOptions: 'Use getSDKOptions method to get list of available sdkgens',
//     type: 'String',
//     default: '',
//     required: true,
//     description: 'Specifies Language for SDK generation'
//   },
//   {
//     name: 'SDK language variant',
//     id: 'variant',
//     availableOptions: 'any',
//     default: '',
//     type: 'String',
//     required: true,
//     description: 'Specifies Language variant for SDK generation'
//   }
//   ...
// ]
let sdkgen = require('pathToSdkgen');

console.log(sdkgen.getSDKOptions('nodejs', 'request'));
// [
//   {
//     name: 'Set response return method',
//     id: 'returnMethod',
//     availableOptions: [ 'Callback', 'Promise' ],
//     type: 'String',
//     default: 'Callback',
//     required: false,
//     description: 'Set response return method got http response.'
//   },
//   {
//     name: 'SDK output type',
//     id: 'outputType',
//     availableOptions: [ 'File', 'String' ],
//     type: 'String',
//     default: 'String',
//     required: false,
//     description: 'Specifies Type of Output for the generated SDK'
//   },
//   {
//     name: 'SDK output file name',
//     id: 'outputFilePath',
//     availableOptions: null,
//     type: 'String',
//     default: '/home/wolf/development/postman-collection-code-generators/test/unit',
//     required: false,
//     description: 'Specifies output path for generated SDK'
//   }
//   ...
// ]

generate

Collection / Output

let sdkgen = require('pathToSdkgen');

sdkgen.generate({
  type: 'string',
  source: 'https://www.getpostman.com/collections/c8aa0d9bd381c73c5ac3'
}, {
  language: 'Nodejs',
  variant: 'request',
}, (err, snippet) => {
  if (err) return console.log(err);
  console.log(snippet);
});

Development

Installing dependencies

This command will install all the dependencies in production mode.

$ npm install

To install dev dependencies also for all sdkgen run:

$ npm run deepinstall

Testing

To run common repo test as well as tests for all sdkgens

$ npm test

To run structure and individual tests on a single sdkgen

$ npm test <sdken-name>;
# Here "sdkgen-name" is the folder name of the sdkgen inside sdkgen folder

License

This software is licensed under Apache-2.0. Copyright Postman, Inc. See the LICENSE.md file for more information.