gpt4 book ai didi

api - 当我将 Swagger API 导入 Postman 时,Postman GUI 中的所有请求名称都为空白

转载 作者:行者123 更新时间:2023-12-04 21:30:37 24 4
gpt4 key购买 nike

我是质量工程师。开发团队使用 Swagger 为我们产品的 RESTful API 生成文档。我需要将其导入 Postman,以便轻松调用产品的 API。

将 JSON 文件(Swagger 格式)导入 Postman 后,有 1 个大问题:单个请求的所有标题(和描述)都是空白的! (见下面的屏幕截图)。

enter image description here

显然,这是一个已知问题,记录在此处:https://github.com/postmanlabs/postman-app-support/issues/1434

我们实际上有数百个请求。我需要找到一种足够有效但简单的方法来确保 Postman 中的所有请求标题都填充有我想即时计算的值。

我一直在考虑以下方法:

Write a command line tool (using NodeJS or another solid platform) which will receive: 1. ID of the collection to fix 2. api key

It will iterate through all requests in the collection. For each request: if Name field is blank, then a substring of the request URL will be assigned to the Name field; if name is not blank, the request is left alone.

What I am unsure about:

  1. Can I do this programmatically from Postman? It does not make sense to put this code into any one individual request (as pre or post).

(If I have to code this util outside of Postman)

  1. For NodeJS there are "postman-collection" and "postman-sdk" but I am slightly confused which I should use.

  2. Unfortunately, I have not yet found any suitable > library for maintaining Postman collections using C# > or Java.



坦率地说,我对可用的选项感到困惑。任何指导将不胜感激。

最佳答案

我遇到了同样的问题,感谢 Ian T Price 解决方案(只需将 operationId 值复制到新键 summary 中)。我决定为此编写一个小 javascript 实用程序:

function swagPostman(swaggerJson) {
for (let path in swaggerJson.paths) {
let methods = ["get", "head", "post", "put", "delete", "connect", "options", "trace", "patch"];

methods.map(method => {
if ((swaggerJson.paths[path] || {})[method]) {
swaggerJson.paths[path][method].summary =
swaggerJson.paths[path][method].operationId;
}
});
}

return JSON.stringify(swaggerJson);
}

还制作了一个简单的笔,用于使用 GUI 运行脚本: https://codepen.io/0x616c65/full/pMaQpb .您只需将您的 swagger.json 文件复制粘贴到那支笔中,然后woilà!

关于api - 当我将 Swagger API 导入 Postman 时,Postman GUI 中的所有请求名称都为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53142356/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com