LRASGen: LLM-based RESTful API Specification Generation

Sida Deng, Rubing Huang, Man Zhang, Chenhui Cui, Dave Towey, Rongcun WangarXiv 2025

TL;DR

LRASGen is a new automated approach that uses Large Language Models (LLMs) to generate OpenAPI Specifications (OAS) directly from RESTful API source code. By leveraging the code-understanding capabilities of models like GPT-4o mini and DeepSeek V3, it outperforms traditional tools—especially when code is incomplete or missing the standard annotations that older tools rely on.

What Problem Does This Paper Address?

In modern web development, RESTful APIs are the backbone of communication. To use or test these APIs effectively, developers need a formal specification, typically an OpenAPI Specification (OAS). However, keeping these specs in sync with the actual source code is a notorious headache.

Manual updates are time-consuming and prone to human error. Existing automation tools like Swagger Core or Springdoc often require developers to add specific annotations to their code. If a developer forgets an annotation or if the code implementation is incomplete, these tools fail to generate an accurate spec. Furthermore, many current tools are "language-locked," working only for specific frameworks like Java's Spring Boot, leaving Python or C# developers with fewer options.

Methods

The authors introduce LRASGen (LLM-based RESTful API-Specification Generation), a six-step workflow designed to bridge the gap between messy source code and clean API documentation.

Fig. 1. Overview of the LRASGen approach

As shown in Figure 1, the process involves:

  1. Identifying Entry Files: Using framework-specific rules (like regex for Spring Boot annotations or Django configuration files) to find where endpoints are defined.
  2. Code Extraction & Cleaning: Recursively gathering all related code files while stripping away irrelevant lines to ensure the context fits within an LLM's token limits.
  3. Identifying Methods: Prompting the LLM to identify HTTP methods (GET, POST, etc.), paths, and method names.
  4. Identifying Parameters & Responses: Decomposing the details of what goes into a request and what comes out.
  5. Identifying Constraints: Using the LLM to infer logic-based constraints (like string length, ranges, or enums) that might not be explicitly stated in annotations but are present in the business logic.
  6. OAS Generation: Formatting all extracted data into a standardized OAS v3.1.1 JSON/YAML file.

The researchers tested two different LLMs—GPT-4o mini and DeepSeek V3—to power this engine, utilizing zero-shot and few-shot learning techniques to guide the models.

Datasets

The study evaluated LRASGen using 20 real-world RESTful APIs found on GitHub.

  • Java APIs: 15 projects using frameworks like Spring Boot and Jersey.
  • Python APIs: 4 projects using Flask, Django, and Web.py.
  • C# API: 1 project using ASP.NET Core.

The authors also introduced GT*, an enhanced "ground truth" benchmark. They manually audited the source code of these 20 APIs to identify every possible endpoint, parameter, and constraint, creating a more rigorous evaluation standard than the original developer-provided documentation.

Key Insights and Ideas

  • LLMs as "Code Archeologists": One of the most striking findings is that LLMs can "see" API behaviors that developers themselves forgot to document. LRASGen identified nearly 49% more entities (methods, parameters, etc.) than were present in the original developer-provided specifications.
  • Handling Incompleteness: Traditional static analysis tools break when code is partial or annotations are missing. Because LLMs understand the intent and logic of code, LRASGen can generate reasonable specifications even for incomplete implementations.
  • Cross-Language Versatility: Unlike traditional tools that are built for one specific language, LRASGen is largely language-agnostic. By simply adjusting the "entry file" identification rules, the same system successfully processed Java, Python, and C# code.
  • The "Constraint" Gap: Developers rarely document every parameter constraint (like a maximum value or a specific date format). LRASGen was particularly effective at inferring these from the code logic, where traditional tools found almost none.

Key Results

LRASGen demonstrated high accuracy across all tasks:

  • Java APIs: It achieved an average 99.46% precision and 99.99% recall for identifying endpoint methods, significantly outperforming state-of-the-art tools like Respector, Swagger Core, and Springdoc.
  • Comprehensive Coverage: While traditional tools only detected about 4.78% of parameter constraints and 26.75% of endpoint responses, LRASGen achieved 100% precision and recall in these categories for the tested Java APIs.
  • Efficiency: The average running time was roughly 6 to 9 minutes per API, making it a viable tool for continuous integration pipelines.
  • Python & C# Success: LRASGen achieved 100% precision and recall on the Python and C# APIs, where the baseline Java-centric tools could not run at all.

Limitations and Future Work

Despite its success, the authors noted a few hurdles:

  • Token Limitations: Very large projects still struggle with LLM context windows. While the cleaning step helps, extremely complex dependencies can lead to "information forgetting."
  • Prompt Sensitivity: The system's performance is highly dependent on prompt engineering and parameter settings (like "temperature"). The authors found that a low temperature (0.2) was essential for consistent, accurate results.
  • Future Directions: The team plans to investigate more advanced source code simplification techniques and explore how to adjust LLM architectures specifically for better reasoning about API structures to further reduce runtime and improve accuracy on massive codebases.

Summary updated

BibTeX
@misc{deng2025lrasgen,
  author = {Sida Deng and Rubing Huang and Man Zhang and Chenhui Cui and Dave Towey and Rongcun Wang},
  title = {{LRASGen: LLM-based RESTful API Specification Generation}},
  year = {2025},
  eprint = {2504.16833},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.16833},
}
Figure