Skip to content

Commit 6f9748d

Browse files
Merge pull request #6 from jqian33/AddSchemaCmdOption
Add schema command line option
2 parents 8ad64d0 + 97239a7 commit 6f9748d

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Diff for: bin/apib2postman.js

+6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ const apib2postman = require('../src/index.js');
99

1010
var options = nopt({
1111
'output': String,
12+
'schema': String,
1213
'environment': String,
1314
'testTemplate': String,
1415
'help': Boolean
1516
}, {
1617
'o': ['--output'],
18+
's': ['--schema'],
1719
'e': ['--environment'],
1820
't': ['--testTemplate'],
1921
'h': ['--help']
@@ -31,6 +33,7 @@ if (options.help || options.argv.remain.length === 0) {
3133
console.log("Options:")
3234
console.log(" -h --help Print this help and exit.");
3335
console.log(" -o --output <file> Output result to file.");
36+
console.log(" -s --schema <directory> Directory containing json schema output files.");
3437
console.log(" -e --environment <file> The output file for the Postman environment.");
3538
console.log(" -t --testTemplate <template.hbs> The postman test template to use for each action.");
3639
process.exit();
@@ -41,6 +44,9 @@ const collectionFile = options.output || 'API.postman_collection.json';
4144
const environmentFile = options.environment || 'API.postman_environment.json';
4245
const includePath = input ? path.dirname(input) : process.cwd();
4346
var apibData = '';
47+
if (!options.schema) {
48+
options.schema = 'schema';
49+
}
4450

4551
fs.createReadStream(input).on('data', (chunk) => {
4652
apibData += chunk;

Diff for: package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@apib/2postman",
33
"description": "Convert API Blueprints to Postman Collections",
44
"author": "Johnson Controls, Plc.",
5-
"version": "1.2.0",
5+
"version": "1.2.1",
66
"license": "BSD",
77
"dependencies": {
88
"apib-include-directive": "^0.1.0",
@@ -11,7 +11,8 @@
1111
"handlebars": "^4.0.11",
1212
"lodash": "^4.17.10",
1313
"nopt": "^3.0.6",
14-
"uritemplate": "^0.3.4"
14+
"uritemplate": "^0.3.4",
15+
"mkdir-recursive": "^0.4.0"
1516
},
1617
"bin": {
1718
"apib2postman": "./bin/apib2postman.js"

Diff for: src/index.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const _ = require('lodash'),
33
UriTemplate = require('uritemplate'),
44
Handlebars = require('handlebars'),
55
postmanGenerator = require('./generators/postman'),
6+
fx = require('mkdir-recursive');
67
fs = require('fs');
78

89
Handlebars.registerHelper('json', function (obj) {
@@ -23,20 +24,16 @@ function apib2postman(apib, options) {
2324
};
2425

2526
addEnvVariables(environment.values, ['base_url', 'username', 'password', 'include_sad_tests']);
26-
const schemaDir = 'schema';
27-
if (!fs.existsSync(schemaDir)){
28-
fs.mkdirSync(schemaDir);
29-
}
3027

3128
apib.content[0].content
3229
.filter(content => content.element === 'category')
3330
.forEach(category => {
3431
const title = category.meta.title;
3532
const groups = [];
3633

37-
const schemaGroupDir = schemaDir + '/' + title;
34+
const schemaGroupDir = options.schema + '/' + title;
3835
if (!fs.existsSync(schemaGroupDir)){
39-
fs.mkdirSync(schemaGroupDir);
36+
fx.mkdirSync(schemaGroupDir);
4037
}
4138

4239
category.content

0 commit comments

Comments
 (0)