swagger

Swagger在.Net Core 2.0与Core 2.2中的区别

﹥>﹥吖頭↗ 提交于 2020-12-13 07:08:04
最近要做个简单服务并且需要对外开放几个Web API,之前做项目用过.Net Core 1.0和2.0,去年12月份微软正式发布了.Net Core 2.2版本,所以这次项目框架就选择了.Net Core 2.2。API很简单,写完后需要和其他同事做对接,自然而然直接使用Swagger来做API的文档。.Net Core版本的Swagger就是这个库喽 Swashbuckle.AspNetCore 因为之前在Core 1.0和2.0中一直使用Swagger(1.0和2.0在Swagger的用法上也是有一些不同),所以直接Copy .Net Core2.0项目中Swagger使用的代码到2.2版本中,如下图 发现这边报错了,可以看出 PlatformServices 这个对象找不到了,猜测可能是Core 2.2版本中移除了这个对象。 我们回到2.0的项目中查找下 PlatformServices 这个对象到底是在哪个程序集里面 原来这个对象是在上图这个程序集里面,Copy了程序集名字去2.2里面一搜,果然没有,那就简单了,直接安装一下这个 Microsoft.Extensions.PlatformAbstractions 完事。 当然2.2可是2.0的升级版,丢了这个程序集,那肯定是有更好的写法去代替,无非就是获取一些路径,这种最最基础的方法肯定是有的啦,那么就有了下面的替代方法

Can't setup swagger - Cannot read property 'parameters' of undefined

陌路散爱 提交于 2020-12-13 04:12:33
问题 I am having a problem with setting up the swagger into my node.js application. I am using swagger-jsdoc and swagger-ui-express for creating documentation. Here are the versions "swagger-jsdoc": "3.5.0", "swagger-ui-express": "4.1.3" Below is the configs, which I pass to swagger-jsdoc. openapi: 3.0.0 info: description: test version: 3.0.0 title: U-CRM api documentation termsOfService: http://swagger.io/terms/ servers: - url: 'https://localhost:5000' description: Local server tags: - name: U

How to declare binary data response content-type correctly?

喜夏-厌秋 提交于 2020-12-13 03:28:42
问题 For a web application I am working on, I need to fetch some binary (meta) data for an audio file. This is how the endpoint looks like: @RequestMapping( value = "/tracks/{trackId}/metadata", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE ) @ApiResponse( description = "Successful Operation", responseCode = "200", content = @Content(mediaType = MediaType.APPLICATION_OCTET_STREAM_VALUE) ) public StreamingResponseBody getTrackMetadata(@PathVariable("trackId") Long

Swashbuckle polymorphism support issue

最后都变了- 提交于 2020-12-12 11:56:32
问题 I am using Swashbuckle v3.0. I am not sure weather this is a bug or not, but polymorphism is not working as it should. I have the following classes: BasePersonDocumentDto { Id, Number } IdentityDto: BasePersonDocumentDto { } PassportDto: BasePersonDocumentDto { VisaNumber } To apply Inheritance & Polymorphism, i have created a schema and document filters. I followed this answer Below are the code i used. public class PolymorphismSchemaFilter<T> : ISchemaFilter { private List<Type>

Swagger: Dynamic Schema

女生的网名这么多〃 提交于 2020-12-12 07:35:04
问题 I'm having difficulty understanding the correct way to include validation information in a swagger file, when the validation logic can be dynamic (default, minValue, maxValue, etc.). Consider the following example: In a banking application, we a have a REST API for withdrawals. The withdrawal amount cannot be greater than the account value of the person taking the withdrawal. This value is going to depend on the context (Who's bank account we are withdrawing from) to get that maximum value.

Swagger: Dynamic Schema

女生的网名这么多〃 提交于 2020-12-12 07:33:42
问题 I'm having difficulty understanding the correct way to include validation information in a swagger file, when the validation logic can be dynamic (default, minValue, maxValue, etc.). Consider the following example: In a banking application, we a have a REST API for withdrawals. The withdrawal amount cannot be greater than the account value of the person taking the withdrawal. This value is going to depend on the context (Who's bank account we are withdrawing from) to get that maximum value.

Swagger: Dynamic Schema

允我心安 提交于 2020-12-12 07:33:12
问题 I'm having difficulty understanding the correct way to include validation information in a swagger file, when the validation logic can be dynamic (default, minValue, maxValue, etc.). Consider the following example: In a banking application, we a have a REST API for withdrawals. The withdrawal amount cannot be greater than the account value of the person taking the withdrawal. This value is going to depend on the context (Who's bank account we are withdrawing from) to get that maximum value.

