Skip to content

Commit d852e54

Browse files
committed
Add mock command
1 parent 823e862 commit d852e54

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

config/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"host": {
33
"url": "http://apis.host"
4+
},
5+
"mock": {
6+
"url": "http://mock.local:3020"
47
}
58
}

lib/mock.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var _ = require('lodash');
2+
var request = require('request');
3+
4+
exports.swagger = true;
5+
exports.login = true;
6+
7+
/*
8+
* This will completely change 100%, and all files
9+
* uploaded to apis.host will be removed! It's just
10+
* a placeholder to kinda have something that works.
11+
*/
12+
13+
exports.run = function(config, info) {
14+
console.log('Uploading Swagger file...');
15+
16+
request.post(config.mock.url + '/upload', {
17+
'form': {
18+
'swagger': JSON.stringify(info.swagger),
19+
},
20+
json: true
21+
}, function(err, res, data) {
22+
var samples = [];
23+
_.each(info.swagger.paths, function(types, path) {
24+
_.each(types, function(endpoint, type) {
25+
if(['get', 'post'].indexOf(type.toLowerCase()) >= 0) {
26+
samples.push([type, path]);
27+
}
28+
});
29+
});
30+
31+
console.log("Success!".green.bold + " You now have an API you can test against:");
32+
console.log("");
33+
console.log(" " + data.url);
34+
console.log("");
35+
if(samples.length) {
36+
console.log("Here's some example URLs you can try:");
37+
console.log("");
38+
_.each(samples, function(s) {
39+
console.log((" ["+s[0] +"] " + data.url + (info.swagger.basePath || "") + s[1]).grey);
40+
});
41+
}
42+
});
43+
};

0 commit comments

Comments
 (0)