Interface document generation method and device and electronic equipment

By automatically extracting and generating interface documents when code changes are detected in the code warehouse, the problem of high labor costs and high error rates of manually writing and maintaining interface documents is solved, and timely update and efficient generation of interface documents is achieved.

CN119829051APending Publication Date: 2025-04-15CHINA TELECOM BESTPAY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411832150.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-12
Publication Date
2025-04-15

AI Technical Summary

Technical Problem

In the prior art, manual writing and maintenance of interface documents has high labor costs and high error rates, resulting in untimely update of interface documents.

Method used

When a code in the code repository is detected to change, the target annotation information is obtained, the initial interface information is extracted, and the interface configuration information of the service provider and the service consumer end can be automatically generated and updated.

Benefits of technology

It realizes timely automatic generation and update of interface documents, reduces labor costs, reduces error rates, and improves the efficiency of interface documents generation and updates.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119829051A_ABST
    Figure CN119829051A_ABST
Patent Text Reader

Abstract

The invention discloses an interface document generation method and device and electronic equipment. Relates to the field of software development, and the method comprises the steps that under the condition that it is detected that codes in a code repository are changed, target annotation information in the code repository is acquired, and the target annotation information is at least used for identifying a service provided by a service providing end, a service consumption end of the service and an interface class and a version number of the service; obtaining initial interface information based on the target annotation information; obtaining interface configuration information respectively corresponding to the service providing end and the service consuming end; and generating a target interface document based on the initial interface information and interface configuration information respectively corresponding to the service providing end and the service consumption end. According to the method and the device, the technical problems of high labor cost and high error rate in manual compiling and maintenance of the interface document in related technologies are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to an interface document generation method, device and electronic device. Background Art

[0002] In project development, writing external interface documents is a key step to ensure service quality and collaboration efficiency. The document records in detail the interface name, input parameters, output results, calling methods, error handling and other information, which helps developers, testers and operation teams understand the interface functions, follow unified calling specifications, reduce communication costs, and prevent problems caused by misunderstandings. In addition, interface documents are also the basis for system maintenance and upgrades, which helps maintain the stability and scalability of the system. However, in related technologies, interface documents are mainly written, maintained and updated manually, which has low efficiency and high error rate, and is prone to untimely updates of interface documents.

[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0004] The embodiments of the present invention provide a method, device and electronic device for generating an interface document, so as to at least solve the technical problems of high labor cost and high error rate in manually writing and maintaining interface documents in the related art.

[0005] According to one aspect of an embodiment of the present invention, a method for generating an interface document is provided, comprising: in a case where a code change in a code repository is detected, obtaining target annotation information in the code repository, wherein the target annotation information is at least used to identify a service provided by a service provider, a service consumer of the service, and an interface class and version number of the service; obtaining initial interface information based on the target annotation information; obtaining interface configuration information corresponding to the service provider and the service consumer, respectively; and generating a target interface document based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, respectively.

[0006] Optionally, when a code change is detected in the code repository, obtaining target annotation information in the code repository includes: detecting whether a code change occurs in the code repository through a continuous integration and continuous deployment tool; when a code change is detected in the code repository, triggering a code building process in the continuous integration and continuous deployment process to obtain the target annotation information from the code repository.

[0007] Optionally, obtaining the target annotation information from the code repository includes: using a reflection application program interface to scan the source code in the code repository, and extracting service annotation information and reference annotation information in the code repository, wherein the service annotation information is at least used to identify the service provided by the service provider, as well as the interface class and version number of the service, and the reference annotation information is at least used to identify the service consumed by the service consumer, as well as the interface class and version number of the service; based on the service annotation information and the reference annotation information, the target annotation information is obtained.

[0008] Optionally, generating a target interface document based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, respectively, includes: converting the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, respectively, into a predetermined document format to obtain the target interface document.

[0009] Optionally, after generating the target interface document based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, the method further includes: testing the target interface document to obtain a test result; if the test result indicates that the target interface document has passed the test, sending the target interface document to a document server, wherein the document server is used to store and manage interface documents; and updating the initial interface document stored in the document server to the target interface document.

[0010] Optionally, the testing of the target interface document to obtain the test result includes: obtaining a test case, wherein the test case is used to simulate an interface calling process based on the target interface document; testing the target interface document based on the test case to obtain the test result, wherein the test result is at least used to indicate whether interface parameters corresponding to the interface called based on the target interface document meet predetermined conditions.

