A code generation method, apparatus, device, and medium

By using tools to parse and generate interface configuration files, the problem of low efficiency in traditional interface development is solved, achieving efficient and unified code generation and maintenance, and ensuring consistency between front-end and back-end interfaces.

CN115599359BActive Publication Date: 2026-04-14CHINA CONSTRUCTION BANK +1
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-28
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Traditional interface development solutions suffer from low development efficiency and difficult code maintenance, especially due to repetitive operations and differences in writing styles among different developers, which make the code difficult to maintain.

Method used

By calling a code generation tool to parse the configuration file of the interface to be developed, the fields and logical relationships are obtained, and target files and test files are generated. A unified code generation tool is used to improve development efficiency and unify code style.

Benefits of technology

It improves interface development efficiency, reduces labor costs and code error rate, ensures consistent code style, facilitates subsequent maintenance, and enables joint debugging of front-end and back-end interfaces through standardized configuration file format.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115599359B_ABST
    Figure CN115599359B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of interface development, in particular to a code generation method and device, equipment and medium, which are used for solving the problems of low development efficiency and difficult code maintenance of a traditional interface development scheme. The method comprises the following steps: in response to a code generation operation for a first control, calling a code generation tool corresponding to the first control, parsing a configuration file of a to-be-developed interface to obtain various fields contained in the configuration file and logical relationships between the various fields; and then generating a target file and a test file corresponding to the to-be-developed interface based on the various fields and the logical relationships between the various fields, wherein the target file comprises at least one of the configuration file and an application file of the to-be-developed interface. In this way, the development efficiency can be improved, the labor cost can be reduced, the front-end and back-end interface can be debugged in advance, the code format is consistent, and the code maintenance is facilitated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of interface development technology, specifically to a code generation method, apparatus, device, and medium. Background Technology

[0002] In traditional interface development solutions, a configuration file (such as an Excel interface configuration file) for the interface to be developed is usually prepared in advance. Then, the corresponding data dictionary is looked up based on the fields in the configuration file, the data structure is prepared, and message conversion configuration is performed to complete the interface development.

[0003] For the traditional interface development solutions mentioned above, the process of generating code based on configuration files involves many repetitive operations, such as searching for each field in the configuration file from the data dictionary, and writing data structures for the same field. This results in low development efficiency for interfaces. Furthermore, the same functionality may be written by different developers, and each developer's writing style usually differs. This makes the final code difficult to maintain and may even lead to problems such as mismatch between the interface formats of the front-end and back-end. Summary of the Invention

[0004] This application provides a code generation method, apparatus, device, and medium to solve the problems of low development efficiency and difficulty in subsequent code maintenance in traditional interface development solutions.

[0005] Firstly, this application provides a code generation method, including:

[0006] In response to the code generation operation for the first control, the code generation tool corresponding to the first control is invoked to parse the configuration file of the interface to be developed, and to obtain the various fields contained in the configuration file and the logical relationships between the various fields.

[0007] Based on the fields and the logical relationships between them, a target file and a test file corresponding to the interface to be developed are generated, wherein the target file includes at least one of the configuration file and application file of the interface to be developed.

[0008] In one possible embodiment, parsing the configuration file of the interface to be developed to obtain the various fields contained in the configuration file and the logical relationships between the various fields includes:

[0009] The configuration file of the interface to be developed is parsed line by line to obtain the various fields;

[0010] Based on the hierarchical relationship of each field in the configuration file, the logical relationship between each field is obtained.

[0011] In one possible embodiment, generating the target file and test file corresponding to the interface to be developed based on the various fields and the logical relationships between the fields includes:

[0012] Based on the logical relationships between the various fields, a logical data structure is constructed;

[0013] The fields are filled into the logical data structure according to preset rules;

[0014] Based on the data dictionary corresponding to the code generation tool, the missing fields corresponding to each field are determined, and the missing fields are added to the logical data structure.

