Can you please help me out in converting a Postman file to openAPI 3.0 and download them to machine?
This has to be implemented in Node.js and I am very new to it.
Thanks.
Can you please help me out in converting a Postman file to openAPI 3.0 and download them to machine?
This has to be implemented in Node.js and I am very new to it.
Thanks.
I think you can use this npm library. https://www.npmjs.com/package/postman-to-openapi It will solve your problem.
There's a sample code as below. you can change it according to your code.
const postmanToOpenApi = require('postman-to-openapi')
const postmanCollection = './path/to/postman/collection.json'
const outputFile = './api/collection.yml'
// Async/await
try {
const result = await postmanToOpenApi(postmanCollection, outputFile, { defaultTag: 'General' })
// Without save the result in a file
const result2 = await postmanToOpenApi(postmanCollection, null, { defaultTag: 'General' })
console.log(`OpenAPI specs: ${result}`)
} catch (err) {
console.log(err)
}
// Promise callback style
postmanToOpenApi(postmanCollection, outputFile, { defaultTag: 'General' })
.then(result => {
console.log(`OpenAPI specs: ${result}`)
})
.catch(err => {
console.log(err)
})
you can find more details at this link. https://joolfe.github.io/postman-to-openapi/
finally, to download the file, you can use the Javascript file downloader. Use the link below. https://www.npmjs.com/package/js-file-download
you can just upload the Postman Collection file on postmantoopenapispec.com and it returns an OpenApi spec.