[0011] Optionally, updating the initial interface document stored in the document server to the target interface document includes: detecting whether the target interface document and the initial interface document are consistent; if the target interface document and the initial interface document are inconsistent, updating the initial interface document stored in the document server to the target interface document.

[0012] Optionally, the method further includes: when the target interface document and the initial interface document are inconsistent, generating interface update information based on difference information between the target interface document and the initial interface document; and sending the interface update information to the target terminal.

[0013] According to another aspect of an embodiment of the present invention, an interface document generation device is also provided, including: an annotation information acquisition module, used to acquire target annotation information in the code repository when a change is detected in the code in the code repository, wherein the target annotation information is at least used to identify the service provided by the service provider, the service consumer of the service, and the interface class and version number of the service; an interface information acquisition module, used to obtain initial interface information based on the target annotation information; a configuration information acquisition module, used to acquire interface configuration information corresponding to the service provider and the service consumer respectively; an interface document generation module, used to generate a target interface document based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer respectively.

[0014] According to another aspect of an embodiment of the present invention, there is also provided an electronic device, comprising one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement any one of the interface document generation methods described.

[0015] In an embodiment of the present invention, when a code change is detected in a code repository, target annotation information in the code repository is obtained, wherein the target annotation information is at least used to identify the service provided by a service provider, a service consumer of the service, and an interface class and version number of the service; initial interface information is obtained based on the target annotation information; interface configuration information corresponding to the service provider and the service consumer, respectively, is obtained; and a target interface document is generated based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, thereby achieving the purpose of extracting interface information based on annotation information when a code update is detected, and automatically generating a target interface document based on the interface information and the configuration information of the service provider and the service consumer, thereby achieving the technical effect of timely automatic generation and updating of interface documents and improving the efficiency of interface document generation and updating, thereby solving the technical problems of high labor cost and high error rate in manually writing and maintaining interface documents in related technologies. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0017] Figure 1 is a flow chart of a method for generating an interface document according to an embodiment of the present invention;

[0018] Figure 2 is a flowchart of an optional method for generating an interface document according to an embodiment of the present invention;

[0019] Figure 3 It is a schematic diagram of an interface document generating device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0020] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0022] First, to facilitate understanding of the embodiments of the present invention, some terms or nouns involved in the present invention are explained below:

[0023] Continuous Integration and Continuous Deployment (CI / CD) are important components of modern software development practices, designed to accelerate the software delivery process and improve software quality. Continuous integration emphasizes frequent integration of developers' code changes into a shared master branch, and immediate execution of automated builds and tests to ensure that new code is compatible with existing code. Continuous deployment further automates the deployment process from tested code to the production environment, allowing updates to be pushed to users quickly and securely.

[0024] Dubbo is an open source, high-performance Java RPC framework that aims to simplify the development and governance of distributed services. It is mainly used to help build a distributed service architecture and implement remote calls and communications between services. Dubbo provides service registration and discovery, load balancing, fault tolerance, monitoring, and management functions, allowing service providers to expose services and service consumers to call these services transparently.

[0025] Distributed service architecture is an architecture that splits the system into multiple independent services and communicates and collaborates through the network. In the distributed service architecture, each service can be independently operated, maintained and expanded, and the services can communicate with each other through application programming interfaces to achieve distributed deployment and high availability of the system.

[0026] Dubbo interface documentation is a document that describes the interaction between the service provider and the service consumer. It mainly includes the definition of the service interface, method signatures, detailed descriptions of parameters and return values, and possible exception information. It usually contains the interface name, interface description, method name, input parameter type, output return type, and the purpose and example of each method. The interface document is crucial for the service consumer to understand how to call the service, and for the service provider to keep the interface stable when maintaining and upgrading the service.

[0027] Jenkins, an open source continuous integration (CI) tool, can be used to automate software building, testing, and deployment. It provides an easy-to-use interface that allows development teams to automatically build, test, and deploy their applications after code is submitted.

[0028] GitLab CI / CD is a continuous integration and continuous delivery tool provided by GitLab. It is integrated with the GitLab version control system, allowing development teams to use CI / CD functions to automatically build, test, and deploy their applications while managing code repositories on GitLab.