[0015] Based on the supplemented logical data structure, the target file and test file corresponding to the interface to be developed are generated.

[0016] In one possible embodiment, generating the target file and test file corresponding to the interface to be developed based on the supplemented logical data structure includes:

[0017] Based on the supplemented logical data structure, a logical structure view file corresponding to the interface to be developed is generated.

[0018] Based on the logical structure view file, the target file and test file corresponding to the interface to be developed are generated using the code templates included in the code generation tool, wherein the code templates are compiled based on a preset coding language.

[0019] In one possible embodiment, each field is at least one of a request message field and a response message field; in the configuration file, the data composition of each request message field and each response message field has the same format.

[0020] In one possible embodiment, after generating the target file and test file corresponding to the interface to be developed based on the respective fields and the logical relationships between the respective fields, the method further includes:

[0021] In response to the test operation for the second control, the test file corresponding to the interface to be developed is loaded, wherein the test file is a code file after adjusting the application logic in the application file;

[0022] The test file is invoked to test the actual test file, and an exception message is output based on the test results, wherein the exception message is used to prompt modification of any of the application logic.

[0023] Secondly, this application provides a code generation apparatus, comprising:

[0024] The parsing module is used to respond to the code generation operation for the first control by calling the code generation tool corresponding to the first control to parse the configuration file of the interface to be developed, and to obtain the various fields contained in the configuration file and the logical relationships between the various fields.

[0025] The code generation module is used to generate target files and test files corresponding to the interface to be developed based on the fields and the logical relationships between the fields, wherein the target files include at least one of the configuration files and application files of the interface to be developed.

[0026] In one possible embodiment, the parsing module is specifically used for:

[0027] The configuration file of the interface to be developed is parsed line by line to obtain the various fields;

[0028] Based on the hierarchical relationship of each field in the configuration file, the logical relationship between each field is obtained.

[0029] In one possible embodiment, the code generation module is specifically used for:

[0030] Based on the logical relationships between the various fields, a logical data structure is constructed;

[0031] The fields are filled into the logical data structure according to preset rules;

[0032] Based on the data dictionary corresponding to the code generation tool, the missing fields corresponding to each field are determined, and the missing fields are added to the logical data structure.

[0033] Based on the supplemented logical data structure, the target file and test file corresponding to the interface to be developed are generated.

[0034] In one possible embodiment, the code generation module is specifically used for:

[0035] Based on the supplemented logical data structure, a logical structure view file corresponding to the interface to be developed is generated.

[0036] Based on the logical structure view file, the target file and test file corresponding to the interface to be developed are generated using the code templates included in the code generation tool, wherein the code templates are compiled based on a preset coding language.

[0037] In one possible embodiment, each field is at least one of a request message field and a response message field; in the configuration file, the data composition of each request message field and each response message field has the same format.

[0038] In one possible embodiment, the code generation module is further configured to:

[0039] After generating the target file and test file corresponding to the interface to be developed based on the fields and the logical relationships between the fields, in response to the actual test operation for the second control, the actual test file corresponding to the interface to be developed is loaded, wherein the actual test file is a code file after adjusting the application logic in the application file;

[0040] The test file is invoked to test the actual test file, and an exception message is output based on the test results, wherein the exception message is used to prompt modification of any of the application logic.

[0041] Thirdly, this application provides an electronic device, comprising:

[0042] Memory, used to store program instructions;

[0043] A processor is configured to invoke program instructions stored in the memory and execute the steps of the method described in any one of the first aspects according to the obtained program instructions.

[0044] Fourthly, this application provides a computer-readable storage medium storing a computer program, the computer program including program instructions, which, when executed by a computer, cause the computer to perform the method described in any one of the first aspects.

[0045] Fifthly, this application provides a computer program product comprising: computer program code, which, when run on a computer, causes the computer to perform the method described in any one of the first aspects.

