-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-gen.js
executable file
·55 lines (41 loc) · 1.29 KB
/
api-gen.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
50
51
52
53
54
55
#! /usr/bin/env node
var type = 'angular';
var fs = require('fs');
var CodeGen = require('swagger-js-codegen').CodeGen;
var request = require('request');
var gen = function(url,dest,className){
request(url, function (error, response, body) {
if (error) {
console.error("Error fetching "+url);
console.error(error);
return;
}
if (!error && response.statusCode == 200) {
//console.log(body);
var swagger = JSON.parse(body);
var code = null;
if (type=='angular') {
// code = CodeGen.getAngularCode({ className: className, swagger: swagger });
code = CodeGen.getCustomCode({
moduleName:className,
className:className,
swagger:swagger,
template:{
class: fs.readFileSync('./template/angular-class.mustache', 'utf-8'),
method: fs.readFileSync('./template/method.mustache', 'utf-8'),
request: fs.readFileSync('./template/angular-request.mustache','utf-8')
}
});
} else {
code = CodeGen.getNodeCode({ className: className, swagger: swagger });
}
fs.writeFile(dest, code, function(err) {
if(err) {
return console.error(err);
}
});
}
});
}
// gen(url,dest,className);
exports.gen = gen;