LRASGen: توليد مواصفات واجهة برمجة التطبيقات RESTful المعتمدة على LLM LRASGen: LLM-based RESTful API Specification Generation

شارك:
المجلة: ACM Transactions on Software Engineering and Methodology
DOI: https://doi.org/10.1145/3810241
تاريخ النشر: 2026-04-17
المؤلف: Zhenyun Du وآخرون
الموضوع الرئيسي: أبحاث هندسة البرمجيات

نظرة عامة

يقدم هذا القسم نظرة عامة على نهج جديد يسمى توليد مواصفات واجهة برمجة التطبيقات RESTful المعتمد على نماذج اللغة الكبيرة (LRASGen)، والذي يستخدم نماذج اللغة الكبيرة (LLMs) لتوليد مواصفات OpenAPI (OAS) لواجهات برمجة التطبيقات RESTful. يعتمد REST، وهو نمط معماري لتطبيقات الويب، على التواصل بدون حالة عبر HTTP، وغالبًا ما يتم تعريف المواصفات لواجهات برمجة التطبيقات RESTful باستخدام معايير مثل مواصفة OpenAPI (OAS). يمكن أن تكون الطرق التقليدية لتوليد هذه المواصفات كثيفة العمل وعرضة للأخطاء، خاصة عندما تتطور متطلبات البرمجيات. يتناول LRASGen هذه التحديات من خلال توليد OASs مباشرة من كود مصدر واجهة برمجة التطبيقات، حتى عندما يكون هذا الكود غير مكتمل أو يفتقر إلى التعليقات التوضيحية.

أظهرت التقييمات التجريبية لـ LRASGen على 20 واجهة برمجة تطبيقات RESTful في العالم الحقيقي فعاليتها، وكشفت أنها تفوقت على أدوات توليد المواصفات الحالية مثل Respector وSwagger Core وSpringdoc، خاصة لواجهات برمجة التطبيقات المعتمدة على Java. أظهرت النتائج أن المواصفات التي تم توليدها بواسطة LRASGen تضمنت في المتوسط 48.85% من الكيانات أكثر من تلك التي قدمها المطورون، مما يبرز قدرتها على تحديد طرق النقاط النهائية والمعلمات والقيود والاستجابات بدقة. علاوة على ذلك، يسمح تصميم LRASGen له بالعمل دون الحاجة إلى بيئة تشغيل أو ضبط دقيق لنموذج اللغة الكبير، مما يجعله قابلاً للتكيف عبر لغات البرمجة والأطر المختلفة. ستركز الأعمال المستقبلية على تحسين عملية تحليل كود المصدر للتخفيف من المشكلات المتعلقة بحدود الرموز وكفاءة الحساب، مما يضمن بقاء LRASGen فعالاً مع زيادة تعقيد الكود.

مقدمة

تناقش مقدمة هذه الورقة البحثية النمط المعماري لنقل الحالة التمثيلية (REST) وأهميته في تصميم تطبيقات الويب، خاصة من خلال واجهات برمجة التطبيقات RESTful. تستفيد هذه الواجهات من البنية التحتية الحالية للويب وطرق HTTP القياسية (GET وPOST وPUT وDELETE) لتسهيل العمليات على الموارد، مع الإشارة إلى الاستجابات بواسطة رموز الحالة القياسية لـ HTTP. على الرغم من اعتمادها على نطاق واسع، غالبًا ما تعاني جودة مواصفات واجهة برمجة التطبيقات، مثل مواصفة OpenAPI (OAS)، مما يؤدي إلى مشكلات في التكامل وثغرات أمنية. تسلط الورقة الضوء على التحديات المتعلقة بالحفاظ على مواصفات دقيقة، خاصة مع تطور واجهات برمجة التطبيقات، وتلاحظ أن الأدوات الحالية لتوليد المواصفات تعتمد غالبًا على التعليقات التوضيحية أو التدخل اليدوي.

لمعالجة هذه التحديات، يقدم المؤلفون نهجًا جديدًا يسمى توليد مواصفات واجهة برمجة التطبيقات RESTful المعتمد على نماذج اللغة الكبيرة (LRASGen)، والذي يستخدم نماذج اللغة الكبيرة (LLMs) لأتمتة توليد OAS مباشرة من كود مصدر واجهات برمجة التطبيقات RESTful. يحدد LRASGen طرق النقاط النهائية والمعلمات والقيود والاستجابات من خلال عملية منظمة من ست خطوات، مما يظهر معدلات دقة واسترجاع عالية عبر لغات البرمجة والأطر المختلفة. تدعي الورقة أن LRASGen هو التقنية الأولى التي تستفيد بفعالية من LLMs لهذا الغرض، مما يوفر تقدمًا كبيرًا في أتمتة توليد مواصفات واجهة برمجة التطبيقات ويعزز موثوقية توثيق واجهات برمجة التطبيقات RESTful.

