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();
@SliimTechnologies
Copy link

Hi!
when i run node converter.js i get this exception

node:internal/fs/utils:670
throw new ERR_INVALID_ARG_TYPE(propName, ['string', 'Buffer', 'URL'], path);
^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
at Object.openSync (node:fs:577:10)
at Object.readFileSync (node:fs:453:35)
at handleConversion (D:\Produits\Angular\Shyne\Application\Api\api\converter.js:8:12)
at Object. (D:\Produits\Angular\Shyne\Application\Api\api\converter.js:20:1)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'ERR_INVALID_ARG_TYPE'

@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