Text generation method, device, electronic device, storage medium and product
By obtaining and processing interface comment text and automatically generating interface call code, the problem of front-end and back-end development dependency on manual labor is solved, and a more efficient application development process is achieved.
Patent Information
- Application Number
- CN202111615578.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2041-12-27
AI Technical Summary
The docking operations of front-end and back-end development of applications rely heavily on labor, resulting in high labor costs and long-term consumption. When there are too many back-end interfaces, it is prone to vulnerabilities, and the application development efficiency is low.
By obtaining the comment text of the target interface, determining the interface attribute information, and character objectifying it, generating the target text, which is used to instruct the application to call the target interface, reducing the need for manual code writing.
It effectively reduces application development costs, shortens application development time, improves application development automation, and thus improves application development efficiency.
Smart Images

Figure CN114528013B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a text generation method, device, electronic device, storage medium and product. Background Art
[0002] During the application development process, the front-end and back-end development of the application may be decoupled. The front-end page corresponding to the application is responsible for providing the view, and the back-end service is responsible for providing the corresponding content. The front-end and back-end need to be connected for the application to run normally.
[0003] In related technologies, front-end technicians often need to define the field types involved in the back-end interface according to the interface documents provided by the back-end, create simulation data, and write program code for the front-end to call the back-end interface, so as to complete the docking operation between the front-end and the back-end.
[0004] However, in the related technologies, the docking operations between the front-end and back-end development of applications are highly dependent on manual labor, the application development labor cost is high and time-consuming, vulnerabilities are prone to occur when there are too many back-end interfaces, and the application development efficiency is low. Summary of the invention
[0005] The present disclosure provides a text generation method, device, electronic device, storage medium and product to at least solve the problems in the related art that the docking operation of front-end and back-end development of applications is highly dependent on manual labor, the application development labor cost is high and time-consuming, vulnerabilities are prone to occur when there are too many back-end interfaces, and the application development efficiency is low. The technical solution of the present disclosure is as follows:
[0006] According to a first aspect of an embodiment of the present disclosure, there is provided a text generation method, comprising:
[0007] Get the comment text corresponding to the target interface;
[0008] Based on the annotation text, determining interface attribute information corresponding to the target interface;
[0009] Performing character object processing on the interface attribute information to obtain a character object corresponding to the target interface;
[0010] Based on the character object, a target text corresponding to the target interface is generated, and the target text is used to instruct the application program to call the target interface.
[0011] In an exemplary embodiment, determining the interface attribute information corresponding to the target interface based on the annotation text includes:
[0012] Extracting interface address information, request method information, interface request information, and interface response information corresponding to the target interface from the interface attribute information; wherein the interface attribute information includes the interface address information, the request method information, the interface request information, and the interface response information;
[0013] The character object processing of the interface attribute information to obtain the character object corresponding to the target interface includes:
[0014] The interface address information, the request method information, the interface request information and the interface response information are subjected to the character object processing to obtain a character object corresponding to the target interface.
[0015] In an exemplary embodiment, the character object includes at least one type of object attribute information, and the at least one type of object attribute information is used to characterize the interface attribute information. The step of generating a target text corresponding to the target interface based on the character object includes:
[0016] Performing a first recursive operation on the character object to obtain data type information corresponding to the at least one object attribute information;
[0017] The target text is generated based on the at least one object attribute information and the data type information.
[0018] In an exemplary embodiment, the method further comprises:
[0019] Get operating environment parameter information;
[0020] Determine the target file type according to the operating environment parameter information;
[0021] The generating the target text based on the at least one object attribute information and the data type information includes:
[0022] A second recursive operation is performed on the at least one object attribute information and the data type information to generate a target text corresponding to the target file type.
[0023] In an exemplary embodiment, the method further comprises:
[0024] Based on the data type information, simulated resource data corresponding to the target interface is generated, the data type of the simulated resource data matches the data type information, and the simulated resource data is used to replace the actual resource data corresponding to the target interface for interface testing.
[0025] In an exemplary embodiment, the method further comprises:
[0026] Based on the target text, sending an interface service request for the target interface;
[0027] Intercepting the interface service request;
[0028] If the destination address corresponding to the interface service request matches the interface address information, first response information associated with the target interface is generated based on the simulation resource data, where the first response information is response information generated based on the simulation resource data.
[0029] In an exemplary embodiment, the method further comprises:
[0030] Based on the target text, sending an interface service request to a server corresponding to the target interface;
[0031] Second response information sent by the server is received, where the second response information is response information generated based on actual resource data corresponding to the target interface.
[0032] In an exemplary embodiment, obtaining the annotation text corresponding to the target interface includes:
[0033] Get the target document;
[0034] Obtain a target regular expression, where the target regular expression is used to characterize annotation text features corresponding to the target interface;
[0035] Character matching processing is performed on the target document based on the target regular expression to obtain the annotation text in the target document that matches the target regular expression.
[0036] According to a second aspect of an embodiment of the present disclosure, there is provided a text generation device, comprising:
[0037] An annotation text acquisition module is configured to execute and acquire the annotation text corresponding to the target interface;
[0038] An interface attribute determination module is configured to determine interface attribute information corresponding to the target interface based on the annotation text;
[0039] A character object generation module is configured to perform character object processing on the interface attribute information to obtain a character object corresponding to the target interface;
[0040] The target text generation module is configured to generate a target text corresponding to the target interface based on the character object, wherein the target text is used to instruct the application to call the target interface.
[0041] In an exemplary embodiment, the interface attribute determination module includes:
[0042] an attribute information extraction unit, configured to extract interface address information, request method information, interface request information, and interface response information corresponding to the target interface from the interface attribute information; wherein the interface attribute information includes the interface address information, the request method information, the interface request information, and the interface response information;
[0043] The character object generation module is specifically configured to perform the character object processing on the interface address information, the request method information, the interface request information and the interface response information to obtain the character object corresponding to the target interface.
[0044] In an exemplary embodiment, the character object includes at least one object attribute information, and the at least one object attribute information is used to characterize the interface attribute information. The target text generation module includes:
[0045] A data type determination unit is configured to perform a first recursive operation on the character object to obtain data type information corresponding to the at least one object attribute information;
[0046] The target text generating unit is configured to generate the target text based on the at least one object attribute information and the data type information.
[0047] In an exemplary embodiment, the apparatus further comprises:
[0048] An environment parameter acquisition module is configured to execute and acquire operating environment parameter information;
[0049] A file type determination module is configured to determine the target file type according to the operating environment parameter information;
[0050] The target text generation unit is specifically configured to perform a second recursive operation on the at least one object attribute information and the data type information to generate a target text corresponding to the target file type.
[0051] In an exemplary embodiment, the apparatus further comprises:
[0052] The simulation data generation module is configured to generate simulation resource data corresponding to the target interface based on the data type information, the data type of the simulation resource data matches the data type information, and the simulation resource data is used to replace the actual resource data corresponding to the target interface for interface testing.
[0053] In an exemplary embodiment, the apparatus further comprises:
[0054] An interface request sending module, configured to execute, based on the target text, sending an interface service request for the target interface;
[0055] An interface request interception module, configured to intercept the interface service request;
[0056] The first response information generation module is configured to generate first response information associated with the target interface based on the simulation resource data if the destination address corresponding to the interface service request matches the interface address information, and the first response information is response information generated based on the simulation resource data.
[0057] In an exemplary embodiment, the apparatus further comprises:
[0058] An interface request sending module is configured to send an interface service request to a server corresponding to the target interface based on the target text;
[0059] The second response information generating module is configured to receive second response information sent by the server, where the second response information is response information generated based on actual resource data corresponding to the target interface.
[0060] In an exemplary embodiment, the annotation text acquisition module includes:
[0061] A target document acquisition module is configured to execute acquisition of a target document;
[0062] A regular expression acquisition module is configured to execute and acquire a target regular expression, wherein the target regular expression is used to characterize the annotation text feature corresponding to the target interface;
[0063] The annotation text matching module is configured to perform character matching processing on the target document based on the target regular expression to obtain the annotation text in the target document that matches the target regular expression.
[0064] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement a method as described in any one of the above-mentioned first aspects.
[0065] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute any method described in the first aspect of the embodiment of the present disclosure.
[0066] According to a fifth aspect of an embodiment of the present disclosure, there is provided a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the methods described in the first aspect of the embodiment of the present disclosure.
[0067] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:
[0068] By obtaining the annotation text corresponding to the target interface, the interface attribute information corresponding to the target interface can be determined from the annotation text. By character objectification of the interface attribute information, a character object can be obtained. Based on the character object, a target text that can instruct the application to call the target interface can be automatically generated. There is no need to manually write program code to connect the front and back ends of the application, which effectively reduces the cost of application development, shortens the time spent on application development, improves the degree of automation of application development, and improves the overall efficiency of application development.
[0069] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0071] Figure 1 It is a schematic diagram of an application environment according to an exemplary embodiment.
[0072] Figure 2 A text generation method according to an exemplary embodiment is shown in FIG. Figure 1 ;
[0073] Figure 3 A text generation method according to an exemplary embodiment is shown in FIG. Figure 2 ;
[0074] Figure 4 A schematic diagram of an annotation text is exemplarily shown;
[0075] Figure 5 A text generation method according to an exemplary embodiment is shown in FIG. Figure 3 ;
[0076] Figure 6 A schematic diagram of a target text is exemplarily shown;
[0077] Figure 7 A schematic diagram of simulating resource data is exemplarily shown;
[0078] Figure 8An example of an editor executing a target code is shown. Figure 1 ;
[0079] Fig. 9 An example of an editor executing a target code is shown. Figure 2 ;
[0080] Fig.10 is a block diagram of a text generation device according to an exemplary embodiment;
[0081] Fig.11 It is a block diagram of an electronic device for text generation according to an exemplary embodiment. DETAILED DESCRIPTION
[0082] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0083] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0084] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.
[0085] See also Figure 1 , Figure 1 is a schematic diagram of an application environment according to an exemplary embodiment. Figure 1 As shown, the application environment may include a terminal 100 and a server 200 .
[0086] The terminal 100 can be used to provide a list data display service to any user. Specifically, the terminal 100 may include but is not limited to a smart phone, a desktop computer, a tablet computer, a laptop computer, a smart speaker, a digital assistant, an augmented reality (AR) / virtual reality (VR) device, a smart wearable device and other electronic devices, and may also be software running on the above electronic devices, such as an application program. Optionally, the operating system running on the electronic device may include but is not limited to Android, IOS, Linux, Windows, etc.
[0087] In an optional embodiment, the server 200 may provide background services for the terminal 100. Specifically, the server 200 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server.
[0088] In addition, it should be noted that Figure 1 What is shown is only one application environment provided by the present disclosure. In actual application, other application environments may also be included, for example, more terminals may be included.
[0089] In the embodiments of this specification, the terminal 100 and the server 200 may be directly or indirectly connected via wired or wireless communication, which is not limited in this disclosure.
[0090] Figure 2 A text generation method according to an exemplary embodiment is shown in FIG. Figure 1 ,like Figure 2 As shown, the text generation method is used in a terminal electronic device and includes the following steps (201-204).
[0091] Step 201, obtaining the annotation text corresponding to the target interface.
[0092] The comment text is used to represent the interface information of the target interface and to provide corresponding explanations for the target interface. Program developers can learn relevant information about the target interface based on the comment text.
[0093] The above target interface is the backend interface corresponding to the application, which is used to connect to the frontend page corresponding to the application. The frontend page can call the backend data or perform corresponding operations on the backend data through the above backend interface.
[0094] An interface is a declaration of a series of abstract methods and a collection of method features. These methods should be abstract and need to be implemented by specific classes. Then a third party can call this set of abstract methods to let specific classes execute specific methods.
[0095] In an exemplary embodiment, if Figure 3 As shown, the implementation process of the above step 201 includes the following steps (2011-2013): Figure 3 A text generation method according to an exemplary embodiment is shown in FIG. Figure 2 .
[0096] Step 2011, obtaining the target document.
[0097] The target document includes the annotation text. Optionally, the target document includes but is not limited to text documents such as interface description documents and code documents corresponding to the target interface.
[0098] Step 2012, obtaining a target regular expression.
[0099] Regular Expression is a powerful tool that can be used for pattern matching and replacement. It is a text matching pattern composed of a series of common characters and special characters that can clearly describe text characters.
[0100] The target regular expression is used to characterize the annotation text features corresponding to the target interface. A regular expression is a search pattern formed by a character sequence, that is, when a user searches for data in a text, the search pattern can be used to describe the content that the user wants to query. Regular expressions can be used for all text search and text replacement operations.
[0101] Obtaining the above target regular expression and the above target document can achieve the following purposes. Test a certain pattern of the target document. For example, you can test the string in the target document to see if the string has a preset pattern, which is also called data validity verification. Replace text. You can use regular expressions to identify specific text in the document, and then search for all of it or replace it with other text. Find text. You can use regular expressions to obtain the specific part that the user wants from the target document.
[0102] Optionally, the target regular expression is a regular expression corresponding to the comment format. Optionally, the regular expression is a JavaScript regular expression.
[0103] Step 2013: Perform character matching processing on the target document based on the target regular expression to obtain the annotation text in the target document that matches the target regular expression.
[0104] In an embodiment of the present application, the target regular expression can be used to perform character matching processing on the text content in the target document to find the comment text in the target document that matches the target regular expression, such as the comment text that conforms to the comment format.
[0105] Optionally, the above comment text is a comment code.
[0106] By performing string matching on the target document using the regular expression, the comment code related to the backend interface in the document can be automatically, quickly and accurately identified without the need for manual search and review of the comment code, thus reducing application development costs.
[0107] Step 202: Determine interface attribute information corresponding to the target interface based on the annotation text.
[0108] The above-mentioned annotation text can represent the relevant information of the target interface. Therefore, after obtaining the content characters in the above-mentioned annotation text, the interface attribute information corresponding to the target interface can be determined therefrom, such as interface identifier (URL), request method (method), request data (request), response data (response) and other attribute information. The embodiments of the present application do not limit this.
[0109] In an exemplary embodiment, if Figure 3 As shown, the above step 202 can be replaced by the following step 2021.
[0110] Step 2021, extracting interface address information, request method information, interface request information, and interface response information corresponding to the target interface from the interface attribute information.
[0111] The interface attribute information includes interface address information, request method information, interface request information and interface response information.
[0112] In an exemplary embodiment, the above interface address information is used to represent the resource address corresponding to the target interface. Optionally, the interface address information is a URL address corresponding to the target interface.
[0113] In an exemplary embodiment, the request method information is used to characterize the request method corresponding to the target interface, including but not limited to GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE, CONNECT and other methods.
[0114] Among them, the GET method is used to request the specified page information and return the entity body; the HEAD method is similar to the GET request, except that the returned response does not have specific content and is used to obtain the header; the POST method is used to submit data to the specified resource for processing the request (such as submitting a form or uploading a file), and the data is included in the request body. POST requests may lead to the creation of new resources and / or the modification of existing resources; the PUT method is used to replace the content of the specified document with data transmitted from the client to the server; the DELETE method is used to request the server to delete the specified page; the CONNECT method is used in the HTTP / 1.1 protocol for proxy servers that can change the connection to a pipeline mode; the OPTIONS method allows the client to view the performance of the server; the TRACE method is used to echo the request received by the server, mainly for testing or diagnosis; the PATCH method is a supplement to the PUT method and is used to partially update known resources.
[0115] In an exemplary embodiment, the above interface request information is used to represent the request data information, such as data attributes, values, data formats, etc. of the request data sent to the target interface.
[0116] In an exemplary embodiment, the above interface response information is used to represent the response result returned by the target interface, such as response data and data operation information returned by the target interface.
[0117] In one example, if Figure 4 As shown, it exemplarily shows a schematic diagram of an annotation text. Figure 4 The first to the eighteenth lines of the editor interface 40 shown show a section of annotation text corresponding to the backend interface. Among them, " / / @ac-method-ur1; post / demo / url" indicates that the request method information corresponding to the backend interface is the post method, and the interface address information corresponding to the backend interface is demo / url; "@ac-request; {"demo":"123"}" indicates that the interface request information corresponding to the backend interface is {"demo":"123"}; "@ac-response{"data":{"demo":[{'test":"123"}]},"result":"1","message":"success"}" indicates that the interface response information corresponding to the backend interface is {"data":{"demo":[{'test":"123"}]},"result":"1","message":"success"}.
[0118] Step 203: convert the interface attribute information into character objects to obtain a character object corresponding to the target interface.
[0119] The character object is an operable object, and the character objectification process is used to convert the interface attribute information into a character object operable by the editor. Optionally, the character object is a JavaScript object.
[0120] In object-oriented programming languages, such as JavaScript, an object is a collection of properties and methods. A property consists of a property name and a value, which can be any type of data or a function. In this case, the function is also called a method. Methods are used to define how an object behaves.
[0121] In a possible implementation, the objectification process is implemented by using the JSON.parse method in JavaScript JSON (JavaScript Object Notation, a lightweight data exchange format based on the JavaScript programming language), and the interface attribute information in the form of a character sequence is restored to an operable JavaScript object, that is, object deserialization. Among them, JSON is mainly used for data exchange with the server, and the JSON.parse method is used to convert a JSON character sequence into an object.
[0122] In an exemplary embodiment, the character object includes at least one kind of object attribute information, and the at least one kind of object attribute information is used to represent the interface attribute information.
[0123] In an exemplary embodiment, after executing the above step 2021, as Figure 3 As shown, the above step 203 can be replaced by the following step 2031.
[0124] Step 2031, performing character object processing on the interface address information, request method information, interface request information and interface response information to obtain a character object corresponding to the target interface.
[0125] The above-mentioned interface address information, request method information, interface request information and interface response information can be converted into object attribute information in a character object. Optionally, at least one object attribute information includes address attribute information, request method attribute information, request data attribute information and interface response attribute information, which correspond to the above-mentioned interface address information, request method information, interface request information and interface response information respectively.
[0126] By obtaining the interface address information, request method information, interface request information and interface response information of the target interface and objectifying them, it is possible to automatically generate operable objects that can represent the various properties of the target interface without the need for manual writing of character objects. This can reduce application development costs, shorten application development time and improve application development efficiency.
[0127] Step 204: Generate target text corresponding to the target interface based on the character object.
[0128] The target text is used to instruct the application to call the target interface. In an exemplary embodiment, the target text is a program code for calling the target interface.
[0129] The target text includes JavaScript interface call code and typeScript interface call code. TypeScript is a superset of JavaScript that supports the ECMAScript 6 standard and can be compiled into pure JavaScript. The compiled JavaScript can run on any browser.
[0130] In an exemplary embodiment, the character object includes at least one kind of object attribute information, and the at least one kind of object attribute information is used to represent the interface attribute information.
[0131] In an exemplary embodiment, according to the file types in different program development environments, code generation operations corresponding to different file types can be performed to generate the above-mentioned target text. Figure 5 As shown, the above method also includes the following steps (205-206) to determine the file type in the program development environment, Figure 5 A text generation method according to an exemplary embodiment is shown in FIG. Figure 3 .
[0132] Step 205, obtaining operating environment parameter information.
[0133] In an exemplary embodiment, the above operating environment parameter information can be obtained according to Electron. The above operating environment parameter information is used to characterize the current program development environment.
[0134] Among them, Electron is a runtime environment library. Based on Electron, desktop applications can be written in front-end programming languages. The runtime environment parameter information includes environment variables, which generally refer to some parameters used in the operating system to specify the operating environment of the operating system.
[0135] Step 206: Determine the target file type according to the operating environment parameter information.
[0136] Provide Electron environment variables, including file type parameters, to determine the current file type. The file type that matches the current program development environment is the target file type, that is, the current file type.
[0137] In the case where the target file type involved in the program development environment is of TypeScript type, such as Figure 3 As shown, the implementation process of the above step 204 includes the following steps (2041-2042).
[0138] Step 2041, performing a first recursive operation on the character object to obtain data type information corresponding to at least one object attribute information.
[0139] The process of the first recursive operation includes traversing each item of character attribute information in the character object to determine the data type corresponding to each object attribute information, and generating an object type text corresponding to the character object. The object type text can represent at least one of the above object attribute information and data type information.
[0140] Optionally, each character field in the character object may represent the above object attribute information, and correspondingly, the data type information is used to represent the data type corresponding to the character field.
[0141] Step 2042, generating a target text based on at least one object attribute information and data type information.
[0142] In the process of generating TypeScript type target text, the data type corresponding to the object attribute information can be determined by recursive operations on character objects, so that TypeScript type target text can be generated based on the object attribute information and data type information, achieving the goal of automatically generating interface call code in the TypeScript environment and ensuring the correctness of the target text.
[0143] In an exemplary embodiment, if Figure 5 As shown, the implementation process of the above step 2042 includes the following step 2042a.
[0144] Step 2042a, performing a second recursive operation on at least one object attribute information and data type information to generate a target text corresponding to the target file type.
[0145] The second recursive operation process includes traversing the character fields representing the character attribute information in the object type text, and being able to obtain and determine the data type corresponding to each character field, so that the target text can be generated according to the data type.
[0146] Since the object type text can represent at least one object attribute information and data type information, the target text can be obtained by adding the character field associated with the target text template in the object type text to the corresponding position in the target text template according to the data type corresponding to the character field. The target text template is a text template that matches the interface attribute information of the target interface.
[0147] By determining the file type corresponding to the current application development environment, an interface calling code matching the current file type can be generated to ensure the correctness of the generated code, and to enrich the application scenarios of the technical solution disclosed herein, and to generate corresponding interface calling codes in different environments.
[0148] In one example, if Figure 6 As shown, it exemplarily shows a schematic diagram of a target text. Figure 6 The 33rd to 35th lines of the editor interface 60 shown display a section of interface call code for calling the backend interface, i.e., the above-mentioned target text. The 20th to 32nd lines of the interface 60 display the type object text that can characterize the data types corresponding to the attribute information in the character object. Among them, "interface fetchDemoUrlParam{demo:string;}" indicates that the data type of the attribute field "demo" in the interface request information of the backend interface (interface) named fetchDemoUrlParam is a string type (string); "interface fetchDemoUrlRes{data:demo:{test:string}[];};result:string;message:string;}" indicates that the data type of the attribute field "demo" in the interface response information corresponding to the interface (interface) named fetchDemoUrlRes is an array type ("[]" indicates an array), the data types of the attribute field "result" and the attribute field "message" are both string types (string), and the data type of the array attribute field "test" included in the "demo" array is a string type (string).
[0149] The above interface call code can be automatically generated according to the above type object text. For example, in the code on line 33, "export function fetchDemoUrl(param:fetchDemoUrlParam):Promise<fetchDemoUrlRes>", "fetchDemoUrl", "fetchDemoUrlParam", and "fetchDemoUrlRes" are all automatically filled into the preset code template by identifying the above type object text, and the rest of the content is from the preset code template. The same is true for the code on line 34. In "return request.post(' / demo / url', param);", "post()" is the method field determined according to the post method corresponding to the request method information of the target interface, " / demo / url'" is the automatically filled request address corresponding to the target interface, and the rest of the content is the code template content.
[0150] In addition, the "export" statement in the target code is used to export functions, objects, or primitive values with live bindings from a module so that other programs can use them through the import statement. The exported bound values can still be modified locally. When using import for import, these bound values can only be read by the importing module, but if the bound values are modified in the export module, the modified values will also be updated in real time. "Promise" is a solution for asynchronous operations, which is more reasonable than traditional processing methods (callback functions / handling events). ES6 incorporated it into the language standard, unified the syntax, and provided Promise natively. A Promise can be imagined as a container containing various results, with the result returned by a certain event inside, and you can take it and perform some event processing when needed.
[0151] In another possible implementation, based on the above character object, obtain the target text template corresponding to the target interface; add the object attribute information (such as character fields) in the character object associated with the target text template to the corresponding positions in the above target text template to obtain the above target text. The above target text template is a text template that matches the interface attribute information of the target interface.
[0152] Optionally, when the file type corresponding to the target text is of the JavaScript type, the above process can be executed, and the above target text can be directly generated according to the character object. Specifically, the current file type can be obtained according to the environment variables provided by Electron, and the above environment variables include file type parameters. If the current file type is of the JavaScript type, the target text corresponding to the target interface can be generated based on the character object.
[0153] Optionally, after generating the above-mentioned operable character object, the interface call code template (i.e., the above-mentioned target text template) applicable to the target interface can be determined based on the interface attribute information corresponding to the interface, such as the URL address, request method, request information, and response information involved in the target interface, and then the fields related to the interface call code template in the character object are filled into the interface call code template to generate the interface call code corresponding to the above-mentioned target interface.
[0154] In an exemplary embodiment, the target text can be executed to implement interactive operations with the target interface, thereby connecting the front and back ends of the application. The specific process includes: based on the target text, an interface service request is sent to the server corresponding to the target interface; after the server interface service request, according to the request information and request method in the interface service request, corresponding operations are performed on the actual resource data corresponding to the target interface in the service, and a second response information is generated and sent to the terminal; the terminal receives the second response information sent by the server, and the second response information is response information generated based on the actual resource data corresponding to the target interface.
[0155] By executing the above automatically generated target text to make an interface call, the front-end request and the back-end response can be achieved, thereby improving the efficiency of application development.
[0156] In some application scenarios, the front-end and back-end of the application are decoupled and developed simultaneously. The target interface only has relevant docking specifications, but does not support calls. In the case that the target interface does not support calls, an interface proxy service can be established to use virtual interface resource data to simulate the service process provided by the interface to implement the test of the target text. Therefore, Figure 5 As shown, the above method also includes the following step 207.
[0157] Step 207: Generate simulation resource data corresponding to the target interface based on the data type information.
[0158] The data type of the simulated resource data matches the data type information, and the simulated resource data is used to replace the actual resource data corresponding to the target interface for interface testing. The above-mentioned simulated resource data can be randomly generated data that conforms to the data type. The above-mentioned simulated resource data corresponds to each character field in the above-mentioned character object and can be used as specific attribute data corresponding to each character field.
[0159] In one example, if Figure 7 As shown, it exemplarily shows a schematic diagram of simulating resource data. Figure 7 The proxy service page 70 shown shows the simulated resource data generated according to the data type of the relevant attribute field. Figure 6In the example, the data type of the array attribute field "text" is a string, and the field data corresponding to the array attribute field "text" is response data. Therefore, when the relevant interface is not developed, or when the local device is not connected to the server corresponding to the relevant interface, simulated resource data that conforms to the string type can be randomly generated for the array attribute field "text", so that the simulated resource data can be used instead of the actual resource data for interface testing.
[0160] The simulated field data corresponding to the array attribute field "text" is displayed in the proxy service page 70. For example, the simulated field data corresponding to "text" is "SYYH3HIZIFNY7CNZHG9F0ZP57NGQ3NLRYKS" and other data. After the interface proxy service detects the request for the relevant interface, it can generate response information based on the simulated resource data and return it to the requester, thereby simulating the actual process of calling the relevant interface, and judging whether the automatically generated interface call code is available based on the result.
[0161] Generating the above-mentioned simulation resource data according to the above-mentioned data types can ensure the accuracy and authenticity of the simulation resource data, thereby ensuring the reliability of the interface proxy service.
[0162] In an exemplary embodiment, the interface proxy service can be built based on the simulated resource data. Optionally, an http service is created through node. When a user requests a corresponding interface, the interface proxy service intercepts the request and matches the requested URL with the URL previously obtained from the annotation text. If the match is successful, randomly generated data is returned. If there is no match, the remote service is accessed. Therefore, Figure 5 As shown, the above method also includes the following steps (208-210).
[0163] Step 208: Send an interface service request for the target interface based on the target text.
[0164] Step 209: intercept the interface service request.
[0165] The interface service request is intercepted by the interface proxy service. The interface proxy service is a local service.
[0166] In one example, if Figure 8 As shown, it exemplarily shows a schematic diagram of an editor executing a target code Figure 1 . Figure 8 In the editor interface 80 shown, an execution status prompt box 81 is displayed. Figure 8The content displayed in the execution status prompt box 81 is "sernice has been started om port 3000", indicating that the above interface call code has been executed and the interface call service has been started on port 3000.
[0167] Step 210: If the destination address corresponding to the interface service request matches the interface address information, first response information associated with the target interface is generated based on the simulated resource data.
[0168] The first response information is response information generated based on the simulated resource data. The simulated resource data is a resource number stored locally, which is used to implement the above interface proxy service and provide data source support for the local interface proxy service.
[0169] In one example, if Fig. 9 As shown, it exemplarily shows a schematic diagram of an editor executing a target code Figure 2 . Fig. 9 The content displayed in the execution status prompt box 81 is updated to "stop server successfuled", indicating that by executing the above interface call code, the response information has been successfully obtained and the service has been stopped.
[0170] By intercepting the interface service request sent by the front end and providing simulated interface services in actual applications based on the simulated resource data stored locally, virtual response information can be returned, so that the target code can be tested locally. There is no need to wait for the target interface service to be built before an interactive test can be performed, which reduces application development and testing costs and improves the flexibility of application development and testing.
[0171] Alternatively, if Figure 5 As shown, after the above step 210, the following steps (211-212) are also included.
[0172] Step 211: If the destination address corresponding to the interface service request does not match the interface address information, continue to send the interface service request to the server corresponding to the target interface.
[0173] Step 212: Receive second response information sent by the server.
[0174] The second response information is response information generated based on actual resource data corresponding to the target interface.
[0175] To sum up, the technical solution provided by the present invention can determine the interface attribute information corresponding to the target interface from the annotation text by obtaining the annotation text corresponding to the target interface, and can obtain the character object by character objectification of the interface attribute information. Based on the character object, the target text that can instruct the application to call the target interface can be automatically generated. There is no need to manually write program code for connecting the front and back ends of the application, which effectively reduces the cost of application development, shortens the time spent on application development, improves the degree of automation of application development, and improves the overall efficiency of application development.
[0176] The front-end and back-end development scenario of an application is a typical application scenario of the technical solution provided by the present disclosure. By applying the technical solution provided by the present disclosure in the front-end and back-end development scenario of an application, the time spent by the front-end technical personnel in docking with the back-end interface can be greatly reduced, and the uniformity and correctness of the interface code output can be greatly improved. After the front-end technical personnel have reduced this part of the time, they have more energy to focus on the front-end page interaction process, which indirectly reduces the number of vulnerabilities and improves the quality of the front-end and back-end handover. In short, using less time to complete the front-end and back-end docking means more time to solve other technical problems, improve the overall application development efficiency, and reduce the application development cost.
[0177] Fig.10 is a block diagram of a text generation device according to an exemplary embodiment. Fig.10 The device 1000 includes: an annotation text acquisition module 1001, an interface attribute determination module 1002, a character object generation module 1003, and a target text generation module 1004.
[0178] An annotation text acquisition module 1001 is configured to execute acquisition of annotation text corresponding to a target interface;
[0179] The interface attribute determination module 1002 is configured to determine the interface attribute information corresponding to the target interface based on the annotation text;
[0180] The character object generation module 1003 is configured to perform character object processing on the interface attribute information to obtain a character object corresponding to the target interface;
[0181] The target text generation module 1004 is configured to generate a target text corresponding to the target interface based on the character object, wherein the target text is used to instruct the application to call the target interface.
[0182] In an exemplary embodiment, the interface attribute determination module 1002 includes:
[0183] an attribute information extraction unit, configured to extract interface address information, request method information, interface request information, and interface response information corresponding to the target interface from the interface attribute information; wherein the interface attribute information includes the interface address information, the request method information, the interface request information, and the interface response information;
[0184] The character object generation module 1003 is specifically configured to perform the character object processing on the interface address information, the request method information, the interface request information and the interface response information to obtain the character object corresponding to the target interface.
[0185] In an exemplary embodiment, the character object includes at least one object attribute information, and the at least one object attribute information is used to characterize the interface attribute information. The target text generation module 1004 includes:
[0186] A data type determination unit is configured to perform a first recursive operation on the character object to obtain data type information corresponding to the at least one object attribute information;
[0187] The target text generating unit is configured to generate the target text based on the at least one object attribute information and the data type information.
[0188] In an exemplary embodiment, the apparatus 1000 further includes:
[0189] An environment parameter acquisition module is configured to execute and acquire operating environment parameter information;
[0190] A file type determination module is configured to determine the target file type according to the operating environment parameter information;
[0191] The target text generation unit is specifically configured to perform a second recursive operation on the at least one object attribute information and the data type information to generate a target text corresponding to the target file type.
[0192] In an exemplary embodiment, the apparatus 1000 further includes:
[0193] The simulation data generation module is configured to generate simulation resource data corresponding to the target interface based on the data type information, the data type of the simulation resource data matches the data type information, and the simulation resource data is used to replace the actual resource data corresponding to the target interface for interface testing.
[0194] In an exemplary embodiment, the apparatus 1000 further includes:
[0195] An interface request sending module, configured to execute, based on the target text, sending an interface service request for the target interface;
[0196] An interface request interception module, configured to intercept the interface service request;
[0197] The first response information generation module is configured to generate first response information associated with the target interface based on the simulation resource data if the destination address corresponding to the interface service request matches the interface address information, and the first response information is response information generated based on the simulation resource data.
[0198] In an exemplary embodiment, the apparatus 1000 further includes:
[0199] An interface request sending module is configured to send an interface service request to a server corresponding to the target interface based on the target text;
[0200] The second response information generating module is configured to receive second response information sent by the server, where the second response information is response information generated based on actual resource data corresponding to the target interface.
[0201] In an exemplary embodiment, the annotation text acquisition module 1001 includes:
[0202] A target document acquisition module is configured to execute acquisition of a target document;
[0203] A regular expression acquisition module is configured to execute and acquire a target regular expression, wherein the target regular expression is used to characterize the annotation text feature corresponding to the target interface;
[0204] The annotation text matching module is configured to perform character matching processing on the target document based on the target regular expression to obtain the annotation text in the target document that matches the target regular expression.
[0205] To sum up, the technical solution provided by the present invention can determine the interface attribute information corresponding to the target interface from the annotation text by obtaining the annotation text corresponding to the target interface, and can obtain the character object by character objectification of the interface attribute information. Based on the character object, the target text that can instruct the application to call the target interface can be automatically generated. There is no need to manually write program code for connecting the front and back ends of the application, which effectively reduces the cost of application development, shortens the time spent on application development, improves the degree of automation of application development, and improves the overall efficiency of application development.
[0206] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0207] Fig.11 is a block diagram of an electronic device for text generation according to an exemplary embodiment. The electronic device may be a terminal, and its internal structure diagram may be as shown in FIG. Fig.11 As shown. The electronic device includes a processor, a memory, a network interface, a display screen and an input device connected via a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a text generation method is implemented. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covering the display screen, or a key, trackball or touchpad provided on the housing of the electronic device, or an external keyboard, touchpad or mouse, etc.
[0208] Those skilled in the art will understand that Fig.11 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present disclosure, and does not constitute a limitation on the electronic device to which the scheme of the present disclosure is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0209] In an exemplary embodiment, an electronic device is also provided, including: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the text generation method as in the embodiment of the present disclosure.
[0210] In an exemplary embodiment, a computer-readable storage medium is also provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the text generation method in the embodiment of the present disclosure.
[0211] In an exemplary embodiment, a computer program product including instructions is also provided. When the computer program product is run on a computer, the computer is enabled to execute the text generation method in the embodiment of the present disclosure.
[0212] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0213] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0214] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A text generation method, characterized in that: The method comprises: Get the comment text corresponding to the target interface; Based on the annotation text, determining interface attribute information corresponding to the target interface; Extracting interface address information, request method information, interface request information, and interface response information corresponding to the target interface from the interface attribute information; wherein the interface attribute information includes the interface address information, the request method information, the interface request information, and the interface response information; Performing character object processing on the interface address information, the request method information, the interface request information, and the interface response information to obtain a character object corresponding to the target interface, wherein the character object includes at least one type of object attribute information, and the at least one type of object attribute information is used to represent the interface attribute information; Get operating environment parameter information; Determine the target file type according to the operating environment parameter information; Based on the character object, a target text corresponding to the target interface is generated, and the target text is used to instruct the application to call the target interface; based on the character object, the target text corresponding to the target interface is generated, including: performing a first recursive operation on the character object to obtain data type information corresponding to the at least one object attribute information; performing a second recursive operation on the at least one object attribute information and the data type information to generate a target text corresponding to the target file type.
2. The method according to claim 1, characterized in that The method further comprises: Based on the data type information, simulated resource data corresponding to the target interface is generated, the data type of the simulated resource data matches the data type information, and the simulated resource data is used to replace the actual resource data corresponding to the target interface for interface testing.
3. The method according to claim 2, characterized in that The method further comprises: Based on the target text, sending an interface service request for the target interface; intercepting the interface service request; If the destination address corresponding to the interface service request matches the interface address information, first response information associated with the target interface is generated based on the simulation resource data, where the first response information is response information generated based on the simulation resource data.
4. The method according to claim 1, characterized in that The method further comprises: Based on the target text, sending an interface service request to a server corresponding to the target interface; Second response information sent by the server is received, where the second response information is response information generated based on actual resource data corresponding to the target interface.
5. The method according to any one of claims 1 to 4, characterized in that: The obtaining of the annotation text corresponding to the target interface includes: Get the target document; Obtain a target regular expression, where the target regular expression is used to characterize annotation text features corresponding to the target interface; Character matching processing is performed on the target document based on the target regular expression to obtain the annotation text in the target document that matches the target regular expression.
6. A text generation device, characterized in that: The device comprises: An annotation text acquisition module is configured to execute and acquire the annotation text corresponding to the target interface; An interface attribute determination module is configured to determine interface attribute information corresponding to the target interface based on the annotation text; The interface attribute determination module comprises: an attribute information extraction unit; the attribute information extraction unit is configured to extract interface address information, request method information, interface request information and interface response information corresponding to the target interface from the interface attribute information; wherein the interface attribute information comprises the interface address information, the request method information, the interface request information and the interface response information; a character object generation module, configured to perform character object processing on the interface address information, the request method information, the interface request information, and the interface response information to obtain a character object corresponding to the target interface, wherein the character object includes at least one object attribute information, and the at least one object attribute information is used to represent the interface attribute information; An environment parameter acquisition module is configured to execute and acquire operating environment parameter information; A file type determination module is configured to determine the target file type according to the operating environment parameter information; The target text generation module is configured to generate a target text corresponding to the target interface based on the character object, wherein the target text is used to instruct the application to call the target interface; the target text corresponding to the target interface based on the character object comprises: performing a first recursive operation on the character object to obtain data type information corresponding to the at least one object attribute information; performing a second recursive operation on the at least one object attribute information and the data type information to generate a target text corresponding to the target file type.
7. The device according to claim 6, characterized in that The device also includes: The simulation data generation module is configured to generate simulation resource data corresponding to the target interface based on the data type information, the data type of the simulation resource data matches the data type information, and the simulation resource data is used to replace the actual resource data corresponding to the target interface for interface testing.
8. The device according to claim 7, characterized in that The device also includes: An interface request sending module, configured to execute, based on the target text, sending an interface service request for the target interface; An interface request interception module, configured to intercept the interface service request; The first response information generation module is configured to generate first response information associated with the target interface based on the simulation resource data if the destination address corresponding to the interface service request matches the interface address information, and the first response information is response information generated based on the simulation resource data.
9. The device according to claim 6, characterized in that The device also includes: An interface request sending module is configured to send an interface service request to a server corresponding to the target interface based on the target text; The second response information generating module is configured to receive second response information sent by the server, where the second response information is response information generated based on actual resource data corresponding to the target interface.
10. The device according to any one of claims 6 to 9, characterized in that The annotation text acquisition module includes: A target document acquisition module is configured to execute acquisition of a target document; A regular expression acquisition module is configured to execute and acquire a target regular expression, wherein the target regular expression is used to characterize the annotation text feature corresponding to the target interface; The annotation text matching module is configured to perform character matching processing on the target document based on the target regular expression to obtain the annotation text in the target document that matches the target regular expression.
11. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the text generation method as described in any one of claims 1 to 5.
12. A computer-readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the text generation method as claimed in any one of claims 1 to 5.
13. A computer program product comprising computer instructions, characterized in that: When the computer instructions are executed by a processor, the text generation method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Interface document generation method and device and interface management equipment
CN113419738A
API-based software development platform
US20210216288A1