Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I wanted to convert a postman file to openAPI 3.0 using Node js [closed]

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.

like image 259
Lakshmi Ganeshan Avatar asked Sep 04 '25 16:09

Lakshmi Ganeshan


1 Answers

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

like image 96
Tharani Karunathilaka Avatar answered Sep 07 '25 08:09

Tharani Karunathilaka