[0046] In this embodiment, in response to a code generation operation on the first control, a code generation tool corresponding to the first control is invoked to parse the configuration file of the interface to be developed, obtaining the fields contained in the configuration file and the logical relationships between the fields. Then, based on the fields and the logical relationships between them, a target file and a test file corresponding to the interface to be developed are generated. The target file includes at least one of the configuration file and the application file of the interface to be developed. In this way, the target file and test file of the interface to be developed can be quickly generated using the code generation tool corresponding to the first control, thereby improving development efficiency, reducing labor costs, and reducing the error rate of the code files. At the same time, it can also ensure a consistent code writing style, which is convenient for subsequent code maintenance. Furthermore, during the interface development process, the request message fields and response message fields included in the configuration file can be used to perform joint debugging of the front-end and back-end interfaces in advance, ensuring that the developed code file format is consistent, which is convenient for subsequent code testing and code maintenance. Attached Figure Description

[0047] Figure 1 A flowchart illustrating a code generation method provided in an embodiment of this application;

[0048] Figure 2 A flowchart illustrating a method for parsing a configuration file, as provided in this application embodiment;

[0049] Figure 3 A flowchart illustrating a method for generating target files and test files provided in this application embodiment;

[0050] Figure 4 A flowchart illustrating a specific method for generating target files and test files, provided in an embodiment of this application;

[0051] Figure 5 A flowchart illustrating a testing method for a test file provided in this application embodiment;

[0052] Figure 6 A flowchart illustrating an overall code generation method provided in this application embodiment;

[0053] Figure 7 A structural diagram of a code generation apparatus provided in an embodiment of this application;

[0054] Figure 8 This is a structural diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0055] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application. Unless otherwise specified, the embodiments and features in the embodiments of this application can be arbitrarily combined with each other. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than that shown here.

[0056] The terms "first" and "second" in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the term "comprising" and any variations thereof are intended to cover non-exclusive protection. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices. The term "multiple" in this application can mean at least two, for example, two, three, or more, and the embodiments of this application do not impose limitations.

[0057] The data collection, dissemination, and use in this application all comply with relevant national laws and regulations.

[0058] Before introducing the code generation method provided in the embodiments of this application, for ease of understanding, the technical background of the embodiments of this application will be described in detail below.

[0059] In traditional interface development solutions, the process typically involves first defining an Excel interface configuration file for the interface to be developed. Then, based on the fields in the Excel interface configuration file, the corresponding data dictionary is searched, the data structure of each field is compiled, message conversion configuration or Structured Query Language (SQL) configuration is performed, and then the interface configuration file, interface implementation class, and corresponding Extensible Markup Language (XML) files are written to complete the interface development work.

[0060] However, in the traditional interface development schemes mentioned above, the process of generating code based on Excel interface configuration files involves many repetitive operations, such as searching for each field in the Excel interface configuration file from the data dictionary; repeatedly writing data structures and configuring message conversion for the same field, resulting in low interface development efficiency.

[0061] In practical applications, there are two scenarios: one where the front-end application needs to call a back-end API to implement business logic; and another where the back-end application needs to call a front-end API to obtain the required data. During API development, the front-end and back-end are typically developed separately. The same or similar functionalities of the front-end and back-end APIs may be written by different developers, and each developer's coding style often differs, resulting in inconsistent code styles. If anomalies occur during code testing, it is often necessary to perform word-by-word and segment-by-segment verification of both the front-end and back-end code for that API. This not only increases the workload of code review but also further reduces the development efficiency of the API and may even affect the packaging, startup, and deployment of the entire service associated with that API.

[0062] In view of this, in order to solve the problems of low development efficiency and difficulty in subsequent code maintenance in traditional interface development solutions, this application provides a code generation method. In this application embodiment, in response to the code generation operation for the first control, the code generation tool corresponding to the first control is called to parse the configuration file of the interface to be developed, and obtain the fields contained in the configuration file and the logical relationships between the fields; then, based on the fields and the logical relationships between the fields, the target file and the test file corresponding to the interface to be developed are generated, wherein the target file includes at least one of the configuration file and the application file of the interface to be developed; in this way, the configuration file and / or application file of the interface to be developed can be quickly generated through the code generation tool corresponding to the first control, thereby improving the interface development efficiency, reducing labor costs, and unifying the code writing style since the same code generation tool is used, which facilitates subsequent code maintenance.

