Device for rapidly verifying application program interface and control method thereof
Technical Field
The invention belongs to the technical field of computer application, and particularly relates to a device for quickly verifying an application program interface and a control method thereof.
Background
At present, as a technical developer in the internet industry, debugging of an application program interface is an essential working link. For interface management, most of the solutions adopted in the industry at present are to use Swagger to manage interface documents, use Postman debugging interface, and use EasyMock and other mock tools to simulate data. Such interface management requires different tools to be maintained, and data consistency between tools is difficult and inefficient. Here, not only is the problem of workload, but also the greater problem is data inconsistency among a plurality of systems, which causes low efficiency of collaboration, frequent problems and unnecessary loss.
Application Programming Interface (API) is some predefined Interface (such as function, HTTP Interface) or refers to the convention for joining different components of a software system. To provide a set of routines that applications and developers can access based on certain software or hardware without accessing source code or understanding the details of internal working mechanisms.
Because of the increasing size of software in recent years, it is often necessary to divide a complex system into small components, and the design and interface of application program interfaces are very important. In a project, a large amount of application program interface communication and docking are often needed, and the verification work before docking is also tedious and time-consuming, so that a device capable of quickly verifying whether an interface is effective is needed.
In the current program development, a large number of application program interfaces are needed to be connected in a butt joint mode, whether each interface is effectively output or not is verified in sequence when a business needs to be developed specifically, and unnecessary labor and time are consumed for verifying the interfaces in sequence.
In the process of program development, an application program interface is generally only responsible for a specific function point, each function is decoupled, a developer needs to use the specific application program interface when realizing specific services, the interface is verified whether to be effective or not when being used every time and then is fed back to the corresponding developer, and a large amount of time cost and communication cost are often needed in the process, and unnecessary manpower and time are consumed.
Through the above analysis, the problems and defects of the prior art are as follows:
data consistency between tools is very difficult and inefficient.
Data inconsistency among a plurality of systems causes low cooperation efficiency, frequent problems and unnecessary loss.
In the process of program development, whether the interface is effective or not can be verified every time the interface is used, and then the interface is fed back to a corresponding developer, so that a large amount of time cost and communication cost are needed, and unnecessary manpower and time are consumed.
Disclosure of Invention
Aiming at the problems in the prior art, the invention provides a device for quickly verifying an application program interface and a control method thereof.
The invention is realized in such a way that a control method of a device for quickly verifying an application program interface comprises the following steps:
step one, supporting import or manual entry of files conforming to OpenApi3.0 (original Swagger) and JSON Schema specifications. By reading JSON content of the file, outputting a visual interface management document, wherein the JSON format comprises an interface title, an interface description, an interface address, an interface HTTP request method (GET, POST, PUT, DELETE), a request parameter data structure, a response body field, a response body parameter data structure, HTTP HEADER information, a HTTP HEADER sample, interface return data, an interface return data structure and the like, and the interface information is supported to be edited again, so that the interface document can be managed better;
reading the formatted interface document JSON, traversing the whole JSON information, and intelligently outputting an interface test sample according to request parameters, a request parameter data structure, response body fields, a response body field data structure, HTTP HEADER information and the like; and then operating the interfaces one by one according to the output interface test sample and an interface HTTP request method, recording the returned data of each interface, and comparing the returned data with an interface document returned data structure to finish the quick verification of all the interfaces.
And step three, outputting the operation information and the operation results of all the interfaces into a visual document report, supporting the export and the retrieval of the interface documents, conveniently and quickly checking the operation condition of each interface, and quickly checking the interface information with problems.
Further, the operation information in the second step includes a real response of the interface and a real response time length of the interface.
Another object of the present invention is to provide an apparatus for quickly verifying an application program interface, comprising:
the API interface reading module supports importing or manually inputting files conforming to OpenApi3.0 (original Swagger) and JSON Schema specifications, outputs the files into visual interface management documents, and the documents comprise interface titles, interface descriptions, interface addresses, interface HTTP request methods (GET, POST, PUT and DELETE), request parameters, request parameter data structures, response body fields, response body parameter data structures, HTTP HEADER information, HTTP HEADER samples, interface return data structures and the like, and supports reediting, modifying and exporting the information;
the API interface verification module reads the formatted interface document JSON and outputs an interface test sample according to the request parameters, a request parameter data structure, a response body field data structure, HTTP HEADER information and other intelligent matching response fields; then operating the interfaces one by one according to the output interface test sample and an interface HTTP request method, recording the return data of each interface, and comparing the return data with an interface document return data structure to finish the quick verification of all the interfaces;
and the API document output module is used for storing all interface basic information (titles, descriptions and the like) and the request result combinations of the interfaces as new JSON information, reading the JSON and outputting corresponding interface documents and interface running condition reports.
Further, the API interface reading module reads the interface in the imported API JSON file according to the title, description, request method, and request parameter information corresponding to the API interface.
Further, the JSON format includes a title, a description, an interface address, a request method, a request parameter, and response body information of an interface.
Further, the API interface output module records the interface title, the interface address, the request method, the request parameter, the response information, the response time length and the error information of each interface and outputs the information into a document.
Further, if the interface is successfully called, the API interface verification module compares and verifies the request parameters and response information of the interface with the original interface document information, checks whether the interface outputs a response according to the request parameters required by the document and the requirements, and records and stores the response time of the interface after the operation is finished; and if the interface call fails, marking and screening the error information, and recording the detailed error information of the interface.
In combination with the technical solutions and the technical problems to be solved, please analyze the advantages and positive effects of the technical solutions to be protected in the present invention from the following aspects:
first, aiming at the technical problems existing in the prior art and the difficulty in solving the problems, the technical problems to be solved by the technical scheme of the present invention are closely combined with results, data and the like in the research and development process, and some creative technical effects are brought after the problems are solved. The specific description is as follows:
in the current technology development process, management of interfaces and other interface tools such as testing of the interfaces are difficult to adjust due to data inconsistency, and unnecessary labor cost and time cost are required. And here, not only is the problem of workload, but also the greater problem is that data is inconsistent among a plurality of systems, so that the cooperation is inefficient, problems frequently occur, and unnecessary loss is caused.
The technical scheme includes that the technical document of OpenApi3.0 specification is supported to be imported, the interface document is read, the interface document comprises an interface title, an interface description, an interface address, an interface HTTP request method (GET, POST, PUT, DELETE), request parameters, a request parameter data structure, a response body field, a response body parameter data structure, HTTP HEADER information, a HTTP HEADER sample, interface return data, an interface return data structure and the like, then the visual, editable and exportable technical document is output, an interface test sample is generated according to the parameter data structure and the data structure of the response body and other information of the interface, batch operation of all interfaces is completed, the operation result of each interface is recorded, and an interface operation report is customized and output.
Secondly, considering the technical scheme as a whole or from the perspective of products, the technical effect and advantages of the technical scheme to be protected by the invention are specifically described as follows:
the technical effects are as follows: by the method and the device, the interface document can be automatically arranged, the record and the modification of the interface document can be persistently stored, and the interface document can be conveniently arranged later; according to a request parameter data structure, a request body data structure and the like, interface information is intelligently matched, test samples are automatically generated, all interfaces are quickly operated in batches, the operation time and operation return information of the interfaces are recorded and compared with an original document, and finally a customized test report is generated;
the advantages are that: after the method is used, developers do not need to perform interface document arrangement, the time for writing the interface is reduced, visual re-editing is supported, and interface document information can be better managed; the invention can automatically match document information to generate test samples, automatically complete the test work of the interface, greatly improve the development efficiency and reduce the development cost; after the test is finished, a test report form of each interface can be generated, the interface condition is clear at a glance, and developers can be helped to quickly check the interfaces needing to be repaired.
Third, as an inventive supplementary proof of the claims of the present invention, there are also presented several important aspects:
the expected income and commercial value after the technical scheme of the invention is converted are as follows: the invention can better manage and test the project interface. And the system can support privatized deployment and client software in the future, and can carry out membership system charging and software use fee for common users and enterprise users.
The technical scheme of the invention solves the technical problem that people are eagerly to solve but can not be successfully solved all the time: the problem of complex arrangement of interface documents of developers is solved, and continuous, visual editing and previewing of project interfaces are supported; and the complex and tedious work of testing and testing is solved, the development efficiency of project projects is accelerated, and the development cost is reduced.
Drawings
Fig. 1 is a block diagram of an apparatus for quickly authenticating an application program interface according to an embodiment of the present invention.
Fig. 2 is a flowchart of a control method for a device for fast verifying an api according to an embodiment of the present invention.
Fig. 3 is a schematic diagram of a control method of a device for quickly verifying an api according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail with reference to the following 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.
First, an embodiment is explained. This section is an explanatory embodiment expanding on the claims so as to fully understand how the present invention is embodied by those skilled in the art.
As shown in fig. 1, an apparatus for quickly verifying an application program interface according to an embodiment of the present invention includes an API interface reading module, an API interface verifying module, and an API interface outputting module.
API interface reading module: reading JSON text of OpenApi3.0 specification, reading an interface document containing an interface title, an interface description, an interface address, an interface HTTP request method (GET, POST, PUT, DELETE), request parameters, a request parameter data structure, a response body field, a response body parameter data structure, HTTP HEADER information, HTTP HEADER sample, interface return data, an interface return data structure and the like, and then outputting a visual, editable and exportable technical document.
API interface verification module: reading the formatted interface document JSON, and outputting an interface test sample according to the request parameters, the request parameter data structure, the response body field data structure, HTTP HEADER information and other intelligent matching response fields; and then operating the interfaces one by one according to the output interface test sample and an interface HTTP request method, recording the return data of each interface, and comparing the return data with an interface document return data structure to finish the quick verification of all the interfaces.
API interface output module: and storing the request information of all the interfaces as JSON information, and outputting corresponding documents. Recording the interface title, interface address, request method, request parameter, response information, response time length and error information of each interface, and outputting into a document.
As shown in fig. 2, a method for controlling a device for quickly verifying an application program interface according to an embodiment of the present invention includes:
s101, reading the whole interface document information through an API (application program interface) interface reading module, and storing the interface information into a JSON (Java Server object) format which is convenient to read, wherein the JSON format comprises a title, a description, an interface address, a request method, a request parameter and response body information of an interface;
s102, traversing the formatted JSON information, making an HTTP request for the interface address corresponding to each interface according to a corresponding request method, storing the operation information of each interface, comparing the document information, and screening out the interfaces with errors;
and S103, outputting the operation information of all the interfaces into a report, and visually displaying the operation condition of each interface.
The operation information in S102 includes a real response of the interface and a real response duration of the interface.
Fig. 3 is a control method principle of a device for fast verifying an application program interface according to an embodiment of the present invention.
Second, the application embodiment. In order to prove the creativity and the technical value of the technical scheme of the invention, the part is the application example of the technical scheme of the claims on specific products or related technologies.
In the Internet development project, the technology is used for finishing the management and archiving work of the whole project interface, and quickly finishing the basic function test, concurrent test and the like of the interface. By using the technology, the relevant interface and the correct input and output format of a certain functional module can be conveniently inquired, and visual editing and previewing can be realized. Moreover, the interface test can be completed quickly, the problems existing in the interface can be found quickly, people can conveniently and quickly troubleshoot the project problems, and the development efficiency is improved.
And thirdly, evidence of relevant effects of the embodiment. The embodiment of the invention achieves some positive effects in the process of research and development or use, and has great advantages compared with the prior art, and the following contents are described by combining data, diagrams and the like in the test process.
Compared with the traditional software development, the management of the interface document is more intelligent, the parameter information of each interface does not need to be written manually, the interface document is generated automatically, the test sample is output intelligently, the interface test is carried out more quickly, and the document information can be better stored. The whole project interface and interface document test can take 3-4 days, the document is marked only in the early development process after the tool is used, and then the complete interface document and test report can be output only in a few minutes.
In the description of the present invention, "a plurality" means two or more unless otherwise specified; the terms "upper", "lower", "left", "right", "inner", "outer", "front", "rear", "head", "tail", and the like, indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, are merely for convenience in describing the present invention and to simplify the description, and do not indicate or imply that the device or element referred to must have a particular orientation, be constructed in a particular orientation, and be operated, and thus, should not be construed as limiting the present invention. Furthermore, the terms "first," "second," "third," and the like are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
It should be noted that the embodiments of the present invention can be realized by hardware, software, or a combination of software and hardware. The hardware portion may be implemented using dedicated logic; the software portions may be stored in a memory and executed by a suitable instruction execution system, such as a microprocessor or specially designed hardware. Those skilled in the art will appreciate that the apparatus and methods described above may be implemented using computer executable instructions and/or embodied in processor control code, such code being provided on a carrier medium such as a disk, CD-or DVD-ROM, programmable memory such as read only memory (firmware), or a data carrier such as an optical or electronic signal carrier, for example. The apparatus of the present invention and its modules may be implemented by hardware circuits such as very large scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, or programmable hardware devices such as field programmable gate arrays, programmable logic devices, or software executed by various types of processors, or a combination of hardware circuits and software, e.g., firmware.
The above description is only for the purpose of illustrating the present invention and the appended claims are not to be construed as limiting the scope of the invention, which is intended to cover all modifications, equivalents and improvements that are within the spirit and scope of the invention as defined by the appended claims.