1.0.8 • Published 5 years ago

@pcg/module-postman v1.0.8

Weekly downloads
7
License
SEE LICENSE IN LI...
Repository
-
Last release
5 years ago

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;
    }
    
// .......
1.0.8

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.0

5 years ago