Method, device and system for automatically establishing data model based on interface document
By preprocessing the interface information file and constructing the tree data structure, the front-end programming language file is generated, which solves the problem of inconsistent definitions of the front-end and back-end interfaces and achieves the accuracy and efficiency of interface synchronization.
Patent Information
- Application Number
- CN202410894758.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-07-04
AI Technical Summary
In the front-end and back-end separation architecture mode, when the back-end service changes the data interface, the front-end developer needs to manually update the interface definition file, resulting in inconsistent interface definitions, increased error probability and maintenance costs, and the lack of effective solutions.
By preprocessing the interface information file, a tree data structure is constructed, and based on this, the front-end programming language file is generated to achieve accurate conversion of the interface information file into the front-end programming language file, simplify the front-end and back-end interaction process, and ensure the consistency of the interface definition.
It reduces the workload and error rate of developers, improves development efficiency, avoids interface synchronization errors, reduces front-end and back-end communication costs, and improves the flexibility and stability of the project.
Smart Images

Figure CN118444960B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a method, device and system for automatically establishing a data model based on an interface document. Background Art
[0002] In the architecture model with separation of front-end and back-end, there are often problems with consistency of interface definition and maintenance workload. At present, when the back-end service changes the data interface, the front-end developer often manually writes the interface definition file based on the changed data interface. For example, when the back-end service frequently changes its data interface according to changes in business needs, it is necessary to manually update the interface document to synchronize the data structure of the front-end and back-end. In this process, the processing flow is cumbersome and the probability of error is high. In addition, the manual update method will also increase the risk of inconsistent interface definitions between the front-end and back-end. Based on this, there is a problem in the related art that inconsistent front-end and back-end interface definitions lead to interface synchronization errors.
[0003] There is currently no effective solution to the problem of interface synchronization errors caused by inconsistent front-end and back-end interface definitions in related technologies. Summary of the invention
[0004] In this embodiment, a method, device and system for automatically establishing a data model based on an interface document are provided to solve the problem of interface synchronization errors caused by inconsistent front-end and back-end interface definitions in related technologies.
[0005] In a first aspect, a method for automatically establishing a data model based on an interface document is provided in this embodiment, comprising:
[0006] Preprocessing the original data of the target interface information file to obtain metadata;
[0007] Constructing a preset tree data structure according to the metadata; wherein the tree data structure is used to store a character string set;
[0008] Based on the traversal of the tree data structure, a front-end programming language file is generated.
[0009] In some of the embodiments, before preprocessing the original data of the target interface information file to obtain the metadata, the method further includes:
[0010] Determine whether there is a configuration file corresponding to the latest interface information file; if so, merge the historical version file corresponding to the latest interface information file with the latest interface information file to obtain the target interface information file; the configuration file indicates the interface information that needs to be converted.
[0011] In some of the embodiments, if the configuration file does not exist, the method further includes:
[0012] The latest interface information file is used as the target interface information file.
[0013] In some of the embodiments, generating a front-end programming language file based on traversing the tree data structure includes:
[0014] Traversing each node in the tree data structure to obtain the type of each node;
[0015] According to the type of each node, convert each node into a code snippet string of a front-end programming language;
[0016] Generate a front-end programming language file based on each of the code snippet strings.
[0017] In some embodiments, converting each of the nodes into a code snippet string of a front-end programming language according to the type of each of the nodes includes:
[0018] A code snippet string of a corresponding front-end programming language is generated according to the root node, the parent node, the child node and the namespace node in the tree data structure respectively.
[0019] In some of the embodiments, generating a front-end programming language file according to each of the code snippet strings includes:
[0020] According to the order of traversing the tree data structure, concatenating the code snippet strings to form a complete data model string;
[0021] The data model character string is formatted to obtain the front-end programming language file.
[0022] In some embodiments, the method further comprises:
[0023] The front-end programming language file is published to a storage warehouse, and the front-end programming language file is pulled from the storage warehouse and installed in an associated project development directory.
[0024] In a second aspect, in this embodiment, a device for automatically establishing a data model based on an interface document is provided, comprising: a preprocessing module, a building module, and a generating module; wherein:
[0025] The preprocessing module is used to preprocess the original data of the target interface information file to obtain metadata;
[0026] The construction module is used to construct a preset tree data structure according to the metadata; wherein the tree data structure is used to store a character string set;
[0027] The generating module is used to generate a front-end programming language file based on traversing the tree data structure.
[0028] In a third aspect, in this embodiment, a data model automatic establishment system based on an interface document is provided, including: a back-end device and a front-end device; wherein:
[0029] The backend device is used to generate an interface information file for interaction;
[0030] The front-end device is used to call a preset script program to execute the method for automatically establishing a data model based on an interface document described in the first aspect above.
[0031] In a fourth aspect, an electronic device is provided in this embodiment, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for automatically establishing a data model based on an interface document as described in the first aspect above is implemented.
[0032] Compared with the related art, the present embodiment provides a method, device and system for automatically establishing a data model based on an interface document. The method for automatically establishing a data model based on an interface document first pre-processes the original data of the target interface information file to obtain metadata; then constructs a preset tree data structure based on the metadata; wherein the tree data structure is used to store a string set; and finally generates a front-end programming language file based on the traversal of the tree data structure. It can realize accurate conversion from interface information files to front-end programming language files, simplify the collaborative process in the front-end and back-end interaction process, realize consistency of front-end and back-end interface definitions, and thus avoid interface synchronization errors caused by inconsistent front-end and back-end interface definitions.
[0033] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0035] Figure 1 is a hardware structure block diagram of a terminal of the method for automatically establishing a data model based on an interface document of this embodiment;
[0036] Figure 2 is a flow chart of the method for automatically establishing a data model based on an interface document of this embodiment;
[0037] Figure 3 This is a schematic diagram of constructing a prefix tree in this embodiment;
[0038] Figure 4 is a schematic diagram of a prefix tree data structure of this embodiment;
[0039] Figure 5 is a flowchart of a method for automatically establishing a data model based on an interface document in some embodiments;
[0040] Figure 6 is a structural block diagram of a device for automatically establishing a data model based on an interface document in this embodiment;
[0041] Figure 7 It is a structural diagram of the system for automatically establishing a data model based on an interface document in this embodiment. DETAILED DESCRIPTION
[0042] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0043] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with general skills in the technical field to which this application belongs. The words "one", "a", "the", "these" and the like in this application do not indicate a quantitative limitation, and they may be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" may mean: A exists alone, A and B exist at the same time, and B exists alone. Generally, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0044] The method embodiment provided in this embodiment can be executed in a terminal, a computer or a similar computing device. For example, running on a terminal, Figure 1 FIG. 1 is a hardware structure diagram of a terminal of the method for automatically establishing a data model based on an interface document of this embodiment. Figure 1 As shown, the terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 and a memory 104 for storing data, wherein the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA. The above terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0045] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for automatically establishing a data model based on an interface document in this embodiment. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0046] The transmission device 106 is used to receive or send data via a network. The above network includes a wireless network provided by a communication provider of the terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet wirelessly.
[0047] In this embodiment, a method for automatically establishing a data model based on an interface document is provided. Figure 2 is a flow chart of the method for automatically establishing a data model based on an interface document of this embodiment. Figure 2 As shown, the process includes the following steps:
[0048] Step S210, pre-processing the original data of the target interface information file to obtain metadata.
[0049] The method for automatically establishing a data model based on an interface document can be implemented by a preset script program. After the user configures the basic information of the interface information file, the script program is executed under the development target to realize the conversion of the interface information file. The interface information file can specifically be an interface document for two exchange computer systems to exchange information securely through the Internet. Most business applications must communicate with other internal and third-party applications to perform various tasks. The interface information file can specifically be a RESTful API (Representational State Transferful API) document. The target interface information file can be an interface information file that currently needs to be converted. Among them, RESTful API is a network application interface design style based on the HTTP protocol. It follows the REST (Representational State Transfer) architectural style and follows safe, reliable and efficient software communication standards. For example, in order to generate a monthly payroll, the internal account system needs to share data with the customer's bank system to automatically issue invoices and communicate with the internal payroll application. In this process, an application interface information file is required to realize information exchange.
[0050] Since the original data exported by the interface information file platform contains interface data in various states, such as "published", "discarded", "under development", etc. Therefore, after determining the target interface information file that needs to be converted, data can be filtered according to the needs of developers. For example, if the current developer only wants to convert the interface data with the status of "published", the interface data in other states will be eliminated. Therefore, the target interface information file can be parsed and cleaned to filter out metadata that meets the needs of developers.
[0051] Step S220, constructing a preset tree data structure according to the metadata; wherein the tree data structure is used to store a string set.
[0052] The tree data structure may be a prefix tree. The metadata includes various Uniform Resource Locator (URL) paths, and the prefix tree is constructed by traversing the metadata and according to various URL paths.
[0053] Figure 3A schematic diagram of a prefix tree construction of this embodiment. When the metadata contains the following three URL paths: "POST / class / student / create", "POST / class / teacher / create", and "GET / class / student / list", the following can be constructed: Figure 3 The data structure shown. For example, for the path "POST / class / student / create", the process of building a prefix tree can be: starting from the root node, find or create the child node "POST". Under the "POST" node, find or create the child node "class". Under the "class" node, find or create the child node "student". Under the "student" node, find or create the child node "create". Store the node content (for example, parameters, request body, response body, etc.) in the "create" node. That is, each subpath in the URL path can be used as a node in the prefix tree, and the subpath under a subpath under the URL path can be used as a child node of the corresponding node in the prefix tree. After the construction is completed, each node in the prefix tree stores a character, and each character stores a subpath in the URL path. Based on this, this step can realize the storage of strings in metadata through a prefix tree.
[0054] Figure 4 Schematic diagram of a prefix tree data structure of this embodiment. Figure 4 As shown, the numbers "1" to "15" represent the node numbers. "a", "b" and "c" represent the different branches of each node. Each node in the data structure stores a subpath in the URL path.
[0055] Step S230, generating a front-end programming language file based on the traversal of the tree data structure.
[0056] The front-end programming language file can specifically be the open source programming language TypeScript. Since the tree data structure reflects the structure of the URL path, each node in the tree data structure is deeply traversed based on the constructed tree data structure, and each sub-path in the URL path can be traversed. Furthermore, based on the traversal of the nodes, combined with the preset code generation logic, the code snippets are converted, and finally, based on the order of traversal access, several code snippets are combined to generate a front-end programming language file. The code generation logic can be used to convert metadata into a data structure organized by the TypeScript namespace model hierarchy.
[0057] Based on this, this embodiment realizes the conversion from the interface information file to the front-end programming language file. When the front-end developer needs to use the target interface information file, he only needs to execute the preset script program to realize the conversion of the target interface new file to the front-end programming language file, so that the developer can quickly obtain the desired data model through the form of class chain call, without having to manually update the interface definition to synchronize the front-end and back-end data structures. In addition, organizing the interface information based on the tree data structure can ensure the correctness of the namespace hierarchy structure.
[0058] In related technologies, developers are often required to manually write interface definition files based on the changed data interfaces, which requires a lot of time to write non-creative interface definition files, resulting in high labor costs and low development efficiency. In addition, the manual writing method has the risk of interface synchronization errors, which in turn affects the stability of the application and user experience. In addition, this method will also increase the communication and collaboration costs between the front-end and back-end teams, and the mutual dependence is strong, making it difficult to flexibly respond to rapid changes in requirements. As the scale of the project expands, the cost of manually maintaining interface definitions will also increase exponentially.
[0059] In view of the above-mentioned problems existing in the related technologies, the method for automatically establishing a data model based on an interface document proposed in this embodiment does not require developers to manually update the interface definition in the front-end programming language file, thereby reducing the excessive consumption of development time by developers and improving development efficiency; a tree data structure is constructed according to the interface information file, and then a front-end programming language file is generated based on the traversal of the tree data structure, thereby avoiding interface synchronization errors caused by human negligence during manual writing, thereby ensuring the stability of the application. In addition, the front-end programming language file is directly generated based on the conversion of the new interface information file, which also reduces the communication and collaboration costs between the front-end and the back-end, reduces the dependence of the front-end and the back-end, improves the flexibility of the project, and also reduces the cost of maintaining the interface definition.
[0060] Through the above steps S210 to S230, the original data of the target interface information file is preprocessed to obtain metadata; a preset tree data structure is constructed according to the metadata; wherein the tree data structure is used to store a string set; and a front-end programming language file is generated based on the traversal of the tree data structure. It can realize the accurate conversion from the interface information file to the front-end programming language file, simplify the collaborative process in the front-end and back-end interaction process, realize the consistency of the front-end and back-end interface definitions, and thus avoid the interface synchronization errors caused by the inconsistent front-end and back-end interface definitions.
[0061] Specifically, in one embodiment, before preprocessing the original data of the target interface information file to obtain the metadata, the method for automatically establishing a data model based on the interface document may further include:
[0062] Determine whether there is a configuration file corresponding to the latest interface information file; if so, merge the historical version file of the latest interface information file with the latest interface information file to obtain a target interface information file; the configuration file indicates the interface information that needs to be converted.
[0063] The above configuration file can be set with the application programming interface (Application Programming Interface, referred to as API) that needs to be updated. By reading the configuration file, it is determined which APIs, that is, the interface information, need to be updated at present. The historical version file is the historical version of the interface information file. In this embodiment, an incremental update mode is provided. When a new interface information file is developed, it is determined whether there is a configuration file corresponding to the new interface information file in the user development root directory. If so, the historical version file is merged with the latest interface information file to generate a new original data as the target interface information file. The user can set a configuration file in the root directory to configure the interface information expected to be updated to the latest target interface information file. When the script detects the configuration file, the latest interface information file is merged with the historical version file according to the configuration file. In the subsequent conversion process, the converted code content can be updated for the interface information expected to be updated. Therefore, this incremental update mode can accurately convert the interface information that the user expects to update when used collaboratively by multiple people.
[0064] In one embodiment, if there is no configuration file, the method for automatically establishing a data model based on an interface document may further include:
[0065] The latest interface information file is used as the target interface information file. If there is no configuration file in the latest interface information file, a batch update mode is adopted to use the latest interface information file as the target interface information file for batch update.
[0066] Additionally, in one embodiment, based on the above step S230, generating a front-end programming language file based on traversing the tree data structure may specifically include:
[0067] Traverse each node in the tree data structure to obtain the type of each node; according to the type of each node, convert each node into a code snippet string of a front-end programming language; and generate a front-end programming language file according to each code snippet string.
[0068] The node type refers to the structural type of the node in the tree data structure, including the root node type, parent node type, child node type, and namespace node type. Traverse each node of the tree data structure, and use different code generation logic to generate code snippet strings according to the different types of each node. Then, write the generated code snippet strings into the memory in sequence according to the traversal access order, and finally generate the front-end programming language file.
[0069] This embodiment traverses the tree data structure, generates a code snippet string, and finally constructs a front-end programming language file, thereby enabling accurate conversion of the interface information file to the front-end programming language file.
[0070] Additionally, in one embodiment, according to the type of each node, converting each node into a code snippet string of a front-end programming language may specifically include:
[0071] Generate a code snippet string of the corresponding front-end programming language according to the root node, parent node, child node and namespace node in the tree data structure.
[0072] For example, Figure 3 As shown in the prefix tree in , the root node is "ROOT", the parent nodes are "POST" and "student", the namespace node is "class", and the node is "create". Among them, the root node does not store any characters. The code will recursively process all child nodes under the root node. The parent node has both path and content, as well as child nodes. Therefore, the code converts the parent node into a namespace to generate a code snippet string for the parent node, and recursively processes the child nodes under the parent node. The child node has a path and content, but does not have child nodes, so the code converts the content of the child node into an independent namespace to generate a code snippet string corresponding to the child node. The namespace node has no path and content, but has child nodes, so the code converts the namespace node into a namespace to generate a code snippet string for the namespace node, and recursively processes its child nodes.
[0073] By performing logical processing on the root node, parent node, child node and namespace node, the code snippet strings corresponding to different nodes are finally generated, which can accurately convert the interface information file into the code snippet string of the front-end programming language, thereby facilitating the subsequent construction of a complete front-end programming language file.
[0074] In one embodiment, generating a front-end programming language file according to each code snippet string may include:
[0075] According to the order of traversing the tree data structure, the code snippet strings are concatenated to form a complete data model string; the data model string is formatted to obtain a front-end programming language file.
[0076] Specifically, after the code snippet strings corresponding to different nodes are generated, the code snippet strings are sequentially written into the memory in the order of traversing the tree data structure and gradually spliced to form a complete data model string, such as a complete TypeScript data model string. Afterwards, the data model string in the memory is read and formatted to generate a front-end programming language file, such as formatting the TypeScript data model string to generate a TypeScript definition file.
[0077] In this embodiment, by splicing the code snippet strings in the traversal order, a data model string is finally generated, and then a front-end programming language file is obtained based on the data model string, which can accurately realize the conversion of the interface information file to the front-end programming language file.
[0078] Additionally, in one embodiment, the method for automatically establishing a data model based on an interface document may further include:
[0079] Publish the front-end programming language file to the storage warehouse, and pull the front-end programming language file from the storage warehouse and install it in the associated project development directory. For example, by executing the script program, the generated TypeScript definition file is automatically published to the specified storage warehouse to achieve automatic login and publishing. After that, the generated file is automatically pulled from the storage warehouse and installed in the user's project development directory. In this way, the user can directly call the generated data model during the project development process. Among them, sending the generated front-end programming language file to the storage warehouse for storage each time can realize the snapshot function, which is convenient for returning to any historical version that has triggered the conversion. Ensure the traceability and recoverability of the historical version of the project.
[0080] Figure 5 1 is a flow chart of a method for automatically establishing a data model based on an interface document in some embodiments. Figure 5 As shown, the method for automatically establishing a data model based on an interface document includes the following steps:
[0081] Step S501, triggering the execution of a script program; wherein the script program may be a shell script program.
[0082] Step S502, determine whether there is a configuration file corresponding to the latest interface information file in the user development root directory, if so, execute step S503; otherwise, execute step S504; specifically, the API that needs to be updated can be determined based on the corresponding configuration file in the root directory. The configuration file is used to configure which APIs need to be updated in the incremental update mode. The program determines which APIs need to be updated by reading which APIs are in the configuration file.
[0083] Step S503, determine the update mode as the incremental update mode, and execute step S505.
[0084] Step S504, determine the update mode as the full update mode, and execute step S506.
[0085] Step S505, read the latest interface information file and the historical version of the interface information file, and execute step S507.
[0086] Step S506, read the latest interface information file, and execute step S508.
[0087] Step S507, merge the latest interface information file with the interface information file of the historical version, clean them into metadata, and execute step S509.
[0088] Step S508, clean the latest interface information file into metadata, and execute step S509.
[0089] Step S509 , classify the metadata according to the Hypertext Transfer Protocol (Http) request method of the API, and convert it into a seed data structure required by the prefix tree.
[0090] Step S510, traverse all nodes of the seed data structure to construct a prefix tree.
[0091] Step S511, traverse the prefix tree, escape the traversed nodes according to different types, and print the nodes to generate a code snippet string of the front-end programming language.
[0092] Step S512, concatenating different code snippet strings in the traversal order to obtain a complete data model string, formatting the data model string, and generating a front-end programming language file.
[0093] Step S513, package the generated front-end programming language file, generate a unique identifier (Identity document) according to the content, and upload it to the storage warehouse.
[0094] Step S514, installing the front-end programming language file into the user project.
[0095] The above steps S501 to S514 can realize the conversion from the interface information file to the front-end programming language file, simplify the collaborative process in the front-end and back-end interaction process, reduce the consumption of development resources, and improve the project development efficiency; achieve the consistency of the front-end and back-end interface definitions, and avoid interface synchronization errors caused by inconsistent front-end and back-end interface definitions; the incremental update mode provided can accurately convert the interface information that the user expects to update when multiple people use it collaboratively; send the generated front-end programming language file to the storage warehouse for storage each time, and realize the snapshot function, which is convenient for returning to any historical version that has triggered the conversion. Ensure the traceability and recoverability of the historical version of the project.
[0096] In this embodiment, a device for automatically establishing a data model based on an interface document is also provided, and the device is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. The terms "module", "unit", "subunit", etc. used below can implement a combination of software and / or hardware of predetermined functions. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0097] Figure 6 is a structural block diagram of the data model automatic establishment device 60 based on the interface document of this embodiment, as shown in Figure 6 As shown, the data model automatic establishment device 60 based on the interface document includes: a pre-processing module 62, a construction module 64 and a generation module 66; wherein:
[0098] The preprocessing module 62 is used to preprocess the original data of the target interface information file to obtain metadata; the construction module 64 is used to construct a preset tree data structure according to the metadata; wherein the tree data structure is used to store a string set; the generation module 66 is used to generate a front-end programming language file based on the traversal of the tree data structure.
[0099] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0100] In this embodiment, a data model automatic establishment system 70 based on interface documents is also provided. Figure 7 70 is a schematic diagram of the structure of the data model automatic establishment system 70 based on the interface document of this embodiment. Figure 7As shown, it includes: a back-end device 72 and a front-end device 74; wherein: the back-end device 72 is used to generate an interface information file for interaction; the front-end device 74 is used to call a preset script program to execute the automatic data model establishment method based on the interface document provided in any of the above embodiments.
[0101] The above-mentioned data model automatic establishment system 70 based on the interface document can realize the accurate conversion from the interface information file to the front-end programming language file, simplify the collaborative process during the front-end and back-end interaction, realize the consistency of the front-end and back-end interface definitions, and thus avoid the interface synchronization errors caused by the inconsistent front-end and back-end interface definitions.
[0102] In this embodiment, an electronic device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0103] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0104] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0105] S1, preprocessing the original data of the target interface information file to obtain metadata;
[0106] S2, constructing a preset tree data structure according to the metadata; wherein the tree data structure is used to store a string set;
[0107] S3, generates front-end programming language files based on the traversal of the tree data structure.
[0108] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and will not be repeated in this embodiment.
[0109] It should be understood that the specific embodiments described herein are only used to explain the application, rather than to limit it. Based on the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of this application.
[0110] 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 used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0111] Obviously, the drawings are only some examples or embodiments of the present application. For ordinary technicians in the field, the present application can also be applied to other similar situations based on these drawings without creative work. In addition, it is understandable that although the work done in this development process may be complicated and lengthy, for ordinary technicians in the field, certain changes in design, manufacturing or production based on the technical content disclosed in this application are only conventional technical means and should not be regarded as insufficient content disclosed in this application.
[0112] The term "embodiment" in this application refers to a specific feature, structure or characteristic described in conjunction with the embodiment that can be included in at least one embodiment of the present application. The appearance of this phrase in various locations in the specification does not necessarily mean the same embodiment, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. It is clearly or implicitly understood by those of ordinary skill in the art that the embodiments described in this application can be combined with other embodiments without conflict.
[0113] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of patent protection. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the attached claims.
Claims
1. A method for automatically establishing a data model based on an interface document, characterized in that: include: Preprocessing the original data of the target interface information file to obtain metadata, wherein the metadata includes various URL paths; By traversing the metadata, a prefix tree is constructed according to the various URL paths; Each node in the prefix tree stores a character, and each character stores a subpath in the URL path; The prefix tree is used to store a string set; Traversing each node in the prefix tree to obtain the type of each node; The types of nodes include: root node type, parent node type, child node type and namespace node type; According to the different types of each node, different code generation logics are used to generate code snippet strings; then the generated code snippet strings are written into the memory in sequence according to the order of traversal access to generate a front-end programming language file.
2. The method for automatically establishing a data model based on an interface document according to claim 1, characterized in that: Before preprocessing the original data of the target interface information file to obtain the metadata, the method further includes: Determine whether there is a configuration file corresponding to the latest interface information file; if so, merge the latest historical version file of the interface information file with the latest interface information file to obtain the target interface information file; the configuration file indicates the interface information that needs to be converted.
3. The method for automatically establishing a data model based on an interface document according to claim 2, characterized in that: If the configuration file does not exist, the method further includes: The latest interface information file is used as the target interface information file.
4. The method for automatically establishing a data model based on an interface document according to claim 1, characterized in that: The step of writing the generated code snippet strings into the memory in sequence according to the order of traversal access to generate the front-end programming language file comprises: According to the order of traversing the prefix tree, concatenate the code snippet strings to form a complete data model string; The data model character string is formatted to obtain the front-end programming language file.
5. The method for automatically establishing a data model based on an interface document according to any one of claims 1 to 4, characterized in that: The method further comprises: The front-end programming language file is published to a storage warehouse, and the front-end programming language file is pulled from the storage warehouse and installed in an associated project development directory.
6. A data model automatic establishment device based on interface documents, characterized in that: include: Preprocessing module, construction module and generation module; among them: The preprocessing module is used to preprocess the original data of the target interface information file to obtain metadata, wherein the metadata includes various URL paths; The construction module is used to construct a prefix tree according to the various URL paths by traversing the metadata; each node in the prefix tree stores a character, and each character stores a subpath in the URL path; the prefix tree is used to store a string set; The generation module is used to traverse each node in the prefix tree to obtain the type of each node; the node types include: root node type, parent node type, child node type and namespace node type; according to the different types of each node, different code generation logics are used to generate code snippet strings; and then the generated code snippet strings are written into the memory in sequence according to the order of traversal access to generate a front-end programming language file.
7. A data model automatic establishment system based on interface documents, characterized in that: include: Back-end equipment and front-end equipment; among which: The backend device is used to generate an interface information file for interaction; The front-end device is used to call a preset script program to execute the method for automatically establishing a data model based on an interface document as described in any one of claims 1 to 5.
8. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the method for automatically establishing a data model based on an interface document according to any one of claims 1 to 5.
Citation Information
Patent Citations
System and method for generating HTTP request code based on interface document
CN114816356A
Code generation method and device based on syntax tree, electronic equipment and storage medium
CN115016793A
