我想使用 Node js 将邮递员文件转换为 openAPI 3.0 [英] I wanted to convert a postman file to openAPI 3.0 using Node js
问题描述
您能帮我将 Postman 文件转换为 openAPI 3.0 并将它们下载到机器上吗?
Can you please help me out in converting a Postman file to openAPI 3.0 and download them to machine?
这必须在 Node.js 中实现,我对它很陌生.
This has to be implemented in Node.js and I am very new to it.
谢谢.
推荐答案
我认为你可以使用这个 npm 库.https://www.npmjs.com/package/postman-to-openapi它会解决你的问题.
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)
})
您可以在此链接中找到更多详细信息.https://joolfe.github.io/postman-to-openapi/
you can find more details at this link. https://joolfe.github.io/postman-to-openapi/
最后,要下载文件,您可以使用 Javascript 文件下载器.使用下面的链接.https://www.npmjs.com/package/js-file-download
finally, to download the file, you can use the Javascript file downloader. Use the link below. https://www.npmjs.com/package/js-file-download
这篇关于我想使用 Node js 将邮递员文件转换为 openAPI 3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!