arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2402.05102cs.SE
收藏

You Can REST Now:基于LLM辅助请求变异的自动化REST API文档生成与测试

You Can REST Now: Automated REST API Documentation and Testing via LLM-Assisted Request Mutations

Alix Decrop, Xavier Devroey, Mike Papadakis, Pierre-Yves Schobbens, Gilles Perrouin

AI总结:

本文提出RESTSpecIT,一种利用LLM自动推断REST API文档并进行黑盒测试的方法,通过生成和变异API请求种子,在最少用户输入下实现高效文档推断与测试辅助。

摘要:

REST API在Web服务实现中十分普遍,通过HTTP协议简化了互操作性。API测试人员和用户利用广泛采用的OpenAPI Specification (OAS),这是一种用于记录REST API的机器可读标准。然而,记录API是一项耗时且容易出错的任务,现有文档并不总是完整、公开可访问或最新的。这种情况限制了测试工具的效率,并阻碍了人类的理解。大型语言模型(LLMs)利用其庞大的训练数据,提供了自动推断API文档的潜力。在本文中,我们提出了RESTSpecIT,这是第一个通过利用LLMs来推断文档并对REST API执行黑盒测试的自动化方法。与最先进的工具相比,我们的方法需要最少的用户输入;给定一个API名称和一个LLM访问密钥,RESTSpecIT生成API请求种子,并使用LLM返回的数据对其进行变异。然后,该工具分析API响应,以用于文档推断和测试目的。RESTSpecIT利用上下文提示掩码策略,无需先前的模型微调。我们使用三个最先进的LLMs评估了我们工具的质量:DeepSeek V3、GPT-4.1和GPT-3.5。我们的评估表明,RESTSpecIT能够(1)推断文档,平均找到88.62%的路由和89.25%的查询参数,(2)发现未记录的API数据,(3)高效运行(在模型成本、发送的请求、运行时方面),以及(4)通过发现服务器错误并为测试工具生成有效的OpenAPI Specification输入来协助REST API测试。

英文摘要:

REST APIs are prevalent among web service implementations, easing interoperability through the HTTP protocol. API testers and users exploit the widely adopted OpenAPI Specification (OAS), a machine-readable standard to document REST APIs. However, documenting APIs is a time-consuming and error-prone task, and existing documentation is not always complete, publicly accessible, or up-to-date. This situation limits the efficiency of testing tools and hinders human comprehension. Large Language Models (LLMs) offer the potential to automatically infer API documentation, using their colossal training data. In this paper, we present RESTSpecIT, the first automated approach that infers documentation and performs black-box testing of REST APIs by leveraging LLMs. Our approach requires minimal user input compared to state-of-the-art tools; Given an API name and an LLM access key, RESTSpecIT generates API request seeds and mutates them with data returned by the LLM. The tool then analyzes API responses for documentation inference and testing purposes. RESTSpecIT utilizes an in-context prompt masking strategy, requiring no prior model fine-tuning. We evaluate the quality of our tool with three state-of-the-art LLMs: DeepSeek V3, GPT-4.1, and GPT-3.5. Our evaluation demonstrates that RESTSpecIT can (1) infer documentation with 88.62% of routes and 89.25% of query parameters found on average, (2) discover undocumented API data, (3) operate efficiently (in terms of model costs, requests sent, runtime), and (4) assist REST API testing by uncovering server errors and generating valid OpenAPI Specification inputs for testing tools.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