[0029] Asciidoctor is a document generation tool that helps users write and publish documents. It supports writing documents using AsciiDoc syntax and converting them into formats such as Hypertext Markup Language (HTML) and Portable Document Format (PDF).

[0030] Markup language document editor MkDocs, a static website generator, is specifically designed for building documentation websites. Users can write documents using Markdown syntax and generate documentation websites through MkDocs.

[0031] According to an embodiment of the present invention, a method embodiment of interface document generation is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0032] Figure 1 is a flowchart of a method for generating an interface document according to an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:

[0033] Step S102, when it is detected that the code in the code repository has changed, obtaining target annotation information in the code repository;

[0034] Optionally, the code repository includes source code required for project development. It is possible to continuously detect whether the code included in the code repository has changed. When a code change is detected in the code repository, it may cause changes in information related to interface calls during project development, which in turn may cause changes in the content of the interface document. Based on this, when a code change is detected in the code repository, the target annotation information in the code repository can be scanned and obtained for subsequent generation and update of interface documents, wherein the interface document may be, but is not limited to, an interface document based on a distributed service structure, such as a Dubbo interface document.

[0035] Optionally, the target annotation information is used to at least identify the service provided by the service provider, the service consumer, and the interface class and version number of the service.

[0036] In an optional embodiment, when a code change in a code repository is detected, target annotation information in the code repository is obtained, including: detecting whether a code change occurs in the code repository through a continuous integration and continuous deployment tool; when a code change is detected in the code repository, triggering a code building process in the continuous integration and continuous deployment process to obtain the target annotation information from the code repository.

[0037] Optionally, a continuous integration and continuous deployment (CI / CD) tool may be used to detect whether code changes occur in the code repository. The CI / CD tool may be, but is not limited to, a Jenkins tool or a GitLab CI / CD tool. The CI / CD tool may be used to detect whether code changes occur in the code repository in a timely manner.

[0038] It should be noted that the CI / CD process is designed to accelerate the software delivery process and improve software quality. Continuous integration emphasizes frequent integration of developers' code changes into shared main branches, and immediate execution of automated builds and tests to ensure that new code is compatible with existing code. The CI / CD process usually includes code building, testing, deployment and other links. It can automatically extract target annotation information related to interface calls during the build phase for subsequent generation and update of interface documents, and synchronize the update of interface documents with code to ensure that developers always use the latest interface document information to reduce erroneous calls and exceptions caused by information lags.

[0039] It is still necessary to explain that in the CI / CD process, CI / CD tools (such as Jenkins or GitLab CI / CD) are configured to detect changes in the code repository in order to achieve continuous integration and continuous deployment. When the code in the code repository changes, the CI / CD tool will detect the change and trigger the corresponding build, test, and deployment process. This can ensure the quality and stability of the code and speed up the delivery of the project.

[0040] In an optional embodiment, target annotation information is obtained from a code repository, including: using a reflection application program interface to scan the source code in the code repository, and extracting service annotation information and reference annotation information in the code repository, wherein the service annotation information is at least used to identify the service provided by the service provider, as well as the interface class and version number of the service, and the reference annotation information is at least used to identify the service consumed by the service consumer, as well as the interface class and version number of the service; based on the service annotation information and the reference annotation information, the target annotation information is obtained.

[0041] Optionally, the service annotation information is the @Service annotation, which is used to mark the implementation class of the service provider and expose it as a remote service for other systems or applications to call. The @Service annotation can also contain information such as the service interface class and version number to identify the service provided by the service provider. The reference annotation information is the @Reference annotation, which is used to mark the interface field or attribute of the service consumer, indicating that the interface needs to remotely call a Dubbo service. The @Reference annotation can contain information such as the service interface class, version number, load balancing strategy, etc., which is used to specify the service consumed by the service consumer. By scanning the @Service annotation and @Reference annotation in the code repository, you can get information related to the interface call, such as the service provided by the interface, the service provider, the service consumer, the service interface class and version number, etc. as the target annotation information for the subsequent generation of interface documents.

