简体   繁体   English

如何从 Swagger 更新 Postman 集合

[英]How to update Postman collection from Swagger

I use Swagger in a Java app and have a collection that sets the parameters eg uuid, name on the corresponding POST requests.我在 Java 应用程序中使用 Swagger,并有一个集合来设置参数,例如 uuid、相应 POST 请求上的名称。 However,on every changes on database, the collections should be updated and I fed up with updating the Postman collections manually.但是,在数据库的每次更改中,都应该更新集合,我厌倦了手动更新 Postman 集合。 I could not found a proper way except from some export approach eg Convert Swagger documentation to Postman Collection .除了从某些导出方法(例如将 Swagger 文档转换为 Postman Collection )之外,我找不到合适的方法。

In this stage, I think I make something wrong and there is a better approach as lots of experienced developers use these tools :在这个阶段,我认为我做错了,并且有一个更好的方法,因为许多有经验的开发人员使用这些工具:

1. How should I transfer swagger requests to Postman and set the parameters while GET requests and use them while POST/PUT requests? 1.我应该如何将swagger请求传递给Postman并在GET请求时设置参数并在POST/PUT请求时使用它们?

2. How can I update these requests whenever the request parameters are changed on Swagger? 2. Swagger 上的请求参数发生变化时,如何更新这些请求?

Postman offers the ability to have a 2-way API sync with your Git Repo. Postman 提供了与您的 Git 存储库进行 2 向 API 同步的能力。 Update the Git repo with the new OpenAPI spec.使用新的 OpenAPI 规范更新 Git 存储库。 Postman will see the diffs and allow you to pull in the new changes Then you can push the changes to your collections How to Connect to Your Git Repository (4min) Using an External Git Repository (Docs) Postman 将看到差异并允许您引入新的更改然后您可以将更改推送到您的集合如何连接到您的 Git 存储库(4 分钟) 使用外部 Git 存储库(文档)

Postman has an manual option to import open-api. Postman 有一个手动选项来导入 open-api。 But in your case you need a utility.但在您的情况下,您需要一个实用程序。 Thankfully postman team has written a converter.幸运的是邮递员团队已经编写了一个转换器。

Postman provides an open source project to convert OpenAPI 3.0 specs to the Postman Collection (v2) . Postman 提供了一个开源项目来将OpenAPI 3.0 规范转换为 Postman Collection (v2)

It provides a CLI openapi2postmanv2它提供了一个 CLI openapi2postmanv2

$ openapi2postmanv2 -s spec.yaml -o collection.json -p -O folderStrategy=Tags,includeAuthInfoInExample=false

Add it to your build process, so you dont have to manually convert.将它添加到您的构建过程中,因此您不必手动转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM