@pcg/module-postman
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

Postman PCG Module

convert OpenAPI Schema v2 to Postman Collection v2.1

Installation npm i @pcg/postman-module

API usage

As PCG cli tool

Go to project root and run $ pcg postman

Your PCG configuration file should have these two properties:

  • loopback.oas2 defines path where module should look for Open API Schema
  • postman-collection defines path where to place Postman Collection file after converting.

For example:

// pcg.config.js

module.exports = {
    loopback: {
        oas2: '/path/to/schema.oas2.json',
    },
    
    'postman-collection': '/path/to/collection.json',
};

Note that this module supported by PCG >= 0.3.3

Manually Using covert

Read OpenAPI schema, covert and write Postman Collection to file. Actually, you can use any other way of reading schema, but this example uses Swagger Parser.

import * as fs from "fs";
import * as SwaggerParser from "swagger-parser";
import { convert } from "@pcg/postman-module";

(async () => {
    const schema = await SwaggerParser.dereference("./path/to/schema.oas2.json");
   
    const collection = convert(schema);

    fs.writeFileSync("./collection.json", JSON.stringify(collection));
})().catch(err => {
    console.error(err);
});

Integrating with PCG as module

import PostmanModule from "@pcg/postman-modue";

// postman modules entry sources .......

    const module = loadModule();
    switch (module) {
        // ....
        case 'postman':
            await PostmanModule({ logger, vfs, config });
            return;
    }
    
// .......

Readme

Keywords

none

Package Sidebar

Install

npm i @pcg/module-postman

Weekly Downloads

0

Version

1.0.8

License

SEE LICENSE IN LICENSE

Unpacked Size

142 kB

Total Files

45

Last publish

Collaborators

  • deepbot
  • ftornik