Interface document processing method and device
By automatically parsing interface documents to generate interface encapsulation functions and error callback functions, the problem of manual encapsulation of interface functions is solved, the front-end development efficiency is improved, and the timely update of interface documents is realized.
Patent Information
- Application Number
- CN202111648289.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2041-12-29
AI Technical Summary
In the prior art, front-end technicians manually encapsulate interface functions are not efficient, especially when facing a large number of interface documents.
By obtaining interface documents and parsing scripts, the automatic parsing scripts are used to automatically convert multiple interfaces in the interface document into multiple interface encapsulation functions, and an error callback function is added to the interface encapsulation function to generate an automated parsing file of the interface encapsulation function.
It greatly improves the efficiency of front-end technicians calling interfaces in interface documents, reduces human errors, ensures the normal operation of the program, and monitors and feedbacks error information in real time through error callback functions to achieve timely update of interface documents.
Smart Images

Figure CN114385141B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a method and device for processing interface documents. Background Art
[0002] With the development of Internet technology, separation of front-end and back-end has become a standard usage method in the development of Internet projects. The core idea of separation of front-end and back-end is that front-end technicians call interfaces based on interface documents written by back-end technicians to interact with data.
[0003] Currently, the existing solution converts the interfaces in the interface document into callable interface encapsulation functions. Generally, the front-end technicians manually encapsulate each interface in the interface document into an independent function, store it in a public file, and call it when the front-end is in use.
[0004] However, when faced with an interface document containing a large number of interfaces, it is not efficient for front-end technicians to manually encapsulate individual interface functions. Summary of the Invention
[0005] The embodiments of the present application provide a method and apparatus for processing an interface document to solve the problem of low efficiency of manually encapsulating a single interface function in the prior art.
[0006] In a first aspect, the present application provides a method for processing an interface document, the method comprising:
[0007] Acquire a first target interface document, where the first target interface document includes a plurality of interfaces;
[0008] Get the first parsing script;
[0009] Parsing the first target interface document using the first parsing script to obtain a first target parsing file;
[0010] The first target parsing file includes a plurality of interface encapsulation functions corresponding to the plurality of interfaces.
[0011] In a second aspect, the present application provides a device for processing an interface document, the device comprising:
[0012] An acquisition module is configured to acquire a first target interface document, wherein the first target interface document includes a plurality of interfaces; and acquire a first parsing script;
[0013] a processing module, configured to parse the first target interface document using the first parsing script to obtain a first target parsed file;
[0014] The first target parsing file includes a plurality of interface encapsulation functions corresponding to the plurality of interfaces.
[0015] In a third aspect, the present application provides a server comprising: a processor, a memory, and a program or instruction stored on the memory and running on the processor, wherein the program or instruction implements the steps of the method of the first aspect when executed by the processor.
[0016] In a fourth aspect, the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method of the first aspect are implemented.
[0017] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects:
[0018] In an embodiment of the present application, a first target interface document is obtained, wherein the first target interface document includes multiple interfaces; a first parsing script is obtained; the first target interface document is parsed by the first parsing script to obtain a first target parsing file; wherein the first target parsing file includes multiple interface encapsulation functions corresponding to the multiple interfaces. In this way, the first parsing script can be used to automatically parse the first target interface document including multiple interfaces to obtain a first target parsing file including multiple interface encapsulation functions corresponding to the multiple interfaces. This can greatly improve the efficiency of front-end technicians in calling interfaces in the first target interface document, thereby solving the problem of low efficiency of manually encapsulating individual interface functions in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0020] Figure 1 A flowchart of a method for processing an interface document provided in an embodiment of the present application;
[0021] Figure 2 A flowchart of a method for processing an interface document provided in an embodiment of the present application;
[0022] Figure 3 A flowchart of a method for processing an interface document provided in an embodiment of the present application;
[0023] Figure 4 A schematic diagram of a method for processing an interface document provided in an embodiment of the present application;
[0024] Figure 5 A structural block diagram of an interface document processing device provided in an embodiment of the present application;
[0025] Figure 6A structural block diagram of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] To make the purpose, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this application and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0027] The terms "first," "second," and the like in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of this application can be implemented in an order other than that illustrated or described herein, and that the objects distinguished by "first," "second," and the like are generally of the same type, and do not limit the number of objects; for example, the first object can be one or more. In addition, the term "and / or" in the specification and claims refers to at least one of the connected objects, and the character " / " generally indicates that the objects connected are in an "or" relationship.
[0028] The following describes in detail the technical solutions provided by various embodiments of the present application in conjunction with the accompanying drawings.
[0029] The interface document processing method provided in the embodiment of the present application can be executed by the front-end server.
[0030] Figure 1 This is a flowchart of a method for processing an interface document provided in an embodiment of the present application. Figure 1 The method for processing the interface document provided in the embodiment of the present application may include:
[0031] Step 110: Obtain a first target interface document, where the first target interface document includes multiple interfaces.
[0032] The first target interface document may be a Representational State Transfer Application Programming Interface (RESTFULAPI) document; the API interface document may include multiple API interfaces. It is understood that the first target interface document may be written by backend technical personnel, that is, the front-end server may obtain the first target interface document from the back-end server.
[0033] In the embodiment of the present application, the interface may be some predefined functions, or may refer to the agreement for connecting different components of the software system. The purpose of the interface may be to provide applications and developers with the ability to access a set of routines based on a certain software or hardware without having to access the source code or understand the details of the internal working mechanism. The interface can be divided into four parts: method, Uniform Resource Locator (URL), request parameters, and return parameters. Among them, URL is the Uniform Resource Locator of the World Wide Web, that is, the network address. The URL can be composed of three parts: resource type, host domain name where the resource is stored, and resource file name; it can also be composed of four parts: protocol, host, port, and path.
[0034] Step 120, obtaining a first parsing script;
[0035] The first parsing script may be a script pre-configured by a user for reading and parsing the content of the first target interface document; the first parsing script may include user-defined parsing rules.
[0036] It should be understood that the order of step 110 and step 120 can be selected according to actual circumstances and is not limited here. For example, step 110 can be performed first and then step 120; step 120 can be performed first and then step 110; or step 110 and step 120 can be performed simultaneously.
[0037] Step 130: Parse the first target interface document using the first parsing script to obtain a first target parsing file.
[0038] It is understandable that the process of parsing the first target interface document by the first parsing script can be a process of automatically parsing by executing instructions by the front-end server. Specifically, in an embodiment of the present application, the first parsing script can be executed on the front-end server through Node Package Manager (NPM) instructions to parse the first target interface document.
[0039] NPM is a package management and distribution tool installed along with the runtime environment (Node JavaScript, NodeJS). NPM makes it easy for programming language (JavaScript) developers to download, install, upload, and manage installed packages. NodeJS can optimize for specific use cases and provide alternative API interfaces. JavaScript is a lightweight, interpreted or just-in-time compiled programming language with a function-first approach. JavaScript is a multi-paradigm, dynamic scripting language based on prototype programming, and supports object-oriented, imperative, declarative, and functional programming paradigms. JavaScript is an event-driven language, and Node leverages this advantage to create highly scalable servers. Node chose an "event loop" architecture that improves performance while reducing development complexity, making it both easy and secure to write highly scalable servers.
[0040] In an embodiment of the present application, each interface in the first target interface document can be converted into a corresponding interface encapsulation function, and the first target parsing file can include multiple interface encapsulation functions corresponding to the multiple interfaces. While parsing the content of the first target interface document to obtain multiple interface encapsulation functions, type declarations for related parameters and method return values are also generated; that is, the first target parsing file can also include type declarations for parameters and method return values related to the interface encapsulation functions.
[0041] In an embodiment of the present application, the parsing rules in the first parsing script may be rules for converting each interface into a corresponding interface encapsulation function. It should be understood that the parsing rules for automatically parsing interface documents may be customized according to the specifications of different interface documents.
[0042] The interface document processing method provided in the embodiment of the present application obtains a first target interface document, wherein the first target interface document includes multiple interfaces; obtains a first parsing script; parses the first target interface document through the first parsing script to obtain a first target parsing file; wherein the first target parsing file includes multiple interface encapsulation functions corresponding to the multiple interfaces. In this way, the first parsing script can be used to automatically parse the first target interface document including multiple interfaces to obtain a first target parsing file including multiple interface encapsulation functions corresponding to the multiple interfaces. This can greatly improve the efficiency of front-end technicians in calling interfaces in the first target interface document, thereby solving the problem of low efficiency of manually encapsulating a single interface function in the prior art.
[0043] Optionally, in one embodiment of the present application, the first target parsing file may further include: a type declaration of the return value of the interface encapsulation function and a type declaration of a parameter in the interface encapsulation function; after step 130, the interface document processing method may further include: compiling the first target parsing file based on the type declaration of the return value of the interface encapsulation function and the type declaration of the parameter in the interface encapsulation function to obtain a first target compiled file. In this way, the first target parsing file can be compiled based on the type declaration of the parameter and return value of the interface encapsulation function, thereby ensuring the efficient operation of the interface encapsulation function in the first target parsing file during compilation.
[0044] In the embodiment of the present application, compiling the first target parsing file can be understood as front-end technicians compiling the first target parsing file when they need to call the interface encapsulation function in the first target parsing file, so that the interface encapsulation function can be directly called. The first target compiled file can be a file compiled from the first target parsing file.
[0045] Optionally, in one embodiment of the present application, before step 130, the interface document processing method may further include: obtaining node package manager instructions; executing the first parsing script according to the node package manager instructions; wherein the node package manager instructions are set in the scripts object in the package file.
[0046] Among them, the Node Package Manager (NPM) instruction is an instruction of the package management and distribution tool installed together with NodeJS. In an embodiment of the present application, the user can further execute the first parsing script by executing the NPM instruction in the console of the front-end server, thereby parsing the first target interface document through the first parsing script. It should be understood that the command for executing the first parsing script (for example, the NPM instruction) can be customized in the scripts object in the package file.
[0047] In this way, the first parsing script can be executed through instructions, so that the interface encapsulation functions can be generated in batches by parsing the first target interface document through the first parsing script, which greatly improves the R&D efficiency of front-end technical personnel and creates favorable conditions for the rapid development of the project.
[0048] In one embodiment of the present application, the specific process of parsing the first target interface document by the first parsing script to obtain the first target parsing file in step 130 can be implemented in various different ways.
[0049] A specific implementation example is given below. Please note that the following is only an example and is not intended to be limiting.
[0050] See Figure 2 The specific process of parsing the first target interface document by the first parsing script in step 130 to obtain the first target parsing file may include: step 230, step 240 and step 250. Figure 2 This is a flowchart of a method for processing an interface document provided in an embodiment of the present application. Figure 2 The method for processing the interface document provided in the embodiment of the present application may include:
[0051] Step 210: Obtain a first target interface document, where the first target interface document includes multiple interfaces.
[0052] Step 220, obtaining a first parsing script;
[0053] Step 230: Read the multiple interfaces in the first target interface document through the first parsing script;
[0054] In an embodiment of the present application, after executing the NPM instruction, the front-end server can automatically read the multiple interfaces in the first target interface document through the first parsing script.
[0055] Step 240: convert the multiple interfaces into the multiple interface encapsulation functions corresponding to the multiple interfaces;
[0056] In an embodiment of the present application, the front-end server may convert the multiple interfaces in the first target interface document into the multiple interface encapsulation functions corresponding to the multiple interfaces according to the parsing rules. The parsing rules may be rules for converting each interface individually into a corresponding interface encapsulation function. It should be understood that the parsing rules for automatically parsing interface documents may be customized according to the specifications of different interface documents.
[0057] Step 250: Output the multiple interface encapsulation functions to a designated file, and use the designated file as the first target parsing file.
[0058] The designated file may be a file storing the plurality of interface encapsulation function sets.
[0059] It can be understood that the first target parsing file may include the multiple interface encapsulation functions and type declarations of parameters and method return values generated corresponding to the multiple interface encapsulation functions.
[0060] The interface document processing method provided in the embodiment of the present application can automatically read multiple interfaces in the first target interface document through a first parsing script, and then batch convert the multiple interfaces into multiple interface encapsulation functions corresponding to the multiple interfaces to obtain a first target parsing file including multiple interface encapsulation functions, thereby greatly improving the efficiency of front-end technicians in encapsulating interfaces in the first target interface document.
[0061] In one embodiment of the present application, the first target parsing file may further include multiple error callback functions, and one of the multiple error callback functions may correspond to one of the multiple interface encapsulation functions; the specific process of parsing the first target interface document through the first parsing script to obtain the first target parsing file in step 130 may be implemented in various different ways.
[0062] A specific implementation example is given below. Please note that the following is only an example and is not intended to be limiting.
[0063] See Figure 3 The specific process of parsing the first target interface document by the first parsing script in step 130 to obtain the first target parsing file may also include: step 330, step 340, step 350 and step 360. Figure 3 This is a flowchart of a method for processing an interface document provided in an embodiment of the present application. Figure 3 The method for processing the interface document provided in the embodiment of the present application may include:
[0064] Step 310: Obtain a first target interface document, where the first target interface document includes multiple interfaces.
[0065] Step 320, obtaining a first parsing script;
[0066] Step 330: Read the multiple interfaces in the first target interface document through the first parsing script;
[0067] Step 340: convert the multiple interfaces into the multiple interface encapsulation functions corresponding to the multiple interfaces;
[0068] Step 350: adding the error callback function to each of the multiple interface encapsulation functions;
[0069] The error callback function can be a reject callback function, which changes the state of the Promise object from "uncompleted" to "failed". It is called when an asynchronous operation fails and passes the error reported by the asynchronous operation as a parameter. Simply put, a Promise is a container that stores the result of an event (usually an asynchronous operation) that will not end in the future. Syntactically, a Promise is an object from which asynchronous operation messages can be obtained. Promise provides a unified API interface, and various asynchronous operations can be handled in the same way.
[0070] In an embodiment of the present application, the error callback function can be used to feed back error information when the interface encapsulation function is running to the backend server. The error information can be information about a parameter error in the interface encapsulation function, or information about an error in calling the interface encapsulation function, etc.
[0071] Step 360: Output the multiple interface encapsulation functions and the multiple error callback functions corresponding to the multiple interface encapsulation functions to a designated file, and use the designated file as the first target parsing file.
[0072] The designated file may be a file storing the plurality of interface encapsulation functions and the plurality of error callback functions. It should be understood that an error callback function may be added after each interface encapsulation function, that is, the first target parsing file may include a function set of the plurality of interface encapsulation functions and the error callback functions.
[0073] In an embodiment of the present application, the first target parsing file may further include type declarations of parameters and method return values generated corresponding to the multiple interface encapsulation functions.
[0074] The interface document processing method provided in the embodiment of the present application can batch convert multiple interfaces in the first target interface document into multiple interface encapsulation functions corresponding to the multiple interfaces through a first parsing script, and then add an error callback function to each interface encapsulation function to obtain a first target parsing file, thereby greatly improving the efficiency of front-end technicians in encapsulating the interfaces in the first target interface document. At the same time, the error callback function can be used to monitor the error information during the operation of the first target parsing file in real time and feedback it to the back-end server to perform timely update operations on the first target interface document.
[0075] Optionally, in one embodiment of the present application, after step 130, the interface document processing method may further include: if a target interface encapsulation function among the multiple interface encapsulation functions encounters a runtime error, feeding back error information to the backend device via the error callback function. In this way, the nature of the error callback function can be utilized to promptly feed back error information that occurs during runtime of the target interface encapsulation function to the backend device.
[0076] The target interface encapsulation function may be one of the multiple interface encapsulation functions called by the front-end server; or the target interface encapsulation function may be N interface encapsulation functions called by the front-end server, where N may be a positive integer and may be greater than 1 and less than or equal to the total number of the interface encapsulation functions in the first target parsing file. The back-end device may be a back-end server; the error message may be information about a parameter error in the interface encapsulation function, or information about an error in calling the interface encapsulation function, etc.
[0077] In an embodiment of the present application, after obtaining the first target parsing file, the front-end server can directly call the interface encapsulation function through the first target parsing file without having to access the back-end server to retrieve data.
[0078] Optionally, in one embodiment of the present application, after the error information is fed back to the back-end device through the error callback function, the interface document processing method may further include: receiving a second target interface document sent by the back-end device, the second target interface document being an updated document of the first target interface document; obtaining a second parsing script; parsing the second target interface document through the second parsing script to obtain a second target parsing file.
[0079] Among them, the second target interface document can be a document that the back-end technical staff repairs and updates the first target interface document according to the received error information; that is, the second target interface document can be a RESTFUL API document that updates the target interface encapsulation function in the first target interface document. The second parsing script can be the same as the first parsing script, or different from the first parsing script; when the second parsing script is different from the first parsing script, the second parsing script can be an updated script based on the first parsing script, and the updated content of the second parsing script can correspond to the updated content of the second target interface document. The second target parsing file can include the multiple updated interface encapsulation functions and the type declarations of the parameters and method return values generated corresponding to the multiple updated interface encapsulation functions.
[0080] In this embodiment of the present application, the error callback function can be used to promptly feedback error information that occurs during the execution of the target interface encapsulation function to the backend device. After receiving the error information, the backend technician can repair the error information on the backend device. In other words, repairing the error information can modify the content of the first target interface document accordingly, thereby promptly updating the second target interface document sent by the backend device to the front-end server.
[0081] In this way, after timely feeding back error information to the backend device using the error callback function, the updated second target interface document sent by the backend device can be received, thereby timely repairing and updating the first target interface document.
[0082] Optionally, in one embodiment of the present application, the interface document processing method may further include: the backend device receiving the error information fed back by the front-end server; the backend device repairing and updating the first target interface document based on the error information to obtain the second target interface document; and the backend device sending the second target interface document to the front-end server. In this manner, the backend device may manually repair and update the first target interface document based on the received error information, and send the updated second target interface document to the front-end server, thereby achieving timely updating of the first target interface document.
[0083] Optionally, in one embodiment of the present application, the second target parsing file may also include multiple interface encapsulation functions and multiple error callback functions. After the second target parsing script parses the second target interface document to obtain the second target parsing file, the interface document processing method may further include: if a runtime error occurs in the interface encapsulation function in the second target parsing file, continuing to feedback error information to the backend device via the error callback function. In this way, if a runtime error occurs again in the interface encapsulation function in the second target parsing file obtained after the update, error information can be fed back to the backend device via the error callback function again, thereby timely updating the second target interface document again.
[0084] The following is a detailed description of the interface document processing method provided by the embodiment of the present application in combination with actual application scenarios. Figure 4 As shown, the interface document processing method provided in the embodiment of the present application is only an example and not a limitation, and is intended to facilitate those skilled in the art to better understand the technical solution of the present application. The interface document processing method can be specifically applied to a front-end server.
[0085] Reference Figure 4 The method for processing the interface document provided in the embodiment of the present application may include the following steps:
[0086] Step 410: Acquire a first target interface document, where the first target interface document includes multiple interfaces.
[0087] Step 420: Obtain a first parsing script.
[0088] Step 430: Read the multiple interfaces in the first target interface document through the first parsing script.
[0089] Step 440: Convert the multiple interfaces into the multiple interface encapsulation functions corresponding to the multiple interfaces.
[0090] Step 450: Add the error callback function to each of the multiple interface encapsulation functions.
[0091] Step 460: Output the multiple interface encapsulation functions and the multiple error callback functions corresponding to the multiple interface encapsulation functions to a designated file, and use the designated file as the first target parsing file.
[0092] Step 470 : When a running error occurs in the target interface encapsulation function among the multiple interface encapsulation functions, error information is fed back to the backend device through the error callback function.
[0093] In one embodiment of the present application, the NPM command can be executed on the console of the front-end server to read and parse the content of the first target interface document through the first parsing script, and according to the preset rules, the multiple interfaces in the first target interface document are converted into multiple interface encapsulation functions corresponding to the multiple interfaces, and then an error callback function is automatically added to each generated interface encapsulation function. The generated interface encapsulation function and the error callback function are output to a specified file, and the specified file is used as the first target parsing file, so that the front-end technician can call the required interface encapsulation function through the first target parsing file during the development process. When the interface encapsulation function is running, the error callback function can be used to monitor the occurrence of runtime errors and promptly feedback the error information to the back-end device. In this way, the first target interface document can be automatically read and parsed by the first parsing script, avoiding the generation of human errors caused by manually encapsulating interface functions and ensuring the normal operation of the program; the method of batch generating interface encapsulation functions by executing the NPM command can replace the method of manually encapsulating interface functions individually, greatly improving the efficiency of research and development and creating favorable conditions for the rapid development of the project; the corresponding error callback function can also be added to the batch generated interface encapsulation function to monitor the error information of the interface encapsulation function in real time and promptly feedback it to the back-end device, so as to perform timely repair and update operations on the first target interface document. In addition, while batch-generating interface encapsulation functions, type declarations of parameters and method return values related to the interface encapsulation functions are also batch-generated, ensuring efficient operation of the program during compilation.
[0094] The interface document processing method provided in the embodiment of the present application can batch convert multiple interfaces in the first target interface document into multiple interface encapsulation functions corresponding to the multiple interfaces through a first parsing script, and then add an error callback function to each interface encapsulation function to obtain a first target parsing file, thereby greatly improving the efficiency of front-end technicians in encapsulating the interfaces in the first target interface document. At the same time, the error callback function can be used to monitor the error information during the operation of the first target parsing file in real time and feedback it to the back-end device to perform timely update operations on the first target interface document.
[0095] Figure 5 This is a structural block diagram of an interface document processing device provided in an embodiment of the present application. Figure 5 , an interface document processing device 500 provided in an embodiment of the present application may include: an acquisition module 510 and a processing module 520.
[0096] The acquisition module 510 is configured to acquire a first target interface document, wherein the first target interface document includes a plurality of interfaces; and acquire a first parsing script;
[0097] The processing module 520 is configured to parse the first target interface document using the first parsing script to obtain a first target parsed file;
[0098] The first target parsing file includes a plurality of interface encapsulation functions corresponding to the plurality of interfaces.
[0099] The interface document processing device provided in the embodiment of the present application obtains a first target interface document, wherein the first target interface document includes multiple interfaces; obtains a first parsing script; and parses the first target interface document using the first parsing script to obtain a first target parsing file; wherein the first target parsing file includes multiple interface encapsulation functions corresponding to the multiple interfaces. In this way, the first parsing script can be used to automatically parse the first target interface document including multiple interfaces to obtain a first target parsing file including multiple interface encapsulation functions corresponding to the multiple interfaces. This can greatly improve the efficiency of front-end technicians in calling interfaces in the first target interface document, thereby solving the problem of low efficiency of manually encapsulating individual interface functions in the prior art.
[0100] Optionally, in one embodiment, the processing module 520 can be specifically used to: read the multiple interfaces in the first target interface document through the first parsing script; convert the multiple interfaces into the multiple interface encapsulation functions corresponding to the multiple interfaces; output the multiple interface encapsulation functions to a specified file, and use the specified file as the first target parsing file.
[0101] Optionally, in one embodiment, the first target parsing file may also include multiple error callback functions, and one of the multiple error callback functions may correspond to one of the multiple interface encapsulation functions; the processing module 520 may be specifically used to: read the multiple interfaces in the first target interface document through the first parsing script; convert the multiple interfaces into the multiple interface encapsulation functions corresponding to the multiple interfaces; add the error callback function to each of the multiple interface encapsulation functions; output the multiple interface encapsulation functions and the multiple error callback functions corresponding to the multiple interface encapsulation functions to a designated file, and use the designated file as the first target parsing file.
[0102] Optionally, in one embodiment, after the first target interface document is parsed by the first parsing script to obtain the first target parsing file, the processing module 520 can also be used to: in the event that a runtime error occurs in the target interface encapsulation function among the multiple interface encapsulation functions, feedback error information to the back-end device through the error callback function.
[0103] Optionally, in one embodiment, after the error information is fed back to the back-end device through the error callback function, the interface document processing device 500 may also include: a receiving module for receiving a second target interface document sent by the back-end device, where the second target interface document is an updated document of the first target interface document; the acquisition module 510 may also be used to: obtain a second parsing script; the processing module 520 may also be used to: parse the second target interface document through the second parsing script to obtain a second target parsing file.
[0104] It should be noted that the interface document processing device provided in the embodiment of the present application corresponds to the interface document processing method mentioned above. For related content, please refer to the description of the interface document processing method above, and no further details will be given here.
[0105] In addition, if Figure 6 As shown, an embodiment of the present application also provides a server 600, the server 600 including: a processor 610, a memory 620 and a program or instruction stored on the memory 620 and running on the processor 610, wherein the program or instruction implements the steps of any of the methods described above when executed by the processor 610. For example, when the program is executed by the processor 620, the following process is implemented: obtaining a first target interface document, the first target interface document including multiple interfaces; obtaining a first parsing script; parsing the first target interface document by the first parsing script to obtain a first target parsing file; wherein the first target parsing file includes multiple interface encapsulation functions corresponding to the multiple interfaces. In this way, the first target interface document including multiple interfaces can be automatically parsed by the first parsing script to obtain a first target parsing file including multiple interface encapsulation functions corresponding to the multiple interfaces, which can greatly improve the efficiency of front-end technicians in calling interfaces in the first target interface document, thereby solving the problem of low efficiency of manually encapsulating single interface functions in the prior art.
[0106] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by the processor 610, the steps of any of the methods described above are implemented. For example, when the program is executed by the processor 610, the following process is implemented: obtaining a first target interface document, wherein the first target interface document includes multiple interfaces; obtaining a first parsing script; parsing the first target interface document by the first parsing script to obtain a first target parsing file; wherein the first target parsing file includes multiple interface encapsulation functions corresponding to the multiple interfaces. In this way, the first target interface document including multiple interfaces can be automatically parsed by the first parsing script to obtain a first target parsing file including multiple interface encapsulation functions corresponding to the multiple interfaces, which can greatly improve the efficiency of front-end technicians in calling interfaces, thereby solving the problem of low efficiency of manually encapsulating single interface functions in the prior art.
[0107] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0108] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0109] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0110] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps for the function specified in one or more boxes.
[0111] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0112] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0113] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0114] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0115] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0116] The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A method for processing an interface document, characterized in that: The method comprises: Acquire a first target interface document, where the first target interface document includes a plurality of interfaces; Get the first parsing script; Parsing the first target interface document using the first parsing script to obtain a first target parsing file; The first target parsing file includes a plurality of interface encapsulation functions corresponding to the plurality of interfaces and a plurality of error callback functions, one of the plurality of error callback functions corresponds to one of the plurality of interface encapsulation functions, and the error callback function is used to feed back error information to the backend device; The obtaining of a first target parsed file by parsing the first target interface document using the first parsing script includes: Reading the multiple interfaces in the first target interface document through the first parsing script; Converting the multiple interfaces into the multiple interface encapsulation functions corresponding to the multiple interfaces; Adding the error callback function to each of the multiple interface encapsulation functions; Output the multiple interface encapsulation functions and the multiple error callback functions corresponding to the multiple interface encapsulation functions into a designated file, and use the designated file as the first target parsing file; When a target interface encapsulation function among the multiple interface encapsulation functions has a running error, feeding back error information to a backend device through the error callback function; receiving a second target interface document sent by the back-end device, where the second target interface document is an updated document of the first target interface document; Get the second parsing script; The second target interface document is parsed by the second parsing script to obtain a second target parsing file, which includes multiple updated interface encapsulation functions and type declarations of parameters and method return values generated corresponding to the multiple updated interface encapsulation functions.
2. The processing method according to claim 1, characterized in that The obtaining of a first target parsed file by parsing the first target interface document using the first parsing script includes: Reading the multiple interfaces in the first target interface document through the first parsing script; Converting the multiple interfaces into the multiple interface encapsulation functions corresponding to the multiple interfaces; The multiple interface encapsulation functions are output to a designated file, and the designated file is used as the first target parsing file.
3. The processing method according to claim 1, characterized in that The first target parsing file further includes: a type declaration of a return value of the interface encapsulation function and a type declaration of a parameter in the interface encapsulation function; After parsing the first target interface document through the first parsing script to obtain the first target parsing file, the method further includes: compiling the first target parsing file based on the type declaration of the return value of the interface encapsulation function and the type declaration of the parameters in the interface encapsulation function to obtain a first target compiled file.
4. The processing method according to claim 1, characterized in that Before parsing the first target interface document by the first parsing script to obtain a first target parsed file, the method further includes: Get the node package manager instructions; Executing the first parsing script according to the node package manager instruction; The node package manager instructions are set in the scripts object in the package file.
5. The processing method according to claim 1, characterized in that The first parsing script is a script pre-configured by the user, and the first parsing script includes customized parsing rules.
6. The processing method according to claim 1, characterized in that The first target interface document is a representational state transfer application program interface document, and the second target interface document is a representational state transfer application program interface document obtained by updating the target interface encapsulation function in the first target interface document.
7. An interface document processing device, characterized in that: The device comprises: An acquisition module is configured to acquire a first target interface document, wherein the first target interface document includes a plurality of interfaces; and acquire a first parsing script; a processing module, configured to parse the first target interface document using the first parsing script to obtain a first target parsed file; The first target parsing file includes a plurality of interface encapsulation functions corresponding to the plurality of interfaces and a plurality of error callback functions, one of the plurality of error callback functions corresponds to one of the plurality of interface encapsulation functions, and the error callback function is used to feed back error information to the backend device; The processing module is specifically configured to read the multiple interfaces in the first target interface document through the first parsing script; Converting the multiple interfaces into the multiple interface encapsulation functions corresponding to the multiple interfaces; Adding the error callback function to each of the multiple interface encapsulation functions; Output the multiple interface encapsulation functions and the multiple error callback functions corresponding to the multiple interface encapsulation functions into a designated file, and use the designated file as the first target parsing file; The processing module is further configured to feed back error information to the backend device through the error callback function when a target interface encapsulation function among the multiple interface encapsulation functions has an operation error; a receiving module, configured to receive a second target interface document sent by the back-end device, where the second target interface document is an updated version of the first target interface document; The acquisition module is further used to acquire a second parsing script; The processing module is also used to parse the second target interface document through the second parsing script to obtain a second target parsing file, wherein the second target parsing file includes multiple updated interface encapsulation functions and type declarations of parameters and method return values generated corresponding to the multiple updated interface encapsulation functions.
8. A server, characterized in that: The server includes: a processor, a memory, and a program or instruction stored in the memory and running on the processor, and when the program or instruction is executed by the processor, the steps of any one of the methods described in claims 1-6 are implemented.
Citation Information
Patent Citations
Interface code generation method and device, electronic equipment and storage medium
CN110515608A