[0063] The following is a brief introduction to the application scenarios to which the technical solutions of the embodiments of this application are applicable. It should be noted that the application scenarios described below are only for illustrating the embodiments of this application and are not intended to limit the scope. In specific implementation, the technical solutions provided by the embodiments of this application can be flexibly applied according to actual needs.

[0064] The code generation method provided in this application can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, or smartwatch, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms; the software can be an application implementing the code generation method, etc., but is not limited to the above forms.

[0065] To further illustrate the technical solutions provided by the embodiments of this application, the technical solutions provided by the embodiments of this application will be described in detail below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are only for illustration and explanation of this application and are not intended to limit this application. Furthermore, the embodiments of this application and the features in the embodiments can be combined with each other without conflict.

[0066] Figure 1 A flowchart illustrating a code generation method provided in this application embodiment is provided below. Figure 1 The method includes the following steps.

[0067] In step 101, in response to the code generation operation for the first control, the code generation tool corresponding to the first control is called to parse the configuration file of the interface to be developed, and obtain the various fields contained in the configuration file and the logical relationships between the fields.

[0068] In this embodiment of the application, before executing step 101, the developer prepares the configuration file in advance. The configuration file includes the interface purpose description information of the interface to be developed, request messages and response messages. The request message contains multiple request message fields, and the response message contains at least one response message field. In the same configuration file, the data composition format corresponding to each request message field and each response message field is the same. For example, each field includes the field item name, Chinese name, data item number, XML input length, field attributes, etc.

[0069] In this embodiment of the application, the configuration file can be an Excel interface configuration file. Developers pre-compile an Excel interface configuration file to define the interface purpose description information corresponding to the interface to be developed, as well as request messages and response messages. The request message includes each request message field of the interface to be developed, as well as the logical relationship between each request message field. For example, the logical relationship between request message field 1 and request message field 2 is that request message field 2 is the next level of request message field 1; the logical relationship between request message field 2 and request message field 3 is that request message field 2 and request message field 3 are at the same level.

[0070] After the personnel have prepared the above configuration file, they can perform a code generation operation on the first control, and the device will respond to the code generation operation and execute step 101.

[0071] In some embodiments, see Figure 2 As shown, when executing step 101, the following steps are specifically performed:

[0072] In step 1011, the configuration file of the interface to be developed is parsed line by line to obtain each field.

[0073] In step 1012, the logical relationships between the fields are obtained based on the hierarchical relationship of each field in the configuration file.

[0074] In this embodiment of the application, when performing step 1011, if the configuration file contains multiple pages, the configuration file is parsed page by page, and each page is parsed line by line.

[0075] For example, let's take the configuration file of the interface to be developed as the Excel interface configuration file.

[0076] Assume the Excel interface configuration file example is shown in the table below:

[0077] Example table of Excel interface configuration file

[0078]

[0079] In the table above, "." is used to represent the hierarchical relationship of each field in the configuration file. For example, if there is no "." before field 1 and field 2, and field 1's field attribute is "C", then the field corresponding to field 1 and field 2 are at the same level. If there is no "." before field 2, and field 3 has a "." before field 3, and field 2's field attribute is "GROUP", then the field corresponding to field 3 is the next level below the field corresponding to field 2. The "Data Item Number" in the table above represents the specific location of the data information corresponding to that field in the data dictionary.

[0080] Upon receiving the code generation operation for the first control, the code generation tool corresponding to the first control is invoked to parse the Excel interface configuration file line by line to obtain the various fields. In the table above, each row of data corresponds to one field, and each field is at least one of the request message field and the response message field.