[0042] Optionally, the service provider refers to the component responsible for implementing specific functions and exposing them to other systems or applications. The service provider is used to implement certain functions or services, and uses the corresponding technical framework to expose these functions as services, so that other systems or applications can use these services through network calls. The service consumer refers to the component that needs to call services provided by other systems or applications. The service consumer can access the functions or services provided by the service provider through the network by calling the interface exposed by the service provider to implement its own business logic. In a distributed system, the service provider and the service consumer communicate and interact through the network. The service provider exposes the services it provides, and the service consumer calls these services through the network to implement its own business needs. Through the collaboration of service providers and service consumers, distributed systems can achieve modularity, flexibility and scalability of functions.

[0043] Step S104, obtaining initial interface information based on the target annotation information;

[0044] Optionally, information related to the interface call identified in the target annotation information, such as the service provided by the interface, the service provider, the service consumer, the interface class and version number of the service, etc., can be used as the initial interface information.

[0045] Step S106, obtaining interface configuration information corresponding to the service provider and the service consumer respectively;

[0046] Optionally, the interface configuration information corresponding to the service provider and service consumer can be further obtained. The interface configuration information can include, but is not limited to, the interface description information of the corresponding end (service provider or service consumer). The interface description information can be obtained by scanning the metadata corresponding to the service provider and service consumer in the service registration center, but is not limited to. Among them, the metadata of the service registration center refers to the information about each service provider and service consumer stored in the service registration center, including the name, interface, version number, address, load balancing strategy, health status and other related data of the service. The service registration center is used for service registration, discovery and calling. By registering the information of the service provider to the service registration center and allowing the service consumer to obtain the information of the service provider from the service registration center, communication and collaboration between services are achieved. When generating interface documents, combining the metadata of the service registration center can help collect and describe service information more accurately, thereby generating detailed and accurate interface documents and improving the efficiency of development and maintenance.

[0047] For example, in the Dubbo framework, the service registry plays a vital role in managing the registration and discovery of Dubbo services. The Dubbo framework will register the information of the service provider to the service registry, and the service consumer can obtain the address and other relevant information of the service provider from the service registry to implement the service call. In the process of generating Dubbo interface documents, combining the metadata of the service registry can provide a more comprehensive understanding of the information of each service, including details such as interfaces, methods, parameters, etc., so as to generate structured interface descriptions and documents. When integrating Dubbo interface document generation in the CI / CD process, combining the metadata of the service registry can help more accurately collect and describe the information of Dubbo services, thereby generating detailed and accurate interface documents and improving the efficiency of development and maintenance.

[0048] Step S108, generating a target interface document based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, respectively.

[0049] It can be understood that since the initial interface information is obtained by scanning the code repository, based on the initial interface information, the interface-related information that needs to be called for code development can be preliminarily obtained. Further, by obtaining the interface configuration information, it can help to more accurately collect and describe the relevant information of the service, thereby generating detailed and accurate target interface documents and improving development and maintenance efficiency.

[0050] Optionally, during the code building phase, use reflection technology to scan the project, find classes with @Service annotations and @Reference annotations, collect interface, method, parameter and other details, and combine with the metadata of the service registry to generate structured interface descriptions and documents and target interface documents. Execute the above method as part of the code building to ensure that the document is automatically updated after each code update.

[0051] In an optional embodiment, a target interface document is generated based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, including: converting the initial interface information and the interface configuration information corresponding to the service provider and the service consumer into a predetermined document format to obtain the target interface document.

[0052] Optionally, a preset document template can be applied, and the initial interface information and the configuration interface information can be filled into the document template accordingly to obtain a target interface document that meets the predetermined document format. In the above manner, a target interface document that is easier to read can be obtained. In the target interface document, a clear description can be provided for each interface, which can include but is not limited to the interface name, interface description, method name, input parameter type, output return type, and the purpose and examples of each method.

[0053] Optionally, a document template engine may be used to convert the initial interface information and the configuration interface information into a predetermined document format to obtain a target interface document. The document template engine may be, but is not limited to, a standard exchange code document editor Asciidoctor, a markup language document editor MkDocs, and the like.

[0054] In an optional embodiment, after generating the target interface document based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer respectively, the method further includes: testing the target interface document to obtain a test result; when the test result indicates that the target interface document test has passed, sending the target interface document to a document server, wherein the document server is used to store and manage the interface document; and updating the initial interface document stored in the document server to the target interface document.

