Api data import method and system, and mock data generation method
Patent Information
- Application Number
- CN201911286100.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-13
- Publication Date
- 2026-09-11
- Estimated Expiration
- 2039-12-13
AI Technical Summary
[0003]本领域中,Mock测试指的是在测试过程中,对于某些不容易构造或者不容易获取的对象,用一个虚拟的对象来创建以便测试的测试方法,现有的导入方案导入的数据只有API数据,Mock数据需要系统根据接口数据的类型进行实时生成,并且生成的数据不一定满足开发者的需求,再次修改Mock规则会平添开发者工作量
[0102] On the one hand, this invention preprocesses API data according to specific rules, including filling in key values and describing hierarchical relationships. This allows it to traverse and classify the data in the imported API data into data types that reflect hierarchical relationships and to annotate relationship bindings. These two processing methods preserve all hierarchical relationships in the API data, eliminating the need for manual classification and improving the efficiency of data import and saving. On the other hand, this invention aggregates sample data written by developers for the returned data to generate mock data for the corresponding interface. This avoids automatically generated data from the system not meeting developer needs and prevents developers from modifying mock rules again, thus improving development efficiency.
Smart Images

Figure CN111177240B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data import technology, and in particular to an API data import method, an API data import system, and a Mock data generation method. Background Technology
[0002] Importing API data is a common function of API management platforms / systems. However, existing solutions only support importing data from the first-level directory. This is especially problematic for importing data from older projects, many of which have massive amounts of data. As a result, all other directories under the first-level directory are discarded by default, and the hierarchy of API data within the first-level directory is flattened. This leads to thousands of data entries appearing in a single first-level directory, requiring users to manually categorize them.
[0003] In this field, Mock testing refers to a testing method that uses a virtual object to test certain objects that are not easy to construct or obtain. Existing import schemes only import API data, while Mock data needs to be generated in real time by the system based on the type of interface data. Furthermore, the generated data may not meet the needs of developers, and modifying the Mock rules again will increase the workload of developers. Summary of the Invention
[0004] In view of this, the present invention aims to propose an API data import method, an API data import system, and a Mock data generation method, which can improve the import efficiency of interface data, retain all hierarchical relationships of the import, and avoid developers from modifying the Mock rules twice, thereby improving development efficiency.
[0005] To achieve the above objectives, the present invention discloses the following:
[0006] An API data import method includes:
[0007] The API data is preprocessed according to preset rules to obtain the hierarchical relationship of the data in the API data;
[0008] Import the API data;
[0009] The data type is labeled according to the hierarchical relationship obtained from the preprocessing;
[0010] Based on the hierarchical relationship obtained from the preprocessing, relationship binding labels are added to the data. The relationship binding labels are used to mark data that has the hierarchical relationship with the data.
[0011] Save the data, the data type corresponding to the data, and the relationship binding label of the data.
[0012] Furthermore, the preprocessing of the API data according to preset rules to obtain the hierarchical relationship of the data in the API data includes:
[0013] For the API data, a first field is added to describe the data that have a parent-child relationship, and the attribute of the first field is an array.
[0014] Furthermore, the preprocessing of the API data according to preset rules to obtain the hierarchical relationship of the data in the API data also includes:
[0015] Identify the key values in the API data;
[0016] Before labeling the data type according to the hierarchical relationship obtained from the preprocessing, the method further includes:
[0017] Verify the key value. If the API data has a complete key value, continue; otherwise, stop.
[0018] Furthermore, the key values include at least one of the following: interface title, interface path, interface protocol, default HTTP, interface request method, query parameters, return value type, example fields of the return value, and request body.
[0019] Further, the step of labeling the data type based on the hierarchical relationship obtained through preprocessing includes:
[0020] If the data with child levels is determined to be of directory data type, then it is of interface data type.
[0021] Further, based on the hierarchical relationship obtained through preprocessing, relationship binding annotations are added to the data, including:
[0022] For data that is a child of the data type in the directory, mark the data of its parent.
[0023] Furthermore, before adding relationship binding labels to the data based on the hierarchical relationship obtained through preprocessing, the process also includes:
[0024] Assign a unique ID to the data;
[0025] Based on the hierarchical relationship obtained from the preprocessing, relationship binding labels are added to the data, including:
[0026] For data of the directory data type, label the ID of the data in its parent category.
[0027] Furthermore, the step of labeling the data type based on the hierarchical relationship obtained through preprocessing also includes:
[0028] A second field is used to mark the data type corresponding to the data, wherein when the data is marked as X, the data is a directory data type; when the data is marked as Y, the data is an interface data type, and X and Y are natural numbers.
[0029] Furthermore, after labeling the data type according to the hierarchical relationship obtained from the preprocessing, the method further includes:
[0030] Store the data of the interface data type, and the data type of that data;
[0031] The process of saving the data, along with the corresponding data type and relationship binding annotation, includes:
[0032] Store the data of the directory data type, as well as the data of the data type and the data of the corresponding parent.
[0033] Furthermore, the importing of the API data further includes:
[0034] Select the corresponding item for the API data.
[0035] This invention also discloses an API data import system, comprising:
[0036] The preprocessing module is used to preprocess the API data according to preset rules in order to obtain the hierarchical relationship of the data in the API data.
[0037] The import module is used to import the API data.
[0038] The classification module is used to label the data type according to the hierarchical relationship obtained by the preprocessing.
[0039] The binding annotation module is used to add relationship binding annotations to the data according to the hierarchical relationship obtained by the preprocessing. The relationship binding annotations are used to mark data that has the hierarchical relationship with the data.
[0040] The storage module is used to store the data, the corresponding data type, and the relationship binding annotation.
[0041] Furthermore, the preprocessing module is specifically used for:
[0042] For the API data, a first field is added to describe the data that have a parent-child relationship, and the attribute of the first field is an array.
[0043] Furthermore, the preprocessing module is also used for:
[0044] Identify the key values in the API data;
[0045] The classification module is also used for:
[0046] Verify the key value. If the API data has a complete key value, continue; otherwise, stop.
[0047] Furthermore, the key values include at least one of the following: interface title, interface path, interface protocol, default HTTP, interface request method, query parameters, return value type, example fields of the return value, and request body.
[0048] Furthermore, the classification module is specifically used for:
[0049] If the data with child levels is determined to be of directory data type, then it is of interface data type.
[0050] Furthermore, the binding annotation module is specifically used for:
[0051] For data that is a child of the data type in the directory, mark the data of its parent.
[0052] Furthermore, the binding and labeling module is also used to assign a unique ID to the data;
[0053] The binding annotation module is used to add relationship binding annotations to the data based on the hierarchical relationship obtained through preprocessing. The relationship binding annotations are used to mark data that has the hierarchical relationship with the data, including:
[0054] For data of the directory data type, label the ID of the data in its parent category.
[0055] Furthermore, the classification module is also used for:
[0056] A second field is used to mark the data type corresponding to the data, wherein when the data is marked as X, the data is a directory data type; when the data is marked as Y, the data is an interface data type, and X and Y are natural numbers.
[0057] Furthermore, the storage module is also used to store the data of the interface data type and the data type of the data after the classification module labels the data according to the hierarchical relationship obtained by the preprocessing;
[0058] The storage module is used to store the data, the corresponding data type, and the relationship binding annotation, including:
[0059] Store the data of the directory data type, as well as the data of the data type and the data of the corresponding parent.
[0060] Furthermore, the import module is also used to select the corresponding item for the API data.
[0061] This invention also discloses a method for generating mock data, comprising:
[0062] The API data is preprocessed according to preset rules to obtain the hierarchical relationship of the data in the API data and to determine the key values in the API data; wherein the key values include: return value type and example fields of return value;
[0063] Import the API data;
[0064] The data type is labeled according to the hierarchical relationship obtained from the preprocessing;
[0065] Parse the return value of the API data to obtain the example field;
[0066] Based on the hierarchical relationship obtained from the preprocessing, relationship binding labels are added to the data. The relationship binding labels are used to mark data that has the hierarchical relationship with the data.
[0067] Save the data, along with the corresponding data type and relationship binding annotations;
[0068] Obtain the mapping relationship between the example fields and the corresponding API data, and construct the mock data according to the structure of the return value;
[0069] Obtain the Mock data and the corresponding data from the API, and save the Mock data and the data.
[0070] Further, the step of labeling the data type based on the hierarchical relationship obtained through preprocessing includes:
[0071] If the data with child elements is determined to be a directory data type, then it is an interface data type.
[0072] The process of parsing the return value of the API data to obtain the example fields includes:
[0073] Parse the return value of the current interface data and obtain the example field corresponding to the returned field if and only if the data being iterated is an interface type.
[0074] Further, based on the hierarchical relationship obtained through preprocessing, relationship binding labels are added to the data. These relationship binding labels are used to mark data that has the hierarchical relationship with the data. This process also includes:
[0075] Assign a unique ID to the data;
[0076] The step of obtaining the Mock data and the corresponding data in the API, and saving the Mock data and the data, includes:
[0077] Obtain the Mock data and the corresponding ID of the data, and save the Mock data and the ID.
[0078] This invention also discloses a Mock data generation system, comprising:
[0079] The preprocessing module is used to preprocess the API data according to preset rules to obtain the hierarchical relationship of the data in the API data and to determine the key values in the API data; wherein the key values include: return value type and example fields of the return value;
[0080] The import module is used to import the API data.
[0081] The classification module is used to label the data type according to the hierarchical relationship obtained by the preprocessing.
[0082] The parsing module is used to parse the return value of the API data and obtain the example field;
[0083] The binding annotation module adds relationship binding annotations to the data based on the hierarchical relationship obtained from the preprocessing. The relationship binding annotations are used to mark data that has the hierarchical relationship with the data.
[0084] The storage module is used to store the data, the corresponding data type, and the relationship binding annotation;
[0085] The data construction module is used for:
[0086] Obtain the mapping relationship between the example fields and the corresponding API data, and construct the mock data according to the structure of the return value;
[0087] In addition, the Mock data and the corresponding data in the API are obtained, and the Mock data and the data are saved.
[0088] Furthermore, the classification module is specifically used for:
[0089] If the data with child elements is determined to be a directory data type, then it is an interface data type.
[0090] The parsing module is specifically used for:
[0091] Parse the return value of the current interface data and obtain the example field corresponding to the returned field if and only if the data being iterated is an interface type.
[0092] Furthermore, before adding relationship binding labels to the data based on the hierarchical relationship obtained through preprocessing, the binding labeling module is also used for:
[0093] Assign a unique ID to the data;
[0094] The data construction module is specifically used for:
[0095] Obtain the Mock data and the corresponding ID of the data, and save the Mock data and the ID.
[0096] The present invention also discloses a computer-readable storage medium storing a computer program for executing the API data import method and the Mock data generation method described in any of the above embodiments.
[0097] The present invention also discloses an electronic device, the electronic device comprising:
[0098] processor;
[0099] Memory used to store the processor's executable instructions;
[0100] The processor is configured to read the executable instructions from the memory and execute the instructions to implement the API data import method and the Mock data generation method as described in any of the above embodiments.
[0101] The present invention has at least the following beneficial effects:
[0102] On the one hand, this invention preprocesses API data according to specific rules, including filling in key values and describing hierarchical relationships. This allows it to traverse and classify the data in the imported API data into data types that reflect hierarchical relationships and to annotate relationship bindings. These two processing methods preserve all hierarchical relationships in the API data, eliminating the need for manual classification and improving the efficiency of data import and saving. On the other hand, this invention aggregates sample data written by developers for the returned data to generate mock data for the corresponding interface. This avoids automatically generated data from the system not meeting developer needs and prevents developers from modifying mock rules again, thus improving development efficiency.
[0103] Other features and advantages of the present invention will be described in detail in the following detailed description section. Attached Figure Description
[0104] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an improper limitation of the invention.
[0105] In the attached diagram:
[0106] Figure 1 This is a flowchart of the API data import method according to an embodiment of the present invention;
[0107] Figure 2 This is a flowchart illustrating the data parsing process of an embodiment of the present invention.
[0108] Figure 3 This is a flowchart of the Mock data generation method according to an embodiment of the present invention. Detailed Implementation
[0109] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the scope of the present invention.
[0110] like Figure 1 The API data import method shown includes the following steps:
[0111] (1) Preprocess the API data according to preset rules to obtain the hierarchical relationship of the data in the API data;
[0112] (2) Import the API data;
[0113] (3) Label the data type according to the hierarchical relationship obtained from the preprocessing;
[0114] (4) Based on the hierarchical relationship obtained from the preprocessing, add relationship binding labels to the data, wherein the relationship binding labels are used to mark data that has the hierarchical relationship with the data;
[0115] (5) Save the data and the corresponding data type and relationship binding label.
[0116] In some embodiments of the present invention, the preprocessing of API data according to preset rules to obtain the hierarchical relationship of data in the API data includes:
[0117] For the API data, data with parent-child relationships are described using a nested first field, where the attribute of the first field is an array. For example, if the current data contains children, it is marked by adding a `list` field, where the `list` attribute is an array. If it contains child nodes, the child nodes are stored in the array, and the child nodes can further mark their lower-level relationships using the `list` field. For example, data A is the parent of B, and B is the child of A, which can be represented by equation ① for ease of understanding:
[0118] A(listB) ①;
[0119] If data B also includes child C, and B is the parent of C, then for ease of understanding, the whole can be represented as equation ②:
[0120] A(listB(listC)) ②;
[0121] It is worth noting that the above examples, for ease of understanding, do not represent the fields that appear in actual programming.
[0122] In addition to the preprocessing described above, the API data should also undergo the following preprocessing, including:
[0123] The key values in the API data are determined, including: API title, API path, API protocol, default HTTP, API request method, Query parameters, return value type, example fields of the return value, and request body. These key values are mandatory fields in the API data because the system needs to generate API data that meets the conditions according to the preprocessing rules of the above data when importing external data. If custom mock data needs to be generated, the `example` field needs to be set in the return value.
[0124] After importing API data, it is necessary to verify whether the pre-processed API data conforms to the specifications, that is, to verify the key values. If the API data has complete key values, then proceed; otherwise, stop. Specifically, two aspects are verified: First, whether the API data conforms to the aforementioned data specifications. When the data format does not conform to the data specifications defined in the pre-processing, parsing terminates and a format error message is returned to the developer. Second, if the data format conforms to the data specifications, then the specific key values are verified. If the field corresponding to the key value is missing, the current record will be skipped and not stored.
[0125] In some embodiments of the present invention, the step of labeling the data type according to the hierarchical relationship obtained by the preprocessing includes:
[0126] If the data has child levels, it is determined that the data is a directory data type; otherwise, the data is an interface data type. By determining the data type of each piece of data, the position of the data in the hierarchical relationship is determined to a certain extent. Then, by combining the relationship binding annotations of the data, all hierarchical relationships in the API data can be completely obtained. For example, in the hierarchical relationship expressed in equation ②, data A and B are both marked with child levels by the `list` field; therefore, data A and B belong to the directory data type. Data C, however, has no corresponding child levels, so it belongs to the interface data type.
[0127] In some special cases, although the data may be labeled with a list field, it may not contain any actual content. For example, in equation ③:
[0128] A(listB(list)) ③;
[0129] Although data B is labeled using the first field, its content is empty. In this case, it will be determined that data B has no children. Therefore, in equation ③, A belongs to the directory data type, and B belongs to the interface data type.
[0130] In some embodiments of the present invention, based on the hierarchical relationship obtained by the preprocessing, relational binding annotations are added to the data, including: for data whose hierarchical relationship with the directory data type is that of a child, the parent data is annotated. For API data, combining data type and relational binding annotations can form a description of the hierarchical relationship between data in a way different from that of preprocessing. Taking Equation ② above as an example, the parent of data B is A, so data A is used to annotate its relational binding. As can be seen from the above description, B is a directory data type, which must have children; data C is an interface data type, which has no children, so its relational binding annotation is data B; data A of the directory data type is first-level / primary data, which has no parent, so its relational binding annotation is empty. Through the above relatively independent annotations of data A, B, and C, the hierarchical relationship between the three can be obtained through combination analysis, i.e., Equation ②.
[0131] In some embodiments of the present invention, in practical applications, the data is often quite large, which will occupy a large amount of storage space and slow down the processing speed. Therefore, it is necessary to simplify the data. Specifically, a unique ID is assigned to the data. When adding relationship binding labels, for data of the directory data type, it is only necessary to label the ID of the parent data. It is not necessary to label all the data content.
[0132] In some embodiments of the present invention, the step of labeling the data type according to the hierarchical relationship obtained by the preprocessing further includes: using a second field to label the data type corresponding to the data, wherein when the data is labeled as X, the data is a directory data type; when the data is labeled as Y, the data is an interface data type, and X and Y are natural numbers. For example, the current record type can be labeled by the type field, where type 1 indicates an interface data type and type 0 indicates a directory data type.
[0133] In some embodiments of the present invention, after labeling the data type according to the hierarchical relationship obtained by the preprocessing, the method further includes: saving the data of the interface data type and the data type of the data; when parsing the received API data, all data is traversed, and if it is determined that the data is an interface data type, it can be saved directly without waiting for the traversal to be completed, which helps to improve processing efficiency. For saving the data of the directory data type, it is also necessary to traverse its child levels and subsequent levels, and the specific processing method is the same as the processing method for the first level of data described above, until all data in the API data has been traversed.
[0134] In some embodiments of the present invention, APIs are often the main data of a project that the developer is working on. Therefore, after importing the API data, the method further includes selecting the corresponding project for the API data for easy management.
[0135] This invention also discloses an API data import system, comprising:
[0136] The preprocessing module is used to preprocess the API data according to preset rules in order to obtain the hierarchical relationship of the data in the API data.
[0137] The import module is used to import the API data.
[0138] The classification module is used to label the data type according to the hierarchical relationship obtained by the preprocessing.
[0139] The binding annotation module is used to add relationship binding annotations to the data according to the hierarchical relationship obtained by the preprocessing. The relationship binding annotations are used to mark data that has the hierarchical relationship with the data.
[0140] The storage module is used to store the data, the corresponding data type, and the relationship binding annotation.
[0141] In some embodiments of the present invention, the preprocessing module is specifically used for:
[0142] For the API data, a first field is added to describe the data that have a parent-child relationship, and the attribute of the first field is an array.
[0143] In some embodiments of the present invention, the preprocessing module is further configured to:
[0144] Identify the key values in the API data;
[0145] The classification module is also used for:
[0146] Verify the key value. If the API data has a complete key value, continue; otherwise, stop.
[0147] In some embodiments of the present invention, the key values include: interface title, interface path, interface protocol, default HTTP, interface request method, query parameters, return value type, example fields of the return value, and request body.
[0148] In some embodiments of the present invention, the classification module is specifically used for:
[0149] If the data with child levels is determined to be of directory data type, then it is of interface data type.
[0150] In some embodiments of the present invention, the binding annotation module is specifically used for:
[0151] For data that is a child of the data type in the directory, mark the data of its parent.
[0152] In some embodiments of the present invention, the binding and labeling module is further configured to assign a unique ID to the data;
[0153] The binding annotation module is used to add relationship binding annotations to the data according to the hierarchical relationship obtained by preprocessing, to indicate data that has the hierarchical relationship with the data, including:
[0154] For data of the directory data type, label the ID of the data in its parent category.
[0155] In some embodiments of the present invention, the classification module is further configured to:
[0156] A second field is used to mark the data type corresponding to the data, wherein when the data is marked as X, the data is a directory data type; when the data is marked as Y, the data is an interface data type, and X and Y are natural numbers.
[0157] In some embodiments of the present invention, the storage module is further configured to store the data of the interface data type and the data type of the data after the classification module labels the data type of the data according to the hierarchical relationship obtained by the preprocessing;
[0158] The storage module is used to store the data, the corresponding data type, and the relationship binding annotation, including:
[0159] Store the data of the directory data type, as well as the data of the data type and the data of the corresponding parent.
[0160] In some embodiments of the present invention, the import module is further configured to select a corresponding item for the API data.
[0161] like Figure 3 As shown, this invention also discloses a method for generating Mock data, which needs to be implemented based on the above-mentioned API data import method. Its principle lies in aggregating the example fields of the returned fields to form customized Mock data for the current interface, specifically including:
[0162] The API data is preprocessed according to preset rules to obtain the hierarchical relationship of the data in the API data and to determine the key values in the API data; wherein the key values include: return value type and example fields of return value;
[0163] Import the API data;
[0164] The data type is labeled according to the hierarchical relationship obtained from the preprocessing;
[0165] Parse the return value of the API data to obtain the example field;
[0166] Based on the hierarchical relationship obtained from the preprocessing, relationship binding labels are added to the data. The relationship binding labels are used to mark data that has the hierarchical relationship with the data.
[0167] Save the data, along with the corresponding data type and the relationship binding label.
[0168] Obtain the mapping relationship between the example fields and the corresponding API data, and construct the mock data according to the structure of the return value;
[0169] Obtain the Mock data and the corresponding data from the API, and save the Mock data and the data.
[0170] In some embodiments of the present invention, the step of labeling the data type according to the hierarchical relationship obtained by the preprocessing includes:
[0171] If the data with child elements is determined to be a directory data type, then it is an interface data type.
[0172] The process of parsing the return value of the API data to obtain the example fields includes:
[0173] Parse the return value of the current interface data and obtain the example field corresponding to the returned field if and only if the data being iterated is an interface type.
[0174] In some embodiments of the present invention, relationship binding labels are added to the data based on the hierarchical relationship obtained through preprocessing, and the process further includes:
[0175] Assign a unique ID to the data;
[0176] The step of obtaining the Mock data and the corresponding data in the API, and saving the Mock data and the data, includes:
[0177] Obtain the Mock data and the corresponding ID of the data, and save the Mock data and the ID.
[0178] This invention also discloses a Mock data generation system, comprising:
[0179] The preprocessing module is used to preprocess the API data according to preset rules to obtain the hierarchical relationship of the data in the API data and to determine the key values in the API data; wherein the key values include: return value type and example fields of the return value;
[0180] The import module is used to import the API data.
[0181] The classification module is used to label the data type according to the hierarchical relationship obtained by the preprocessing.
[0182] The parsing module is used to parse the return value of the API data and obtain the example field;
[0183] The binding annotation module adds relationship binding annotations to the data based on the hierarchical relationship obtained from the preprocessing. The relationship binding annotations are used to mark data that has the hierarchical relationship with the data.
[0184] The storage module is used to store the data, the corresponding data type, and the relationship binding annotation;
[0185] The data construction module is used for:
[0186] Obtain the mapping relationship between the example fields and the corresponding API data, and construct the mock data according to the structure of the return value;
[0187] In addition, the Mock data and the corresponding data in the API are obtained, and the Mock data and the data are saved.
[0188] In some embodiments of the present invention, the classification module is specifically used for:
[0189] If the data with child elements is determined to be a directory data type, then it is an interface data type.
[0190] The parsing module is specifically used for:
[0191] Parse the return value of the current interface data and obtain the example field corresponding to the returned field if and only if the data being iterated is an interface type.
[0192] In some embodiments of the present invention, before adding relationship binding labels to the data according to the hierarchical relationship obtained through preprocessing, the binding labeling module is further configured to:
[0193] Assign a unique ID to the data;
[0194] The data construction module is specifically used for:
[0195] Obtain the Mock data and the corresponding ID of the data, and save the Mock data and the ID.
[0196] The present invention also discloses a computer-readable storage medium storing a computer program for executing the API data import method and the Mock data generation method described in any of the above embodiments.
[0197] The present invention also discloses an electronic device, the electronic device comprising:
[0198] processor;
[0199] Memory used to store the processor's executable instructions;
[0200] The processor is configured to read the executable instructions from the memory and execute the instructions to implement the API data import method and the Mock data generation method as described in any of the above embodiments.
[0201] To facilitate a better understanding of the present invention, detailed descriptions will be provided below based on embodiments that embody the above-described technical features of the present invention.
[0202] Example
[0203] To achieve complete and rapid import of API data and generation of mocks, this embodiment includes the following process:
[0204] I. Design Data Specifications
[0205] This specification can be used for preprocessing API data, as well as for validating and parsing API data after importation.
[0206] 1. Define the API data fields, i.e., determine the key values, including: API title, API path, API protocol (default HTTP), API request method, Query parameters, return value type (with the `example` field serving as the sample field in the return value), and request body. These are the required fields for API data. When importing external data, you need to generate API data that meets these criteria according to these data rules. If you need to generate custom mock data, you need to set the `example` field in the return value.
[0207] 2. Determine the data hierarchy association rules
[0208] If the current data contains child nodes, they are marked by adding a list field. The list attribute is an array. If it contains child nodes, the child nodes are stored in the array. Child nodes can continue to mark their subordinate relationships through the list field.
[0209] II. Design Data Storage Rules
[0210] The stored records in the database are divided into interface data (type) and directory data (type). The current record type is marked by the type field. When type is 1, it is interface data, and when type is 0, it is directory data. The unique ID generated when each record is stored in the database is the unique credential for retrieval.
[0211] Both interface data and directory data need to have a parent field added. When the data obtained through traversal is interface data, it is stored directly. Under the first level / level data, the parent field is empty. If the data obtained through traversal is a directory attribute, it is saved as directory data. Similarly, the parent field is empty. If the child list attribute of the current directory is not empty, the child list data is traversed.
[0212] When storing child data, the parent field should be the record ID of the parent node stored in the database. When traversing the directory data, repeat the above steps to traverse again, and store the database ID of the current data storage as the content of the parent field.
[0213] III. Design a data parsing scheme
[0214] Based on the rules in points one and two above, it is able to parse API data.
[0215] First, users need to select the project from which the data is imported and determine the relationship between the API data and the corresponding project.
[0216] like Figure 2 As shown, according to the established data specifications, the parsed API data is a nested API array. Before data parsing, the data format and required fields need to be validated. If the data format does not conform to the data specifications established above, the parsing will terminate and return a format error message to the developer. If the data format conforms to the specifications but the required fields are missing, the current record will be skipped and stored.
[0217] After the data format validation passes, the array is traversed. When the current data is obtained, the data type is first determined. If the current data object contains a list property, the current data is stored as a directory type; otherwise, it is API data. The array is traversed one level at a time. When the data obtained is API data, it is stored directly. If the data obtained is a directory property, the data is saved, and the child list of the current directory data is checked for emptiness. If it is not empty, the child list data is traversed. After the child list is traversed, the current level array is traversed again.
[0218] When traversing the next level array, the traversal method is the same as above. If it is interface data, it is stored normally. If it is directory data, the child list of the directory data is traversed, and the traversal method repeats the third step.
[0219] IV. Mock Aggregation Solution
[0220] When iterating through imported data, the return value of the current interface data is parsed and the example field of the corresponding returned field is obtained only if the data being iterated is of an interface type.
[0221] The example and API data are stored and then assigned IDs, which are then mapped and constructed according to the structure of the returned data to obtain the customized Mock data corresponding to the interface.
[0222] After data storage, the record ID stored in the database is obtained, and the record ID and the Mock data constructed in the previous step are stored in the database.
[0223] The optional embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the embodiments of the present invention are not limited to the specific details in the above embodiments. Within the scope of the technical concept of the embodiments of the present invention, various simple modifications can be made to the technical solutions of the embodiments of the present invention, and these simple modifications all fall within the protection scope of the embodiments of the present invention.
[0224] It should also be noted that the various specific technical features described in the above embodiments can be combined in any suitable manner without contradiction. To avoid unnecessary repetition, the embodiments of the present invention will not describe the various possible combinations separately.
[0225] Those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing related hardware. This program is stored in a storage medium and includes several instructions to cause a microcontroller, chip, or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0226] Furthermore, various different implementations of the present invention can be combined arbitrarily, as long as they do not violate the spirit of the present invention, they should also be regarded as the content disclosed in the present invention.
Claims
1. An API data import method, characterized in that, include: The API data is preprocessed according to preset rules to obtain the hierarchical relationship of the data in the API data; Import the API data; The data type is labeled according to the hierarchical relationship obtained from the preprocessing; including: If the data with child levels is determined to be a directory data type, then it is an interface data type. Assign a unique ID to the data, and add a relationship binding label to the data according to the hierarchical relationship obtained by the preprocessing. The relationship binding label is used to mark data that has the hierarchical relationship with the data. Based on the hierarchical relationship obtained from the preprocessing, relationship binding labels are added to the data, including: For data that is a child of the data type in the directory, mark the data of its parent. For data of the directory data type, mark the ID of the data in its parent category; Store the data of the interface data type, and the data type of that data; and Store the data of the directory data type, as well as the data of the data type and the data of the corresponding parent of the data; The process of preprocessing the API data according to preset rules to obtain the hierarchical relationship of the data in the API data includes... For the API data, data with a parent-child relationship are described using a nested first field, where the attribute of the first field is an array; and Identify the key values in the API data; Before labeling the data type based on the hierarchical relationship obtained from the preprocessing, the method further includes: verifying the key value; if the API data has a complete key value, then continue; otherwise, stop.
2. The API data import method according to claim 1, characterized in that, The key values include at least one of the following: interface title, interface path, interface protocol, default HTTP, interface request method, query parameters, return value type, example fields of the return value, and request body.
3. The API data import method according to claim 1, characterized in that, The step of labeling the data type according to the hierarchical relationship obtained from the preprocessing also includes: A second field is used to mark the data type corresponding to the data, wherein when the data is marked as X, the data is a directory data type; when the data is marked as Y, the data is an interface data type, and X and Y are natural numbers.
4. The API data import method according to claim 1, characterized in that, After importing the API data, the process further includes selecting the corresponding item for the API data.
5. An API data import system, characterized in that, include: The preprocessing module is used to preprocess the API data according to preset rules in order to obtain the hierarchical relationship of the data in the API data. The import module is used to import the API data. A classification module is used to label the data type based on the hierarchical relationship obtained through preprocessing; it includes: If the data with child levels is determined to be a directory data type, then it is an interface data type. The binding and labeling module is used to assign a unique ID to the data and add relationship binding labels to the data according to the hierarchical relationship obtained by the preprocessing. The relationship binding labels are used to mark data that has the hierarchical relationship with the data. Based on the hierarchical relationship obtained from the preprocessing, relationship binding labels are added to the data, including: For data that is a child of the data type in the directory, mark the data of its parent. For data of the directory data type, mark the ID of the data in its parent category; A storage module is used to store data of the interface data type, and the data type of that data; and Store the data of the directory data type, as well as the data of the data type and the data of the corresponding parent of the data; The preprocessing module is specifically used for: adding a first field to the data in the API data that have a parent-child relationship for nested description, wherein the attribute of the first field is an array; and determining the key values in the API data. The classification module is further configured to: verify the key value; if the API data has a complete key value, then continue; otherwise, stop.
6. The API data import system according to claim 5, characterized in that, The key values include at least one of the following: interface title, interface path, interface protocol, default HTTP, interface request method, query parameters, return value type, example fields of the return value, and request body.
7. The API data import system according to claim 5, characterized in that, The classification module is further configured to: use a second field to mark the data type corresponding to the data, wherein when the data is marked as X, the data is a directory data type; when the data is marked as Y, the data is an interface data type, and X and Y are natural numbers.
8. The API data import system according to claim 5, characterized in that, The import module is also used to select the corresponding item for the API data.
9. A method for generating mock data, characterized in that, include: The API data is preprocessed according to preset rules to obtain the hierarchical relationship of the data in the API data and to determine the key values in the API data; The key values mentioned include: return value type and example fields of the return value; Import the API data; The data type is labeled according to the hierarchical relationship obtained from the preprocessing; Parse the return value of the API data to obtain the example field; Assign a unique ID to the data, and add a relationship binding label to the data according to the hierarchical relationship obtained by the preprocessing. The relationship binding label is used to mark data that has the hierarchical relationship with the data. Save the data, along with the corresponding data type and relationship binding annotations; Obtain the mapping relationship between the example fields and the corresponding API data, and construct the mock data according to the structure of the return value; Obtain the Mock data and the corresponding data from the API, and save the Mock data and the data; The step of labeling the data type according to the hierarchical relationship obtained from the preprocessing includes: If the data with child levels is determined to be a directory data type, then it is an interface data type. The step of parsing the return value of the API data and obtaining the example field includes: parsing the return value of the current interface data and obtaining the example field corresponding to the returned field if and only if the data being traversed is an interface type.
10. The Mock data generation method according to claim 9, characterized in that, The step of obtaining the Mock data and the corresponding data in the API, and saving the Mock data and the data, includes: obtaining the Mock data and the corresponding ID of the data, and saving the Mock data and the ID.
11. A mock data generation system, characterized in that, include: The preprocessing module is used to preprocess the API data according to preset rules in order to obtain the hierarchical relationship of the data in the API data and to determine the key values in the API data. The key values mentioned include: return value type and example fields of the return value; The import module is used to import the API data. The classification module is used to label the data type according to the hierarchical relationship obtained by the preprocessing. The parsing module is used to parse the return value of the API data and obtain the example field; The binding and labeling module is used to assign a unique ID to the data and add relationship binding labels to the data according to the hierarchical relationship obtained by the preprocessing. The relationship binding labels are used to mark data that has the hierarchical relationship with the data. The storage module is used to store the data, the corresponding data type, and the relationship binding annotation; The data construction module is used for: Obtain the mapping relationship between the example fields and the corresponding API data, and construct the mock data according to the structure of the return value; In addition, the Mock data and the corresponding data in the API are obtained, and the Mock data and the data are saved; The classification module is specifically used to: determine whether the data with child levels is a directory data type; otherwise, it is an interface data type; The parsing module is specifically used to: parse the return value of the current interface data and obtain the example field corresponding to the returned field if and only if the data being traversed is an interface type.
12. The Mock data generation system according to claim 11, characterized in that, Before adding relationship binding labels to the data based on the hierarchical relationship obtained from the preprocessing, the binding labeling module is further configured to: Assign a unique ID to the data; The data construction module is specifically used to: obtain the Mock data and the corresponding ID of the data, and save the Mock data and the ID.
13. A computer-readable storage medium storing a computer program for performing the method of any one of claims 1-4, 9, and 10.
14. An electronic device, the electronic device comprising: processor; Memory used to store the processor's executable instructions; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the method of any one of claims 1-4, 9, and 10.
Citation Information
Patent Citations
Multilevel and multidimensional method and device for analyzing data attributes
CN102467559A
API document generating method and system based on SpringMVC
CN107515771A
Server running state monitoring method, device, processor and server
CN109522179A
Test data construction method, device and equipment and computer readable storage medium
CN110297760A