我想使用Node js将一个postman文件转换为openAPI 3.0 [已关闭]

8yoxcaq7  于 2023-08-05  发布在  Postman
关注(0)|答案(2)|浏览(138)

已关闭。此问题需要更多focused。它目前不接受回答。
**希望改进此问题?**更新问题,使其仅针对editing this post的一个问题。

去年关闭。
Improve this question
你能帮我把Postman文件转换成openAPI 3.0并下载到机器上吗?
这必须在Node.js中实现,我对它非常陌生。

  • 谢谢-谢谢
xe55xuns

xe55xuns1#

我想你可以使用这个npm库。https://www.npmjs.com/package/postman-to-openapi它会解决你的问题。
下面是一个示例代码。你可以根据你的代码修改它。

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/
最后,要下载文件,您可以使用JavaScript文件下载器。使用下面的链接。https://www.npmjs.com/package/js-file-download

hl0ma9xz

hl0ma9xz2#

你可以在postmantoopenapispec.com上上传Postman Collection文件,它会返回一个OpenApi规范。

相关问题