[0055] Optionally, after obtaining the target interface document, the target interface document can be further tested to determine whether the obtained target interface document meets the requirements. If the test result indicates that the target interface document has passed the test, that is, the target interface document meets the requirements, the target interface document is sent to the document server, and the document server is used to store, manage and update the target interface document. If the target interface document has passed the test, the target interface document can also be submitted to the version control system.

[0056] It should be noted that by submitting the target interface document to the version control system, the history of the interface document can be retained, including the content, changes and revisions of each update, etc., which can facilitate the development team to track the change history of the document, view old versions of the document, and compare and restore the document content; submitting the interface document to the version control system can promote collaboration and communication among team members. Team members can view the latest document version through the version control system, jointly edit and update the document content, and ensure document consistency and collaboration efficiency among teams. Publishing the interface document to the document server can make the document accessible in real time, and team members and other relevant personnel can view the latest document content at any time to understand the usage and specifications of the interface. The interface document published on the document server can also have better visualization effects, and the structure, parameters, examples and other information of the interface can be intuitively viewed through an online browser to improve the readability and ease of use of the document.

[0057] In an optional embodiment, the target interface document is tested to obtain test results, including: obtaining a test case, wherein the test case is used to simulate an interface calling process based on the target interface document; testing the target interface document based on the test case to obtain a test result, wherein the test result is at least used to indicate whether interface parameters corresponding to the interface called based on the target interface document meet predetermined conditions.

[0058] Optionally, after the target interface document is generated, you can write automated test cases to verify whether the content of the interface document is accurate. These test cases can cover, but are not limited to, verification of interface parameters, return values, exception handling, etc. Specifically, test cases for interface document verification are written through the testing framework of the programming language; the test cases can simulate calling the interface to verify whether the parameters and return values ​​of the interface meet expectations, and whether the handling of abnormal situations is correct. These test cases for interface document verification are executed during the testing phase of the CI / CD process. If the test fails, the build is blocked and the development team is notified. Integrate the process of interface document generation and verification into the CI / CD process. Document generation can be performed during the build phase, and test cases for document verification can be executed during the test phase. If document verification fails, the build process can be stopped through the CI / CD tool and a notification can be sent to relevant development team members.

[0059] In an optional embodiment, the initial interface document stored in the document server is updated to the target interface document, including: detecting whether the target interface document and the initial interface document are consistent; if the target interface document and the initial interface document are inconsistent, updating the initial interface document stored in the document server to the target interface document.

[0060] It should be noted that the update of the code in the code repository is not necessarily accompanied by the update of the interface document. Based on this, by detecting whether the target interface document is consistent with the initial interface document, it is possible to accurately determine whether there is an update to the interface document. If they are inconsistent, the initial interface document stored in the document server is updated to the target interface document, thereby implementing the update of the interface document. If the content of the target interface document is consistent with that of the initial interface document, there is no need to update the interface document at this time, thereby simplifying the document update process and avoiding unnecessary document updates.

[0061] In an optional embodiment, the method further includes: when the target interface document and the initial interface document are inconsistent, generating interface update information based on difference information between the target interface document and the initial interface document; and sending the interface update information to the target terminal.

[0062] Optionally, when the target interface document is inconsistent with the initial interface document, that is, when the interface document is updated, the difference information between the target interface document and the initial interface document can be determined as interface update information, and the difference information can be sent to the corresponding terminal of the relevant personnel (i.e., the target terminal) so that the relevant personnel can be informed of the interface update in a timely manner. The interface update information may include but is not limited to the updated interface name, description, scope of impact, and a link to view the updated document, so that developers, testers, and operation and maintenance teams can be aware of the changes in a timely manner and make corresponding adjustments.

[0063] Through the above steps S102 to S108, it is possible to achieve the purpose of extracting interface information based on annotation information when a code update is detected, and automatically generating a target interface document based on the interface information and the configuration information of the service provider and service consumer, thereby achieving the technical effect of timely automatic generation and updating of interface documents and improving the efficiency of interface document generation and updating, thereby solving the technical problems of high labor cost and high error rate in manually writing and maintaining interface documents in related technologies.