软件测试开发实战|接口自动化测试框架开发(pytest+allure+aiohttp+用例自动生成)

寵の児 提交于 2020-12-11 08:41:36
近期准备优先做接口测试的覆盖,为此需要开发一个测试框架,经过思考,这次依然想做点儿不一样的东西。 接口测试是比较讲究效率的,测试人员会希望很快能得到结果反馈,然而接口的数量一般都很多,而且会越来越多,所以提高执行效率很有必要 接口测试的用例其实也可以用来兼做简单的压力测试,而压力测试需要并发 接口测试的用例有很多重复的东西,测试人员应该只需要关注接口测试的设计,这些重复劳动最好自动化来做 pytest和allure太好用了,新框架要集成它们 接口测试的用例应该尽量简洁,最好用yaml,这样数据能直接映射为请求数据,写起用例来跟做填空题一样,便于向没有自动化经验的成员推广 加上我对Python的协程很感兴趣,也学了一段时间,一直希望学以致用,所以http请求我决定用aiohttp来实现。 但是pytest是不支持事件循环的,如果想把它们结合还需要一番功夫。于是继续思考,思考的结果是其实我可以把整个事情分为两部分。 第一部分,读取yaml测试用例,http请求测试接口,收集测试数据。 第二部分,根据测试数据,动态生成pytest认可的测试用例,然后执行,生成测试报告。 这样一来,两者就能完美结合了,也完美符合我所做的设想。想法既定,接着 就是实现了。 第一部分(整个过程都要求是异步非阻塞的) 读取yaml测试用例 一份简单的用例模板我是这样设计的,这样的好处是,参数名和aiohttp

API管理的重要性

佐手、 提交于 2020-12-10 04:13:22
在API应用如此广泛的今天,API管理已经成为产品开发的重要组成部分,如果没有API管理,程序可能会遇到许多有关于安全或稳定的问题。API管理的范围非常广,不仅需要确保API的安全性与稳定性,还需要提供出色的API文档,可写作可分享等。 API管理的基础 API管理是指API的生命周期管理,这其中包括API的设计、开发、协作、测试(自动化测试)、发布、监控,最终成为产品,供用户使用。API管理服务是API开发者和API用户之间代理,为开发者提供了使用情况报告、测试分析报告,为用户提供了API的文档、示例等。 为什么需要管理API 一旦程序上线API就会被使用,想开发并使用好API,有必要对API进行管理,而想做好API管理,选择一个API管理工具是一个不错的选择。如果团队没有一套API管理系统支持,很可能无法及时发现API的异常,难于控制API的版本或分析API的安全性或性能。 合适的工具 如何判断API管理工具的好坏,要从多个方面了解。首先,该工具应该提供易读且全面的API文档,强大的测试功能,容易上手,可分配不同的身份权限…… 下面列举了几个能提供强大管理服务的API管理工具(本文使用eolinker演示): Swagger:具有基于云的API管理和分析功能,并提供了开发人员和合作伙伴门户。 Postman:提供旨在提供简单API设计以及高级集成和测试功能的开源解决方案。

为什么需要使用api文档

女生的网名这么多〃 提交于 2020-12-06 18:39:37
什么是API文档? API文档是一份可交付的技术内容,其中包含有关如何有效使用和集成API的说明。这也是一本简单明了的参考手册,编写了使用API所需的所有信息,以及有关功能、返回类型、参数等详细信息,并提供了教程和示例支持。 API文档通常由常规的内容创建和维护工具以及文本编辑器完成的。例如 Swagger、eolinker规范之类的API描述格式已经自动化了文档处理过程,从而使团队可以更轻松地生成和维护API。 第三方开发人员是API的主要用户,正忙于解决复杂的编程难题。API是技术用户达到目的的一种手段,他们希望尽快集成推进他们的软件开发,这意味着他们应该快速了解你的API的价值和用途。开发人员在发现、学习使用并最终与API集成时所积累的经验称为开发人员经验。API文档是获得出色开发人员经验的关键。 为什么要使用文档API? 在API生命周期的所有阶段中,文档可能是增长最快的领域。对于围绕文档的工具生态系统尤其如此。注意到这一趋势很有趣,因为从传统上讲,文档是开发人员在编写代码时很少关注的东西。实际上,实现代码比编写良好的文档要容易得多。 提高用户使用率 拥有良好的API文档的一个重要原因是,它改善了开发人员使用API的体验,这与API的采用直接相关。如果API文档正确无误,那么更多的人将很容易在提供的服务中发现价值,从而可以更好地发展和采用。 节省支持时间和成本