[0081] In this embodiment of the application, when performing step 1102, the logical relationship between each field is obtained based on the hierarchical relationship of each field in the configuration file, namely "." and column attributes in the table above.

[0082] In step 102, based on each field and the logical relationship between each field, the target file and test file corresponding to the interface to be developed are generated. The target file includes at least one of the configuration file and application file of the interface to be developed.

[0083] In the embodiments of this application, please refer to Figure 3 When executing step 102, the following steps are specifically performed:

[0084] In step 1021, a logical data structure is constructed based on the logical relationships between the various fields.

[0085] In specific implementation, when executing step 1021, a corresponding logical data structure is constructed based on the logical relationship between each field. For example, if the column attribute corresponding to field 1 is "GROUP", then a list structure is set for field 1 in the logical data structure.

[0086] In step 1022, each field is filled into the logical data structure according to preset rules.

[0087] In this embodiment of the application, after the logical data structure is constructed by performing step 1021, each field is filled into the logical data structure based on the preset rules in the data dictionary corresponding to the code generation tool.

[0088] In step 1023, based on the data dictionary corresponding to the code generation tool, the missing fields corresponding to each field are determined, and the missing fields are added to the logical data structure.

[0089] In practical applications, it is common for the predefined configuration file to fail to include all the fields required for subsequent code generation. Therefore, after executing step 1022, step 1023 is executed to obtain each missing field based on the data dictionary, and then these missing fields are added to the logical data structure.

[0090] In step 1024, based on the supplemented logical data structure, the target file and test file corresponding to the interface to be developed are generated.

[0091] In the embodiments of this application, see the following: Figure 4 As shown, when executing step 1024, the following steps are specifically performed:

[0092] In step 401, based on the supplemented logical data structure, a logical structure view file corresponding to the interface to be developed is generated.

[0093] The logical structure view file contains a complete input / output logical view.

[0094] In step 402, based on the logical structure view file, the target file and test file corresponding to the interface to be developed are generated using the code templates included in the code generation tool. The code templates are compiled based on a preset coding language.

[0095] The code templates can be in formats including, but are not limited to, Java and Excel.

[0096] In practice, after executing step 102, the target file and test file of the interface to be developed are obtained. At this point, the basic development work of the interface to be developed is completed, and the subsequent step is to proceed to the actual testing phase. Typically, before conducting actual testing, it is necessary to adapt the application logic and runtime environment of the application files included in the target file. That is, some or all of the application logic of the application files included in the target file needs to be adjusted to obtain the actual test file used for testing (which can be the interface code file used in the actual application scenario). Please refer to [reference needed]. Figure 5 The test file obtained by the above code generation method is used to test the actual test file in the embodiments of this application, specifically including the following steps.

[0097] In step 501, in response to the test operation for the second control, the test file corresponding to the interface to be developed is loaded, wherein the test file is the code file after adjusting the application logic in the application file.

[0098] In this embodiment of the application, after the developer performs a test operation on the second control, step 501 is executed, and in response to the test operation, the test file is loaded.

[0099] In step 502, the test file is called to test the actual test file, and an exception message is output based on the test results. The exception message is used to prompt modification of any application logic.

[0100] For example, let's take the configuration file of the interface to be developed as the Excel interface configuration file.

[0101] Let's still assume that the Excel interface configuration file is as shown in the table above.

[0102] So, see Figure 6As shown, the overall process of the code generation method provided in this application is as follows:

[0103] In step 601, in response to the code generation operation for the first control, the code generation tool corresponding to the first control is called to parse the configuration file of the interface to be developed line by line to obtain each field.

[0104] The first control represents the online service.

[0105] In step 602, the logical relationships between the fields are obtained based on the hierarchical relationship of each field in the configuration file.

[0106] In step 603, a logical data structure is constructed based on the logical relationships between the various fields.

[0107] In step 604, each field is filled into the logical data structure according to preset rules.

[0108] In step 605, based on the data dictionary corresponding to the code generation tool, the missing fields corresponding to each field are determined, and the missing fields are added to the logical data structure.

