一句话:提出 Respector,用静态与符号分析从源码自动生成 REST API 规范。
Web API 允许服务通过网络访问,其中 REST API 常使用 OpenAPI 等标准规范来描述。然而,从源码手工编写和维护这些规范耗时且易错,软件演化更会导致规范不完整或不一致,从而影响 API 的使用与测试。本文提出 Respector,首个利用静态与符号程序分析从 REST API 源码生成规范的技术。它推断端点方法、端点参数、方法响应以及参数属性,包括导致成功 HTTP 响应或错误的约束。作者在 15 个真实 API 上评估,端点方法、参数、响应和参数属性的推断取得较好的精确率与召回率。与开发者提供的规范对比,Respector 发现许多缺失的端点方法、参数、约束和响应,以及 API 实现与规范间的不一致;同时优于基于注解或直接调用 API 的规范推断技术。
Web Application Programming Interfaces (APIs) allow services to be accessed over the network. RESTful (or REST) APIs, which use the REpresentation State Transfer (REST) protocol, are a popular type of web API. To use or test REST APIs, developers use specifications written in standards such as OpenAPI. However, creating and maintaining these specifications is time-consuming and error-prone, especially as software evolves, leading to incomplete or inconsistent specifications that negatively affect the use and testing of the APIs. To address this problem, we present Respector (REST API specification generator), the first technique to employ static and symbolic program analysis to generate specifications for REST APIs from their source code. We evaluated Respector on 15 real-world APIs with promising results in terms of precision and recall in inferring endpoint methods, endpoint parameters, method responses, and parameter attributes, including constraints leading to successful HTTP responses or errors. Furthermore, these results could be further improved with additional engineering. Comparing the Respector-generated specifications with the developer-provided ones shows that Respector was able to identify many missing end-point methods, parameters, constraints, and responses, along with some inconsistencies between developer-provided specifications and API implementations. Finally, Respector outperformed several techniques that infer specifications from annotations within API implementations or by invoking the APIs.