@pcg/module-postman
v1.0.8
Published
PCG Postman Module
Downloads
6
Readme
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 Schemapostman-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;
}
// .......