# Usage
+## As library
+
Use the library is as easy as use a single method `async postmanToOpenApi(inputPath, outputPath, options)`, the parameters are:
| Param | Description |
@@ -86,6 +95,20 @@ postmanToOpenApi(postmanCollection, outputFile, { defaultTag: 'General' })
})
```
+## As cli
+
+After install just need to
+
+```bash
+p2o ./path/to/PostmantoCollection.json -f ./path/to/result.yml -o ./path/to/options.json
+```
+
+All the field described in [options](#options) can be provided and used in the cli, for more info an all the available options just check the cli help
+
+```bash
+p2o -h
+```
+
## Options
The third parameter used in the library method is an `options` object containing the optional parameters for the transformation, the allowed parameters are:
diff --git a/package-lock.json b/package-lock.json
index 72f3d35..9d4ca75 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,28 +1,36 @@
{
"name": "postman-to-openapi",
- "version": "1.7.3",
+ "version": "1.8.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
- "version": "1.7.3",
+ "version": "1.8.0",
"license": "MIT",
"dependencies": {
+ "commander": "^7.2.0",
"js-yaml": "^4.1.0",
"marked": "^2.0.3"
},
+ "bin": {
+ "p2o": "bin/cli.js"
+ },
"devDependencies": {
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"conventional-changelog-cli": "^2.1.1",
- "eslint": "^7.24.0",
+ "eslint": "^7.25.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
+ "execa": "^5.0.0",
"husky": "^6.0.0",
"mocha": "^8.3.2",
"nyc": "^15.1.0"
+ },
+ "engines": {
+ "node": ">=10 <15"
}
},
"node_modules/@babel/code-frame": {
@@ -512,9 +520,6 @@
},
"engines": {
"node": ">=10"
- },
- "funding": {
- "url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/@commitlint/top-level/node_modules/locate-path": {
@@ -527,9 +532,6 @@
},
"engines": {
"node": ">=10"
- },
- "funding": {
- "url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/@commitlint/top-level/node_modules/p-limit": {
@@ -542,9 +544,6 @@
},
"engines": {
"node": ">=10"
- },
- "funding": {
- "url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/@commitlint/top-level/node_modules/p-locate": {
@@ -557,9 +556,6 @@
},
"engines": {
"node": ">=10"
- },
- "funding": {
- "url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/@commitlint/types": {
@@ -1194,6 +1190,14 @@
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"dev": true
},
+ "node_modules/commander": {
+ "version": "7.2.0",
+ "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz",
+ "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==",
+ "engines": {
+ "node": ">= 10"
+ }
+ },
"node_modules/commondir": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
@@ -1939,9 +1943,9 @@
}
},
"node_modules/eslint": {
- "version": "7.24.0",
- "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.24.0.tgz",
- "integrity": "sha512-k9gaHeHiFmGCDQ2rEfvULlSLruz6tgfA8DEn+rY9/oYPFFTlz55mM/Q/Rij1b2Y42jwZiK3lXvNTw6w6TXzcKQ==",
+ "version": "7.25.0",
+ "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.25.0.tgz",
+ "integrity": "sha512-TVpSovpvCNpLURIScDRB6g5CYu/ZFq9GfX2hLNIV4dSBKxIWojeDODvYl3t0k0VtMxYeR8OXPCFE5+oHMlGfhw==",
"dev": true,
"dependencies": {
"@babel/code-frame": "7.12.11",
@@ -1987,9 +1991,6 @@
},
"engines": {
"node": "^10.12.0 || >=12.0.0"
- },
- "funding": {
- "url": "https://opencollective.com/eslint"
}
},
"node_modules/eslint-config-standard": {
@@ -2406,9 +2407,6 @@
"dev": true,
"engines": {
"node": "^10.12.0 || >=12.0.0"
- },
- "peerDependencies": {
- "eslint": "^7.0.0"
}
},
"node_modules/eslint-scope": {
@@ -2618,6 +2616,26 @@
"node": ">=0.10.0"
}
},
+ "node_modules/execa": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/execa/-/execa-5.0.0.tgz",
+ "integrity": "sha512-ov6w/2LCiuyO4RLYGdpFGjkcs0wMTgGE8PrkTHikeUy5iJekXyPIKUjifk5CsE0pt7sMCrMZ3YNqoCj6idQOnQ==",
+ "dev": true,
+ "dependencies": {
+ "cross-spawn": "^7.0.3",
+ "get-stream": "^6.0.0",
+ "human-signals": "^2.1.0",
+ "is-stream": "^2.0.0",
+ "merge-stream": "^2.0.0",
+ "npm-run-path": "^4.0.1",
+ "onetime": "^5.1.2",
+ "signal-exit": "^3.0.3",
+ "strip-final-newline": "^2.0.0"
+ },
+ "engines": {
+ "node": ">=10"
+ }
+ },
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@@ -3159,6 +3177,15 @@
"node": ">=10"
}
},
+ "node_modules/get-stream": {
+ "version": "6.0.1",
+ "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz",
+ "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==",
+ "dev": true,
+ "engines": {
+ "node": ">=10"
+ }
+ },
"node_modules/git-raw-commits": {
"version": "2.0.10",
"resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-2.0.10.tgz",
@@ -3408,6 +3435,15 @@
"integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==",
"dev": true
},
+ "node_modules/human-signals": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz",
+ "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==",
+ "dev": true,
+ "engines": {
+ "node": ">=10.17.0"
+ }
+ },
"node_modules/husky": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/husky/-/husky-6.0.0.tgz",
@@ -3415,9 +3451,6 @@
"dev": true,
"bin": {
"husky": "lib/bin.js"
- },
- "funding": {
- "url": "https://github.com/sponsors/typicode"
}
},
"node_modules/ignore": {
@@ -3943,10 +3976,8 @@
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
"dev": true,
"dependencies": {
+ "graceful-fs": "^4.1.6",
"universalify": "^2.0.0"
- },
- "optionalDependencies": {
- "graceful-fs": "^4.1.6"
}
},
"node_modules/jsonparse": {
@@ -4178,6 +4209,21 @@
"node": ">=10"
}
},
+ "node_modules/merge-stream": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
+ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==",
+ "dev": true
+ },
+ "node_modules/mimic-fn": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
+ "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==",
+ "dev": true,
+ "engines": {
+ "node": ">=6"
+ }
+ },
"node_modules/min-indent": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz",
@@ -4464,6 +4510,18 @@
"node": ">=0.10.0"
}
},
+ "node_modules/npm-run-path": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz",
+ "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==",
+ "dev": true,
+ "dependencies": {
+ "path-key": "^3.0.0"
+ },
+ "engines": {
+ "node": ">=8"
+ }
+ },
"node_modules/nyc": {
"version": "15.1.0",
"resolved": "https://registry.npmjs.org/nyc/-/nyc-15.1.0.tgz",
@@ -4754,6 +4812,18 @@
"wrappy": "1"
}
},
+ "node_modules/onetime": {
+ "version": "5.1.2",
+ "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz",
+ "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==",
+ "dev": true,
+ "dependencies": {
+ "mimic-fn": "^2.1.0"
+ },
+ "engines": {
+ "node": ">=6"
+ }
+ },
"node_modules/optionator": {
"version": "0.9.1",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz",
@@ -5527,6 +5597,15 @@
"node": ">=0.10.0"
}
},
+ "node_modules/strip-final-newline": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz",
+ "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==",
+ "dev": true,
+ "engines": {
+ "node": ">=6"
+ }
+ },
"node_modules/strip-indent": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz",
@@ -7115,6 +7194,11 @@
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"dev": true
},
+ "commander": {
+ "version": "7.2.0",
+ "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz",
+ "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw=="
+ },
"commondir": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
@@ -7708,9 +7792,9 @@
"dev": true
},
"eslint": {
- "version": "7.24.0",
- "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.24.0.tgz",
- "integrity": "sha512-k9gaHeHiFmGCDQ2rEfvULlSLruz6tgfA8DEn+rY9/oYPFFTlz55mM/Q/Rij1b2Y42jwZiK3lXvNTw6w6TXzcKQ==",
+ "version": "7.25.0",
+ "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.25.0.tgz",
+ "integrity": "sha512-TVpSovpvCNpLURIScDRB6g5CYu/ZFq9GfX2hLNIV4dSBKxIWojeDODvYl3t0k0VtMxYeR8OXPCFE5+oHMlGfhw==",
"dev": true,
"requires": {
"@babel/code-frame": "7.12.11",
@@ -8156,8 +8240,7 @@
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-5.1.0.tgz",
"integrity": "sha512-NGmI6BH5L12pl7ScQHbg7tvtk4wPxxj8yPHH47NvSmMtFneC077PSeY3huFj06ZWZvtbfxSPt3RuOQD5XcR4ng==",
- "dev": true,
- "requires": {}
+ "dev": true
},
"eslint-scope": {
"version": "5.1.1",
@@ -8263,6 +8346,23 @@
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
"dev": true
},
+ "execa": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/execa/-/execa-5.0.0.tgz",
+ "integrity": "sha512-ov6w/2LCiuyO4RLYGdpFGjkcs0wMTgGE8PrkTHikeUy5iJekXyPIKUjifk5CsE0pt7sMCrMZ3YNqoCj6idQOnQ==",
+ "dev": true,
+ "requires": {
+ "cross-spawn": "^7.0.3",
+ "get-stream": "^6.0.0",
+ "human-signals": "^2.1.0",
+ "is-stream": "^2.0.0",
+ "merge-stream": "^2.0.0",
+ "npm-run-path": "^4.0.1",
+ "onetime": "^5.1.2",
+ "signal-exit": "^3.0.3",
+ "strip-final-newline": "^2.0.0"
+ }
+ },
"fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@@ -8694,6 +8794,12 @@
"integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==",
"dev": true
},
+ "get-stream": {
+ "version": "6.0.1",
+ "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz",
+ "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==",
+ "dev": true
+ },
"git-raw-commits": {
"version": "2.0.10",
"resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-2.0.10.tgz",
@@ -8882,6 +8988,12 @@
"integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==",
"dev": true
},
+ "human-signals": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz",
+ "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==",
+ "dev": true
+ },
"husky": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/husky/-/husky-6.0.0.tgz",
@@ -9478,6 +9590,18 @@
}
}
},
+ "merge-stream": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
+ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==",
+ "dev": true
+ },
+ "mimic-fn": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
+ "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==",
+ "dev": true
+ },
"min-indent": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz",
@@ -9704,6 +9828,15 @@
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
"dev": true
},
+ "npm-run-path": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz",
+ "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==",
+ "dev": true,
+ "requires": {
+ "path-key": "^3.0.0"
+ }
+ },
"nyc": {
"version": "15.1.0",
"resolved": "https://registry.npmjs.org/nyc/-/nyc-15.1.0.tgz",
@@ -9939,6 +10072,15 @@
"wrappy": "1"
}
},
+ "onetime": {
+ "version": "5.1.2",
+ "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz",
+ "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==",
+ "dev": true,
+ "requires": {
+ "mimic-fn": "^2.1.0"
+ }
+ },
"optionator": {
"version": "0.9.1",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz",
@@ -10557,6 +10699,12 @@
"is-utf8": "^0.2.0"
}
},
+ "strip-final-newline": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz",
+ "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==",
+ "dev": true
+ },
"strip-indent": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz",
diff --git a/package.json b/package.json
index c6aea0d..0110140 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,11 @@
{
"name": "postman-to-openapi",
- "version": "1.7.3",
+ "version": "1.8.0",
"description": "Convert postman collection to OpenAPI spec",
"main": "lib/index.js",
+ "bin": {
+ "p2o": "./bin/cli.js"
+ },
"scripts": {
"lint": "eslint **/*.js",
"lint:fix": "eslint **/*.js --fix",
@@ -13,6 +16,10 @@
"changelog": "conventional-changelog --config ./changelog.config.js -i CHANGELOG.md -s",
"prepare": "husky install"
},
+ "files": [
+ "bin/*",
+ "lib/*"
+ ],
"repository": {
"type": "git",
"url": "git+https://github.com/joolfe/postman-to-openapi.git"
@@ -38,11 +45,12 @@
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"conventional-changelog-cli": "^2.1.1",
- "eslint": "^7.24.0",
+ "eslint": "^7.25.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
+ "execa": "^5.0.0",
"husky": "^6.0.0",
"mocha": "^8.3.2",
"nyc": "^15.1.0"
@@ -52,11 +60,15 @@
"@commitlint/config-conventional"
]
},
+ "engines": {
+ "node": ">=10 <15"
+ },
"nyc": {
"all": true,
"include": [
"lib/**/*.js",
- "test/**/*.js"
+ "test/**/*.js",
+ "bin/**/*.js"
],
"exclude": [],
"reporter": [
@@ -71,6 +83,7 @@
"check-coverage": true
},
"dependencies": {
+ "commander": "^7.2.0",
"js-yaml": "^4.1.0",
"marked": "^2.0.3"
},
diff --git a/test/cli.spec.js b/test/cli.spec.js
new file mode 100644
index 0000000..dc5441c
--- /dev/null
+++ b/test/cli.spec.js
@@ -0,0 +1,92 @@
+'use strict'
+
+const { describe, it, afterEach } = require('mocha')
+const { readFileSync, existsSync, unlinkSync } = require('fs')
+const { equal, rejects, ok } = require('assert').strict
+const execa = require('execa')
+
+const cliPath = './bin/cli.js'
+const COLLECTION_BASIC = './test/resources/input/v21/PostmantoOpenAPI.json'
+const COLLECTION_SIMPLE = './test/resources/input/v21/SimplePost.json'
+const OPTIONS_INFO = './test/resources/input/options.json'
+const INVALID_OPTIONS_INFO = './test/resources/input/invalidOptions.txt'
+const EXPECTED_INFO_OPTS = readFileSync('./test/resources/output/InfoOpts.yml', 'utf8')
+const EXPECTED_BASIC = readFileSync('./test/resources/output/Basic.yml', 'utf8')
+const OUTPUT_PATH = './openAPIRes.yml'
+const HELP_OUTPUT = readFileSync('./test/resources/console/help.txt', 'utf8')
+
+const { version } = require('../package.json')
+
+describe('Cli specs', function () {
+ afterEach('remove file', function () {
+ if (existsSync(OUTPUT_PATH)) {
+ unlinkSync(OUTPUT_PATH)
+ }
+ })
+
+ it('should transform correctly a basic collection (HP)', async function () {
+ const { stdout } = await execa('node', [cliPath, COLLECTION_BASIC])
+ equal(stdout, EXPECTED_BASIC)
+ })
+
+ it('should return an error when collection argument is not provided', async function () {
+ await rejects(execa('node', [cliPath]), {
+ name: 'Error',
+ stderr: "error: missing required argument 'collection'",
+ exitCode: 1
+ })
+ })
+
+ it('should print an error when collection file doesn\'t exist', async function () {
+ await rejects(execa('node', [cliPath, './none/file.json']), {
+ name: 'Error',
+ stderr: "Error: ENOENT: no such file or directory, open './none/file.json'",
+ exitCode: 1
+ })
+ })
+
+ it('should print an error when result file cannot be created', async function () {
+ await rejects(execa('node', [cliPath, COLLECTION_BASIC, '-f', './no_exist/result.yml']), {
+ name: 'Error',
+ stderr: "Error: ENOENT: no such file or directory, open './no_exist/result.yml'",
+ exitCode: 1
+ })
+ })
+
+ it('should transform and write into a file the output (HP)', async function () {
+ const { stdout } = await execa('node', [cliPath, COLLECTION_BASIC, '-f', OUTPUT_PATH])
+ ok(existsSync(OUTPUT_PATH))
+ equal(stdout, EXPECTED_BASIC)
+ })
+
+ it('should transform correctly a basic collection when using option file (HP)', async function () {
+ const { stdout } = await execa('node', [cliPath, COLLECTION_SIMPLE, '-o', OPTIONS_INFO])
+ equal(stdout, EXPECTED_INFO_OPTS)
+ })
+
+ it('should print an error when "options" file doesn\'t exist', async function () {
+ await rejects(execa('node', [cliPath, COLLECTION_SIMPLE, '-o', './no_exist/options.json']), {
+ name: 'Error',
+ stderr: "Error: invalid \"options\" parameter -> ENOENT: no such file or directory, open './no_exist/options.json'",
+ exitCode: 1
+ })
+ })
+
+ it('should print an error when options file is not a valid json', async function () {
+ await rejects(execa('node', [cliPath, COLLECTION_SIMPLE, '-o', INVALID_OPTIONS_INFO]), {
+ name: 'Error',
+ stderr: 'Error: invalid "options" parameter -> Unexpected token i in JSON at position 6',
+ exitCode: 1
+ })
+ })
+
+ it('should print correctly the version of the cli', async function () {
+ const { stdout } = await execa('node', [cliPath, '-v'])
+ equal(stdout, version)
+ })
+
+ it('should print correctly help command', async function () {
+ const { stdout } = await execa('node', [cliPath, '-h'])
+ equal(stdout, HELP_OUTPUT)
+ })
+})
diff --git a/test/resources/console/help.txt b/test/resources/console/help.txt
new file mode 100644
index 0000000..302a915
--- /dev/null
+++ b/test/resources/console/help.txt
@@ -0,0 +1,20 @@
+Usage: p2o [options]
+
+Transform a postman collection to OpenAPI specification yml.
+
+Arguments:
+ collection Relative path to the Postman collection json file
+
+Options:
+ -v, --vers Output the current version of the library.
+ -f, --file Relative path to the file where result will be
+ saved. If empty result will be returned by cli.
+ -o, --options Relative path to json file that contain the optional
+ parameters for the transformation.
+ -h, --help display help for command
+
+
+Example calls:
+ $ p2o ./path/to/PostmantoCollection.json -f ./path/to/result.yml -o ./path/to/options.json
+
+For more info about how to use it visit our documentation in
diff --git a/test/resources/input/invalidOptions.txt b/test/resources/input/invalidOptions.txt
new file mode 100644
index 0000000..7541589
--- /dev/null
+++ b/test/resources/input/invalidOptions.txt
@@ -0,0 +1,8 @@
+{
+ info": {
+ "title": "Options title",
+ "version: "6.0.7-beta",
+ "description": "Description from options",
+ "termsOfService": "http://tos.myweb.com"
+ }
+}
\ No newline at end of file
diff --git a/test/resources/input/options.json b/test/resources/input/options.json
new file mode 100644
index 0000000..f03c51e
--- /dev/null
+++ b/test/resources/input/options.json
@@ -0,0 +1,8 @@
+{
+ "info": {
+ "title": "Options title",
+ "version": "6.0.7-beta",
+ "description": "Description from options",
+ "termsOfService": "http://tos.myweb.com"
+ }
+}
\ No newline at end of file
diff --git a/test/resources/options/info.json b/test/resources/options/info.json
new file mode 100644
index 0000000..da192bb
--- /dev/null
+++ b/test/resources/options/info.json
@@ -0,0 +1,8 @@
+{
+ "info": {
+ "title": "Options title",
+ "version": "6.0.7-beta",
+ "description": "Description from options",
+ "termsOfService": "http://tos.myweb.com"
+ }
+ }
\ No newline at end of file