Interface document generation method and device, equipment and computer readable storage medium
By automatically generating interface documentation and utilizing information from code repositories and databases, the interface documentation is updated by parsing source code files. This solves the problems of low efficiency and poor accuracy for software developers when writing interface documentation, and achieves timeliness and accuracy in interface documentation.
Patent Information
- Application Number
- CN202110309768.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-23
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2041-03-23
AI Technical Summary
Software developers are inefficient and inaccurate when writing interface documentation, which can easily lead to inconsistencies between the interface documentation and the function code.
By obtaining code commit information from the code repository, querying interface documentation information in the database, generating a list of files to be parsed, parsing the source code files to update the interface documentation, and responding to the interface documentation viewing event to generate the interface documentation.
It improves the efficiency and timeliness of API documentation generation, avoids issues such as repeated parsing or omission of source code files, and ensures the accuracy of API documentation.
Smart Images

Figure CN115113854B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to an interface document generation method and device, equipment and computer readable storage medium. BACKGROUND
[0002] With the development of Internet technology, more and more software developers will choose to open the program code they have completed in the form of services, and a set of service system corresponds to multiple APIs (Application Programming Interface). In order to make other users can easily use the API provided by themselves, the software developers need to write the corresponding interface document for other users to consult. The inventor found in practice that most software developers often focus on programming and architecture, and are not good at document writing, which easily leads to low efficiency of document writing. Moreover, the software developers need to artificially compare the function code to obtain the content required by the interface document in the process of writing the interface document, and fill the content in the interface document, so that the manual operation is easy to cause the inconsistency between the interface document and the function code, thereby leading to low accuracy of the interface document. SUMMARY
[0003] The embodiments of the present application provide an interface document generation method, device, equipment and computer readable storage medium, which can automatically generate the interface document according to the submitted code source file, and improve the generation efficiency and timeliness of the interface document.
[0004] The technical scheme of the embodiments of the present application is implemented as follows:
[0005] The embodiments of the present application provide an interface document generation method, comprising: obtaining code submission information sent by a code repository in response to a code submission event; the code submission information comprises a change file list and a project branch corresponding to the code submission event; the code submission event represents that a user end submits at least one change code source file corresponding to the change file list to the code repository; querying interface document information corresponding to the project branch in a database to generate a query result; the query result is used to represent whether the interface document information corresponding to the project branch exists in the database; generating a to-be-parsed file list based on the query result; the to-be-parsed file list comprises the at least one change code source file; parsing the code source file in the to-be-parsed file list, updating the interface document information of the project branch; in response to an interface document viewing event for the project branch, generating an interface document based on the interface document information.
[0006] In some embodiments of the present application, the method further comprises: receiving a generation request for virtual data of a target interface; sending target parameter information to a virtual data generator to enable the virtual data generator to generate a virtual parameter corresponding to the target parameter information; and sending virtual data containing the virtual parameter to a user terminal. The code repository sends code submission information in response to a code submission event; the code submission information includes a list of changed files corresponding to the code submission event and a project branch; the code submission event represents that the user terminal submits at least one changed code source file corresponding to the list of changed files to the code repository; the interface document information corresponding to the project branch is queried in the database to generate a query result; the query result is used to represent whether the interface document information corresponding to the project branch exists in the database; based on the query result, a list of files to be parsed is generated; the list of files to be parsed includes at least one changed code source file; the code source files in the list of files to be parsed are parsed, and the interface document information of the project branch is updated; and in response to an interface document viewing event for the project branch, an interface document is generated based on the interface document information.
[0007] The embodiment of the present application provides an interface document generation device, and the device comprises:
[0008] The first obtaining module is configured to obtain code submission information sent by a code repository in response to a code submission event; the code submission information includes a list of changed files corresponding to the code submission event and a project branch; and the code submission event represents that a user terminal submits at least one changed code source file corresponding to the list of changed files to the code repository.
[0009] The query module is configured to query interface document information corresponding to the project branch in the database to generate a query result; and the query result is used to represent whether the interface document information corresponding to the project branch exists in the database.
[0010] The first generation module is configured to generate a list of files to be parsed based on the query result; and the list of files to be parsed includes at least one changed code source file.
[0011] The parsing module is configured to parse the code source files in the list of files to be parsed, and update the interface document information of the project branch.
[0012] The second generation module is configured to generate an interface document based on the interface document information in response to an interface document viewing event for the project branch.
[0013] The embodiment of the present application provides an interface document generation device, and the device comprises:
[0014] The memory is configured to store executable instructions;
[0015] The processor is configured to execute the executable instructions stored in the memory to implement the interface document generation method provided by the embodiment of the present application.
[0016] The embodiment of the present application provides a computer readable storage medium, which stores executable instructions, and is used for causing a processor to execute the interface document generation method provided by the embodiment of the present application.
[0017] The embodiment of the present application has the following beneficial effects:
[0018] The embodiment of the present application receives code submission information sent by a code repository in response to a code submission event, and then executes an interface document updating operation of a project branch corresponding to the code submission event, so that the timeliness of interface document updating can be ensured. Meanwhile, the embodiment of the present application queries whether corresponding interface document information of the code submission event exists in a database, to determine a to-be-analyzed file list that needs to be analyzed, so that all code source files can be analyzed in the case that no interface document information is generated for the project branch, and only the code source files in the changed file list can be analyzed in the case that interface document information is generated for the project branch, so that the analysis efficiency can be improved, and the problems of repeated analysis or missed code source files can be avoided. BRIEF DESCRIPTION OF DRAWINGS
[0019] Figure 1 is an optional architecture schematic diagram of an interface document generation system provided by the embodiment of the present application;
[0020] Figure 2 is a structure schematic diagram of an interface document generation device provided by the embodiment of the present application;
[0021] Figure 3 is an optional flow schematic diagram of an interface document generation method provided by the embodiment of the present application;
[0022] Figure 4 is an optional flow schematic diagram of an interface document generation method provided by the embodiment of the present application;
[0023] Figure 5 is an optional flow schematic diagram of an interface document generation method provided by the embodiment of the present application;
[0024] Figure 6 is an optional flow schematic diagram of an interface document generation method provided by the embodiment of the present application;
[0025] Figure 7 is an optional flow schematic diagram of an interface document generation method provided by the embodiment of the present application;
[0026] Figure 8 is an optional flow schematic diagram of an interface document generation method provided by the embodiment of the present application;
[0027] Figure 9Ais an optional flowchart of the interface document generation method provided by the embodiment of the present application;
[0028] Figure 9B is a flowchart of the project creation process provided by the embodiment of the present application;
[0029] Figure 9C is a flowchart of the project initialization process provided by the embodiment of the present application;
[0030] Figure 9D is a flowchart of the project update process provided by the embodiment of the present application;
[0031] Figure 9E is a flowchart of the interface document viewing process provided by the embodiment of the present application;
[0032] Figure 9F is a flowchart of the virtual data generation process provided by the embodiment of the present application;
[0033] Figure 10A is a java source code file schematic diagram provided by the embodiment of the present application;
[0034] Figure 10B is a partial abstract syntax tree schematic diagram of Package information provided by the embodiment of the present application;
[0035] Figure 10C is a partial abstract syntax tree schematic diagram of Import information provided by the embodiment of the present application;
[0036] Figure 10D is a partial abstract syntax tree schematic diagram of interface definition provided by the embodiment of the present application;
[0037] Figure 11A is an input parameter definition source code file schematic diagram provided by the embodiment of the present application;
[0038] Figure 11B is an abstract syntax tree schematic diagram of input parameter definition source code provided by the embodiment of the present application;
[0039] Figure 12A is an output parameter definition source code file schematic diagram provided by the embodiment of the present application;
[0040] Figure 12B is an abstract syntax tree schematic diagram of output parameter definition source code provided by the embodiment of the present application;
[0041] Figure 13A is an interface definition source code schematic diagram of Go source code provided by the embodiment of the present application;
[0042] Figure 13B is an abstract syntax tree schematic diagram of Go source code provided by the embodiment of the present application;
[0043] Figure 14 FIG. 1 is a schematic diagram of interface information and field information display according to an embodiment of the present application. DETAILED DESCRIPTION
[0044] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings, and the described embodiments should not be regarded as limiting the present application. All other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.
[0045] In the following description, "some embodiments" are described, which describe a subset of all possible embodiments, but it can be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict.
[0046] In the following description, the terms "first\second\third" are only to distinguish similar objects, and do not represent a specific order of the objects. It can be understood that "first\second\third" can be interchanged in a specific order or sequence as allowed, so that the embodiments of the present application described in the present embodiment can be implemented in an order other than that illustrated or described in the present embodiment.
[0047] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present application belongs. The terms used herein are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0048] The relevant data collection and processing in the embodiments of the present application should strictly comply with the requirements of relevant laws and regulations, obtain the informed consent or separate consent of the personal information subject, and within the scope of authorization of laws and regulations and the personal information subject, carry out subsequent data use and processing.
[0049] Before the embodiments of the present application are further described in detail, the terms and phrases involved in the embodiments of the present application are explained, and the terms and phrases involved in the embodiments of the present application are applicable to the following explanations.
[0050] (1) AST: Abstract Syntax Tree, an abstract representation of the syntax structure of source code. Abstract syntax tree is a tree-like form of programming language syntax structure, each node on the tree represents a structure in the source code. The reason why the syntax is "abstract" is that the syntax here does not represent every detail that appears in the real syntax. For example, nested parentheses are implied in the structure of the tree and are not presented in the form of nodes; and conditional jump statements such as if-condition-then can be represented using a node with three branches.
[0051] (2) Git: an open source distributed version control system that can effectively and quickly handle version management of projects from small to very large. Such as Github, etc.
[0052] (3) Webhook: Webhook is a method of increasing or changing the performance of a web page through a custom callback function. These callbacks can be saved, modified and managed by third-party users and developers who may be related to the original website or application.
[0053] (4) Code as documentation: In software engineering, different systems need to provide interface documents (api), and code as documentation is a way to generate interface documents through code itself and optional annotation comments.
[0054] Referring to Figure 1 , Figure 1 is an optional architecture diagram of the interface document generation system 100 provided by the embodiments of the present application, to realize the support of an interface document generation application, the terminal (exemplarily shows the terminal 400-1 and the terminal 400-2) connects the server 200 through the network 300, and the network 300 can be a wide area network or a local area network, or a combination of the two. Figure 1 It is also shown that the server 200 can be a server cluster, which includes servers 200-1 to 200-3. Similarly, the servers 200-1 to 200-3 can be physical machines or virtual machines constructed by using virtualization technologies (such as container technology and virtual machine technology). The embodiments of the present application do not limit this, and of course, a single server can also be used to provide services in the present embodiment.
[0055] Referring to Figure 2 , Figure 2 is a structure diagram of the interface document generation device 500 provided by the embodiments of the present application, Figure 2The illustrated interface document generation device 500 includes at least one processor 510, a memory 550, at least one network interface 520, and a user interface 530. The various components of the interface document generation device 500 are coupled together by a bus system 540, which is used to facilitate communication between the components. It is understood that the bus system 540 is used to facilitate communication between the components and is not necessarily limited to the busses described herein. The various busses can include, for example, a power bus, a control signal bus, and a status signal bus, in addition to a data bus. However, it is noted that the busses in the bus system 540 are illustrated as single busses, it is understood that the busses can be implemented as multiple busses and / or as single busses including multiple bus segments. Figure 2 The various busses are shown as single busses for clarity, it is understood that the busses can be implemented as multiple busses and / or as single busses including multiple bus segments.
[0056] The processor 510 can be an integrated circuit chip, having a processing capability of signals, such as a general purpose processor, a digital signal processor (DSP), or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, etc., wherein the general purpose processor can be a microprocessor or any conventional processor.
[0057] The user interface 530 includes one or more output devices 531 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 530 also includes one or more input devices 532 that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0058] The memory 550 includes volatile memory or non-volatile memory, and can include both volatile and non-volatile memory. The non-volatile memory can be read only memory (ROM), and the volatile memory can be random access memory (RAM). The memory 550 described in the embodiments of the present application is intended to include any suitable type of memory. The memory 550 can optionally include one or more storage devices physically separate from the processor 510.
[0059] In some embodiments of the present application, the memory 550 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or subsets or supersets thereof, which are exemplarily described below.
[0060] The operating system 551 includes system programs for processing various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks;
[0061] network communication module 552, configured to reach other computing devices via one or more (wired or wireless) network interfaces 520, exemplary network interfaces 520 including: Bluetooth, Wireless Fidelity (WiFi), and Universal Serial Bus (USB), etc.;
[0062] display module 553, configured to enable presentation of information via one or more output devices 531 (e.g., display screen, speaker, etc.) associated with the user interface 530 (e.g., user interface for operating the peripheral device and displaying content and information);
[0063] input processing module 554, configured to detect and interpret one or more user inputs or interactions from one or more input devices 532.
[0064] In some embodiments of the present application, the interface document generation apparatus provided by the embodiments of the present application can be implemented in a combination of software and hardware, for example, the interface document generation apparatus provided by the embodiments of the present application can be a processor in the form of a hardware decoding processor, which is programmed to execute the interface document generation method provided by the embodiments of the present application.
[0065] In some embodiments of the present application, the interface document generation apparatus provided by the embodiments of the present application can be implemented in software, Figure 2 An interface document generation apparatus 555 stored in the memory 550 is shown, which can be software in the form of programs and plug-ins, etc., including the following software modules: a first acquisition module 5551, a query module 5552, a first generation module 5553, an analysis module 5554, and a second generation module 5555. These modules are logical, and thus can be combined or further split according to the implemented functions.
[0066] The functions of the various modules will be described below.
[0067] In some embodiments, the apparatus provided by the embodiments of the present application can be implemented in a hardware manner. For example, the apparatus provided by the embodiments of the present application can be a processor in the form of a hardware decoding processor programmed to perform the interface document generation method provided by the embodiments of the present application. For example, the processor in the form of a hardware decoding processor can be implemented by using one or more application specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field programmable gate arrays (FPGAs), or other electronic elements.
[0068] The embodiments of the present application will be described below in conjunction with an exemplary application and implementation of a server. In the embodiments of the present application, the interface document generation method provided by the embodiments of the present application will be described with the server as the execution subject, where the server can be a document platform.
[0069] Referring to Figure 3 , Figure 3 is an optional flow diagram of the interface document generation method provided by the embodiments of the present application, which will be described in conjunction with the steps shown in Figure 3 .
[0070] In step 301, code commit information sent by a code repository in response to a code commit event is acquired; the code commit information includes a list of changed files corresponding to the code commit event and a project branch; the code commit event represents that a user terminal submits at least one changed code source file corresponding to the list of changed files to the code repository.
[0071] In some embodiments of the present application, the code repository is configured to receive code source files submitted by the user terminal. Before step 301, the method can further include: the code repository receiving a project creation request for an updated project sent by the user terminal, and in response to the project creation request, the code repository creating a code project for storing and managing code source files of the updated project. After the creation of the code project is completed, after receiving code source files submitted by the user terminal for the updated project, the code repository can determine a list of changed files corresponding to a current code commit event of the user terminal according to historical code source files saved in the code project and code source files submitted by the user terminal this time, where the list of changed files includes at least one changed code source file.
[0072] In some embodiments of the present application, in the code repository, different project branches can be set for the to-be-updated project. Among them, the branch is an independent code environment used by the developer to develop different businesses at the same time and to cooperate with the tester; the business-independent function can be tested, and the mutual influence between businesses is avoided. The to-be-updated project can correspond to at least one project branch, and different project branches can be used to store different versions of code source files, that is, all code source files in a project branch can be used to define all interfaces of the to-be-updated project.
[0073] In further embodiments, the user end also specifies the project branch corresponding to the code source file submitted this time in the process of submitting the code source file to the code repository. Accordingly, in the process of generating the code submission information based on the code submission event, the code repository generates the corresponding code submission information according to the project branch and the above change file list, and sends the code submission information to the document platform.
[0074] It should be noted that the code submission information can include at least one project branch, and for each project branch, the code submission information includes a change file list corresponding to each project branch. In order to facilitate understanding, subsequent embodiments will be further described taking the code submission information including only one project branch and the change file list corresponding to the project branch as an example.
[0075] In step 302, the interface document information corresponding to the project branch is queried in the database to generate a query result; the query result is used to represent whether the interface document information corresponding to the project branch exists in the database.
[0076] In some embodiments of the present application, the document platform saves the interface document information corresponding to all project branches of the to-be-updated project through the database, and the database can be set in the server corresponding to the document platform, and can also be set in other cloud servers. The interface document information is used to store the interface data corresponding to the project branch, and the interface data can include at least one interface corresponding to the project branch, and interface information and parameter information corresponding to each interface. Among them, the interface information can include at least one of the following: interface name, interface request path, interface request Http method, interface input parameter definition, interface output parameter definition, etc.; the parameter information can include: field name, field type, field description, whether it is required, etc.
[0077] In some embodiments of the present application, the interface document information corresponding to the project branch can be a parsing result corresponding to each code source file corresponding to the project branch,
[0078] In step 303, based on the query result, a to-be-parsed file list is generated; the to-be-parsed file list includes at least one changed code source file.
[0079] In some embodiments of the present application, in the case that the interface document information corresponding to the project branch does not exist in the database, it indicates that the code repository has not received the code source file corresponding to the project branch before, and therefore the document platform has not parsed the code source file corresponding to the project branch; it can also indicate that even if the code repository has received the code source file corresponding to the project branch before, due to communication problems between the code repository and the document platform, the document platform has not received the code submission information corresponding to the project branch, and therefore has not parsed the code source file corresponding to the project branch. Of course, there are other cases that cause the interface document information corresponding to the project branch to not exist in the document platform, at this time, based on the case that the interface document information corresponding to the project branch does not exist in the database, the generated to-be-parsed file list can include all code source files corresponding to the project branch in the code repository.
[0080] In some embodiments of the present application, in the case that the interface document information corresponding to the project branch exists in the database, it indicates that the code repository has received the code source file corresponding to the project branch before, and the document platform has also received the historical code submission information generated by the code repository for the previously submitted code source file, and the interface document information corresponding to the project branch in the code repository is parsed to obtain the interface document information corresponding to the project branch, which is saved in the database. At this time, the document platform can determine the to-be-parsed file list according to the change file list in the code submission information, that is, the to-be-parsed file list can include the at least one changed code source file.
[0081] In step 304, the code source files in the to-be-parsed file list are parsed, and the interface document information of the project branch is updated.
[0082] In some embodiments of the present application, the above-mentioned parsing of the code source files in the to-be-parsed file list can be implemented in the following manner: based on the to-be-parsed file list, all code source files included in the to-be-parsed file list are obtained from the code repository, and a code parsing task corresponding to each code source file is generated, all code parsing tasks are added to a preset execution queue, all code parsing tasks are executed in sequence through the execution queue to obtain a parsing result corresponding to each code source file, and then the interface document information corresponding to the project branch is updated according to the parsing result corresponding to each code source file.
[0083] In some embodiments of the present application, before resolving the code source files in the to-be-resolved file list, the to-be-resolved file list can also be filtered, and the method comprises the following steps: obtaining the project type of the project branch, obtaining the file type of each code source file in the to-be-resolved file list, and filtering the corresponding code source file in the to-be-resolved file list in the case that the file type is inconsistent with the project type. The file types of all code source files in the to-be-resolved file list after the filtering operation are consistent with the project type of the project branch.
[0084] For example, a java project only processes files with the suffix.java, and other files (such as xml files) are ignored. A Go project only processes files with the suffix.Go, and other files are ignored.
[0085] In step 305, in response to an interface document viewing event for a project branch, an interface document is generated based on interface document information.
[0086] In some embodiments of the present application, the document platform can receive an interface document viewing request from any user terminal and generate an interface document viewing event corresponding to the interface document viewing request. Taking the interface file viewing event for the project branch as an example, the document platform can generate the interface document information according to the interface document information of the project branch generated in step 304.
[0087] The document platform can preset a display template of the interface document, and in the process of generating the interface document, the interface information and parameter information included in the interface file information can be added to the display template according to the filling rules of the display template to obtain the interface document.
[0088] According to the above exemplary implementation of the present application, Figure 3 According to the above exemplary implementation of the present application,
[0089] Referring to Figure 4 , Figure 4 is an optional flowchart of the interface document generation method provided by the embodiments of the present application, based onFigure 3 Before step 301, the method further comprises steps 401-402, and before step 302, the method further comprises steps 403-404, and step 302 can be updated to step 405, which will be described in combination with Figure 4 the steps shown.
[0090] In step 401, a project creation request sent by a user terminal is received; the project creation request includes a code address of a to-be-updated project in a code repository and a branch rule of the to-be-updated project.
[0091] In some embodiments of the present application, in order to realize that the developer can directly receive the code submission information corresponding to the code submission event while submitting the code source file to the code repository, before the embodiments, the document platform needs to initialize the to-be-updated project corresponding to the code submission event, and the specific initialization process can include steps 401-402. Figure 3
[0092] In the embodiments of the present application, for the to-be-updated project, the user terminal can create a document project corresponding to the to-be-updated project in the document platform, and the document project is used to store all project branches corresponding to the to-be-updated project and the related information of the interface document in each project branch, including the interface document information forming the interface document and the interface document obtained after processing the interface document information. Correspondingly, the user terminal can create a code project corresponding to the to-be-updated project in the code repository, and the code project is used to store all project branches corresponding to the to-be-updated project and the code source file corresponding to each project branch. In step 401, the code address of the to-be-updated project in the code repository carried in the project creation request is the code address of the code project corresponding to the to-be-updated project in the code repository, and through the code address, all code source files corresponding to the to-be-updated project can be obtained, and in the case that any one of the project branch information of the to-be-updated project is determined, all code source files corresponding to the project branch information in the to-be-updated project can be further obtained from the code repository.
[0093] In some embodiments of the present application, the branch rule is used to determine whether the current project branch needs to generate the interface document. The branch rule can be described by a regular expression, that is, the project branch matching the regular expression needs to generate the interface document.
[0094] In some embodiments of the present application, the document platform can display the project creation interface to the user end; receive a project creation operation issued by the user through the project creation interface; and parse the project creation operation to obtain document project information corresponding to the to-be-updated project, the document project information including a code address of the to-be-updated project in the code repository and a branch rule of the to-be-updated project.
[0095] In step 402, in response to the project creation request, a notification address of the to-be-updated project is generated according to the code address; the notification address, after being configured to the code repository, is used to send code submission information to the document platform in response to the code repository receiving a code submission event corresponding to the to-be-updated project.
[0096] In some embodiments of the present application, the document platform creates a document project corresponding to the to-be-updated project, and generates a notification address of the to-be-updated project according to the code address. The notification address can be a Webhook address, which, after being configured to a repository address corresponding to the to-be-updated project in the code repository, causes the code submission information corresponding to a file update event uploaded by the user end for the to-be-updated project to be sent to the document platform based on the Webhook address each time the code repository receives the file update event. Wherein, the document platform can send the Webhook address to the user end through an address copy interface after generating the Webhook address. That is, the developer can copy the Webhook address by clicking a copy button in the address copy interface, and configure the Webhook address to the code repository.
[0097] In step 403, the branch rule of the to-be-updated project is obtained.
[0098] In step 404, branch information of a project branch in the code submission information is obtained.
[0099] The branch information is name information corresponding to the project branch.
[0100] In step 405, in a case where the branch information meets the branch rule, interface document information corresponding to the project branch is queried in the database to generate a query result; the query result is used to represent whether the interface document information corresponding to the project branch exists in the database.
[0101] Through the embodiments of the present application, the following advantages can be achieved Figure 4According to the above exemplary embodiments, in the process of configuring the project on the document platform, the branch rule corresponding to the project is added, so that in the case of simultaneously submitting the code source files of the test branch and the version branch, the branch information submitted is detected by using the branch rule, the code source files of the version branch meeting the branch rule are subjected to the subsequent interface document generation steps of querying and parsing, and the code source files of the version branch not meeting the branch rule are not subjected to the corresponding interface document generation steps, so that the flexibility of the application is improved.
[0102] Referring to Figure 5 , Figure 5 is an optional flowchart of the interface document generation method provided by the embodiments of the application, based on Figure 3 , step 303 can be implemented by step 501 or step 502, which will be described in combination with the steps shown in Figure 5 .
[0103] In step 501, in the case that the query result is used to represent that the interface document information corresponding to the project branch does not exist in the database, a to-be-parsed file list is determined based on the code file list corresponding to the project branch; the code file list includes all code source files corresponding to the project branch.
[0104] In step 502, in the case that the query result is used to represent that the interface document information corresponding to the project branch exists in the database, a to-be-parsed file list is determined based on the code submission information.
[0105] According to the above exemplary embodiments of the application, Figure 5 , the application determines the to-be-parsed file list that needs to be parsed by querying whether the corresponding interface document information exists in the database, so that all code source files can be parsed in the case that the interface document information of the project branch has not been generated, and only the code source files in the change file list can be parsed in the case that the interface document information of the project branch has been generated, so that the parsing efficiency is improved.
[0106] Referring to Figure 6 , Figure 6 is an optional flowchart of the interface document generation method provided by the embodiments of the application, which will be described in combination with the steps shown in Figure 6 .
[0107] In step 601, a current submission identifier and a first historical submission identifier carried by the code submission information are acquired; the current submission identifier is a unique identifier of the code submission information, and the first historical submission identifier is a unique identifier of first historical code submission information corresponding to the project branch; the first historical code submission information is adjacent submission information sent by the code repository before the code submission information is sent.
[0108] In some embodiments of the present application, the code submission information includes two submission identifiers generated by the code repository, one of which is the current submission identifier, which is a unique identifier of the code submission information sent by the current code repository; the other is the first historical submission identifier, which is the adjacent submission information before the current code submission information of the code repository, and the first historical submission identifier is a unique identifier of the adjacent submission message.
[0109] It should be noted that the code repository generates and stores a unique identifier corresponding to each code submission information in the process of sending each code submission information to the document platform, and carries the unique identifier corresponding to the current code submission information and the unique identifier of the last sent code submission information in the process of sending any code submission information.
[0110] In step 602, the current submission identifier in the code submission information is saved.
[0111] In some embodiments of the present application, the document platform saves the current submission identifier in the code submission information when it receives the code submission information. Accordingly, the document platform also saves the historical code submission identifier corresponding to each historical code submission information after receiving the historical code submission information before the current code submission information.
[0112] In step 603, the second historical submission identifier of the second historical code submission information stored locally is compared with the first historical submission identifier of the first historical code submission information carried in the code submission information.
[0113] In some embodiments of the present application, the second historical code submission information is the adjacent code submission information received by the document platform before the current code submission information, and the second historical submission identifier is a unique identifier of the second historical code submission information. By comparing the second historical submission identifier stored locally by the document platform with the first historical submission identifier carried in the code submission information, it can be determined whether the code submission information is missing or lost, etc.
[0114] In step 604, in the case that the first historical submission identifier and the second historical submission identifier are inconsistent, the to-be-analyzed file list is determined based on the second historical code submission information and the code submission information.
[0115] Among them, the code source file changed between the second historical code submission information saved in the document platform and the code submission information this time can be taken as the to-be-analyzed file list.
[0116] In some embodiments of the present application, the determination of the to-be-parsed file list based on the second historical code submission information and the code submission information can be implemented through steps 6041 to 6044.
[0117] In step 6041, at least two lists of changed files between the code submission information and the locally stored historical code submission information in the code repository are obtained; the at least two lists of changed files at least include a list of changed files in the code submission information and a list of changed files in the locally stored historical code submission information.
[0118] In step 6042, the file identifier and the change time of each code source file in each list of changed files are obtained.
[0119] In step 6043, at least one code source file corresponding to each file identifier is filtered according to the change time, and the latest code source file corresponding to each file identifier is retained.
[0120] In step 6044, the to-be-parsed file list is determined based on the latest code source file corresponding to each file identifier.
[0121] For example, if the first historical submission identifier is inconsistent with the second historical submission identifier, at least two lists of changed files can be determined according to the second historical submission information and the current code submission information. Wherein, at least one missing submission identifier between the second historical submission identifier and the current submission identifier can be obtained first, at least two lists of changed files corresponding to the historical submission information of each missing submission identifier and the current code submission information are obtained, and then the to-be-parsed file list is determined based on the at least two lists of changed files.
[0122] Through the above exemplary implementation of the present application, Figure 6 As can be seen from the above exemplary implementation of the present application, the submission identifier of each submission is recorded, when the next submission event is received, the submission identifier of the last submission is obtained from the submission information, and whether the obtained last submission identifier is inconsistent with the last submission identifier recorded by the document platform is compared, and then it is determined whether there is a problem of missing code submission information. At the same time, the code source files changed between the second historical code submission information saved in the document platform and the current code submission information are taken as the to-be-parsed file list, the code source files corresponding to the missing code submission information can be added to the to-be-parsed file list, so that the accuracy of the interface document information of the to-be-updated project in the document platform can be ensured; and in the process of supplementally parsing the missing code source files, the code source files with earlier change time are ignored, unnecessary code parsing process can be reduced, and the parsing efficiency is improved.
[0123] Referring toFigure 7 , Figure 7 is an optional flow diagram of the interface document generation method provided by the embodiments of the present application, based on the above embodiments, based on Figure 3 for example, Figure 3 Step 304 in the above embodiments can be implemented by steps 701-703, which will be described in combination with Figure 7 illustrated steps.
[0124] In step 701, at least one code source file corresponding to the list of files to be parsed is obtained from the code repository.
[0125] In step 702, the parsing result is saved to the database to update the interface document information of the project to be updated.
[0126] In some embodiments of the present application, the above-mentioned saving the parsing result to the database to update the interface document information of the project to be updated can be implemented by steps 7021-7023:
[0127] In step 7021, a current version number related to the submission time is added to the parsing result according to the submission time of the code submission information.
[0128] In step 7022, the parsing result carrying the version number is saved to the database.
[0129] In step 7023, the parsing result with a version number less than the current version number in the database is deleted to obtain the interface document information of the project to be updated.
[0130] In step 703, at least one code source file is parsed to obtain the parsing result of the code to be parsed in each code source file; the parsing result includes field identification and field definition information of the defined field; the defined field includes the interface field and / or the parameter field.
[0131] In some embodiments of the present application, the above-mentioned parsing at least one code source file to obtain the parsing result of the code to be parsed in each code source file can be implemented by steps 7031-7032:
[0132] In step 7041, each code source file is converted into a corresponding abstract code tree to obtain at least one abstract code tree.
[0133] In step 7042, each abstract code tree is parsed to obtain identification information and definition information of each code source file; the identification information is used to locate the code source file in the database to obtain the definition information; the definition information includes field identification and field definition information of the defined field included in the code source file; the defined field includes the interface field and / or the parameter field.
[0134] The parsing result can include field identification and field definition information of the interface field, i.e., interface identification and interface definition information of the interface. The parsing interface can also include field identification and field definition information of the parameter field, i.e., parameter identification and parameter definition information of the parameter.
[0135] In some embodiments of the present application, in the process of parsing the abstract code tree corresponding to each code source file, if the definition field is a parameter field, the parameter definition information includes built-in types and composite types. The parameter definition information corresponding to the built-in type includes specific parameter descriptions of the parameter field, such as parameter type, parameter range, etc. The parameter definition information corresponding to the composite type does not include specific descriptions of the parameter field, but includes identification information of other code source files referenced by the parameter field. Through the identification information of the other code source files and the parameter identification of the parameter field, the parent code source file referenced by the parameter definition information can be located, and then the specific parameter description of the parent code source file for the parameter field can be obtained.
[0136] Through the above exemplary implementation of the present application, Figure 7 It can be known from the above exemplary implementation of the present application that, by parsing the code source file through the abstract code tree, the description information of the interface and the in-out parameter information in the source code can be accurately obtained, and through the abstract code tree, the attribute inheritance relationship in the source code compilation process can be preserved, and in the process of obtaining the parameter attribute, the specific definition data of the parameter can be obtained.
[0137] Referring to Figure 8 , Figure 8 is an optional flowchart of the interface document generation method provided by the embodiments of the present application, based on Figure 3 , step 305 can be implemented by steps 801 to 804, which will be described in combination with the steps shown in Figure 8 .
[0138] In step 801, the target project identification and the target interface identification carried by the interface document viewing request are obtained.
[0139] In step 802, the target interface document information corresponding to the target project identification is queried in the database.
[0140] In step 803, the target interface information and the target parameter information corresponding to the target interface are obtained in the target interface document information based on the target interface identification.
[0141] In some embodiments of the present application, the above step of obtaining the target interface information and the target parameter information corresponding to the target interface in the target interface document information based on the target interface identification can be implemented by the following steps 8031 to 8033:
[0142] In step 8031, according to the target interface identifier, target interface information corresponding to the target interface is obtained from the target interface document information; the target interface information includes interface identifier information corresponding to the interface;
[0143] In step 8032, based on the interface identifier information, interface parsing results corresponding to the interface source file are determined;
[0144] In step 8033, definition information in the interface parsing results is obtained; and target parameter information of the interface is generated based on the definition information.
[0145] In the above embodiment, the definition information in the interface parsing results is obtained by the following method: parameter identifier and parameter definition information of at least one interface parameter definition field in the definition information are obtained; in the case that the parameter definition information of the interface parameter definition field is an internal type, field identifier and field definition information of the interface parameter definition field are taken as the target parameter information; in the case that the parameter definition information of the interface parameter definition field is a composite type, reference identifier information is determined based on the field identifier of the interface parameter definition field; field parsing results corresponding to the reference identifier information are obtained, and the target parameter information of the interface is generated based on the definition information in the field parsing results.
[0146] In step 804, the interface document is generated based on the target interface information and the target parameter information.
[0147] In some embodiments of the present application, the method further includes: receiving a generation request of virtual data for the target interface; sending the target parameter information to a virtual data generator to make the virtual data generator generate virtual parameters corresponding to the target parameter information; and sending the virtual data containing the virtual parameters to a user terminal.
[0148] According to the above exemplary implementation of the present application, Figure 8 It can be seen from the above exemplary implementation of the present application that the target interface information and the target parameter information obtained by parsing can be rendered to obtain an intuitive interface document in response to a viewing request of the interface document, and virtual data matched with the interface document can be generated in response to a mock request, thereby providing technical support for project development.
[0149] In the following, an exemplary application of the present application in an actual application scenario will be described.
[0150] For the management of the interface document, the following solutions exist in the related art:
[0151] (1) Based on the interface document management scheme of word file, markdown file, etc. Among them, the content of the interface document is recorded in the word file, markdown file, etc. according to the self-organized format by manual, the viewer requests the above file for viewing, and the writer needs to modify the interface document in time with the change of the system and notify the viewer; This scheme tool is simple to obtain, without relying on other systems.
[0152] (2) Interface document management platform, such as RAP interface management platform. Among them, the input personnel can enter the interface information one by one into the interface document management platform according to the project management interface, or import the file with fixed format into the interface document management platform, and the viewer can view the interface information through the interface document management platform. Among them, the platform can also store detailed interface field information for interfacing with other systems.
[0153] (3) Document parsing scheme based on annotation or java doc. Among them, the input personnel need to annotate the code according to a certain format, and the parser reads the annotation, converts the content of the annotation into formatted storage, and is used for subsequent display, which can be updated with the change of the code to ensure that the document can be updated with the code.
[0154] (4) Swagger java project document parsing scheme. Among them, this scheme introduces the swagger package into the java project, and the structure information of the interface is obtained when the java project runs, and the interface document is displayed. This scheme makes full use of the structure of the code, without the need for developers to write field information manually.
[0155] The applicant found that the above solutions have the following technical problems: (1) The document needs to be written manually, the initial work investment is large, the real-time interface change needs to be ensured in the later period, the maintenance cost is high, and the interface file placement management is difficult. (2) The input personnel need to enter one by one, the writing cost is high in the early stage, and the update and maintenance success is also high in the later stage. (3) The developer needs to record the interface document information in the code, which means that only the position of writing the interface document one by one is changed, and the annotation information in the code needs to be updated when the interface field changes. (4) The display of the interface document depends on the start of the project, and the project needs to be restarted every time the interface is updated, which cannot manage the interface document according to the version, and there is no centralized platform for circulation and viewing.
[0156] Based on the above technical problems, the present application provides an interface document generation method, please refer to Figure 9A , Figure 9A shows an optional flowchart. It will be explained in conjunction with the following steps.
[0157] In step A01, the code repository receives the code submitted by the developer through the user terminal.
[0158] Wherein, before step A01, the developer has created a project corresponding to the code on the document platform.
[0159] In step A02, the code repository requests the document platform through Webhook.
[0160] Wherein, the code repository sends the submission information carried in step A01 to the document platform through the Webhook corresponding to the project in the document platform. The submission information can include at least one of the following: submitter, submission time, submitted code (Git) branch, code repository information to which the project belongs, changed file list, and project identifier in the document platform.
[0161] In step A03, the document platform receives the Webhook notification and queries the project information.
[0162] Wherein, after receiving the Webhook notification, the document platform obtains the submission information carried by the Webhook notification and verifies the project identifier in the submission information. The main verification is the correctness of the signature in the project identifier to ensure the legal source of the Webhook notification. Then, it queries whether the project identifier exists. If the verification fails, it returns error information.
[0163] After successful verification, the document platform queries the project information. Wherein, the document platform can generate a regular expression according to the branch rule configured when creating. In the process of querying project information, it verifies whether the Git branch information in the Webhook notification matches the configured regular expression. If it does not match, it means that the Git branch of this submission does not need to generate interface documents (for example, some hotfix, test branch), and it is not processed directly. If it matches, it means that this Git branch needs to generate interface documents, and step A04 is executed.
[0164] In step A04, whether to initialize.
[0165] Wherein, after determining the Git branch that needs to generate interface documents, the document platform determines whether the Git branch has completed initialization. In the case that there is document information in the Git branch, it means that the initialization has been completed. In the case that there is no document information in the Git branch, it means that the initialization has not been completed.
[0166] In step A05, Git clone (copy) the project of the specified branch.
[0167] In step A06, traverse the copied project to obtain all file contents.
[0168] If the branch does not exist, it means that the branch has not generated the interface document, and the code of this submission change cannot be parsed alone. In this case, the entire branch code needs to be cloned, and all code source files need to be traversed to obtain the content for parsing.
[0169] In step A07, the source code file of the change is obtained from the Webhook notification.
[0170] In step A08, the file content is requested from the code repository interface.
[0171] If the branch already exists, it means that the previous submission of this project has been parsed and the document has been generated. In this case, only the code of this submission change needs to be parsed, the file path is requested from the Git interface to obtain the detailed content of the file, and then the file content is parsed.
[0172] In step A09, the code parser is called to obtain the interface information and field information.
[0173] After obtaining the source code file path and content, the file format is judged. For a java project, only files with.java suffix are processed, and other files (such as xml files) are ignored. For a Go project, only files with.Go suffix are processed, and other files are ignored. The file content that meets the file format requirement is submitted to the code parser for parsing. The code parser converts the source code into AST, performs tree traversal on the AST, obtains the defined interface (including interface name, interface request path, interface request Http method, interface input parameter definition, interface output parameter definition, etc.) and protocol information (including field name, field type, field description, whether it is required, etc.) according to the syntax and annotation comments of the code, and records the obtained information in the database.
[0174] In step A10, the interface information and field information are recorded in the database.
[0175] Wherein, when the interface information is parsed from the source code and updated, the disorder of webhook notification arrival, plus the time-consuming in parsing the source code, may cause the newer changes to be processed first, and the old changes to be processed later due to the time-consuming of notification and processing, which may cause the newer information of the interface to be overwritten by the old information. To solve the above problem, the document platform records the commit time of each file in Git, and when parsing the file to update the document information, it first judges whether the update time of the file to be processed is later than the update time of the file recorded by the document platform. If the file update time is earlier, it means that the interface information has been updated by the newer same source code file, and it is not necessary to parse and ignore directly. Only when the update time of the file to be processed is later than the update time recorded by the document platform, the parsing and processing are performed. Because the update time of the file is taken from the commit time of the file recorded in the Git repository, the time is from the Git commit record, and the time can correctly reflect the order of file changes.
[0176] In some embodiments, the changes of the document platform interface information are obtained by parsing the source code file to get the interface information and field information recorded to the database. This way can well handle the addition and change cases, but the deletion of the interface and field cannot be perceived. In actual use, the deletion of the field and interface is common, so this situation needs to be handled. The solution adopted by the document platform is to record the file information to which the interface and field belong when recording the definition of the interface and the definition of the field. When updating the information of the source file each time, the document platform uses the commit time of the file as the version number, and updates the version number of the interface and field record with each file change. In this case, for the interfaces and fields that have been deleted from the file, their version numbers will no longer be updated, and after the file is parsed and the information is recorded to the database, the interface definition and field definition with the version number less than the current update version number are deleted, so that the interface and field definitions that no longer exist in the file are deleted, to realize the deletion of the interface that no longer exists in the code.
[0177] In step A11, the document renderer associates the interfaces and fields of different files and the processing of generics.
[0178] Wherein, when the user views the interface information, the stored interface information and field information are read from the database. Since the interface definition and the interface in-out parameter field type definition can be distributed in different files, and the Java source code has special processing conditions such as generics and class inheritance, the Go language also has conditions such as pointer type, structure reuse, and composite type. The document renderer needs to associate the limited class name (i.e., the full name of the containing package and class name) of each interface and field type definition file, and perform real type replacement for generics, merge and cover the fields of class inheritance, remove pointers for Go's pointer type, and copy fields for Go's structure reuse. Finally, the complete name of the interface, the request address, the Http method, the input parameter detailed information, and the output parameter detailed information are spliced.
[0179] In step A12, the interface document is displayed.
[0180] Wherein, the interface platform can display the interface document corresponding to the project through the interface.
[0181] Please refer to Figure 9B which shows a flowchart of a project creation process, which will be explained in conjunction with the following steps.
[0182] In step B01, the user end sends a creation request of a code project to the code repository.
[0183] Wherein, the document platform is based on code source files to parse and generate, therefore, a code project needs to be created in the code repository, which is used to manage the corresponding code source files. After the code repository completes the creation of the code project, step B02 is executed.
[0184] In step B02, the code repository sends the project path corresponding to the code project to the user end.
[0185] Wherein, the code repository creates the code project in response to the creation request, and generates the project path corresponding to the code project. The project path is used to obtain the code source files corresponding to the code project in the code repository.
[0186] In step B03, the user end sends a new request of a document project to the document platform.
[0187] Wherein, the new request includes the project path. In some embodiments, the new request also includes the project information of the document project.
[0188] In step B04, the document platform queries the project information of the code project through the interface provided by the code repository.
[0189] Wherein, the document platform needs to access the code repository through the login account corresponding to the document platform in the process of accessing the code repository. In the case that the login account has access rights to the code project, the code project can be queried from the above interface; in the case that the login account does not have access rights to the code project, the process is ended and an error is reported.
[0190] In step B05, the code repository sends the project information of the code project to the document platform.
[0191] In step B06, the document platform sends the creation success information and the Webhook address of the project information to the user end.
[0192] Wherein, the document platform generates a Webhook address corresponding to the document project according to the project information of the code project and displays it on the front end.
[0193] In step B07, the user end sends configuration information carrying the Webhook address to the code repository.
[0194] Wherein, after the code repository receives the Webhook address, it can generate a Webhook notification after the code project receives the code submitted by the user end, and send it to the document project corresponding to the document platform.
[0195] In step B08, the code repository returns configuration success information to the user end.
[0196] It should be noted that the code repository also provides an interface that allows the document platform to directly configure the Webhook address, but operating the interface requires granting the code repository to the document platform public account. This solution will increase the risk of the code project.
[0197] Please refer to Figure 9C , which shows a flowchart of a project initialization process, which will be explained in conjunction with the following steps.
[0198] In step C01, the user end submits the code source file to the code repository.
[0199] Wherein, the user end is provided with a client corresponding to the code repository, and the user end can access the code repository through the client.
[0200] In step C02, the code repository sends the change file information to the document platform through Webhook.
[0201] Wherein, after receiving the code source file, the code repository can obtain a list of changed code files from the code source file and generate corresponding change file information.
[0202] In step C03, the document platform sends a project information query request (and rules) to the database;
[0203] In step C04, the database sends a project information query response to the document platform.
[0204] In step C05, the document platform generates an initialization task based on the project query response.
[0205] The initialization task includes a project initialization task and a branch initialization task. If it is queried that the project branch has not generated an interface, it means that only the changed files can be parsed, and all code files of the entire project need to be obtained for parsing processing. In the case of pulling all source code of the entire project, the time consumption will be relatively long, and it cannot be guaranteed to return in a synchronized state.
[0206] In step C06, the document platform writes the initialization task into the message queue.
[0207] In step C07, the message queue sends a write result to the document platform.
[0208] In step C08, the document platform sends a Webhook response to the code repository.
[0209] In step C09, the code repository sends a code submission response to the user end.
[0210] Subsequently, the information in the message queue is consumed by an asynchronous task, and then the source code files of the specified branch of the code repository are cloned to the local; then all source code files are traversed, and the interface definition and field definition in the source code file are obtained by requesting the code parser one by one, and finally the entire task is completed; in this way, the interface information and field information defined in all source code files in the current branch are recorded in the database.
[0211] In step C10, the asynchronous task processing module sends a task acquisition request to the message queue.
[0212] In step C11, the message queue sends an initialization task to the asynchronous task processing module.
[0213] In step C12, the asynchronous task processing module sends a code acquisition request to the code repository.
[0214] The code acquisition request is used to pull the source code files corresponding to the initialization task.
[0215] In step C13, the code repository sends a code acquisition response to the asynchronous task processing module.
[0216] In step C14, the asynchronous task processing module traverses all code source files and sends the code source files to the code parser.
[0217] In step C15, the code parser parses the code source files to obtain the interface definition and field definition corresponding to the code source files.
[0218] In step C16, the code parser returns the interface definition and field definition to the asynchronous task processing module.
[0219] In step C17, the asynchronous task processing module stores the interface definition and field definition in the database.
[0220] In step C18, the database returns the storage result to the asynchronous task processing module.
[0221] Through the above method, the interface definition and field definition corresponding to the code source files in the change file can be obtained and stored in the database.
[0222] Please refer to Figure 9D , which shows a flowchart of a project update process, which will be explained in conjunction with the following steps.
[0223] In step D01, the user end submits the code source file to the code repository.
[0224] In step D02, the code repository sends the change file information to the document platform through Webhook.
[0225] In step D03, the document platform sends a project information query request to the database.
[0226] In step D04, the database sends a project information query response to the document platform.
[0227] Among them, steps D01 to D04 correspond to C01 to C04 in the above embodiment.
[0228] In step D05, in the case where it is determined that the project branch has been initialized, the code path of the changed code source file is sent to the code parser.
[0229] In step D06, the code parser sends a code acquisition request to the code repository.
[0230] In step D07, the code repository sends a code acquisition response to the code parser.
[0231] In step D08, the code parser parses the code source files to obtain the interface definition and field definition corresponding to the code source files.
[0232] In step D09, the code parser returns the interface definition and field definition to the document platform.
[0233] In step D10, the document platform stores the interface definition and field definition into the database.
[0234] In step D11, the database returns the storage result to the document platform.
[0235] In step D12, the document platform sends a webhook response to the code repository.
[0236] In step D13, the code repository sends a code submission response to the user end.
[0237] In some embodiments of the present application, since the webhook notification has no retry mechanism, and at the same time, the code repository may not trigger the webhook for the code submission; once the above problems occur, the document platform will have missing source code file change information, which will cause the interface document to be unable to update. In the face of such a situation, the document platform records the commit Id (submission identifier) of each submission, and when receiving the next submission event, it will obtain the last submission commit Id from the webhook notification information. If the last submission commit Id obtained is inconsistent with the last submission commit Id recorded by the document platform, it indicates that there is a submission missing between the two submissions. At this time, the changed files between the two commit Ids will be obtained through the interface of the code repository, and then the missing files will be parsed according to the above described process (if the missing file submission time is older than the document platform record, it will be ignored directly). In this way, the problem of missing interface information caused by the quality of webhook notification is solved.
[0238] Please refer to Figure 9E , which shows a flowchart of an interface document viewing process, which will be described in combination with the following steps.
[0239] In step E01, the user end sends an interface information viewing request to the document platform.
[0240] In step E02, the document platform sends a parameter query request to the database.
[0241] In step E03, the database returns the query result carrying the interface information to the document platform.
[0242] In step E04, the document platform sends the interface information to the document renderer.
[0243] The interface information in the query result is fragmented, such as interface definition and field definition distributed in different code source files, the type of the field itself refers to the field definition in another file, the type of the generic needs to be specified, and the class where the field definition is located needs to be inherited, and thus the interface information needs to be processed by the document renderer.
[0244] In step E05, the document renderer processes the interface information to obtain an interface document.
[0245] In step E06, the document renderer sends the interface document to the document platform.
[0246] In step E07, the document platform displays the interface document through an interface.
[0247] Referring to Figure 9F , a flowchart of a virtual data generation process is shown, which will be described in combination with the following steps.
[0248] In step F01, the user terminal sends an interface information viewing request to the document platform.
[0249] In step F02, the document platform sends a parameter query request to the database.
[0250] In step F03, the database returns a query result to the document platform.
[0251] In step F04, the document platform sends the interface information to the document renderer.
[0252] In step F05, the document renderer processes the interface information to obtain an interface document.
[0253] In step F06, the document renderer sends the interface document to the document platform.
[0254] In step F07, the document platform sends the interface document to the virtual data generation module.
[0255] In step F08, the virtual data generation module sends the generated virtual data to the document platform.
[0256] In step F09, the document platform sends the virtual data to the user terminal.
[0257] In some embodiments of the present application, an implementation method of a code parser is also provided, which obtains interface information from source code. The core basis of such code and document scheme is AST, i.e. Abstract Syntax Tree. The Abstract Syntax Tree represents all syntax definitions in the code (including but not limited to class definition, method definition, method parameter, structure and field definition, comment, annotation, etc.) as a series of nodes on the tree, and the relationship between various definitions in the source code is also reflected in the parent-child sibling node relationship of the tree. In order to facilitate understanding, actual code will be used as an example for illustration.
[0258] Please refer to Figure 10A , which shows a code diagram of java source code, in which the interface name and interface route are provided through annotation, and the input and output parameters (i.e. the parameters and return of the method) are specified on the interface method definition.
[0259] The Java source code provided by Figure 10A is converted into the corresponding Abstract Syntax Tree, and the Abstract Syntax Tree diagram as shown in Figure 10B to Figure 10D can be obtained. Among them, Figure 10B is the partial Abstract Syntax Tree of the Package information in the source code, Figure 10C is the partial Abstract Syntax Tree of the Import information in the source code (exemplarily showing one of the Import information), Figure 10D is the partial Abstract Syntax Tree of the interface definition in the source code.
[0260] Figure 10B The AST representation for Package definition can obtain the Package where the class is located, and the qualified name of the class can be obtained in combination with the name of the class, which is unique in the entire project. Figure 10C The information of Import of the source code, through which the qualified name of the other class definition referenced in the source code can be obtained, so that the file where the field definition is located can be uniquely located through the obtained qualified name. Figure 10DThe interface definition is shown. The interface name can be read from the annotation in line 110, the request path of the interface can be read from the annotation in line 117, and the return type Response of the interface can be obtained in line 121. In combination with the Import, the qualified name of the parameter is obtained as com.tencent.sr.mktbackend.protocol.demo.Response. The Response defines a generic type, and the name of the Response generic type can be obtained in line 125. Thus, the complete parameter definition of the interface is obtained. The parameter of the interface is Protocol, and the qualified name of the Protocol is obtained as com.tencent.sr.mktbackend.protocol.demo.Protocol in combination with the Import. In combination with the Package information, the qualified name of the class in which the interface is defined is obtained as com.tencent.sr.mktbackend.controller.zhuji.DemoController. The parameter definition of the class is in com.tencent.sr.mktbackend.protocol.demo.Protocol, and the return value definition of the class is in com.tencent.sr.mktbackend.protocol.demo.Response.
[0261] Correspondingly, based on the interface definition code in Figure 10A , the parameter definition source code of the parameter corresponding to the interface can be referred to the parameter definition source code shown in Figure 11A . The parameter definition source code provided by Figure 11A is converted into the corresponding abstract syntax tree, and the abstract syntax tree diagram as shown in Figure 11B is obtained.
[0262] As shown in Figure 11BAs shown, the class name of the field definition is obtained at line 223, and the qualified name of the class is obtained as com.tencent.sr.mktbackend.protocol.demo.Protocol in combination with the definition of the Package. The class name Parent inherited by the field definition class is obtained at line 225. The description of the first field is obtained at line 235, the type of the first field is obtained at line 239, and the name of the first field is obtained at line 240, so that all information of the first field is obtained. The description of the second field is obtained at line 249, and the type of the second field is obtained at line 253, and it is known that the second field is a composite type. In combination with the Import, the qualified name of the type is obtained as com.tencent.sr.mktbackend.protocol.other.Other, and the name of the second field is obtained at line 254, so that all information of the second field is obtained. However, the specific definition of the type of the second field needs to be found through the qualified name com.tencent.sr.mktbackend.protocol.other.Other, and if a composite type is continuously encountered, the above operations are performed in the same manner.
[0263] Correspondingly, based on the interface definition code in Figure 10A , the parameter definition source code of the out-parameter corresponding to the interface can be referred to the out-parameter definition source code shown in Figure 12A . The out-parameter definition source code provided by Figure 12A is converted into the corresponding abstract syntax tree, and the abstract syntax tree diagram as shown in Figure 12B is obtained.
[0264] As shown in Figure 12B , the qualified name com.tencent.sr.mktbackend.protocol.demo.Response is obtained according to the class name and the Package. It is obtained at line 311 in combination with line 354 that the current class is a generic class, and the name of the generic type is T, which needs to be replaced with the real type when the type is used. The definition of the remaining types is obtained in the same manner as the type of the in-parameter.
[0265] In some embodiments of the present application, the definition of the interface is obtained by the above manner and recorded into the database, the request path and the description information of the interface are obtained, the qualified name of the in-parameter is com.tencent.sr.mktbackend.protocol.demo.Protocol, and the definition of the in-parameter is Figure 11BThe field definition class of the corresponding embodiment is parsed to obtain the qualified name, and the combination of the two can complete the association of the interface input parameter to the input parameter specific definition; the qualified name of the output parameter is com.tencent.sr.mktbackend.protocol.demo.Response, that is Figure 12B The field definition class of the corresponding embodiment is parsed to obtain the qualified name, and the combination of the two can complete the association of the interface input parameter to the input parameter specific definition; the qualified name of the output parameter is com.tencent.sr.mktbackend.protocol.demo.Response, that is
[0266] Please refer to Figure 13A which shows the interface definition source code diagram of the Go source code, and correspondingly, Figure 13B shows the abstract syntax tree diagram of the Go source code. The AST style of the Go language and the parsing and structure of the java language are different, but the basic idea of the basic parsing is consistent. In Figure 13B , the name of the first field can be obtained in line 65, the type of the first field can be obtained in line 75, and the note information of the first field can be obtained in line 81, so the information of the first field is obtained, and the information of other fields is obtained in turn.
[0267] In some embodiments of the present application, the above document renderer can be implemented in the following way: the interface information and the input and output parameter information obtained in the above embodiments are combined and recorded to the database. The interface name apiname, the interface request path route, the interface Http request method method, the interface input parameter qualified name com.tencent.moonzhi.apijava.protocol.rest.FileProcessRequest and the interface output parameter qualified name com.tencent.moonzhi.apijava.protocol.rest.FileProcess Response can be queried by the id of the interface. Then, the field definitions of the input and output parameters are queried from the field definition table according to the qualified names of the input and output parameters. The input parameter field path and the three output parameter fields code, data and massage can be queried, wherein the field data is a composite type. The Figure 14 shows the interface information and field information display diagram. The qualified name in the field_type of this record is further queried to obtain the detailed field definition of the composite type, and so on. Finally, the interface information, the detailed field information of the input parameter and the detailed field information of the output parameter are combined to show the complete interface information.
[0268] In some embodiments of the present application, it can be known whether the field is generic when the field is parsed, and the generic class is replaced by the type actually passed in when the generic class is used during document rendering. The subsequent processing mode is as described above. For inherited classes, the document renderer lists the fields of the inherited class and the fields of the inherited class, and the fields of the two are combined. If the field exists in both the inherited class and the inherited class, the field definition of the inherited class is used as the standard; the parsing process of each field is also as described above. In addition, the document renderer also processes the conversion and normalization of types, such as converting java's BigDecimal to a numerical type for interface display. In summary, the document renderer associates the scattered interface information and field information to render complete and readable interface information for front-end display and output to quality testing, mock, and other platforms.
[0269] In some embodiments of the present application, the present application obtains code changes based on Git's Webhook notification. For example, if the code is hosted in svn or other platforms that support Webhook notification, the present application can also be implemented. It should be noted that in the above embodiments, the present application is verified using java and Go language, and other languages that support AST parsing, including but not limited to c++, js, and other development languages can also be implemented using the present application.
[0270] The interface document generation method provided by the above embodiment can achieve the following technical effects: (1) The implementation of the code-as-document scheme uses the code managed by the Git repository and the version of the document platform corresponding to the branch of the Git to render and generate the document at any time, that is, the code information is stored, and the document information is stored; (2) The document is generated by parsing the code, which saves the time of manually writing the document; (3) After the code is changed and submitted to the Git repository, the changed code can be updated in the document platform through the Webhook, which ensures the timeliness of the interface document update and reduces the time and effort cost of manually updating the interface document; (4) The field, method name and the like in the code can be directly used as the field information of the document, and the association relationship (such as parent-child type) in the code can be directly used as the association relationship of the interface document, so that the developer can complete the setting of the relationship in the interface document after completing the code writing and uploading, to generate accurate interface documents; (5) The annotation of the additional description information of the interface is next to the field definition of the code, and the developer can update the annotation with the minimum cursor movement, the additional annotation is used for the additional description information of the document and the explanation of the code, which increases the readability of the code and achieves two purposes at once; (6) Through the unified and centralized interface management platform, it is convenient to provide for each demand side to view, without relying on the operation of the project, and more management functions such as permission management and module division can be provided; (7) Based on the detailed interface information recorded by the document platform, the mock service can be used to provide the interface protocol information to the quality test team for generating test cases, to the security scanning platform for constructing scanning cases, and to the sdk based on the detailed interface protocol, which reduces the manual input cost of the corresponding platform; (8) In the verification use of the present application, the project has complete, accurate and timely updated interface documents, which solves the problem of missing and lagging interface documents caused by high cost of creating and maintaining documents, and in addition, the quality team returns to the document platform to help them save more than one-third of the workload.
[0271] The following continues to illustrate an exemplary structure of the implementation of the interface document generation apparatus 555 as a software module provided by the embodiments of the present application. In some embodiments of the present application, as shown in Figure 2 The software module stored in the interface document generation apparatus 555 of the memory 550 can include:
[0272] The first acquisition module 5551 is configured to acquire code submission information sent by a code repository in response to a code submission event; the code submission information includes a list of changed files corresponding to the code submission event and a project branch; the code submission event represents that a user terminal submits at least one changed code source file corresponding to the list of changed files to the code repository;
[0273] The query module 5552 is configured to query the interface document information corresponding to the project branch in the database, and generate a query result. The query result is used to indicate whether the interface document information corresponding to the project branch exists in the database.
[0274] The first generation module 5553 is configured to generate a to-be-parsed file list based on the query result. The to-be-parsed file list includes at least one changed code source file.
[0275] The parsing module 5554 is configured to parse the code source file in the to-be-parsed file list, and update the interface document information of the project branch.
[0276] The second generation module 5555 is configured to generate an interface document based on the interface document information in response to an interface document viewing event of the project branch.
[0277] In some embodiments of the present application, the interface document generation apparatus 555 further includes a creation module and a virtual data generation module.
[0278] In some embodiments of the present application, the creation module is configured to receive a project creation request sent by a user end. The project creation request includes a code address of a to-be-updated project in a code repository and a branch rule of the to-be-updated project. In response to the project creation request, the creation module is configured to generate a notification address of the to-be-updated project according to the code address. The notification address, after being configured to the code repository, is configured to send code submission information to a document platform in response to the code repository receiving a code submission event corresponding to the to-be-updated project.
[0279] In some embodiments of the present application, the query module 5552 is further configured to obtain the branch rule of the to-be-updated project, obtain branch information of the project branch in the code submission information, and in a case where the branch information conforms to the branch rule, query the interface document information corresponding to the project branch in the database, and generate a query result.
[0280] In some embodiments of the present application, the first generation module 5553 is further configured to, in a case where the query result indicates that the interface document information corresponding to the project branch does not exist in the database, determine the to-be-parsed file list based on a code file list corresponding to the project branch. The code file list includes all code source files corresponding to the project branch. In a case where the query result indicates that the interface document information corresponding to the project branch exists in the database, the first generation module 5553 is configured to determine the to-be-parsed file list based on the code submission information.
[0281] In some embodiments of the present application, the first generation module 5553 is further configured to determine the changed file list as the to-be-parsed file list.
[0282] In some embodiments of the present application, the first generation module 5553 is further configured to obtain a current submission identifier and a first historical submission identifier carried by the code submission information; the current submission identifier is a unique identifier of the code submission information, and the first historical submission identifier is a unique identifier of first historical code submission information corresponding to the project branch; the first historical code submission information is adjacent submission information sent by the code repository before the code submission information is sent; save the current submission identifier in the code submission information; compare the second historical submission identifier of the second historical code submission information stored locally with the first historical submission identifier of the first historical code submission information carried by the code submission information; and in a case where the first historical submission identifier and the second historical submission identifier are inconsistent, determine the to-be-analyzed file list based on the second historical code submission information and the code submission information.
[0283] In some embodiments of the present application, the first generation module 5553 is further configured to obtain at least two changed file lists between the code submission information and the locally stored historical code submission information in the code repository; the at least two changed file lists at least include a changed file list in the code submission information and a changed file list in the locally stored historical code submission information; obtain a file identifier and a change time of each code source file in each changed file list; filter at least one code source file corresponding to each file identifier according to the change time, and retain the latest code source file corresponding to each file identifier; and determine the to-be-analyzed file list based on the latest code source file corresponding to each file identifier.
[0284] In some embodiments of the present application, the analysis module 5554 is further configured to obtain at least one code source file corresponding to the to-be-analyzed file list from the code repository; analyze the at least one code source file to obtain an analysis result of to-be-analyzed code in each code source file; the analysis result includes a field identifier and field definition information of a defined field; the defined field includes an interface field and / or a parameter field; and save the analysis result to a database to update the interface document information of the to-be-updated project.
[0285] In some embodiments of the present application, the analysis module 5554 is further configured to add a current version number related to a submission time of the code submission information to the analysis result according to the submission time; save the analysis result carrying the version number to the database; and delete the analysis result with a version number less than the current version number in the database to obtain the interface document information of the to-be-updated project.
[0286] In some embodiments of the present application, the parsing module 5554 is further configured to convert each code source file into a corresponding abstract code tree to obtain at least one abstract code tree; parse each abstract code tree to obtain identification information and definition information of each code source file; the identification information is used to locate the code source file in the database to obtain the definition information; the definition information includes field identification and field definition information of a definition field included in the code source file; the definition field includes an interface field and / or a parameter field.
[0287] In some embodiments of the present application, the second generation module 5555 is further configured to obtain a target project identification and a target interface identification carried by the interface document viewing request; query target interface document information corresponding to the target project identification in the database; obtain target interface information and target parameter information corresponding to the target interface in the target interface document information based on the target interface identification; and generate the interface document based on the target interface information and the target parameter information.
[0288] In some embodiments of the present application, the second generation module 5555 is further configured to obtain target interface information corresponding to the target interface in the target interface document information according to the target interface identification; the target interface information includes interface identification information corresponding to the interface; determine interface parsing results corresponding to the interface source file based on the interface identification information; obtain definition information in the interface parsing results; and generate target parameter information of the interface based on the definition information.
[0289] In some embodiments of the present application, the second generation module 5555 is further configured to obtain parameter identification and parameter definition information of at least one interface parameter definition field in the definition information; in a case where the parameter definition information of the interface parameter definition field is an internal type, take the field identification and the field definition information of the interface parameter definition field as the target parameter information; in a case where the parameter definition information of the interface parameter definition field is a composite type, determine reference identification information based on the field identification of the interface parameter definition field; obtain field parsing results corresponding to the reference identification information, and generate target parameter information of the interface based on definition information in the field parsing results.
[0290] In some embodiments of the present application, the virtual data generation module is configured to receive a generation request for virtual data of a target interface; send target parameter information to a virtual data generator to enable the virtual data generator to generate a virtual parameter corresponding to the target parameter information; and send virtual data containing the virtual parameter to a user terminal. The code repository is configured to send code submission information in response to a code submission event; the code submission information includes a list of changed files corresponding to the code submission event and a project branch; the code submission event represents that the user terminal submits at least one changed code source file corresponding to the list of changed files to the code repository; the database is configured to query interface document information corresponding to the project branch to generate a query result; the query result is used to represent whether the interface document information corresponding to the project branch exists in the database; based on the query result, a list of files to be parsed is generated; the list of files to be parsed includes the at least one changed code source file; the code source files in the list of files to be parsed are parsed, and the interface document information of the project branch is updated; and in response to an interface document viewing event of the project branch, an interface document is generated based on the interface document information.
[0291] The embodiment of the present disclosure provides a computer program product or a computer program, which comprises computer instructions stored in a computer readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions, so that the computer device executes the interface document generation method provided in the embodiment of the present application.
[0292] The embodiment of the present disclosure provides a computer readable storage medium storing executable instructions, wherein the executable instructions are stored in the computer readable storage medium. When the executable instructions are executed by a processor, the processor will execute the interface document generation method provided by the embodiment of the present application, for example, the method shown in the embodiment of the present application. Figure 3 to Figure 8
[0293] In some embodiments of the present application, the computer readable storage medium can be FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disc, or CD-ROM memory, etc. It can also be various devices including one or any combination of the above-mentioned memories.
[0294] In some embodiments of the present application, the executable instructions can be in the form of programs, software, software modules, scripts or codes, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and can be deployed in any form, including being deployed as independent programs or as modules, components, subroutines or other units suitable for use in a computing environment.
[0295] By way of example, executable instructions can correspond to a file in a file system, but in many cases can not be so confined. For example, executable instructions can be stored in one or more files, in a single file, in a portion of a file, in multiple files distributed across multiple storage media, and so on.
[0296] By way of example, executable instructions can be deployed to be executed on one computer, or on multiple computers of a distributed system, or on one computer of a distributed system that is located at one site, or on multiple computers of a distributed system that are located at multiple sites, or on one computer of a distributed system that is located at one site and on one computer of a distributed system that is located at a different site, and so on.
[0297] The above description is implemented only as an example of the present application, and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement and improvement within the spirit and scope of the present application are included in the protection scope of the present application.
Claims
1. An interface document generation method characterized by, The method comprises: acquiring code submission information sent by a code repository in response to a code submission event; the code submission information comprises a list of changed files corresponding to the code submission event and a project branch; the code submission event represents that a user end submits at least one changed code source file corresponding to the list of changed files to the code repository; querying interface document information corresponding to the project branch in a database to generate a query result; the query result is used to represent whether the interface document information corresponding to the project branch exists in the database; in a case where the query result represents that the interface document information corresponding to the project branch does not exist in the database, determining a to-be-parsed file list based on a code file list corresponding to the project branch; the code file list comprises all code source files corresponding to the project branch; in a case where the query result represents that the interface document information corresponding to the project branch exists in the database, determining the to-be-parsed file list based on the code submission information; the to-be-parsed file list comprises the at least one changed code source file; parsing the code source files in the to-be-parsed file list, and updating the interface document information of the project branch; generating an interface document based on the interface document information in response to an interface document viewing event for the project branch.
2. The method of claim 1, wherein, The method further comprises: receiving a project creation request sent by the user end; the project creation request comprises a code address of a to-be-updated project in the code repository and a branch rule of the to-be-updated project; generating a notification address of the to-be-updated project according to the code address in response to the project creation request; the notification address, after being configured to the code repository, is used to send the code submission information to a document platform in response to the code repository receiving a code submission event corresponding to the to-be-updated project.
3. The method of claim 2, wherein, Before querying the interface document information corresponding to the project branch in the database to generate a query result, the method further comprises: acquiring the branch rule of the to-be-updated project; acquiring branch information of the project branch in the code submission information; in a case where the branch information conforms to the branch rule, querying the interface document information corresponding to the project branch in the database to generate a query result.
4. The method of claim 1, wherein, The determination of the to-be-parsed file list based on the code submission information comprises: acquiring a current submission identifier and a first historical submission identifier carried in the code submission information; the current submission identifier is a unique identifier of the code submission information, and the first historical submission identifier is a unique identifier of first historical code submission information corresponding to the project branch; the first historical code submission information is adjacent submission information sent by the code repository before the code submission information is sent; saving the current submission identifier in the code submission information; comparing a second historical submission identifier of a second historical code submission information stored locally with the first historical submission identifier of the first historical code submission information carried in the code submission information; In a case where the first historical commit identifier is inconsistent with the second historical commit identifier, determining the to-be-resolved file list based on the second historical code commit information and the code commit information.
5. The method of claim 4, wherein, The determining the to-be-resolved file list based on the second historical code commit information and the code commit information comprises: obtaining at least two changed file lists between the code commit information and the locally stored historical code commit information in the code repository; the at least two changed file lists at least include a changed file list in the code commit information and a changed file list in the locally stored historical code commit information; obtaining file identifiers and change times of code source files in each changed file list; filtering at least one code source file corresponding to each file identifier according to the change times, and retaining a latest code source file corresponding to each file identifier; determining the to-be-resolved file list based on the latest code source file corresponding to each file identifier.
6. The method according to claim 2 or 3, characterized in that, The updating the interface document information of the project branch based on the to-be-resolved file list comprises: obtaining at least one code source file corresponding to the to-be-resolved file list from the code repository; parsing the at least one code source file to obtain a parsing result of to-be-resolved code in each code source file; the parsing result includes field identifiers and field definition information of definition fields; the definition fields include interface fields and / or parameter fields; saving the parsing result to the database to update the interface document information of the to-be-updated project.
7. The method of claim 6, wherein, The saving the parsing result to the database to update the interface document information of the to-be-updated project comprises: adding a current version number related to a commit time of the code commit information to the parsing result according to the commit time; saving the parsing result carrying the version number to the database; deleting the parsing result with a version number less than the current version number in the database to obtain the interface document information of the to-be-updated project.
8. The method of claim 6, wherein, The parsing the at least one code source file to obtain a parsing result of to-be-resolved code in each code source file comprises: converting each code source file into a corresponding abstract code tree to obtain at least one abstract code tree; parsing each abstract code tree to obtain identification information and definition information of each code source file; the identification information is used to locate the code source file in the database to obtain the definition information; the definition information includes field identifiers and field definition information of definition fields included in the code source file; the definition fields include interface fields and / or parameter fields.
9. The method of claim 1, wherein, The generating an interface document based on the interface document information in response to an interface document viewing event of the project branch comprises: obtaining a target project identifier and a target interface identifier carried by the interface document viewing request; querying target interface document information corresponding to the target project identifier in the database; and generating an interface document based on the target interface document information. obtaining target interface information and target parameter information corresponding to a target interface based on the target interface identifier in the target interface document information; generating the interface document based on the target interface information and the target parameter information.
10. The method of claim 9, wherein, The obtaining target interface information and target parameter information corresponding to a target interface based on the target interface identifier in the target interface document information comprises: obtaining target interface information corresponding to the target interface in the target interface document information according to the target interface identifier; the target interface information comprises interface identifier information corresponding to the interface; determining interface parsing results corresponding to an interface source file based on the interface identifier information; obtaining definition information in the interface parsing results; and generating target parameter information of the interface based on the definition information.
11. The method of claim 10, wherein, The generating target parameter information of the interface based on the definition information comprises: obtaining parameter identifier and parameter definition information of at least one interface parameter definition field in the definition information; in a case where parameter definition information of the interface parameter definition field is an internal type, taking field identifier and field definition information of the interface parameter definition field as the target parameter information; in a case where parameter definition information of the interface parameter definition field is a composite type, determining reference identifier information based on the field identifier of the interface parameter definition field; obtaining field parsing results corresponding to the reference identifier information, and generating target parameter information of the interface based on definition information in the field parsing results.
12. An interface document generation apparatus characterized by comprising: comprises: a first obtaining module configured to obtain code submission information sent by a code repository in response to a code submission event; the code submission information comprises a change file list and a project branch corresponding to the code submission event; the code submission event represents that a user terminal submits at least one change code source file corresponding to the change file list to the code repository; a querying module configured to query interface document information corresponding to the project branch in a database, and generate a query result; the query result is used to represent whether the interface document information corresponding to the project branch exists in the database; a first generating module configured to, in a case where the query result represents that the interface document information corresponding to the project branch does not exist in the database, determine a to-be-parsed file list based on a code file list corresponding to the project branch; the code file list comprises all code source files corresponding to the project branch; in a case where the query result represents that the interface document information corresponding to the project branch exists in the database, determine the to-be-parsed file list based on the code submission information; the to-be-parsed file list comprises the at least one change code source file; a parsing module configured to parse the code source files in the to-be-parsed file list, and update interface document information of the project branch; a second generating module configured to, in response to an interface document viewing event for the project branch, generate an interface document based on the interface document information.
13. The apparatus of claim 12, wherein, The apparatus further comprises: A creating module is configured to receive a project creating request sent by the user terminal, the project creating request comprising a code address of a to-be-updated project in the code repository and a branch rule of the to-be-updated project; in response to the project creating request, a notification address of the to-be-updated project is generated according to the code address; after the notification address is configured to the code repository, the notification address is used to send the code submission information to the document platform in response to the code repository receiving a code submission event corresponding to the to-be-updated project.
14. The apparatus of claim 13, wherein, The querying module is further configured to acquire the branch rule of the to-be-updated project, acquire branch information of the project branch in the code submission information, and in a case where the branch information conforms to the branch rule, query the interface document information corresponding to the project branch in the database to generate a query result.
15. The apparatus of claim 12, wherein, The first generating module is further configured to acquire a current submission identifier and a first historical submission identifier carried in the code submission information, the current submission identifier being a unique identifier of the code submission information, and the first historical submission identifier being a unique identifier of first historical code submission information corresponding to the project branch; The first historical code submission information is adjacent submission information sent by the code repository before the code submission information is sent; The current submission identifier in the code submission information is saved; A second historical submission identifier of second historical code submission information stored locally is compared with the first historical submission identifier of the first historical code submission information carried in the code submission information; In a case where the first historical submission identifier and the second historical submission identifier are inconsistent, the to-be-analyzed file list is determined based on the second historical code submission information and the code submission information.
16. The apparatus of claim 15, wherein, The first generating module is further configured to acquire at least two change file lists between the code submission information and the locally stored historical code submission information in the code repository, the at least two change file lists at least comprising a change file list in the code submission information and a change file list in the locally stored historical code submission information; File identifiers and change times of respective code source files in each change file list are acquired; At least one code source file corresponding to each file identifier is filtered according to the change times, and the latest code source file corresponding to each file identifier is reserved; The to-be-analyzed file list is determined based on the latest code source file corresponding to each file identifier.
17. The apparatus of claim 13 or 14, wherein, The parsing module is further configured to obtain at least one code source file corresponding to the list of files to be parsed from the code repository; parse the at least one code source file to obtain a parsing result of the code to be parsed in each code source file; the parsing result comprises field identification and field definition information of a definition field; the definition field comprises an interface field and / or a parameter field; and save the parsing result to the database to update the interface document information of the project to be updated.
18. The apparatus of claim 17, wherein, The parsing module is further configured to add a current version number related to a commit time of the code commit information to the parsing result according to the commit time; and save the parsing result carrying the version number to the database. Delete the parsing result with a version number less than the current version number in the database to obtain the interface document information of the project to be updated.
19. The apparatus of claim 17, wherein, The parsing module is further configured to convert each code source file into a corresponding abstract code tree to obtain at least one abstract code tree; parse each abstract code tree to obtain identification information and definition information of each code source file; the identification information is used to locate the code source file in the database to obtain the definition information; the definition information comprises field identification and field definition information of a definition field contained in the code source file; and the definition field comprises an interface field and / or a parameter field.
20. The apparatus of claim 12, wherein, The second generation module is further configured to obtain a target project identification and a target interface identification carried by the interface document viewing request; query target interface document information corresponding to the target project identification in the database; obtain target interface information and target parameter information corresponding to a target interface in the target interface document information based on the target interface identification; generate the interface document based on the target interface information and the target parameter information.
21. The apparatus of claim 20, wherein, The second generation module is further configured to obtain target interface information corresponding to the target interface in the target interface document information according to the target interface identification; the target interface information comprises interface identification information corresponding to the interface; determine interface parsing result corresponding to an interface source file based on the interface identification information; obtain definition information in the interface parsing result; generate target parameter information of the interface based on the definition information.
22. The apparatus of claim 21, wherein, The second generation module is further configured to acquire a parameter identifier and parameter definition information of at least one interface parameter definition field in the definition information; in a case where the parameter definition information of the interface parameter definition field is an internal type, taking the field identifier and field definition information of the interface parameter definition field as the target parameter information; in a case where the parameter definition information of the interface parameter definition field is a composite type, determining reference identifier information based on the field identifier of the interface parameter definition field; acquiring a field analysis result corresponding to the reference identifier information, and generating target parameter information of the interface based on definition information in the field analysis result.
23. An interface document generating apparatus characterized by comprising: Comprise: a memory for storing executable instructions; a processor for executing the executable instructions stored in the memory to implement the method of any one of claims 1 to 11.
24. A computer-readable storage medium, characterized in that, executable instructions stored for being executed by a processor to implement the method of any one of claims 1 to 11.
25. A computer program product comprising computer instructions, characterized in that, The computer instructions are executed by the processor to implement the method of any one of claims 1 to 11.
Citation Information
Patent Citations
Interface document generation method and device, electronic equipment and medium
CN111638908A