[0109] In step 606, based on the supplemented logical data structure, a logical structure view file corresponding to the interface to be developed is generated.

[0110] In step 607, based on the logical structure view file, the code generation tool uses code templates to generate target files and test files corresponding to the interface to be developed. The target files include at least one of the configuration file and application file of the interface to be developed.

[0111] In this embodiment of the application, it is assumed that after the developer obtains the target file and the test file, he / she adjusts the application logic of the application file in the target file to obtain the test file and performs the test operation on the second control. Then, the process proceeds to step 608.

[0112] In step 608, in response to the test operation for the second control, the test file corresponding to the interface to be developed is loaded, wherein the test file is the code file after adjusting the application logic in the application file.

[0113] In step 609, the test file is called to test the actual test file, and an exception message is output based on the test results. The exception message is used to prompt modification of any application logic.

[0114] In step 607, after obtaining the logical structure view file corresponding to the interface to be developed based on each field and the logical relationships between them, a tool for generating mapping code from a data dictionary can be used to map fields to code during the execution of step 607. This achieves the aforementioned function of generating the target file and test file corresponding to the interface to be developed based on the logical structure view file. The generated target file includes at least one of the following: view object (VO) related code files, service interface implementation class files, registration service configuration files, and mapping messages. The generated test file includes at least one of the following: test code and test data. The test file can be an HTTP client debugging simulation message, etc.

[0115] In this embodiment, the code generation tool can be a data service layer code generation tool, an outbound call service code generation tool, or an online service code generation tool (as shown in the aforementioned Excel interface configuration file). Accordingly, for the data service layer code generation tool, the generated target file can include at least one of a PortableObject (PO) file, a Disk Operating System (DOS) file, and an XML file corresponding to iBatis; the generated test file can be a DOSTest file. For the outbound call service code generation tool, the generated target file can include at least one of a VO-related code file, an outbound call service interface implementation class file, and a mapping message; the generated test file can be an outbound call test message, etc.

[0116] In this embodiment of the application, the operation process of other types of code generation tools is similar to that of the online service code generation tool described above, and will not be repeated here.

[0117] It should be noted that, in the embodiments of this application, the specific forms of the target files and test files mentioned above are merely examples, and there are no specific limitations on their specific file forms or file types in the embodiments of this application.

[0118] In this embodiment of the application, the configuration file of the interface to be developed includes the response message of the interface to be developed, and is also used for front-end logic development.

[0119] In this way, by calling the aforementioned code generation tool, code files can be generated quickly and automatically, improving code generation speed and thus increasing the development efficiency of APIs while reducing the error rate of target files. Furthermore, since the code generation tool generates both target and test files, a consistent coding style can be maintained, facilitating subsequent code maintenance. Moreover, during API development, by standardizing the data format of configuration files (such as the format of request and response messages), front-end and back-end API integration testing can be performed in advance, ensuring consistent code formats between the front-end and back-end interfaces, further reducing the difficulty and efficiency of subsequent code maintenance.

[0120] In some feasible embodiments, the code generation method provided in this application can also make the code generation runtime environment more flexible. That is, by importing the configuration file into the integrated device, the integrated device can generate the required target files and test files by directly running the above-mentioned code generation tool, which can greatly improve development efficiency.

[0121] Based on the same inventive concept, embodiments of this application provide a code generation apparatus, please refer to... Figure 7 The device includes:

[0122] The parsing module 701 is used to respond to the code generation operation for the first control by calling the code generation tool corresponding to the first control to parse the configuration file of the interface to be developed, and to obtain the various fields contained in the configuration file and the logical relationship between the various fields.

[0123] The code generation module 702 is used to generate target files and test files corresponding to the interface to be developed based on the fields and the logical relationships between the fields, wherein the target files include at least one of the configuration files and application files of the interface to be developed.

[0124] In one possible embodiment, the parsing module 701 is specifically used for:

[0125] The configuration file of the interface to be developed is parsed line by line to obtain the various fields;

[0126] Based on the hierarchical relationship of each field in the configuration file, the logical relationship between each field is obtained.

[0127] In one possible embodiment, the code generation module 702 is specifically used for:

[0128] Based on the logical relationships between the various fields, a logical data structure is constructed;

[0129] The fields are filled into the logical data structure according to preset rules;

[0130] Based on the data dictionary corresponding to the code generation tool, the missing fields corresponding to each field are determined, and the missing fields are added to the logical data structure.

[0131] Based on the supplemented logical data structure, the target file and test file corresponding to the interface to be developed are generated.

[0132] In one possible embodiment, the code generation module 702 is specifically used for:

[0133] Based on the supplemented logical data structure, a logical structure view file corresponding to the interface to be developed is generated.

[0134] Based on the logical structure view file, the target file and test file corresponding to the interface to be developed are generated using the code templates included in the code generation tool, wherein the code templates are compiled based on a preset coding language.

[0135] In one possible embodiment, each field is at least one of a request message field and a response message field; in the configuration file, the data composition of each request message field and each response message field has the same format.

[0136] In one possible embodiment, the code generation module 702 is further configured to:

[0137] After generating the target file and test file corresponding to the interface to be developed based on the fields and the logical relationships between the fields, in response to the actual test operation for the second control, the actual test file corresponding to the interface to be developed is loaded, wherein the actual test file is a code file after adjusting the application logic in the application file;

[0138] The test file is invoked to test the actual test file, and an exception message is output based on the test results, wherein the exception message is used to prompt modification of any of the application logic.

[0139] Based on the same inventive concept, this application provides an electronic device that can achieve the functions described above. Please refer to... Figure 8 The device includes one or more processors 801 and memory 802.

[0140] Processor 801 may include one or more central processing units (CPUs) or digital processing units, etc. Processor 801 is used to implement the above-described code generation method when calling computer programs stored in memory 802.

[0141] The memory 802 is used to store computer programs executed by the processor 801. The memory 802 may mainly include a program storage area and a data storage area. The program storage area may store the operating system and programs required to run instant messaging functions, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.

[0142] Memory 802 may be volatile memory, such as random-access memory (RAM); memory 802 may also be non-volatile memory, such as read-only memory, flash memory, hard disk drive (HDD), or solid-state drive (SSD); or memory 802 may be any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but is not limited thereto. Memory 802 may be a combination of the above-mentioned memories.

[0143] This application embodiment does not limit the specific connection medium between the processor 801 and the memory 802. This application embodiment... Figure 8 The processor 801 and memory 802 are connected via bus 803, and bus 803 is in Figure 8 The connections between other components are shown in thick lines only and are not intended to be limiting. The 803 bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, Figure 8 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0144] Based on the same inventive concept, embodiments of this application provide a computer-readable storage medium. The computer program product includes computer program code, which, when run on a computer, causes the computer to execute any of the code generation methods described above. Since the principle by which the computer-readable storage medium solves the problem is similar to that of the code generation method, the implementation of the computer-readable storage medium can be found in the implementation of the method; repeated details will not be elaborated further.

[0145] Based on the same inventive concept, this application also provides a computer program product, which includes computer program code. When the computer program code is run on a computer, it causes the computer to execute any of the code generation methods described above. Since the principle by which the above computer program product solves the problem is similar to that of the code generation method, the implementation of the above computer program product can be referred to the implementation of the method, and repeated details will not be repeated.

[0146] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0147] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations 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, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in one or more blocks of the flowchart illustrations and / or one or more blocks of the block diagrams.

[0148] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more processes in a flowchart and / or one or more blocks in a block diagram.

[0149] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of user-operated steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide steps for implementing the function specified in one or more processes in the flowchart and / or one or more blocks in the block diagram.

[0150] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.

Claims