طرق

في قسم الطرق، يصف المؤلفون نهجًا محسّنًا لتوليد المواصفات من كود المصدر باستخدام نموذج لغة كبير (LLM). في البداية، حاولوا معالجة كود المصدر بالكامل في تقديم واحد، لكنهم واجهوا مشكلات مثل الاستخدام المفرط للرموز، والاستجابات غير ذات الصلة، والنتائج المزيفة. لمعالجة هذه التحديات، قاموا بتقسيم العملية إلى خطوات منفصلة، مع التركيز على استخراج طرق النقاط النهائية من خلال تقديم ملف إدخال نقطة نهائية إلى LLM. شمل هذا النهج تصميم مطالبات لتوجيه LLM وتقديم أمثلة بتنسيق عائد محدد (JSON)، مع تجنب تضمين ملفات كود مستوردة أخرى للتخفيف من المشكلات المتعلقة بالرموز.

شملت المنهجية التجريبية توليد مواصفات لـ 20 واجهة برمجة تطبيقات RESTful في العالم الحقيقي باستخدام LRASGen، المنفذ بلغة بايثون. تم تسجيل أوقات التشغيل المتوسطة كـ 9 دقائق و36 ثانية مع GPT-4o mini و6 دقائق و5 ثوانٍ مع DeepSeek V3، مع ملاحظة أسرع تنفيذ تحت دقيقة واحدة. تم تقييم دقة المواصفات المولدة مقابل حقيقة محسنة وتمت مقارنتها مع المواصفات المقدمة من المطورين لتحديد التباينات في طرق النقاط النهائية والمعلمات والقيود والاستجابات. كما أجرى المؤلفون تحليلًا مقارنًا ضد ثلاث تقنيات متطورة – Respector وSwagger Core وSpringdoc – مع تسليط الضوء على نقاط القوة والقيود في LRASGen في دقة توليد المواصفات، والكمال، والكفاءة.

نقاش

يتناول قسم النقاش في الورقة المبادئ المعمارية لواجهات برمجة التطبيقات RESTful، كما قدمها روي فيلدينغ، مع التركيز على قابليتها للتوسع ومرونتها واستقلالية تفاعلات العميل والخادم. تستخدم واجهات برمجة التطبيقات RESTful طرق HTTP القياسية (GET وPOST وPUT وDELETE) للتلاعب بالموارد، وغالبًا ما يتم توثيقها باستخدام مواصفة OpenAPI (OAS). تسهل OAS واجهة قابلة للقراءة الآلية لواجهات برمجة التطبيقات RESTful، مما يعزز الفهم وقابلية استخدام خدمات الويب بينما يمكّن من توليد الكود الآلي والاختبار الدقيق. ومع ذلك، يمكن أن تكون عملية كتابة وصيانة هذه المواصفات مرهقة وعرضة للأخطاء، مما يستلزم البحث المستمر في منهجيات اختبار محسّنة.

تسلط الورقة الضوء أيضًا على الدور التحويلي لنماذج اللغة الكبيرة (LLMs) في معالجة اللغة الطبيعية وإمكاناتها في توليد الكود ومواصفات واجهة برمجة التطبيقات. من خلال التدريب على الوثائق الحالية، يمكن لنماذج اللغة الكبيرة إنتاج أوصاف دقيقة وقابلة للقراءة البشرية لنقاط نهاية واجهة برمجة التطبيقات، وملء الفجوات في المواصفات غير المكتملة، وتبسيط عملية التكامل. يقترح المؤلفون منهجية منظمة، LRASGen، لتوليد مواصفات OpenAPI باستخدام نماذج اللغة الكبيرة، والتي تتضمن استخراج الكود ذي الصلة، وتنظيفه، وتحديد معلمات النقاط النهائية والقيود بشكل منهجي. يهدف هذا النهج إلى الاستفادة من قدرات LLM لتعزيز جودة وكفاءة توليد مواصفات واجهة برمجة التطبيقات، وبالتالي معالجة التحديات المرتبطة بتوثيق واجهات برمجة التطبيقات RESTful.

Journal: ACM Transactions on Software Engineering and Methodology
DOI: https://doi.org/10.1145/3810241
Publication Date: 2026-04-17
Author(s): Zhenyun Du et al.
Primary Topic: Software Engineering Research

Overview

