Interface document generation method and device, computer equipment and storage medium
Through Maven plug-in scanning and processing of Java source code and annotation information, standard interface documents are generated, which solves the problems of inefficient and invasive dependency package generation methods, and realizes efficient and convenient interface document generation, suitable for front-end and back-end Separate architecture.
Patent Information
- Application Number
- CN202411129544.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2024-11-29
AI Technical Summary
Traditional interface document generation methods are inefficient and highly invasive in dependence on packages, especially in modern software architectures with front-end and back-end separation.
Provides an interface document generation method. After receiving the compilation instructions, the Maven plug-in scans and processes Java source code and compiled source code, extracts comments and annotations information, and generates standard interface documents without introducing Swagger packages to avoid dependencies. Invasive.
Improves the efficiency and convenience of interface document generation, and can automatically generate standard interface documents without adding Swagger annotations to each interface method. Documents can be generated for historical applications that have not used Swagger, reducing workload and widening the scope of application. .
Smart Images

Figure CN119045827A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer application technology, and in particular to an interface document generation method, device, computer equipment and storage medium. Background Art
[0002] Interface documentation, also known as API documentation (Application Programming Interface Document), is a technical document that details the interaction between software services. It is an indispensable part of the development process, especially in modern software architectures with separated front-end and back-end.
[0003] However, traditional methods of generating interface documents have problems such as low efficiency or reliance on framework packages that are highly invasive. Summary of the invention
[0004] Based on this, it is necessary to provide an interface document generation method, device, computer equipment and storage medium that can improve efficiency and avoid dependency on framework package intrusion in response to the above technical problems.
[0005] In a first aspect, a method for generating an interface document is provided, the method comprising:
[0006] In response to receiving a Maven compilation instruction, triggering a pre-configured Maven plug-in;
[0007] In response to the Maven plug-in being in a source code processing stage, the Java source code is scanned and processed to obtain interface annotation information, and the interface annotation information is stored in an annotation dictionary file;
[0008] In response to the Maven plug-in being in a compiling process, the compiled Java source code is scanned to obtain interface annotation information, and interface information location identification information associated with the interface annotation information is determined according to the interface annotation information;
[0009] Interface annotation information is obtained after querying the annotation dictionary file according to the interface information location identification information, and standard interface document information is generated according to the interface annotation information and the interface annotation information.
[0010] In one of the embodiments, the method further includes: generating a configuration file in response to a configuration operation on configuration parameters of the Maven plug-in; the configuration file includes the configuration parameters; and generating the Maven plug-in according to the configuration file.
[0011] In one of the embodiments, the Java source code is scanned to obtain interface annotation information, including: scanning the Java source code to obtain annotation information in the Java source code; filtering the annotation information according to filtering conditions to obtain interface annotation information; wherein the interface annotation information includes interface type annotation, interface method annotation, interface input parameter annotation, interface input parameter POJO object annotation, interface output parameter annotation and interface output parameter POJO object annotation.
[0012] In one embodiment, storing the interface annotation information in the annotation dictionary file includes: creating a temporary file and storing the interface annotation information in the temporary file; naming the temporary file as the annotation dictionary file.
[0013] In one embodiment, the compiled Java source code is scanned to obtain interface annotation information, including:
[0014] Based on the Java reflection mechanism, the compiled Java source code is scanned to obtain the SpringMvc interface annotation information; wherein the interface annotation information includes the SpringMvc interface annotation information; the SpringMvc interface annotation information includes the interface uniform resource locator annotation, the interface request parameter annotation, the interface request body annotation and the interface response body annotation.
[0015] In one of the embodiments, the method further includes: converting the format of the standard interface document information to obtain the standard interface document information in the swagger format; generating an interface file in the swagger.xml format according to the standard interface document information in the swagger format; and uploading the interface file to the interface document platform in response to an upload operation on the interface file.
[0016] In one of the embodiments, uploading an interface file to an interface document platform includes: generating a hash value of the interface file based on the interface file; verifying the interface file on the interface document platform based on the hash value to obtain a verification result; the verification result includes a verification pass or a verification failure; a verification pass is used to characterize that the interface file does not exist on the interface document platform; a verification failure is used to characterize that the interface file exists on the interface document platform; in response to the verification result being a verification pass, uploading the interface file to the interface document platform based on the hash value; in response to the verification result being a verification failure, feeding back verification failure information.
[0017] In a second aspect, an interface document generation device is provided, the device comprising a plug-in trigger module, an annotation scanning module, an annotation scanning module and an information generation module.
[0018] Among them, the plug-in trigger module is used to trigger a pre-configured Maven plug-in in response to receiving a Maven compilation instruction; the annotation scanning module is used to scan and process the Java source code in response to the Maven plug-in being in the source code processing stage, obtain interface annotation information, and store the interface annotation information in the annotation dictionary file; the annotation scanning module is used to scan and process the compiled Java source code in response to the Maven plug-in being in the compilation processing stage, obtain interface annotation information, and determine the interface information location identification information associated with the interface annotation information based on the interface annotation information; the information generation module is used to obtain interface annotation information after querying the annotation dictionary file based on the interface information location identification information, and generate standard interface document information based on the interface annotation information and the interface annotation information.
[0019] In a third aspect, a computer device is provided. The computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps of any method in the above method embodiments are implemented.
[0020] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any method in the above method embodiments are implemented.
[0021] The above-mentioned interface document generation method, device, computer equipment and storage medium trigger a pre-configured Maven plug-in in response to receiving a Maven compilation instruction; then, in response to the Maven plug-in being in the source code processing stage, the Java source code is scanned and processed to obtain interface annotation information, and the interface annotation information is stored in the annotation dictionary file; then, in response to the Maven plug-in being in the compilation processing stage, the compiled Java source code is scanned and processed to obtain interface annotation information, and the interface information location identification information associated with the interface annotation information is determined according to the interface annotation information; then, according to the interface information location identification information, the interface annotation information is obtained after querying the annotation dictionary file to obtain the interface annotation information, and the standard interface document information is generated according to the interface annotation information and the interface annotation information, so that the complete interface information can be obtained through the standard interface document information, without the need to additionally introduce the Swagger framework package, without invasive dependence, without adding Swagger annotations to each interface method, and the standard interface document information can be automatically generated for historical applications that have not used Swagger, thereby reducing the workload, improving efficiency and convenience, and expanding the scope of application. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 An application environment diagram of an interface document generation method in an embodiment;
[0023] Figure 2 A schematic diagram of a first process flow of a method for generating an interface document in one embodiment;
[0024] Figure 3 A second flow chart of a method for generating an interface document in one embodiment;
[0025] Figure 4 A schematic diagram of a process for obtaining interface annotation information after scanning Java source code in one embodiment;
[0026] Figure 5 A schematic diagram of a process of storing interface annotation information into an annotation dictionary file in one embodiment;
[0027] Figure 6 A third flow chart of a method for generating an interface document in one embodiment;
[0028] Figure 7 A schematic diagram of a process of uploading an interface file to an interface document platform in one embodiment;
[0029] Figure 8 It is a structural block diagram of an interface document generating device in one embodiment;
[0030] Fig. 9 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0031] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0032] In order to facilitate understanding of the present application, the present application will be described more fully below with reference to the relevant drawings. Embodiments of the present application are provided in the drawings. However, the present application can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the disclosure of the present application more thorough and comprehensive.
[0033] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application.
[0034] It is understood that the terms "first", "second", etc. used in this application may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish a first element from another element. For example, without departing from the scope of this application, a first resistor may be referred to as a second resistor, and similarly, a second resistor may be referred to as a first resistor. Both the first resistor and the second resistor are resistors, but they are not the same resistor.
[0035] It can be understood that the “connection” in the following embodiments should be understood as “electrical connection”, “communication connection”, etc. if the connected circuits, modules, units, etc. have electrical signals or data transmission between each other.
[0036] When used herein, the singular forms "a", "an", and "said / the" may also include plural forms, unless the context clearly indicates otherwise. It should also be understood that the terms "include / comprise" or "have" etc. specify the presence of stated features, wholes, steps, operations, components, parts or combinations thereof, but do not exclude the possibility of the presence or addition of one or more other features, wholes, steps, operations, components, parts or combinations thereof.
[0037] The interface document generation method provided in this application can be applied to Figure 1 In the application environment shown, the terminal 102 communicates with the server 104 through a network. The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices, and the server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.
[0038] In one embodiment, Figure 2 As shown, a method for generating an interface document is provided, and the method is applied to Figure 1 The server 104 in the example is used for explanation, and the steps include the following steps 201 to 204.
[0039] Step 201, in response to receiving a Maven compilation instruction, triggering a pre-configured Maven plug-in.
[0040] Specifically, a Maven plug-in is pre-configured in the server 104. When the server 104 recognizes that a Maven compilation instruction has been received, it triggers the pre-configured Maven plug-in, thereby starting the generation of the interface document.
[0041] In a specific example, the Maven compilation instruction is an instruction for compiling the source code of the project, i.e., the mvn compile instruction. It is understandable that the Maven compilation instruction can be received when building an application through jenkins. The above is only a specific example. In actual application, it is flexibly set according to user needs and is not limited here.
[0042] In one embodiment, if Figure 3 As shown, the method further includes step 301 to step 302.
[0043] Step 301 : generating a configuration file in response to performing a configuration operation on configuration parameters of a Maven plug-in.
[0044] Step 302: Generate a Maven plug-in according to the configuration file.
[0045] The configuration file includes configuration parameters. Specifically, the server 104 generates a configuration file upon identifying that a configuration operation is performed on the configuration parameters of the Maven plug-in; and then generates the Maven plug-in according to the configuration file, thereby improving the efficiency and convenience of generating the Maven plug-in.
[0046] In this embodiment, in response to the configuration operation on the configuration parameters of the Maven plug-in, a configuration file is generated; then, the Maven plug-in is generated according to the configuration file, thereby improving the efficiency and convenience of generating the Maven plug-in.
[0047] Step 202, in response to the Maven plug-in being in the source code processing stage, the Java source code is scanned and processed to obtain interface annotation information, and the interface annotation information is stored in an annotation dictionary file.
[0048] The Maven life cycle includes source code processing, compilation, testing, packaging, integration, verification, and deployment. The interface annotation information is JavaDoc interface annotation information. Specifically, when the server 104 recognizes that the Maven plug-in is in the source code processing stage, it scans the Java source code to obtain the interface annotation information and stores the interface annotation information in the annotation dictionary file.
[0049] In one embodiment, if Figure 4 As shown, after scanning the Java source code, interface annotation information is obtained, including steps 401 to 402.
[0050] Step 401, scan the Java source code to obtain the comment information in the Java source code.
[0051] Step 402: filter the annotation information according to the filtering condition to obtain interface annotation information.
[0052] The interface annotation information includes interface type annotation, interface method annotation, interface input parameter annotation, interface input parameter POJO object annotation, interface output parameter annotation and interface output parameter POJO object annotation.
[0053] Specifically, the server 104 scans the Java source code to obtain the annotation information in the Java source code; then, the annotation information is filtered according to the filtering condition to obtain the interface annotation information, thereby improving the accuracy and efficiency of obtaining the interface annotation information. In addition, the filtering condition is flexibly pre-set according to user needs and is not limited here.
[0054] In this embodiment, the Java source code is scanned to obtain the annotation information in the Java source code; then, the annotation information is filtered according to the filtering condition to obtain the interface annotation information, thereby improving the accuracy and efficiency of obtaining the interface annotation information.
[0055] In one embodiment, if Figure 5 As shown, the interface annotation information is stored in the annotation dictionary file, including steps 501 and 502.
[0056] Step 501, create a temporary file and store the interface annotation information in the temporary file.
[0057] Step 502, naming the temporary file as an annotation dictionary file.
[0058] Specifically, the server 104 creates a temporary file and stores the interface annotation information in the temporary file; then, the temporary file is named as an annotation dictionary file, which improves the convenience of storing and querying the interface annotation information.
[0059] In this embodiment, a temporary file is created, and the interface annotation information is stored in the temporary file; then, the temporary file is named as an annotation dictionary file, which improves the convenience of storing and querying the interface annotation information.
[0060] Step 203, in response to the Maven plug-in being in the compiling process stage, the compiled Java source code is scanned to obtain interface annotation information, and interface information location identification information associated with the interface annotation information is determined according to the interface annotation information.
[0061] The server 104 can identify that the Maven plug-in is in the compilation process stage, scan the compiled Java source code to obtain the interface annotation information, and determine the interface information location identification information associated with the interface annotation information according to the interface annotation information.
[0062] In a specific example, the interface information location identification information includes the package where the interface information is located, the class where the interface information is located, the method of the interface information and the method signature of the interface information. The above is only a specific example, and it can be flexibly set according to user needs in actual applications and is not limited here.
[0063] In one embodiment, the compiled Java source code is scanned to obtain interface annotation information, including:
[0064] Based on the Java reflection mechanism, the compiled Java source code is scanned to obtain the SpringMvc interface annotation information.
[0065] The interface annotation information includes the SpringMvc interface annotation information; the SpringMvc interface annotation information includes the interface uniform resource locator annotation, the interface request parameter annotation, the interface request body annotation, and the interface response body annotation. Specifically, the server 104 can scan the compiled Java source code based on the Java reflection mechanism to obtain the SpringMvc interface annotation information, thereby improving the convenience and accuracy of obtaining the interface annotation information. In addition, the SpringMvc interface annotation information also includes the attribute information of the interface request parameter; the attribute information of the interface request parameter includes the attribute information of the interface input parameter and the attribute information of the interface output parameter.
[0066] In this embodiment, based on the Java reflection mechanism, the compiled Java source code is scanned to obtain the SpringMvc interface annotation information, which improves the convenience and accuracy of obtaining the interface annotation information.
[0067] Step 204, obtaining interface annotation information after querying the annotation dictionary file according to the interface information location identification information, and generating standard interface document information according to the interface annotation information and the interface annotation information.
[0068] Among them, the server 104 obtains the interface annotation information after querying the annotation dictionary file according to the interface information location identification information, and generates standard interface document information according to the interface annotation information and the interface annotation information, so that the complete interface information can be obtained through the standard interface document information, without the need to introduce the Swagger framework package, without invasive dependencies, and without adding Swagger annotations to each interface method. Standard interface document information can also be automatically generated for historical applications that have not used Swagger, reducing workload, improving efficiency and convenience, and expanding the scope of application.
[0069] Based on this, the above interface document generation method, in response to receiving a Maven compilation instruction, triggers a pre-configured Maven plug-in; then, in response to the Maven plug-in being in the source code processing stage, the Java source code is scanned and processed to obtain interface annotation information, and the interface annotation information is stored in the annotation dictionary file; then, in response to the Maven plug-in being in the compilation processing stage, the compiled Java source code is scanned and processed to obtain interface annotation information, and the interface information location identification information associated with the interface annotation information is determined according to the interface annotation information; then, according to the interface information location identification information, the interface annotation information is obtained after querying the annotation dictionary file to obtain the interface annotation information, and the standard interface document information is generated according to the interface annotation information and the interface annotation information, so that the complete interface information can be obtained through the standard interface document information, without the need to additionally introduce the Swagger framework package, without invasive dependence, without adding Swagger annotations to each interface method, and the standard interface document information can be automatically generated for historical applications that have not used Swagger, thereby reducing workload, improving efficiency and convenience, and expanding the scope of application.
[0070] In one embodiment, if Figure 6 As shown, the method further includes steps 601 to 603.
[0071] Step 601, convert the standard interface document information into a format to obtain the standard interface document information in a swagger format.
[0072] Step 602: Generate an interface file in swagger.xml format according to the standard interface document information in swagger format.
[0073] Step 603: In response to the upload operation of the interface file, the interface file is uploaded to the interface document platform.
[0074] Specifically, the server 104 converts the format of the standard interface document information to obtain the standard interface document information in the swagger format; then, an interface file in the swagger.xml format is generated according to the standard interface document information in the swagger format; then, in response to an upload operation on the interface file, the interface file is uploaded to the interface document platform, so as to facilitate direct query of the standard interface document information through the interface document platform, thereby improving the convenience and efficiency of information query.
[0075] In this embodiment, the standard interface document information is formatted to obtain standard interface document information in swagger format; then, an interface file in swagger.xml format is generated according to the standard interface document information in swagger format; then, in response to an upload operation on the interface file, the interface file is uploaded to an interface document platform, so that the standard interface document information can be directly queried through the interface document platform, thereby improving the convenience and efficiency of information query.
[0076] In a specific example, the method further includes: querying the interface document platform according to the file name of the interface file to obtain the interface file. The above is only a specific example, and it can be flexibly set according to user needs in actual applications and is not limited here.
[0077] In one embodiment, if Figure 7 As shown, uploading the interface file to the interface document platform includes steps 701 to 704.
[0078] Step 701: Generate a hash value of the interface file according to the interface file.
[0079] Step 702, perform interface file verification on the interface document platform according to the hash value to obtain a verification result.
[0080] Step 703, in response to the verification result being verification passed, the interface file is uploaded to the interface document platform according to the hash value.
[0081] Step 704: In response to the verification result being a verification failure, feedback of verification failure information is provided.
[0082] The verification result includes verification passed or verification failed; verification passed is used to indicate that the interface file does not exist on the interface document platform; verification failed is used to indicate that the interface file exists on the interface document platform. Specifically, the server 104 generates a hash value (MD5) of the interface file according to the interface file; then, the interface file is verified on the interface document platform according to the hash value to obtain a verification result; then, in response to the verification result being verification passed, the interface file is uploaded to the interface document platform according to the hash value; then, in response to the verification result being verification failed, verification failure information is fed back, thereby improving the accuracy and efficiency of uploading the interface file.
[0083] In this embodiment, a hash value (MD5) of the interface file is generated based on the interface file; then, the interface file is verified on the interface document platform based on the hash value to obtain a verification result; then, in response to the verification result being a passed verification, the interface file is uploaded to the interface document platform based on the hash value; then, in response to the verification result being a failed verification, verification failure information is fed back, thereby improving the accuracy and efficiency of uploading the interface file.
[0084] It should be understood that although Figure 2-7 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2-7 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0085] Second, as Figure 8 As shown, an interface document generation device is provided, which includes a plug-in trigger module 810, an annotation scanning module 820, an annotation scanning module 830 and an information generation module 840.
[0086] Among them, the plug-in trigger module 810 is used to trigger a pre-configured Maven plug-in in response to receiving a Maven compilation instruction; the annotation scanning module 820 is used to scan and process the Java source code in response to the Maven plug-in being in the source code processing stage, obtain interface annotation information, and store the interface annotation information in the annotation dictionary file; the annotation scanning module 830 is used to scan and process the compiled Java source code in response to the Maven plug-in being in the compilation processing stage, obtain interface annotation information, and determine the interface information location identification information associated with the interface annotation information based on the interface annotation information; the information generation module 840 is used to obtain the interface annotation information after querying the annotation dictionary file based on the interface information location identification information, and generate standard interface document information based on the interface annotation information and the interface annotation information.
[0087] In one of the embodiments, the device further includes a plug-in generation module.
[0088] The plug-in generation module is used to generate a configuration file in response to a configuration operation on the configuration parameters of the Maven plug-in; the configuration file includes the configuration parameters; and the plug-in generation module is used to generate a Maven plug-in according to the configuration file.
[0089] In one embodiment, the annotation scanning module 820 includes an annotation scanning unit.
[0090] Among them, the annotation scanning unit is used to scan the Java source code to obtain the annotation information in the Java source code; the annotation scanning unit is used to filter the annotation information according to the filtering conditions to obtain the interface annotation information; among them, the interface annotation information includes interface type annotation, interface method annotation, interface input parameter annotation, interface input parameter POJO object annotation, interface output parameter annotation and interface output parameter POJO object annotation.
[0091] In one embodiment, the annotation scanning module 820 includes an annotation storage unit.
[0092] The annotation storage unit is used to create a temporary file and store the interface annotation information in the temporary file; the annotation storage unit is used to name the temporary file as an annotation dictionary file.
[0093] In one embodiment, the compiled Java source code is scanned to obtain interface annotation information, including:
[0094] Based on the Java reflection mechanism, the compiled Java source code is scanned to obtain the SpringMvc interface annotation information; wherein the interface annotation information includes the SpringMvc interface annotation information; the SpringMvc interface annotation information includes the interface uniform resource locator annotation, the interface request parameter annotation, the interface request body annotation and the interface response body annotation.
[0095] In one of the embodiments, the device further includes a file upload module.
[0096] Among them, the file upload module is used to convert the format of the standard interface document information to obtain the standard interface document information in the swagger format; the file upload module is used to generate an interface file in the swagger.xml format according to the standard interface document information in the swagger format; the file upload module is used to upload the interface file to the interface document platform in response to the upload operation of the interface file.
[0097] In one of the embodiments, the file upload module includes a file upload unit.
[0098] Among them, the file upload unit is used to generate a hash value of the interface file according to the interface file; the file upload unit is used to verify the interface file on the interface document platform according to the hash value to obtain a verification result; the verification result includes a verification pass or a verification failure; the verification pass is used to characterize that the interface file does not exist on the interface document platform; the verification failure is used to characterize that the interface file exists on the interface document platform; the file upload unit is used to upload the interface file to the interface document platform according to the hash value in response to the verification result being a verification pass; the file upload unit is used to feedback verification failure information in response to the verification result being a verification failure.
[0099] For the specific definition of the interface document generation device, please refer to the definition of the interface document generation method above, which will not be repeated here. Each module in the above-mentioned interface document generation device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0100] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig. 9 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store standard interface document information. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an interface document generation method is implemented.
[0101] Those skilled in the art will understand that the structure shown in FIG. Y is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0102] In a third aspect, a computer device is provided. The computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps of any method in the above method embodiments are implemented.
[0103] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any method in the above method embodiments are implemented.
[0104] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing related hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct RAMbus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0105] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0106] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A method for generating an interface document, the method comprising: In response to receiving a Maven compilation instruction, triggering a pre-configured Maven plug-in; In response to the Maven plug-in being in a source code processing stage, scanning the Java source code to obtain interface annotation information, and storing the interface annotation information in an annotation dictionary file; In response to the Maven plug-in being in a compiling process, scanning the compiled Java source code to obtain interface annotation information, and determining interface information location identification information associated with the interface annotation information according to the interface annotation information; The interface annotation information is obtained after querying the annotation dictionary file according to the interface information location identification information, and standard interface document information is generated according to the interface annotation information and the interface annotation information.
2. The method according to claim 1, characterized in that The method further comprises: In response to performing a configuration operation on the configuration parameters of the Maven plug-in, generating a configuration file; the configuration file includes the configuration parameters; The Maven plug-in is generated according to the configuration file.
3. The method according to claim 1, characterized in that: The interface annotation information obtained after scanning the Java source code includes: Scanning a Java source code to obtain annotation information in the Java source code; The annotation information is filtered according to the filtering conditions to obtain the interface annotation information; wherein the interface annotation information includes interface type annotation, interface method annotation, interface input parameter annotation, interface input parameter POJO object annotation, interface output parameter annotation and interface output parameter POJO object annotation.
4. The method according to claim 1, characterized in that: The step of storing the interface annotation information in an annotation dictionary file includes: Creating a temporary file, and storing the interface annotation information in the temporary file; The temporary file is named the annotation dictionary file.
5. The method according to claim 1, characterized in that The interface annotation information is obtained after scanning the compiled Java source code, including: Based on the Java reflection mechanism, the compiled Java source code is scanned to obtain SpringMvc interface annotation information; wherein the interface annotation information includes the SpringMvc interface annotation information; the SpringMvc interface annotation information includes interface uniform resource locator annotation, interface request parameter annotation, interface request body annotation and interface response body annotation.
6. The method according to claim 1, characterized in that The method further comprises: Convert the standard interface document information into a swagger format. Generate an interface file in swagger.xml format according to the standard interface document information in the swagger format; In response to an upload operation on the interface file, the interface file is uploaded to an interface document platform.
7. The method according to claim 6, characterized in that The step of uploading the interface file to the interface document platform includes: Generate a hash value of the interface file according to the interface file; Performing an interface file verification on the interface document platform according to the hash value to obtain a verification result; the verification result includes a verification pass or a verification failure; the verification pass is used to indicate that the interface file does not exist on the interface document platform; the verification failure is used to indicate that the interface file exists on the interface document platform; In response to the verification result being that the verification is passed, uploading the interface file to the interface document platform according to the hash value; In response to the verification result being the verification failure, verification failure information is fed back.
8. An interface document generating device, characterized in that: The device comprises: A plug-in triggering module is used to trigger a pre-configured Maven plug-in in response to receiving a Maven compilation instruction; An annotation scanning module, for scanning and processing the Java source code to obtain interface annotation information in response to the Maven plug-in being in the source code processing stage, and storing the interface annotation information in an annotation dictionary file; An annotation scanning module is used for scanning the compiled Java source code to obtain interface annotation information in response to the Maven plug-in being in the compilation processing stage, and determining the interface information location identification information associated with the interface annotation information according to the interface annotation information; The information generation module is used to obtain the interface annotation information after querying the annotation dictionary file according to the interface information location identification information, and generate standard interface document information according to the interface annotation information and the interface annotation information.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
