Skip to content

Commit

Permalink
Add mock command
Browse files Browse the repository at this point in the history
  • Loading branch information
gkoberger committed Aug 3, 2016
1 parent 823e862 commit d852e54
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"host": {
"url": "http://apis.host"
},
"mock": {
"url": "http://mock.local:3020"
}
}
43 changes: 43 additions & 0 deletions lib/mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var _ = require('lodash');
var request = require('request');

exports.swagger = true;
exports.login = true;

/*
* This will completely change 100%, and all files
* uploaded to apis.host will be removed! It's just
* a placeholder to kinda have something that works.
*/

exports.run = function(config, info) {
console.log('Uploading Swagger file...');

request.post(config.mock.url + '/upload', {
'form': {
'swagger': JSON.stringify(info.swagger),
},
json: true
}, function(err, res, data) {
var samples = [];
_.each(info.swagger.paths, function(types, path) {
_.each(types, function(endpoint, type) {
if(['get', 'post'].indexOf(type.toLowerCase()) >= 0) {
samples.push([type, path]);
}
});
});

console.log("Success!".green.bold + " You now have an API you can test against:");
console.log("");
console.log(" " + data.url);
console.log("");
if(samples.length) {
console.log("Here's some example URLs you can try:");
console.log("");
_.each(samples, function(s) {
console.log((" ["+s[0] +"] " + data.url + (info.swagger.basePath || "") + s[1]).grey);
});
}
});
};

0 comments on commit d852e54

Please sign in to comment.