1. A code generation method, characterized in that, include: In response to the code generation operation for the first control, the code generation tool corresponding to the first control is invoked to parse the configuration file of the interface to be developed, and to obtain the various fields contained in the configuration file and the logical relationships between the various fields. Based on the logical relationships between the various fields, a logical data structure is constructed; The fields are filled into the logical data structure according to preset rules; Based on the data dictionary corresponding to the code generation tool, the missing fields corresponding to each field are determined, and the missing fields are added to the logical data structure. Based on the supplemented logical data structure, a logical structure view file corresponding to the interface to be developed is generated, and the logical structure view file contains a complete input and output logical view. Based on the logical structure view file, the code generation tool generates target files and test files corresponding to the interface to be developed using code templates. The target files include at least one of the configuration file and application file of the interface to be developed, and the code templates are compiled based on a preset coding language.

2. The method as described in claim 1, characterized in that, The configuration file of the interface to be developed is parsed to obtain the fields contained in the configuration file and the logical relationships between the fields, including: The configuration file of the interface to be developed is parsed line by line to obtain the various fields; Based on the hierarchical relationship of each field in the configuration file, the logical relationship between each field is obtained.

3. The method as described in claim 1 or 2, characterized in that, Each field is at least one of a request message field and a response message field; in the configuration file, the data composition of each request message field and each response message field has the same format.

4. The method as described in claim 3, characterized in that, After generating the target file and test file corresponding to the interface to be developed based on the various fields and the logical relationships between the fields, the process further includes: In response to the test operation for the second control, the test file corresponding to the interface to be developed is loaded, wherein the test file is a code file after adjusting the application logic in the application file; The test file is invoked to test the actual test file, and an exception message is output based on the test results, wherein the exception message is used to prompt modification of any of the application logic.

5. A code generation device, characterized in that, include: The parsing module is used to respond to the code generation operation for the first control by calling the code generation tool corresponding to the first control, parsing the configuration file of the interface to be developed, and obtaining the various fields contained in the configuration file and the logical relationships between the various fields. The code generation module is used to construct a logical data structure based on the logical relationships between the various fields; The fields are filled into the logical data structure according to preset rules; Based on the data dictionary corresponding to the code generation tool, the missing fields corresponding to each field are determined, and the missing fields are added to the logical data structure. Based on the added logical data structure, a logical structure view file corresponding to the interface to be developed is generated, and the logical structure view file contains a complete input and output logical view. Based on the logical structure view file, the code generation tool generates target files and test files corresponding to the interface to be developed using code templates. The target files include at least one of the configuration file and application file of the interface to be developed, and the code templates are compiled based on a preset coding language.

6. The apparatus as claimed in claim 5, characterized in that, The parsing module is specifically used for: The configuration file of the interface to be developed is parsed line by line to obtain the various fields; Based on the hierarchical relationship of each field in the configuration file, the logical relationship between each field is obtained.

7. The apparatus as described in claim 5 or 6, characterized in that, Each field is at least one of a request message field and a response message field; in the configuration file, the data composition of each request message field and each response message field has the same format.

8. The apparatus as claimed in claim 7, characterized in that, The code generation module is also used for: After generating the target file and test file corresponding to the interface to be developed based on the fields and the logical relationships between the fields, in response to the actual test operation for the second control, the actual test file corresponding to the interface to be developed is loaded, wherein the actual test file is a code file after adjusting the application logic in the application file; The test file is invoked to test the actual test file, and an exception message is output based on the test results, wherein the exception message is used to prompt modification of any of the application logic.

9. An electronic device, characterized in that, include: Memory, used to store program instructions; A processor is configured to invoke program instructions stored in the memory and execute the steps of the method according to any one of claims 1-4.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a computer, cause the computer to perform the method as described in any one of claims 1-4.

11. A computer program product, characterized in that, The computer program product includes: computer program code, which, when run on a computer, causes the computer to perform the method as described in any one of claims 1-4.

Citation Information

Patent Citations

  • Code generation method and device, equipment and medium

    CN115016794A