From d852e545d67eeb51cdc77876c0435dafeddb6f9e Mon Sep 17 00:00:00 2001 From: Gregory Koberger Date: Wed, 3 Aug 2016 14:35:47 -0700 Subject: [PATCH] Add mock command --- config/config.json | 3 +++ lib/mock.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 lib/mock.js diff --git a/config/config.json b/config/config.json index 29ad2c5ac..8f3e94b52 100644 --- a/config/config.json +++ b/config/config.json @@ -1,5 +1,8 @@ { "host": { "url": "http://apis.host" + }, + "mock": { + "url": "http://mock.local:3020" } } diff --git a/lib/mock.js b/lib/mock.js new file mode 100644 index 000000000..e36f43995 --- /dev/null +++ b/lib/mock.js @@ -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); + }); + } + }); +};