[0064] Based on the above embodiments and optional embodiments, the present invention proposes an optional implementation mode: Figure 2 is a flowchart of an optional method for generating an interface document according to an embodiment of the present invention, such as Figure 2As shown in the figure, the method first configures a continuous integration CI tool (such as Jenkins or GitLab CI / CD) to monitor changes in the code repository. Then, in the code building phase of the CI / CD process, the code information corresponding to the development project in the code repository is scanned through reflection technology, and classes with @Service and @Reference annotations are found to collect details such as interfaces, methods, and parameters as initial interface information. Then, combined with the metadata of the service registration center, a structured interface description is generated to obtain the interface configuration information. A document template engine (such as Asciidoctor or MkDocs) is used to convert this information into an easy-to-read document format. Finally, the generated interface document (i.e., the target interface document) is automatically submitted to the version control system and published to the document server to ensure that the interface document can be updated in a timely manner after each code update, thereby avoiding incorrect calls and exceptions caused by inconsistent information and improving development efficiency and code quality. The specific steps include the following:

[0065] S1, environment configuration, including:

[0066] S11, integrate CI / CD tools (such as Jenkins, GitLab CI / CD or Travis CI) with the project source code repository.

[0067] S12, install and configure the distributed service framework (such as Dubbo) related libraries, document generation tools (such as SmartDoc or custom scripts), and XML parsing libraries.

[0068] S2, code and configuration scanning, including:

[0069] S21, using the reflection application program interface API to scan the Java source code in the code repository, extracting @Service and @Reference annotation information, and obtaining initial interface information based on the @Service and @Reference annotation information.

[0070] S22, parse the XML configuration file of Dubbo, and collect relevant settings of the service provider and the service consumer, such as the interface configuration information corresponding to the service provider and the service consumer respectively.

[0071] S3, interface information (metadata) integration, including:

[0072] S31, combining the interface information obtained by code scanning and the interface configuration information obtained by XML parsing, to create a unified data structure containing all interface detailed information as the fused interface information.

[0073] S32, if applicable, can also obtain the real-time status and additional information of the service from the service registration center.

[0074] S4, interface document generation, including:

[0075] S41, applying a document template to convert the merged interface information into an easy-to-read format, such as Markdown or HTML.

[0076] S42, in this document template, a clear description may be provided for each interface, which may include but is not limited to the methods, parameters, return values ​​and possible exceptions corresponding to the interface.

[0077] S5, automated release and verification, specifically includes:

[0078] S51, in the CI / CD process, generate the interface document as part of the build to ensure that the interface document is automatically updated after each code update.

[0079] S52, perform interface document verification to ensure the content is accurate. If there are any problems, block the build and notify the development team.

[0080] S6, real-time notification, including:

[0081] S61, when the interface document is updated, relevant personnel are automatically notified via email, message notification system (such as Slack or Teams) or other communication channels.

[0082] S62, the notification content may include, but is not limited to, the updated interface name, description, impact scope, and a link to view the updated document, so that developers, testers, and operation and maintenance teams can understand the changes in a timely manner and make corresponding adjustments.

[0083] The present invention achieves at least one of the following effects: 1) It can realize synchronous updating of interface documents and codes, ensuring that developers always use the latest interface information, reducing erroneous calls and exceptions caused by information lags; 2) It can unify document generation and management processes, ensure standardization and consistency of interface descriptions, and reduce communication costs among team members; 3) It can realize automated verification and notification mechanisms, reducing development risks caused by failure to communicate interface changes in a timely manner, and ensuring project stability and reliability.

[0084] In this embodiment, an interface document generation device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the terms "module" and "device" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0085] According to an embodiment of the present invention, there is also provided an apparatus embodiment for implementing the above-mentioned interface document generation method. Figure 3 is a schematic diagram of the structure of an interface document generating device according to an embodiment of the present invention. Figure 3 As shown, the interface document generation device includes: an annotation information acquisition module 300, an interface information acquisition module 302, a configuration information acquisition module 304, and an interface document generation module 306, wherein:

[0086] An annotation information acquisition module 300 is used to acquire target annotation information in the code repository when a code change is detected in the code repository, wherein the target annotation information is used to at least identify the service provided by the service provider, the service consumer, and the interface class and version number of the service;

[0087] The interface information acquisition module 302 is connected to the annotation information acquisition module 300 and is used to obtain initial interface information based on the target annotation information;