The section presents an overview of a novel approach called LLM-based RESTful API-Specification Generation (LRASGen), which utilizes Large Language Models (LLMs) to generate OpenAPI Specifications (OAS) for RESTful APIs. REST, an architectural style for web applications, relies on stateless communication via HTTP, and the specifications for RESTful APIs are often defined using standards like the OpenAPI Specification (OAS). Traditional methods for generating these specifications can be labor-intensive and prone to errors, particularly when software requirements evolve. LRASGen addresses this challenge by generating OASs directly from API source code, even when that code is incomplete or lacks annotations.

Empirical evaluations of LRASGen on 20 real-world RESTful APIs demonstrated its effectiveness, revealing that it outperformed existing specification-generation tools such as Respector, Swagger Core, and Springdoc, particularly for Java-based APIs. The results indicated that LRASGen-generated specifications included an average of 48.85% more entities than those provided by developers, showcasing its ability to accurately identify endpoint methods, parameters, constraints, and responses. Furthermore, LRASGen’s design allows it to operate without requiring a runtime environment or fine-tuning of the LLM, making it adaptable across different programming languages and frameworks. Future work will focus on refining the source code analysis process to mitigate issues related to token limitations and computational efficiency, ensuring that LRASGen remains effective as code complexity increases.

Introduction

The introduction of this research paper discusses the architectural style of Representational State Transfer (REST) and its significance in web application design, particularly through RESTful APIs. These APIs leverage existing web infrastructure and standard HTTP methods (GET, POST, PUT, DELETE) to facilitate operations on resources, with responses indicated by standard HTTP status codes. Despite their widespread adoption, the quality of API specifications, such as the OpenAPI Specification (OAS), often suffers, leading to integration issues and security vulnerabilities. The paper highlights the challenges of maintaining accurate specifications, particularly as APIs evolve, and notes that existing tools for specification generation frequently rely on annotations or manual intervention.

To address these challenges, the authors introduce a novel approach called LLM-based RESTful API-Specification Generation (LRASGen), which utilizes Large Language Models (LLMs) to automate the generation of OAS directly from the source code of RESTful APIs. LRASGen identifies endpoint methods, parameters, constraints, and responses through a structured six-step process, demonstrating high precision and recall rates across various programming languages and frameworks. The paper claims that LRASGen is the first technique to effectively leverage LLMs for this purpose, providing a significant advancement in the automation of API specification generation and enhancing the reliability of RESTful API documentation.

Methods

In the methods section, the authors describe a refined approach to generating specifications from source code using a large language model (LLM). Initially, they attempted to process the entire source code in a single submission, but encountered issues such as excessive token usage, irrelevant responses, and fabricated outcomes. To address these challenges, they segmented the process into discrete steps, focusing on extracting endpoint methods by submitting an endpoint entry file to the LLM. This approach involved designing prompts to guide the LLM and providing examples in a specified return format (JSON), while avoiding the inclusion of other imported code files to mitigate token-related problems.

The experimental methodology involved generating specifications for 20 real-world RESTful APIs using LRASGen, implemented in Python. The average running times were recorded as 9 minutes and 36 seconds with GPT-4o mini and 6 minutes and 5 seconds with DeepSeek V3, with the fastest execution observed under one minute. The accuracy of the generated specifications was assessed against an enhanced ground truth and compared with developer-provided specifications to identify discrepancies in endpoint methods, parameters, constraints, and responses. The authors also conducted a comparative analysis against three state-of-the-art techniques—Respector, Swagger Core, and Springdoc—highlighting LRASGen’s strengths and limitations in specification generation accuracy, completeness, and efficiency.

Discussion

The discussion section of the paper elaborates on the architectural principles of RESTful APIs, as introduced by Roy Fielding, emphasizing their scalability, flexibility, and independence of client-server interactions. RESTful APIs utilize standard HTTP methods (GET, POST, PUT, DELETE) for resource manipulation, and they are often documented using the OpenAPI Specification (OAS). The OAS facilitates a machine-readable interface for RESTful APIs, enhancing the understanding and usability of web services while enabling automated code generation and rigorous testing. However, the process of writing and maintaining these specifications can be cumbersome and error-prone, necessitating ongoing research into improved testing methodologies.

The paper also highlights the transformative role of Large Language Models (LLMs) in natural language processing and their potential for generating code and API specifications. By training on existing documentation, LLMs can produce accurate and human-readable descriptions of API endpoints, fill gaps in incomplete specifications, and streamline the integration process. The authors propose a structured methodology, LRASGen, for generating OpenAPI Specifications using LLMs, which involves extracting relevant code, cleaning it, and systematically identifying endpoint parameters and constraints. This approach aims to leverage LLM capabilities to enhance the quality and efficiency of API specification generation, thereby addressing the challenges associated with RESTful API documentation.