forked from scrive/openapi2slate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·49 lines (43 loc) · 1.19 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
var program = require('commander');
var SwaggerParser = require('swagger-parser');
var openapi2slate = require('./openapi2slate.js');
program
.arguments('<file>')
.option('--validate', 'Validate the API')
.option('--include-internal', 'Include Internal API calls')
.action(function(file) {
apiFilePath = file;
});
program.parse(process.argv);
if(typeof apiFilePath === 'undefined') {
console.error('No file given!');
process.exit(1);
}
if(program.validate) {
SwaggerParser.validate(apiFilePath)
.then(function(api) {
console.log(api.info.title);
})
.catch(function(err) {
console.error('The API is invalid: ' + err.message);
});
}
SwaggerParser.bundle(apiFilePath)
.then(function(api) {
openapi2slate.printSlateMarkdown(api, program.includeInternal);
})
.catch(function(err) {
if (typeof err === 'object') {
if (err.message) {
console.error('\nMessage: ' + err.message)
}
if (err.stack) {
console.error('\nStacktrace:')
console.error('====================')
console.error(err.stack);
}
} else {
console.error('dumpError :: argument is not an object');
}
});