Last active
February 6, 2023 13:27
-
-
Save loopDelicious/590430a11470e9bddd1840c428695b4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
Converter = require('swagger2-postman2-converter'); | |
function handleConversion(originalFileName, newFileName) { | |
// read the local swagger file | |
var swaggerObject = JSON.parse( | |
fs.readFileSync(originalFileName, 'utf8') | |
); | |
// convert Swagger 2.0 to Postman 2.0 | |
var conversionResult = Converter.convert(swaggerObject); | |
// create a new local file in Postman v2.0 format | |
fs.writeFileSync(newFileName, JSON.stringify(conversionResult.collection, null, 2)); | |
console.log('Converted ' + originalFileName + ' to ' + newFileName); | |
} | |
handleConversion(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It requires arguments passed to the script.
Change the last line to
handleConversion(process.argv[2], process.argv[3]);
(these would be not system arguments you pass)and call it like `node converter.js "path from" "new file name"