Disclosure of Invention
In view of the above, the present invention provides an interface code detection report generation method, an electronic device, and a storage medium, and aims to improve the accuracy of detecting a difference between interface development and interface pre-design.
In order to achieve the above object, the present invention provides a method for generating an interface code detection report, including:
a receiving step: receiving a request for generating an interface code detection report sent by a user, wherein the request comprises a first group of interface codes and a second group of interface codes to be detected;
an identification step: analyzing the first group of interface codes and the second group of interface codes by using a preset code analyzer, and respectively extracting preset type code blocks corresponding to the two groups of interface codes;
a conversion step: converting the preset type code block into attribute information corresponding to the two groups of interface codes by using a preset conversion rule, and comparing and analyzing the attribute information of the two groups of interface codes to obtain difference parameters and same parameters of the two groups of interface codes; and
a generation step: and filling the difference parameters and the same parameters into a predetermined template file to generate an interface code detection report, and sending the interface code detection report to the user so that the user can display the interface code detection report.
Preferably, the attribute information of the interface code includes:
the name of the interface, the path of the interface, the uniform resource locator of the interface, the input parameter of the interface, the request mode of the interface and the output parameter of the interface.
Preferably, the preset conversion rule includes:
identifying the annotation line of the preset type code block to obtain the interface type and the interface path of the code block, and identifying the interface function of the preset type code block to obtain the interface name, the input parameters of the interface and the output parameters of the interface of the code block;
preferably, the converting step further comprises:
and converting the preset type code block into interface data in a JSON format by using a preset JSON parser, and storing the interface data into a preset database.
Preferably, the generating step comprises:
filling the same parameters of the two groups of interface codes to a first preset position in a predetermined template file;
and filling the difference parameters of the two groups of interface codes to a second preset position in a predetermined template file.
To achieve the above object, the present invention also provides an electronic device, including: the memory and the processor are characterized in that an interface code detection report generation program is stored on the memory, and the interface code detection report generation program is executed by the processor to realize the following steps:
a receiving step: receiving a request for generating an interface code detection report sent by a user, wherein the request comprises a first group of interface codes and a second group of interface codes to be detected;
an identification step: analyzing the first group of interface codes and the second group of interface codes by using a preset code analyzer, and respectively extracting preset type code blocks corresponding to the two groups of interface codes;
a conversion step: converting the preset type code block into attribute information corresponding to the two groups of interface codes by using a preset conversion rule, and comparing and analyzing the attribute information of the two groups of interface codes to obtain difference parameters and same parameters of the two groups of interface codes; and
a generation step: and filling the difference parameters and the same parameters into a predetermined template file to generate an interface code detection report, and sending the interface code detection report to the user so that the user can display the interface code detection report.
Preferably, the preset conversion rule includes:
and identifying the annotation line of the preset type code block to obtain the interface type and the interface path of the code block, and identifying the interface function of the preset type code block to obtain the interface name, the input parameters of the interface and the output parameters of the interface of the code block.
Preferably, the converting step further comprises:
and converting the preset type code block into interface data in a JSON format by using a preset JSON parser, and storing the interface data into a preset database.
Preferably, the generating step comprises:
filling the same parameters of the two groups of interface codes to a first preset position in a predetermined template file;
and filling the difference parameters of the two groups of interface codes to a second preset position in a predetermined template file.
To achieve the above object, the present invention further provides a computer-readable storage medium, which includes an interface code detection report generation program, and when the interface code detection report generation program is executed by a processor, the computer-readable storage medium implements any step of the interface code detection report generation method as described above.
The interface code detection report generation method, the electronic device and the storage medium provided by the invention have the advantages that the request for generating the interface code detection report sent by a user is received, the request comprises a first group of interface codes and a second group of interface codes to be detected, the first group of interface codes and the second group of interface codes are analyzed by using a preset code analyzer, code blocks corresponding to the two groups of interface codes are respectively extracted, the code blocks are converted into attribute information corresponding to the two groups of interface codes by using a preset conversion rule, the attribute information of the two groups of interface codes is compared and analyzed to obtain difference parameters and same parameters of the two groups of interface codes, the difference parameters and the same parameters are filled into a predetermined template file to generate the interface code detection report, and the interface code detection report is sent to the user. The invention can detect whether the development of the interface is consistent with the pre-design of the interface when the code reconstruction, the data migration and the frequent iteration occur to the interface, thereby improving the accuracy of detecting the difference between the development and the design of the interface and providing an intuitive and visible method for the interface management.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a schematic diagram of an electronic device 1 according to a preferred embodiment of the invention is shown.
The electronic device 1 includes but is not limited to: memory 11, processor 12, display 13, and network interface 14. The electronic device 1 is connected to a network through a network interface 14 to obtain raw data. The network may be a wireless or wired network such as an Intranet (Intranet), the Internet (Internet), a Global System for mobile communications (GSM), Wideband Code Division Multiple Access (WCDMA), a 4G network, a 5G network, Bluetooth (Bluetooth), Wi-Fi, or a communication network.
The memory 11 includes at least one type of readable storage medium including a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the storage 11 may be an internal storage unit of the electronic device 1, such as a hard disk or a memory of the electronic device 1. In other embodiments, the memory 11 may also be an external storage device of the electronic apparatus 1, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like provided in the electronic apparatus 1. Of course, the memory 11 may also comprise both an internal memory unit of the electronic apparatus 1 and an external memory device thereof. In this embodiment, the memory 11 is generally used for storing an operating system installed in the electronic device 1 and various types of application software, such as a program code of the interface code detection report generation program 10. Further, the memory 11 may also be used to temporarily store various types of data that have been output or are to be output.
Processor 12 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 12 is generally used for controlling the overall operation of the electronic device 1, such as performing data interaction or communication related control and processing. In this embodiment, the processor 12 is configured to run the program code or the processing data stored in the memory 11, for example, the program code of the interface code detection report generation program 10.
The display 13 may be referred to as a display screen or display unit. In some embodiments, the display 13 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an Organic Light-emitting diode (OLED) touch screen, or the like. The display 13 is used for displaying information processed in the electronic device 1 and for displaying a visual work interface, for example, results of data statistics.
The network interface 14 may optionally comprise a standard wired interface, a wireless interface (e.g. WI-FI interface), the network interface 14 typically being used for establishing a communication connection between the electronic apparatus 1 and other electronic devices.
Fig. 2 shows only the electronic device 1 with the components 11-14 and the interface code detection report generation program 10, but it is to be understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead.
Optionally, the electronic device 1 may further comprise a user interface, the user interface may comprise a Display (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface may further comprise a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an Organic Light-Emitting Diode (OLED) touch screen, or the like. The display, which may also be referred to as a display screen or display unit, is suitable for displaying information processed in the electronic apparatus 1 and for displaying a visualized user interface.
The electronic device 1 may further include a Radio Frequency (RF) circuit, a sensor, an audio circuit, and the like, which are not described in detail herein.
In the above embodiment, the processor 12, when executing the interface code detection report generation program 10 stored in the memory 11, may implement the following steps:
a receiving step: receiving a request for generating an interface code detection report sent by a user, wherein the request comprises a first group of interface codes and a second group of interface codes to be detected;
an identification step: analyzing the first group of interface codes and the second group of interface codes by using a preset code analyzer, and respectively extracting preset type code blocks corresponding to the two groups of interface codes;
a conversion step: converting the preset type code block into attribute information corresponding to the two groups of interface codes by using a preset conversion rule, and comparing and analyzing the attribute information of the two groups of interface codes to obtain difference parameters and same parameters of the two groups of interface codes; and
a generation step: and filling the difference parameters and the same parameters into a predetermined template file to generate an interface code detection report, and sending the interface code detection report to the user so that the user can display the interface code detection report.
The storage device may be the memory 11 of the electronic apparatus 1, or may be another storage device communicatively connected to the electronic apparatus 1.
For detailed description of the above steps, please refer to the following description of fig. 2 regarding a program module diagram of an embodiment of the interface code detection report generation program 10 and fig. 3 regarding a flowchart of an embodiment of an interface code detection report generation method.
In other embodiments, the interface code detection report generating program 10 may be divided into a plurality of modules, which are stored in the memory 12 and executed by the processor 13 to accomplish the present invention. The modules referred to herein are referred to as a series of computer program instruction segments capable of performing specified functions.
Referring to fig. 2, a block diagram of an embodiment of the interface code detection report generation program 10 in fig. 1 is shown. In this embodiment, the interface code detection report generation program 10 may be divided into: a receiving module 110, an identifying module 120, a converting module 130 and a generating module 140.
The receiving module 110 is configured to receive a request for generating an interface code detection report, where the request includes a first group of interface codes to be detected and a second group of interface codes to be detected.
In this embodiment, the first set of codes may be interface codes actually developed, and the second set of codes may be interface codes designed before development. The request may include two interface code files to be detected, and may also include a storage path and an identifier associated with the interface code files to be detected. That is, the related attribute information of the interface code file to be detected may be entered by the user at the time of submitting the request, or may be acquired from an address specified in the request after the user submits the request for generating the interface code detection report. The method for acquiring the interface code to be detected can also provide a user interaction interface for a user to enter a code file.
The identifying module 120 is configured to analyze the first group of interface codes and the second group of interface codes by using a preset code analyzer, and extract preset type code blocks corresponding to the two groups of interface codes respectively.
In this embodiment, in order to accelerate analysis of parameter differences between two sets of interface codes, a code analyzer is used to identify annotation keywords of a code file, and multiple code blocks of the interface codes are extracted. The code analyzer reads a code file, and extracts code blocks containing "@ RequestMapping", "@ GetMapping", "@ PostMapping", "@ PutMapping", "@ deleteMapping".
For example: when the analyzer analyzes a certain interface code, the following code blocks are extracted:
the index is created according to the preset keywords through the code analyzer, and the full text searching capability of the interface code is achieved, so that when the interface code is analyzed, the whole interface code is not directly analyzed, the index is inquired based on the whole interface code to extract the code block of the preset type, other irrelevant codes are removed, the code block of the preset type is contrastively analyzed, and the efficiency of contrastive analysis can be improved.
The conversion module 130 is configured to convert the preset type code block into attribute information corresponding to two sets of interface codes by using a preset conversion rule, and compare and analyze the attribute information of the two sets of interface codes to obtain a difference parameter and a same parameter of the two sets of interface codes.
In this embodiment, code blocks corresponding to two sets of interface codes are obtained, and the code blocks are analyzed to analyze attribute information of the interfaces. The attribute information of the interface includes, but is not limited to, a name of the interface, a path of the interface, a uniform resource locator of the interface, an input parameter of the interface, a request mode of the interface, an output parameter of the interface, and the like. The interface data is used for describing attribute information of the interface, and the interface data is data in a preset format, and the preset format can be set according to actual requirements, and is not limited here. For example, the preset format may be a JavaScript Object Notation (JSON) format, which is a lightweight text data interchange format that uses a JavaScript syntax to describe data objects.
When writing interface code, developer can make corresponding annotation to interface code, and provide basis for generating corresponding report or document according to annotated interface code. Annotating the interface code specifically includes annotating and interpreting attribute information of the interface, and it can be understood that a developer can annotate the interface code according to a preset annotation mode in the interface development process. The preset annotation manner may be set according to actual requirements, and is not limited herein. For example, the preset annotation mode may be a third-party annotation tool, or the preset annotation mode may be an annotation mode customized by a developer.
The code block is composed of annotation lines and interface functions, and the preset conversion rule comprises: the annotation line for identifying the code block acquires the interface type and the interface path of the code block, and the interface function for identifying the code block acquires the interface name, the input parameters of the interface and the output parameters of the interface of the code block.
The first part of the code block is an annotation line which in the developed interface code block starts with the character "@" and the interface is defined by the annotation. From the annotation line, the interface type and interface path of the defined interface data may be retrieved. For example, the code block @ GetMapping ("XXX") has an interface type of "GET" and an interface path of "XXX".
The second part of the code block is an interface function, and the interface function comprises input parameters, names, output parameters and the like of interface data.
The input parameters of the interface function are the in field array of the interface data.
The name of the interface function is the name field of the interface data.
The output parameter of the interface function is the type field of the interface data out.
For example: some interface function code is obtained as follows:
public String getUserById (@ PathVariable Integer id), then it can identify
The name field of the interface data is: getUserById
The in field array of the interface data is [ { name: "id", type: "Integer", pathType: "var" } ]
The type field of the interface data out is: string
Comparing and analyzing the attribute information of the two groups of interface codes to obtain the difference parameters and the same parameters of the two groups of interface codes.
Further, the code blocks can be converted into corresponding interface data in the JSON format by using a preset JSON parser, and the interface data corresponding to the two groups of interfaces is stored in a preset database. After receiving a request for generating an interface code detection report, interface data corresponding to the interface may be acquired from a preset database, and the interface data may be analyzed to analyze attribute information of the interface. Specifically, the interface data is analyzed according to an analysis method corresponding to the format of the interface data. For example, if the interface data is data in JSON format, the JSON parser may be used to parse the interface data, and the attribute information of the interface may be obtained after parsing the interface data.
The generating module 140 is configured to fill the difference parameter and the same parameter into a predetermined template file, generate an interface code detection report, and send the interface code detection report to the user, so that the user can display the interface code detection report.
In this embodiment, the predetermined template file may be set according to actual requirements, and is not limited herein. For example, the predetermined template file may be an EXCEL document, in which interface attribute information addition frames such as an interface name, an interface path, an interface type, an interface request method, an interface input parameter, and an interface output parameter are set, and the attribute information of two sets of interface data is respectively added to the addition frames set in the EXCEL document, so as to generate a detection report of the interface code.
Further, if the parameters of the attribute information of the two sets of interface codes are completely the same, it indicates that the two sets of interfaces designed and actually developed are the same, and if any one of the parameters of the attribute information in the two sets of interface codes is different, it indicates that the interfaces have been changed, the same parameters of the two sets of interface codes are filled into a first preset position in a predetermined template file, and the difference parameters of the two sets of interface codes are filled into a second preset position in the predetermined template file, so that the interface developers can conveniently refer to the difference parameters.
In addition, the invention also provides a method for generating the interface code detection report. Fig. 3 is a schematic method flow diagram illustrating an embodiment of a method for generating an interface code detection report according to the present invention. The processor 12 of the electronic apparatus 1 realizes the following steps of the interface code detection report generation method when executing the interface code detection report generation program 10 stored in the memory 11:
step S10: receiving a request for generating an interface code detection report sent by a user, wherein the request comprises a first group of interface codes and a second group of interface codes to be detected.
In this embodiment, the first set of codes may be interface codes actually developed, and the second set of codes may be interface codes designed before development. The request may include two interface code files to be detected, and may also include a storage path and an identifier associated with the interface code files to be detected. That is, the related attribute information of the interface code file to be detected may be entered by the user at the time of submitting the request, or may be acquired from an address specified in the request after the user submits the request for generating the interface code detection report. The method for acquiring the interface code to be detected can also provide a user interaction interface for a user to enter a code file.
Step S20: and analyzing the first group of interface codes and the second group of interface codes by using a preset code analyzer, and respectively extracting preset type code blocks corresponding to the two groups of interface codes.
In this embodiment, in order to accelerate analysis of parameter differences between two sets of interface codes, a code analyzer is used to identify annotation keywords of a code file, and multiple code blocks of the interface codes are extracted. The code analyzer reads a code file, and extracts code blocks containing "@ RequestMapping", "@ GetMapping", "@ PostMapping", "@ PutMapping", "@ deleteMapping".
For example: when the analyzer analyzes a certain interface code, the following code blocks are extracted:
the index is created according to the preset keywords through the code analyzer, and the full text searching capability of the interface code is achieved, so that when the interface code is analyzed, the whole interface code is not directly analyzed, the index is inquired based on the whole interface code to extract the code block of the preset type, other irrelevant codes are removed, the code block of the preset type is contrastively analyzed, and the efficiency of contrastive analysis can be improved.
Step S30: and converting the preset type code block into attribute information corresponding to the two groups of interface codes by using a preset conversion rule, and comparing and analyzing the attribute information of the two groups of interface codes to obtain the difference parameters and the same parameters of the two groups of interface codes.
In this embodiment, code blocks corresponding to two sets of interface codes are obtained, and the code blocks are analyzed to analyze attribute information of the interfaces. The attribute information of the interface includes, but is not limited to, a name of the interface, a path of the interface, a uniform resource locator of the interface, an input parameter of the interface, a request mode of the interface, an output parameter of the interface, and the like. The interface data is used for describing attribute information of the interface, and the interface data is data in a preset format, and the preset format can be set according to actual requirements, and is not limited here. For example, the preset format may be a JavaScript Object Notation (JSON) format, which is a lightweight text data interchange format that uses a JavaScript syntax to describe data objects.
When writing interface code, developer can make corresponding annotation to interface code, and provide basis for generating corresponding report or document according to annotated interface code. Annotating the interface code specifically includes annotating and interpreting attribute information of the interface, and it can be understood that a developer can annotate the interface code according to a preset annotation mode in the interface development process. The preset annotation manner may be set according to actual requirements, and is not limited herein. For example, the preset annotation mode may be a third-party annotation tool, or the preset annotation mode may be an annotation mode customized by a developer.
The code block is composed of annotation lines and interface functions, and the preset conversion rule comprises: the annotation line for identifying the code block acquires the interface type and the interface path of the code block, and the interface function for identifying the code block acquires the interface name, the input parameters of the interface and the output parameters of the interface of the code block.
The first part of the code block is an annotation line which in the developed interface code block starts with the character "@" and the interface is defined by the annotation. From the annotation line, the interface type and interface path of the defined interface data may be retrieved. For example, the code block @ GetMapping ("XXX") has an interface type of "GET" and an interface path of "XXX".
The second part of the code block is an interface function, and the interface function comprises input parameters, names, output parameters and the like of interface data.
The input parameters of the interface function are the in field array of the interface data.
The name of the interface function is the name field of the interface data.
The output parameter of the interface function is the type field of the interface data out.
For example: some interface function code is obtained as follows:
public String getUserById (@ PathVariable Integer id), then it can identify
The name field of the interface data is: getUserById
The in field array of the interface data is [ { name: "id", type: "Integer", pathType: "var" } ]
The type field of the interface data out is: string
Comparing and analyzing the attribute information of the two groups of interface codes to obtain the difference parameters and the same parameters of the two groups of interface codes.
Further, the code blocks can be converted into corresponding interface data in the JSON format by using a preset JSON parser, and the interface data corresponding to the two groups of interfaces is stored in a preset database. After receiving a request for generating an interface code detection report, interface data corresponding to the interface may be acquired from a preset database, and the interface data may be analyzed to analyze attribute information of the interface. Specifically, the interface data is analyzed according to an analysis method corresponding to the format of the interface data. For example, if the interface data is data in JSON format, the JSON parser may be used to parse the interface data, and the attribute information of the interface may be obtained after parsing the interface data.
Step S40: and filling the difference parameters and the same parameters into a predetermined template file to generate an interface code detection report, and sending the interface code detection report to the user so that the user can display the interface code detection report.
In this embodiment, the predetermined template file may be set according to actual requirements, and is not limited herein. For example, the predetermined template file may be an EXCEL document, in which interface attribute information addition frames such as an interface name, an interface path, an interface type, an interface request method, an interface input parameter, and an interface output parameter are set, and the attribute information of two sets of interface data is respectively added to the addition frames set in the EXCEL document, so as to generate a detection report of the interface code.
Further, if the parameters of the attribute information of the two sets of interface codes are completely the same, it indicates that the two sets of interfaces designed and actually developed are the same, and if any one of the parameters of the attribute information of the two sets of interface codes is different, it indicates that the interfaces have been changed, the same parameters of the two sets of interface codes are filled into a first preset position in a predetermined template file, and the difference parameters of the two sets of interface codes are filled into a second preset position in the predetermined template file, so that the interface developers can conveniently refer to the difference parameters.
Furthermore, the embodiment of the present invention also provides a computer-readable storage medium, which may be any one or any combination of a hard disk, a multimedia card, an SD card, a flash memory card, an SMC, a Read Only Memory (ROM), an Erasable Programmable Read Only Memory (EPROM), a portable compact disc read only memory (CD-ROM), a USB memory, and the like. The computer readable storage medium includes therein an interface code detection report generation program 10, and when executed by a processor, the interface code detection report generation program 10 implements the following operations:
a receiving step: receiving a request for generating an interface code detection report sent by a user, wherein the request comprises a first group of interface codes and a second group of interface codes to be detected;
an identification step: analyzing the first group of interface codes and the second group of interface codes by using a preset code analyzer, and respectively extracting preset type code blocks corresponding to the two groups of interface codes;
a conversion step: converting the preset type code block into attribute information corresponding to the two groups of interface codes by using a preset conversion rule, and comparing and analyzing the attribute information of the two groups of interface codes to obtain difference parameters and same parameters of the two groups of interface codes; and
a generation step: and filling the difference parameters and the same parameters into a predetermined template file to generate an interface code detection report, and sending the interface code detection report to the user so that the user can display the interface code detection report.
The specific implementation of the computer-readable storage medium of the present invention is substantially the same as the specific implementation of the interface code detection report generation method, and is not described herein again.
It should be noted that the above-mentioned numbers of the embodiments of the present invention are merely for description, and do not represent the merits of the embodiments. And the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, apparatus, article, or method. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, apparatus, article, or method that includes the element.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention essentially or contributing to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) as described above and includes several instructions for enabling a terminal device (such as a mobile phone, a computer, an electronic device, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.