[0088] The configuration information acquisition module 304 is connected to the interface information acquisition module 302 and is used to acquire the interface configuration information corresponding to the service provider and the service consumer respectively;

[0089] The interface document generation module 306 is connected to the configuration information acquisition module 304 and is used to generate a target interface document based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, respectively.

[0090] In an embodiment of the present invention, an annotation information acquisition module 300 is set up to acquire target annotation information in the code repository when a change is detected in the code in the code repository, wherein the target annotation information is at least used to identify the service provided by the service provider, the service consumer, and the interface class and version number of the service; an interface information acquisition module 302 is connected to the annotation information acquisition module 300 and is used to obtain initial interface information based on the target annotation information; a configuration information acquisition module 304 is connected to the interface information acquisition module 302 and is used to acquire interface configuration information corresponding to the service provider and the service consumer respectively; an interface document generation module Block 306 is connected to the configuration information acquisition module 304, and is used to generate a target interface document based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer respectively, so as to achieve the purpose of extracting the interface information based on the annotation information when a code update is detected, and automatically generating the target interface document based on the interface information and the configuration information of the service provider and the service consumer, thereby achieving the technical effect of timely automatic generation and update of the interface document and improving the efficiency of interface document generation and update, and further solving the technical problems of high labor cost and high error rate in manually writing and maintaining interface documents in related technologies.

[0091] It should be noted that the above modules can be implemented by software or hardware. For example, for the latter, it can be implemented in the following ways: the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.

[0092] It should be noted that the above-mentioned annotation information acquisition module 300, interface information acquisition module 302, configuration information acquisition module 304, and interface document generation module 306 correspond to steps S102 to S108 in the embodiment, and the examples and application scenarios implemented by the above-mentioned modules and corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned embodiment. It should be noted that the above-mentioned modules can be run in a computer terminal as part of the device.

[0093] It should be noted that the optional or preferred implementation of this embodiment can refer to the relevant description in the embodiment, which will not be repeated here.

[0094] The above-mentioned interface document generation device may also include a processor and a memory. The above-mentioned annotation information acquisition module 300, interface information acquisition module 302, configuration information acquisition module 304, interface document generation module 306, etc. are all stored in the memory as program modules, and the processor executes the above-mentioned program modules stored in the memory to realize corresponding functions.

[0095] The processor includes a kernel, which retrieves the corresponding program module from the memory. The kernel may be one or more. The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. The memory includes at least one memory chip.

[0096] According to an embodiment of the present application, an embodiment of a non-volatile storage medium is also provided. Optionally, in this embodiment, the non-volatile storage medium includes a stored program, wherein when the program is executed, the device where the non-volatile storage medium is located is controlled to execute any of the above interface document generation methods.

[0097] Optionally, in this embodiment, the non-volatile storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group, and the non-volatile storage medium includes a stored program.

[0098] Optionally, when the program is running, the device where the non-volatile storage medium is located is controlled to perform the following functions: when a change in the code in the code repository is detected, target annotation information in the code repository is obtained, wherein the target annotation information is at least used to identify the service provided by the service provider, the service consumer, and the interface class and version number of the service; based on the target annotation information, initial interface information is obtained; interface configuration information corresponding to the service provider and the service consumer, respectively, is obtained; based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, respectively, a target interface document is generated.

[0099] According to an embodiment of the present application, an embodiment of a processor is also provided. Optionally, in this embodiment, the processor is used to run a program, wherein when the program is run, any one of the interface document generation methods is executed.

[0100] According to an embodiment of the present application, an embodiment of a computer program product is also provided, which, when executed on a data processing device, is suitable for executing a program that initializes any one of the above-mentioned interface document generation method steps.

[0101] Optionally, the above-mentioned computer program product, when executed on a data processing device, is suitable for executing an initialization program having the following method steps: when a change in the code in the code repository is detected, obtaining target annotation information in the code repository, wherein the target annotation information is at least used to identify the service provided by the service provider, the service consumer of the service, and the interface class and version number of the service; based on the target annotation information, obtaining initial interface information; obtaining interface configuration information corresponding to the service provider and the service consumer, respectively; based on the initial interface information, and the interface configuration information corresponding to the service provider and the service consumer, respectively, generating a target interface document.

