Skip to content

Instantly share code, notes, and snippets.

@loopDelicious
Last active February 6, 2023 13:27
Show Gist options
  • Save loopDelicious/590430a11470e9bddd1840c428695b4a to your computer and use it in GitHub Desktop.
Save loopDelicious/590430a11470e9bddd1840c428695b4a to your computer and use it in GitHub Desktop.
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();
@maxiptah
Copy link

maxiptah commented Feb 6, 2023

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment