3

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.

Helen
  • 87,344
  • 17
  • 243
  • 314
  • OpenAPI is a standard. It is not clear what you're trying to do here. – Parth Shah Jul 10 '20 at 06:02
  • 1
    Thanks for the reply!! Is there anyway to convert a postman collection to a swagger file? This module appears to say that it is possible: https://github.com/stoplightio/api-spec-converter .. We currently support only swagger and not postman collections. So, when an end user tries to upload a postman file for API Testing it will fail as we need to convert them to swagger and then proceed. – Lakshmi Ganeshan Jul 10 '20 at 06:05
  • I have a converter APIMATic API Transfromer which will do it for me but I want to implement it myself than depending on converter. – Lakshmi Ganeshan Jul 10 '20 at 06:11
  • Does [this](https://stackoverflow.com/questions/31299098/how-can-i-generate-swagger-based-off-of-existing-postman-collection) answer your question? – Parth Shah Jul 10 '20 at 06:21
  • Thanks but I have tried even this piece of code and got a partial output: { swagger: '2.0', info: { version: '', title: undefined, description: '' }, paths: {}, definitions: {} } – Lakshmi Ganeshan Jul 10 '20 at 06:25
  • You can use postman to Open Api online tool https://www.workversatile.com/postman-to-swagger – Arshad Shaikh Aug 16 '22 at 11:47

2 Answers2

7

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

0

you can just upload the Postman Collection file on postmantoopenapispec.com and it returns an OpenApi spec.

tonaes
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 12 '22 at 09:26