简体   繁体   English

如何在 SwaggerHub 中记录要模拟的 api 调用?

[英]How to record api calls to mock in SwaggerHub?

I want to mock api calls from my application, and host the mock, so my tests can work without calls to real api.我想从我的应用程序模拟 api 调用,并托管模拟,所以我的测试可以在不调用真正的 api 的情况下工作。 There is a service called restbird which does exactly that, but it is far from ideal for me.有一个名为 restbird 的服务可以做到这一点,但它对我来说远非理想。 If you want to collaborate you have to host the service by your self.如果你想合作,你必须自己托管服务。 Also it has some errors like not displaying history of calls, or when it sends server errors for no reason.它还有一些错误,例如不显示呼叫历史记录,或者无缘无故发送服务器错误。 I want a service more robust than this one.我想要一种比这个更强大的服务。

The only service that I think might be a good fit is SwaggerHub, it seems robust, it has virtual servers, and overall it is very popular.我认为唯一适合的服务是 SwaggerHub,它看起来很健壮,它有虚拟服务器,总体来说它很受欢迎。 But the only problem is that I cannot find a way to record api calls from my application.但唯一的问题是我找不到从我的应用程序记录 api 调用的方法。 So how can I record api calls for SwaggerHub?那么如何记录 SwaggerHub 的 api 调用?

There does not currently exist any functionality within SwaggerHub itself to record API calls made from the Swagger UI module within the tool. SwaggerHub 本身目前不存在任何功能来记录从工具内的 Swagger UI 模块进行的 API 调用。 This is a limitation of the open-source Swagger UI tool.这是开源 Swagger UI 工具的限制。

What I can recommend is you use the Swagger Inspector tool.我可以推荐的是您使用 Swagger Inspector 工具。 The Swagger Inspector can be used to make API calls from a client, save both the request and the response, and even generate an OpenAPI file for you based off the request/responses. Swagger Inspector 可用于从客户端进行 API 调用,保存请求和响应,甚至根据请求/响应为您生成 OpenAPI 文件。 If you create an account and sign in, you can even save your API calls to a collection to use later.如果您创建帐户并登录,您甚至可以将 API 调用保存到collection中以供以后使用。

Swagger Inspector: https://inspector.swagger.io/builder Swagger 检查员: https://inspector.swagger.io/builder

It may also be worth considering using ReadyAPI's Virtualization module to handle this use case.也可能值得考虑使用 ReadyAPI 的虚拟化模块来处理这个用例。 With ReadyAPI Virtualization you can record transactions from a browser, build mock services from the recorded transaction or an existing API definition, and then host the mock service using VirtServer.使用 ReadyAPI 虚拟化,您可以从浏览器记录事务,从记录的事务或现有的 API 定义构建模拟服务,然后使用 VirtServer 托管模拟服务。

ReadyAPI is a part of SmartBears API lifecycle products, so there are integrations between the two tools. ReadyAPI 是 SmartBears API 生命周期产品的一部分,因此这两个工具之间存在集成。 For instance, you can port APIs from Swaggerhub into ReadyAPI directly and you can use mock services built in ReadyAPI to do dynamic mocking in Swaggerhub.例如,您可以将 API 从 Swaggerhub 直接移植到 ReadyAPI 中,您可以使用 ReadyAPI 内置的模拟服务在 Swaggerhub 中进行动态 mocking。

You can find more information about ReadyAPI Virtualization here: https://smartbear.com/product/ready-api/api-virtualization/您可以在此处找到有关 ReadyAPI 虚拟化的更多信息: https://smartbear.com/product/ready-api/api-virtualization/

I realise this is a very late response to this thread, but hopefully this information comes in handy.我意识到这是对这个线程的一个很晚的回应,但希望这些信息能派上用场。

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

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