From bbcaaaccdf069bbd2493d7edf0425cb790a02d79 Mon Sep 17 00:00:00 2001 From: Gregory Koberger Date: Mon, 3 Oct 2016 18:52:29 -0700 Subject: [PATCH] Add preliminary support for Postman --- lib/docs.js | 2 -- lib/try.js | 28 ++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 lib/try.js diff --git a/lib/docs.js b/lib/docs.js index 03c1c713e..5665854b2 100644 --- a/lib/docs.js +++ b/lib/docs.js @@ -5,8 +5,6 @@ exports.category = "services"; exports.desc = "Upload your docs to ReadMe ($)"; exports.run = function(config, info) { - console.log('Uploading Swagger file...'); - console.log("You can view your new docs here:"); console.log(""); console.log(" https://swagger.readme.io/preview/" + new Buffer(info.swaggerUrl).toString('base64')); diff --git a/lib/try.js b/lib/try.js new file mode 100644 index 000000000..b08ba11c5 --- /dev/null +++ b/lib/try.js @@ -0,0 +1,28 @@ +var Swagger2Postman = require('swagger2-to-postman'); + +exports.swagger = true; +exports.category = "services"; +exports.desc = "Open your Swagger file in Postman ($)"; + +exports.run = function(config, info) { + var swaggerConverter = new Swagger2Postman(); + //swaggerConverter.setLogger(console.log); // TODO! Add verbose mode? + + var convertResult = swaggerConverter.convert(info.swagger); + + if(convertResult.status === "failed") { + console.log("Error converting to Postman!".red); + if(convertResult.message) { + console.log(" " + convertResult.message); + } + return process.exit(); + } + + console.log("Success!".green + " Here's your Postman collection:"); + console.log(JSON.stringify(convertResult.collection, undefined, 2)); + + console.log(""); + console.log("Postman support is in beta.".yellow + " This doesn't quite do much yet, unfortunately!"); + + process.exit(); +}; diff --git a/package.json b/package.json index bbd376f76..d8b08fbec 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "request": "^2.73.0", "sinon-chai": "^2.8.0", "swagger-parser": "^3.4.1", + "swagger2-to-postman": "^1.1.0", "yamljs": "^0.2.8" }, "devDependencies": {