Postman PCG Module
convert OpenAPI Schema v2 to Postman Collection v2.1
Installation npm i @pcg/postman-module
API usage
PCG cli tool
AsGo 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
covert
Manually Using 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);
});
PCG as module
Integrating withimport PostmanModule from "@pcg/postman-modue";
// postman modules entry sources .......
const module = loadModule();
switch (module) {
// ....
case 'postman':
await PostmanModule({ logger, vfs, config });
return;
}
// .......