[0102] An embodiment of the present invention provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, the following steps are implemented: when a change in the code in the code repository is detected, target annotation information in the code repository is obtained, wherein the target annotation information is at least used to identify the service provided by the service provider, the service consumer, and the interface class and version number of the service; based on the target annotation information, initial interface information is obtained; interface configuration information corresponding to the service provider and the service consumer is obtained; based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, a target interface document is generated.

[0103] The above sequence of the embodiments of the present invention is for description only and does not represent the superiority or inferiority of the embodiments.

[0104] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0105] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the above modules can be a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, modules or indirect coupling or communication connection of modules, which can be electrical or other forms.

[0106] The modules described above as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.

[0107] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of software functional modules.

[0108] If the above-mentioned integrated module is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable non-volatile storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a non-volatile storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the various embodiments of the present invention. The aforementioned non-volatile storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.

[0109] The above are only preferred embodiments of the present invention. It should be pointed out that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for generating an interface document, characterized in that: include: When a code change in a code repository is detected, target annotation information in the code repository is obtained, wherein the target annotation information is used to at least identify a service provided by a service provider, a service consumer of the service, and an interface class and version number of the service; Based on the target annotation information, initial interface information is obtained; Obtain interface configuration information corresponding to the service provider and the service consumer respectively; A target interface document is generated based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, respectively.

2. The method according to claim 1, characterized in that: When detecting that a code in the code repository has been changed, obtaining target annotation information in the code repository includes: Use continuous integration and continuous deployment tools to detect whether code changes have occurred in the code repository; When a code change is detected in the code repository, a code building process in the continuous integration and continuous deployment process is triggered to obtain the target annotation information from the code repository.

3. The method according to claim 2, characterized in that The acquiring the target annotation information from the code repository includes: Scan the source code in the code repository using a reflection application program interface to extract service annotation information and reference annotation information in the code repository, wherein the service annotation information is at least used to identify the service provided by the service provider, as well as the interface class and version number of the service, and the reference annotation information is at least used to identify the service consumed by the service consumer, as well as the interface class and version number of the service; The target annotation information is obtained based on the service annotation information and the reference annotation information.

4. The method according to claim 1, characterized in that: The generating of the target interface document based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, respectively, comprises: The initial interface information and the interface configuration information corresponding to the service provider and the service consumer are converted into a predetermined document format to obtain the target interface document.

5. The method according to any one of claims 1 to 4, characterized in that: After generating the target interface document based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer, the method further includes: Testing the target interface document to obtain a test result; When the test result indicates that the target interface document has passed the test, the target interface document is sent to a document server, wherein the document server is used for storing and managing the interface document; The initial interface document stored in the document server is updated to the target interface document.

6. The method according to claim 5, characterized in that The testing of the target interface document to obtain a test result includes: Obtaining a test case, wherein the test case is used to simulate an interface call process based on the target interface document; The target interface document is tested based on the test case to obtain the test result, wherein the test result is at least used to indicate whether the interface parameters corresponding to the interface called based on the target interface document meet predetermined conditions.

7. The method according to claim 5, characterized in that The updating of the initial interface document stored in the document server to the target interface document comprises: Detecting whether the target interface document is consistent with the initial interface document; When the target interface document is inconsistent with the initial interface document, the initial interface document stored in the document server is updated to the target interface document.

8. The method according to claim 7, characterized in that The method further comprises: In the case where the target interface document and the initial interface document are inconsistent, generating interface update information based on difference information between the target interface document and the initial interface document; The interface update information is sent to the target terminal.

9. An interface document generating device, characterized in that: include: An annotation information acquisition module is used to acquire target annotation information in the code repository when a code change is detected in the code repository, wherein the target annotation information is used to at least identify the service provided by the service provider, the service consumer of the service, and the interface class and version number of the service; An interface information acquisition module, used to obtain initial interface information based on the target annotation information; A configuration information acquisition module, used to acquire interface configuration information corresponding to the service provider and the service consumer respectively; The interface document generation module is used to generate a target interface document based on the initial interface information and the interface configuration information corresponding to the service provider and the service consumer respectively.

10. An electronic device, characterized in that: It includes one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the interface document generation method described in any one of claims 1 to 8.

Citation Information

Cited By

  • Method, system and computer readable medium for automatic generation and updating of description documents

    CN122903527A