WO2023098043A1 - 一种接口参数校验方法及装置 - Google Patents

一种接口参数校验方法及装置 Download PDF

Info

Publication number
WO2023098043A1
WO2023098043A1 PCT/CN2022/100674 CN2022100674W WO2023098043A1 WO 2023098043 A1 WO2023098043 A1 WO 2023098043A1 CN 2022100674 W CN2022100674 W CN 2022100674W WO 2023098043 A1 WO2023098043 A1 WO 2023098043A1
Authority
WO
WIPO (PCT)
Prior art keywords
interface
data structure
structure model
parameter
variable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2022/100674
Other languages
English (en)
French (fr)
Inventor
张利勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
WeBank Co Ltd
Original Assignee
WeBank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by WeBank Co Ltd filed Critical WeBank Co Ltd
Publication of WO2023098043A1 publication Critical patent/WO2023098043A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3692Test management for test results analysis

Definitions

  • the embodiments of the present application relate to the field of financial technology (Fintech), and in particular to a method and device for verifying interface parameters.
  • the server can provide services to the client
  • the banking industry can greatly reduce the need for users to go to offline physical banks to handle business by developing corresponding online services for their various products. , which improves the user experience.
  • the server-client architecture the server can be understood as the back end, and the client can be understood as the front end.
  • data interaction with the back-end is often carried out by sending interfaces, and during the interaction process, it is inevitable that errors in operation will occur due to errors in the input and output of the interface.
  • an interface test link can be set before releasing the front-end.
  • interface testing requires front-end developers to verify the input and output parameters of each interface according to the data structure description in the interface document written by back-end personnel during the development process.
  • Front-end developers must write specific verification codes for the input and output parameters of each interface according to the interface documents. This process is very time-consuming and laborious.
  • Front-end developers may miss the verification of input and output parameters of some interfaces when writing verification codes.
  • This application provides an interface parameter verification method and device, which are used to automatically verify whether the input and output parameters of the front-end interface during use are correct in real time and in an all-round way, which improves the real-time and comprehensive interface parameter verification. performance and detection efficiency.
  • the embodiment of the present application provides a method for verifying interface parameters, the method including: for the invocation request received by the front-end for the first interface, obtaining the front-end parameter data of the first interface from the front-end and back-end conversion configurations Structural model; the front-end parameter data structure model of any interface in the front-end conversion configuration is generated by parsing each data structure model file in the back-end code and each interface definition file in the back-end code. Based on the data structure model of the back-end parameters of the first interface, the parameters in the call request are verified to determine the correctness of the call request.
  • the front-end when the front-end receives a call request for the first interface, by obtaining the front-end parameter data structure model of the first interface, because the front-end parameter data structure model is based on the back-end parameter data structure model of the first interface converted, and because the back-end parameter data structure model of the first interface is obtained by parsing each data structure model file and each interface definition file in the back-end code, because the back-end parameter of the first interface obtained through analysis
  • the data structure model includes whether the verification parameter is necessary, the type of the parameter, etc.
  • the front-end parameter data structure model of any interface in the front-end and back-end conversion configuration is through the data structure model files in the back-end code and the interface definition files in the back-end code
  • the data structure model of the back-end parameter of the interface generated by analyzing and converting includes: obtaining the data structure model file corresponding to each data structure model file according to the analysis of each data structure model file in the back-end code object; any data structure model file object includes externally exposed classes; according to the analysis of each interface definition file in the back-end code, obtain the externally exposed classes corresponding to each interface; for any interface in each interface, according to For the externally exposed class of the interface, a data structure model file object with the same name as the externally exposed class of the interface is determined from each data structure model file object; according to the data structure model file object, the back end of the interface is generated A parameter data structure model; converting the front-end and back-end parameters to the back-end parameter data structure model of the interface to obtain the front-end parameter data structure model of the
  • the back-end code defines the front-end interface
  • it is divided into two parts, including the data structure model file and the interface definition file.
  • the corresponding data structures can be obtained Model file object, any data structure model file object includes an externally exposed class, and through the analysis of each interface definition file, the externally exposed class corresponding to the interface can be obtained, and then for any interface, through the externally exposed class of the interface
  • the exposed class will be able to match a data structure model file object with the same name from each data structure model file object, and then according to the processing of the matched data structure model file object, the back-end parameter data structure of the interface can be generated
  • the front-end parameter data structure model of the interface is obtained by converting the generated back-end parameter data structure model into a data structure model that the front-end can recognize.
  • the acquisition of data structure model file objects corresponding to each data structure model file according to the analysis of each data structure model file in the back-end code includes: for each data structure model file Any data structure model file of any data structure model file, establish the abstract syntax tree of described data structure model file by javaparse tool; Described abstract syntax tree comprises JCImport node and JCClassDecl node; Obtain first information based on described JCImport node; Said first information Including the variable content and import path of each variable; second information is obtained based on the JCClassDecl node; the second information includes the externally exposed class indicated by the data structure model file and the variable information of each variable inside the externally exposed class ; Using the first information and the second information as the data structure model file object of the data structure model file.
  • the process of how to obtain its data structure model file object by parsing a data structure model file including first establishing the abstract syntax tree of the data structure model file through the javaparse tool, wherein, through the abstract
  • the JCImport node in the syntax tree can obtain the variable content of each variable and its import path.
  • the JCClassDecl node in the abstract syntax tree can obtain the externally exposed class indicated by the data structure model file and the externally exposed class.
  • the variable information of each variable so that the information obtained from the two aspects can be used as the data structure model file object of the data structure model file.
  • the Javaparse tool is used to establish a corresponding abstract syntax tree for any data structure model file, so that the data structure model file object of the data structure model file can be established by analyzing the abstract syntax tree.
  • This method realizes the automatic parsing of the data structure model files in the back-end code that need to be used when defining the interface, and improves the efficiency of interface parameter verification.
  • the variable information includes variable name, variable type and variable annotation name;
  • the generating the back-end parameter data structure model of the interface according to the data structure model file object includes: if The data structure model file object of the interface includes at least one first variable whose variable type is a non-custom type, then the variable information of the first variable is used as the back-end parameter of the interface under the first variable Data structure model; if the data structure model file object of the interface includes at least one second variable whose variable type is a user-defined type, then the obtained based on the import path of the second variable and the second variable The content with the same name is used as the back-end parameter data structure model of the interface under the second variable.
  • a data structure with the same name can be matched from the parsed data structure model file objects Model file object; for the matched data structure model file object, it may contain variables of non-customized types as well as variables of custom types. Therefore, for variables of non-customized types, the variable name can be directly The corresponding variable information is placed under the variable, and for a variable of a user-defined type, the content with the same name as the variable can be obtained through the import path corresponding to the variable, and then the obtained content can be placed under the variable. In this way, the transition from the data structure model file object to the back-end parameter data structure model can be realized.
  • the back-end parameter data structure model into a front-end parameter data structure model that can be recognized by the front-end, it can be based on the front-end parameter data structure.
  • the model is used to quickly and accurately verify the parameters designed in the call request of the interface.
  • each interface includes the input parameter data structure of the data carried when the front end sends the interface request to the back end and the output parameter data structure of the data returned when the back end receives the interface request sent by the front end; Analyzing each interface definition file in the back-end code to obtain the externally exposed class corresponding to each interface, including: for any interface definition file in each interface definition file, obtaining the interface definition file indicated by the interface definition file.
  • the input parameter data structure and the output parameter data structure respectively correspond to the first externally exposed class and the second externally exposed class.
  • the front-end interface verification includes the verification of input parameters and output parameters.
  • the verification of input parameters can be based on the data structure of input parameters
  • the verification of output parameters can be based on the data structure of output parameters.
  • the input parameter data structure and output parameter data structure used to verify the correctness of the input parameters and output parameters of the interface can be obtained by matching the names of the externally exposed classes.
  • the conversion of the front-end and back-end parameters to the back-end parameter data structure model of the interface is performed to obtain the front-end parameter data structure model of the interface, including: for the back-end parameters of the interface For any parameter in the data structure model, if the parameter value of the parameter conforms to the basic data type, it is converted based on the basic data type mapping table to obtain the expression of the parameter at the front end; if the parameter value of the parameter does not conform to the specified
  • the above basic data types are converted based on the self-defined data type mapping table to obtain the expression of the parameters at the front end, thereby obtaining the front-end parameter data structure model of the interface.
  • the parameter value of the parameter does not use the expression of the basic data type, but the The data type of the self-defined type has been negotiated, so in this case, it is only necessary to convert according to the custom data type mapping table to obtain the expression of the parameter at the front end, and complete all parameters in the back-end parameter data structure model After conversion, the parameter data structure model of the interface at the front end can be obtained.
  • the front-end parameter data structure model based on the first interface checks each parameter in the call request to determine the correctness of the call request, including: according to the The front-end parameter data structure model of the first interface, recursively traversing each parameter in the call request; if it is determined that there is a first parameter that does not meet the requirements of the first parameter in the front-end parameter data structure model of the first interface If required, determine that the first parameter is wrong and record the error in the first interface parameter error record pool; after the traversal, output each error in the first interface parameter error record pool.
  • each front-end parameter data structure model can be used to verify the call request of the corresponding interface.
  • the parameters to be verified can be traversed in a recursive manner.
  • it can be determined that the parameter transmission error and The error is recorded in the current interface parameter error record pool, so that after the traversal, it can output based on each error in the current interface parameter error record pool, so that the cost of testing and error checking can be reduced.
  • the embodiment of the present application provides an interface parameter verification device, the device includes: a front-end parameter data structure model acquisition unit, used to convert the configuration from the front-end and back-end to the call request for the first interface received by the front-end Obtain the front-end parameter data structure model of the first interface; the front-end parameter data structure model of any interface in the front-end conversion configuration is through each data structure model file in the back-end code and the back-end code Each interface definition file is analyzed and generated, and the back-end parameter data structure model of the interface is converted; the judging unit is used to evaluate each parameter in the call request based on the front-end parameter data structure model of the first interface Checking is performed to determine the correctness of the calling request.
  • a front-end parameter data structure model acquisition unit used to convert the configuration from the front-end and back-end to the call request for the first interface received by the front-end Obtain the front-end parameter data structure model of the first interface
  • the front-end parameter data structure model of any interface in the front-end conversion configuration is through
  • the embodiment of the present application provides a computing device, including:
  • the processor is configured to call the program instructions stored in the memory, and execute any implementation method according to the first aspect according to the obtained program.
  • the embodiment of the present application provides a computer-readable storage medium, the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to make a computer execute any one of the implementations of the first aspect. method.
  • FIG. 1 is a schematic diagram of an interface parameter verification method provided in an embodiment of the present application
  • FIG. 2 is a schematic diagram of an ast syntax tree provided by an embodiment of the present application.
  • FIG. 3 is a schematic flow diagram of an interface verification provided in an embodiment of the present application.
  • FIG. 4 is a schematic diagram of an interface parameter verification device provided in an embodiment of the present application.
  • FIG. 5 is a schematic diagram of a computing device provided by an embodiment of the present application.
  • the front-end developers check the input parameters of each interface based on the data structure description in the interface document written by the back-end developers. Check out the parameters.
  • the front-end developers need to write specific verification codes for the input and output parameters of each interface according to the interface documents. This is obviously time-consuming and labor-intensive. At the same time, it is difficult to ensure that some interface input parameters will not be missed. The problem of ginseng.
  • the embodiment of the present application provides a method for verifying an interface parameter.
  • Figure 1 it is a schematic diagram of an interface parameter verification method provided in the embodiment of the present application, the method includes the following steps:
  • Step 101 for the invocation request for the first interface received by the front end, obtain the front-end parameter data structure model of the first interface from the front-end and back-end conversion configurations.
  • the front-end parameter data structure model of any interface in the front-end conversion configuration is generated by parsing each data structure model file in the back-end code and each interface definition file in the back-end code 1.
  • the back-end parameter data structure model of the interface is converted to obtain it.
  • Step 102 Check each parameter in the call request based on the front-end parameter data structure model of the first interface to determine the correctness of the call request.
  • the front-end when the front-end receives a call request for the first interface, by obtaining the front-end parameter data structure model of the first interface, because the front-end parameter data structure model is based on the back-end parameter data structure model of the first interface converted, and because the back-end parameter data structure model of the first interface is obtained by parsing each data structure model file and each interface definition file in the back-end code, because the back-end parameter of the first interface obtained through analysis
  • the data structure model includes whether the verification parameter is necessary, the type of the parameter, etc.
  • the front-end parameter data structure model of any interface in the front-end and back-end conversion configuration is through the data structure model files in the back-end code and each interface definition file in the back-end code
  • the data structure model of the back-end parameter of the interface generated by analyzing and converting includes: obtaining the data structure model file corresponding to each data structure model file according to the analysis of each data structure model file in the back-end code object; any data structure model file object includes externally exposed classes; according to the analysis of each interface definition file in the back-end code, obtain the externally exposed classes corresponding to each interface; for any interface in each interface, according to For the externally exposed class of the interface, a data structure model file object with the same name as the externally exposed class of the interface is determined from each data structure model file object; according to the data structure model file object, the back end of the interface is generated A parameter data structure model; converting the front-end and back-end parameters to the back-end parameter data structure model of the interface to obtain the front-end parameter data structure model
  • the interface document In the process of front-end development, data interaction with the back-end can be performed by sending interfaces. In this process, in order to achieve the effectiveness of data transmission, it is particularly important to make corresponding specifications for the data that can be transmitted by each interface. Among them, the specification of the data that can be transmitted by the interface is called the interface document. Generally speaking, the interface document is written and maintained by the back-end developer, and its content includes each data structure model file and each interface definition file.
  • each data structure model file and each interface definition file can be processed as follows:
  • the data structure model file object corresponding to the data structure model file can be obtained in the following ways:
  • the acquisition of data structure model file objects corresponding to each data structure model file according to the analysis of each data structure model file in the back-end code includes: for each data structure model file Any data structure model file of any data structure model file, establish the abstract syntax tree of described data structure model file by javaparse tool; Described abstract syntax tree comprises JCImport node and JCClassDecl node; Obtain first information based on described JCImport node; Said first information Including the variable content and import path of each variable; second information is obtained based on the JCClassDecl node; the second information includes the externally exposed class indicated by the data structure model file and the variable information of each variable inside the externally exposed class ; Using the first information and the second information as the data structure model file object of the data structure model file.
  • the ast (Abstract Syntax Tree) syntax tree corresponding to it can be generated for the data structure model file, and the ast grammar
  • the tree is composed of internal classes of JCTree (such as JCCompilationUnit, JCClassDecl, JCVariableDecl, etc.) as syntax nodes.
  • JCTree such as JCCompilationUnit, JCClassDecl, JCVariableDecl, etc.
  • the root node of the entire ast syntax tree is the JCCompilationUnit object, and the sub-nodes of JCCompilationUnit are JCPackage, JCImport, and JCClassDecl.
  • Step 1 the content of JCImport can be obtained. Specifically, all JCImport objects can be obtained through the imports method of the root node JCCompilationUnit object, and the value of the import path and import variable in each JCImport object can be obtained by iteratively looping the JCImport object.
  • the data structure of the JCClassDecl node can be obtained to obtain the data structures of all classes in the current data structure model file.
  • the accept method of JCTree can be used to obtain the JCClassDecl child node in the root node object JCCompilationUnit.
  • the embodiment of this application can implement a JCTree.Visitor subclass, and pass the subclass as a parameter to the JCCompilationUnit.accept method.
  • visitClassDef visit class node
  • the injection parameter of this method is the JCClassDecl node object
  • the name value of this object is the class name.
  • the embodiment of the present application can further implement a JCTree.Visitor subclass, and pass the subclass as a parameter into the JCClassDecl.accept method, and the subclass internally overrides the visitVarDef (visit class node) method, and the injection parameter of this method is It is a JCVariableDecl node object, and the name and type of the variable can be obtained through the name value and vartype value of the object.
  • the name of the annotation list of the variable is obtained through the getAnnotations method of JCVariableDecl, which is convenient for the subsequent front-end to judge whether the variable is necessary and the maximum and minimum values through the agreed annotation name and the parameters passed in, so that the current one can be obtained.
  • the class of the data structure model file and the data structure definition of the class are convenient for the subsequent front-end to judge whether the variable is necessary and the maximum and minimum values through the agreed annotation name and the parameters passed in, so that the current one can be obtained.
  • Step 3 perform character string processing on the path of the current data structure model file. Specifically, it can include removing the content after '.' in the path, and then replacing '/' with '.', using the string obtained after this processing as the key value, and importing the path and import variables obtained in step 1.
  • the value of and the data structure of the class obtained in step 2 are stored in the cache variable, so that the data structure model file object corresponding to the current data structure model file can be obtained.
  • step 1 and step 2 the following examples can be used to illustrate.
  • channelProductId belongs to the data type of String (string);
  • variable named user belongs to the data type USER, and the data type USER is a custom data type.
  • FIG. 2 a schematic diagram of an ast syntax tree provided by the embodiment of the present application shows the JCCompilationUnit object transformed by applying the JavaParse tool to the above-mentioned Search.java data structure model file.
  • step 3 can be illustrated by the following example.
  • the interface definition file indicates an interface of the front end, so by parsing the interface definition file, the externally exposed class corresponding to the interface can be obtained.
  • the externally exposed class of the interface indicated by the interface definition file can be obtained through the following methods:
  • each interface includes the input parameter data structure of the data carried when the front end sends the interface request to the back end and the output parameter data structure of the data returned when the back end receives the interface request sent by the front end; Analyzing each interface definition file in the back-end code to obtain the externally exposed class corresponding to each interface, including: for any interface definition file in each interface definition file, obtaining the interface definition file indicated by the interface definition file.
  • the input parameter data structure and the output parameter data structure respectively correspond to the first externally exposed class and the second externally exposed class.
  • the front-end interface verification includes the verification of both input parameters and output parameters.
  • the verification of input parameters can be based on the input parameter data structure, and the verification of output parameters can be based on the output parameter data structure.
  • the embodiment of the present application can parse any interface definition file in the back-end code, convert it into an ast syntax tree, and then use the part that needs to be used as The url of the interface indicated by the interface definition file is used as a key value and stored in a temporary variable.
  • the parts that can be used in the embodiment of this application include the following two items:
  • the data structure model file object corresponding to each data structure model file can be obtained, and the processing of each interface definition file in the interface document can obtain the instruction of each interface definition file
  • the externally exposed class of the interface after obtaining these two aspects, the embodiment of the present application can generate a back-end parameter data structure model of the interface.
  • the back-end parameter data structure model of the interface can be generated in the following ways:
  • the back-end parameter data structure model of the interface can be generated in the following ways:
  • variable information includes variable name, variable type, and variable annotation name
  • generating the back-end parameter data structure model of the interface according to the data structure model file object includes: if The data structure model file object of the interface includes at least one first variable whose variable type is a non-custom type, then the variable information of the first variable is used as the back-end parameter of the interface under the first variable Data structure model; if the data structure model file object of the interface includes at least one second variable whose variable type is a user-defined type, then the obtained based on the import path of the second variable and the second variable The content with the same name is used as the back-end parameter data structure model of the interface under the second variable.
  • the data structure of this class can be obtained from each data structure model file object.
  • the data structure of variables of some custom types such as the USER type in the above example
  • the data structures of these custom type variables include:
  • the substructure of the parameter (when the parameter is a complex data type, such as object, array and some custom data types, its specific substructure needs to be obtained through recursion).
  • the content of the data structure model of the input parameter of interface A in the backend is as follows:
  • each sub-element is the variable required by the request parameter
  • the name of the sub-element is the parameter name
  • mustFlag indicates whether the parameter is required (O is required, N is not required)
  • fieldType is the data type of the parameter value.
  • the input parameters of interface A include 2 sub-elements/parameters, namely "size” and “params”; among them:
  • this parameter is mandatory, and the data type of the parameter value is a numeric type
  • this parameter is mandatory, and the data type of the parameter value is a custom type, and includes 2 sub-parameters, namely "name” and "id”; among them, for the "name” Sub-parameter, the sub-parameter is required, and the data type of the parameter value is a string. For the sub-parameter "id”, the sub-parameter is not required, and the data type of the parameter value is a numeric type.
  • the embodiment of the present application can generate a back-end parameter data structure model of the interface. Since the generated data structure model still belongs to the back-end data type, it cannot be recognized by the front-end. Therefore, the embodiment of the present application can convert the back-end parameter data structure model of the interface into an expression that can be recognized by the front-end. Among them, the back-end parameter data structure model can be converted in the following ways:
  • the conversion of front-end and back-end parameters to the back-end parameter data structure model of the interface is performed to obtain the front-end parameter data structure model of the interface, including: for the back-end parameters of the interface For any parameter in the data structure model, if the parameter value of the parameter conforms to the basic data type, it is converted based on the basic data type mapping table to obtain the expression of the parameter at the front end; if the parameter value of the parameter does not conform to the specified The above basic data types are converted based on the self-defined data type mapping table to obtain the expression of the parameters at the front end, thereby obtaining the front-end parameter data structure model of the interface.
  • front-end and back-end codes can be converted based on the existing basic data types of the front-end and back-end.
  • the front-end and back-end code personnel can also negotiate some complex data in advance. type and the corresponding conversion method. Therefore, the transformation from the back-end parameter data structure model to the front-end parameter data structure model can be divided into the following two steps:
  • mapping table of basic data types is as follows:
  • the front-end parameter data structure model based on the first interface checks each parameter in the call request to determine the correctness of the call request, including: according to the The front-end parameter data structure model of the first interface, recursively traversing each parameter in the call request; if it is determined that there is a first parameter that does not meet the requirements of the first parameter in the front-end parameter data structure model of the first interface If required, determine that the first parameter is wrong and record the error in the first interface parameter error record pool; after the traversal, output each error in the first interface parameter error record pool.
  • the front-end code can convert the json file of the front-end parameter data structure model obtained above into a file that conforms to the import of the es6 module, and import the front-end project. json file. Then, when the front-end code is running, when sending an interface request for input parameters, through the url value of this interface, the corresponding input parameter data structure model can be obtained in the above-mentioned converted json file, and the specific request input can be compared recursively. Whether the parameter data is correct.
  • the embodiment of this application can obtain the input parameter data structure model of interface A from the imported json file, wherein the content of the input parameter data structure model is as follows:
  • name is the parameter name
  • filedType the data type of this parameter (including string, number, boolen, object, array);
  • minSize When the parameter data type is a number, it indicates the minimum size; when the parameter data type is a string, it indicates the minimum length of the string; when the parameter data type is an array, it indicates the minimum length of the array;
  • maxSize When the parameter data type is a number, it indicates the maximum size; when the parameter data type is a string, it indicates the maximum length of the string; when the parameter data type is an array, it indicates the maximum length of the array;
  • children indicates the data structure type of the subset of this parameter (reference type data such as object, array will have child elements), and its structure is still name, mustFlag, filedType, children, minSize, maxSize.
  • each parameter in the request call can be verified based on the input parameter data structure model of interface A, as shown in Figure 3, which is a schematic flow diagram of an interface verification provided by the embodiment of this application, wherein, for " size”, because its parameter value "10” does not meet the requirement that the maximum number is 8, so the error can be recorded in the error pool.
  • the sub-parameter "id” because its parameter value " test” belongs to the string type and does not conform to the number type, so this error can also be recorded in the error pool. After all the parameters are verified this time, each error in the error pool can be output to reduce the cost of testing and error checking.
  • verification of the output parameters of the interface call request can refer to the above-mentioned process of verifying the input parameters of the interface call request, which will not be repeated here.
  • the embodiment of the present application provides an interface parameter verification device, as shown in Figure 4, which is a schematic diagram of an interface parameter verification device provided in the embodiment of the present application, the device includes front-end parameter data structure model acquisition Unit 401 and judging unit 402;
  • the front-end parameter data structure model acquisition unit 401 is used to obtain the front-end parameter data structure model of the first interface from the front-end conversion configuration for the call request received by the front-end to the first interface;
  • the front-end parameter data structure model of any interface is generated by parsing each data structure model file in the back-end code and each interface definition file in the back-end code, and the back-end parameter data structure model of the interface is Converted;
  • the judging unit 402 is configured to check each parameter in the call request based on the front-end parameter data structure model of the first interface, and determine the correctness of the call request.
  • the front-end parameter data structure model acquisition unit 401 is specifically used to: obtain the data structure model file objects corresponding to each data structure model file according to the analysis of each data structure model file in the back-end code; Any data structure model file object includes externally exposed classes; according to the analysis of each interface definition file in the back-end code, obtain the externally exposed classes corresponding to each interface; for any interface in each interface, according to the described For the externally exposed class of the interface, determine the data structure model file object with the same name as the externally exposed class of the interface from each data structure model file object; generate the back-end parameter data of the interface according to the data structure model file object Structural model; converting the front-end and back-end parameters to the back-end parameter data structure model of the interface to obtain the front-end parameter data structure model of the interface.
  • the device also includes a data structure model file object determination unit 403; the data structure model file object determination unit 403 is used to: for any data structure model file in each data structure model file, set up the data structure model file by javaparse tool
  • the abstract syntax tree of the data structure model file includes a JCImport node and a JCClassDecl node; the first information is obtained based on the JCImport node; the first information includes variable content and an import path of each variable; based on the The JCClassDecl node obtains the second information; the second information includes the externally exposed class indicated by the data structure model file and the variable information of each variable inside the externally exposed class; the first information and the second information
  • a data structure model file object that is the data structure model file.
  • this device also includes a back-end parameter data structure model generation unit 404; the variable information includes variable name, variable type and variable annotation name; the back-end parameter data structure model generation unit 404 is used to: if the The data structure model file object of the interface includes at least one first variable whose variable type is a non-custom type, then the variable information of the first variable is used as the back-end parameter data structure of the interface under the first variable model; if the data structure model file object of the interface includes at least one second variable whose variable type is a user-defined type, then the The content serves as the backend parameter data structure model of the interface under the second variable.
  • the variable information includes variable name, variable type and variable annotation name
  • the back-end parameter data structure model generation unit 404 is used to: if the The data structure model file object of the interface includes at least one first variable whose variable type is a non-custom type, then the variable information of the first variable is used as the back-end parameter data structure of the interface under the first variable model; if the data structure model file object of
  • each interface includes the input parameter data structure of the data carried when the front end sends the interface request to the back end and the return data structure when the back end receives the interface request sent by the front end.
  • the output parameter data structure; the interface exposed class acquisition unit 405 is configured to: for any interface definition file in each interface definition file, obtain the input parameter data structure and the output parameter data structure corresponding to the interface indicated by the interface definition file The first external exposure category and the second external exposure category.
  • the device also includes a front-end and back-end data structure model conversion unit 406; a front-end and back-end data structure model conversion unit 406, configured to: for any parameter in the back-end parameter data structure model of the interface, if the If the parameter value of the parameter conforms to the basic data type, it will be converted based on the basic data type mapping table to obtain the expression of the parameter at the front end; if the parameter value of the parameter does not conform to the basic data type, it will be mapped based on the custom data type The table is converted to obtain the expression of the parameters at the front end, so as to obtain the front-end parameter data structure model of the interface.
  • the judging unit 402 is specifically configured to: recursively traverse each parameter in the call request according to the front-end parameter data structure model of the first interface; if it is determined that there is a first parameter that does not meet the required If the requirement of the first parameter in the front-end parameter data structure model of the first interface is determined, the error of the first parameter is determined and the error is recorded in the first interface parameter error record pool; after the traversal is completed, all Each error in the first interface parameter error record pool is output.
  • the embodiment of the present application also provides a computing device, which may specifically be a desktop computer, a portable computer, a smart phone, a tablet computer, a personal digital assistant (Personal Digital Assistant, PDA), etc.
  • the computing device may include a central processing unit (Center Processing Unit, CPU), memory, input/output devices, etc.
  • the input device may include a keyboard, mouse, touch screen, etc.
  • the output device may include a display device, such as a liquid crystal display (Liquid Crystal Display, LCD), cathode ray tube (Cathode Ray Tube, CRT), etc.
  • the memory which may include read-only memory (ROM) and random-access memory (RAM), provides the processor with program instructions and data stored in the memory.
  • the memory may be used to store program instructions of the interface parameter verification method;
  • the processor is used to call the program instructions stored in the memory, and execute the interface parameter verification method according to the obtained program.
  • FIG. 5 it is a schematic diagram of a computing device provided in the embodiment of the present application, and the computing device includes:
  • the processor 501 is configured to read the program in the memory 502, and execute the above interface parameter verification method;
  • the processor 501 may be a central processing unit (central processing unit, CPU for short), a network processor (network processor, NP for short), or a combination of CPU and NP. It may also be a hardware chip.
  • the aforementioned hardware chip may be an application-specific integrated circuit (ASIC for short), a programmable logic device (PLD for short), or a combination thereof.
  • ASIC application-specific integrated circuit
  • PLD programmable logic device
  • the above-mentioned PLD can be a complex programmable logic device (complex programmable logic device, CPLD for short), a field-programmable gate array (field-programmable gate array, FPGA for short), a generic array logic (generic array logic, GAL for short) or any combination.
  • the memory 502 is used to store one or more executable programs, and may store data used by the processor 501 when performing operations.
  • the program may include program code, and the program code includes computer operation instructions.
  • the memory 502 may include a volatile memory (volatile memory), such as a random-access memory (random-access memory, RAM for short); the memory 502 may also include a non-volatile memory (non-volatile memory), such as a flash memory ( flash memory), hard disk (hard disk drive, referred to as HDD) or solid-state drive (solid-state drive, referred to as SSD); the memory 502 may also include a combination of the above-mentioned types of memory.
  • volatile memory volatile memory
  • RAM random-access memory
  • non-volatile memory such as a flash memory ( flash memory), hard disk (hard disk drive, referred to as HDD) or solid-state drive (solid-state drive, referred to as SSD)
  • the memory 502 may also include a combination of the above-mentioned types of memory.
  • the memory 502 stores the following elements, executable modules or data structures, or their subsets, or their extended sets:
  • Operation instructions include various operation instructions for realizing various operations.
  • Operating system includes various system programs for implementing various basic services and processing hardware-based tasks.
  • the bus 505 may be a peripheral component interconnect standard (PCI for short) bus or an extended industry standard architecture (EISA for short) bus or the like.
  • PCI peripheral component interconnect standard
  • EISA extended industry standard architecture
  • the bus can be divided into address bus, data bus, control bus and so on. For ease of representation, only one thick line is used in FIG. 5 , but it does not mean that there is only one bus or one type of bus.
  • the bus interface 504 may be a wired communication access interface, a wireless bus interface or a combination thereof, wherein the wired bus interface may be, for example, an Ethernet interface.
  • the Ethernet interface can be an optical interface, an electrical interface or a combination thereof.
  • the wireless bus interface may be a WLAN interface.
  • the embodiment of the present application also provides a computer-readable storage medium, where the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to make a computer execute the interface parameter checking method.
  • the embodiments of the present application may be provided as methods or computer program products. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
  • a computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
  • These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions
  • the device realizes the function specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明涉及金融科技(Fintech)领域,公开一种接口参数校验方法及装置,针对前端接收到的对第一接口的调用请求,从前后端转换配置中获取第一接口的前端参数数据结构模型;前后端转换配置中任一接口的前端参数数据结构模型是通过对后端代码中的各数据结构模型文件和所述后端代码中的各接口定义文件进行解析生成的、该接口的后端参数数据结构模型进行转换得到的;基于第一接口的前端参数数据结构模型对调用请求中的各参数进行校验,确定调用请求的正确性。该方案可以实现实时性地、全面性地以及高效率地对前端的调用请求进行校验的目标。

Description

一种接口参数校验方法及装置
相关申请的交叉引用
本申请要求在2021年12月03日提交中国专利局、申请号为202111463409.3、申请名称为“一种接口参数校验方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及金融科技(Fintech)领域,尤其涉及一种接口参数校验方法及装置。
背景技术
随着计算机技术的发展,越来越多的技术(例如:云计算、大数据或区块链)应用在金融领域,传统金融业正在逐步向金融科技转变。例如,基于当前普遍流行的服务端可向客户端提供服务的架构,银行业对于自己的各种产品通过开发相应的网上服务,可以很大程度上减少用户需要去线下实体银行办理业务的情况,提升了用户体验感。对于服务端-客户端的架构,服务端可以理解为后端,客户端可以理解为前端。其中,在对前端进行开发时,经常会通过发送接口而与后端进行数据交互,而在交互过程中难免会发生因为接口入参出参出错的情况所导致运行出错的问题。因而,为了保证用户在对前端进行使用的过程中前后端交互的通畅性,可在对前端进行发布之前,设置接口的测试环节。目前接口测试需要前端开发人员在开发过程中根据后端人员编写的接口文档中的数据结构说明、来对每一个接口的入参出参进行校验。
然而,上述对接口进行测试的过程,存在以下问题:
1、接口文档由于是由后端人员编写并维护的,难免会出现编写错误,以及更新不及时的情况。
2、前端开发人员根据接口文档对每一个接口的入参出参都要进行具体的校验代码的编写,该过程是非常费时费力的。
3、前端开发人员在编写校验代码时可能会遗漏对某些接口入参出参的校验。
因此,目前亟需一种自动化校验前端接口使用过程中的入参出参是否正确的方案。
发明内容
本申请提供一种接口参数校验方法及装置,用以实时、全方位地对前端接口在使用过程中的入参出参是否正确进行自动化校验,提升了接口参数校验的实时性、全面性与检测效率。
第一方面,本申请实施例提供一种接口参数校验方法,该方法包括:针对前端接收到的对第一接口的调用请求,从前后端转换配置中获取所述第一 接口的前端参数数据结构模型;所述前后端转换配置中任一接口的前端参数数据结构模型是通过对后端代码中的各数据结构模型文件和所述后端代码中的各接口定义文件进行解析生成的、所述接口的后端参数数据结构模型进行转换得到的;基于所述第一接口的前端参数数据结构模型对所述调用请求中的各参数进行校验,确定所述调用请求的正确性。
上述方案中,在前端接收到对第一接口的调用请求时,通过获取第一接口的前端参数数据结构模型,其中由于该前端参数数据结构模型是根据第一接口的后端参数数据结构模型进行转换得到的,又由于第一接口的后端参数数据结构模型是根据后端代码中的各数据结构模型文件和各接口定义文件进行解析得到的,由于经解析得到的第一接口的后端参数数据结构模型中包括校验参数是否必须、参数所属的类型等内容,因此通过将所解析得到的后端参数数据结构模型转换为前端可认知的数据结构模型,即前端在第一接口下的参数数据模型,如此就可以基于第一接口的前端参数数据模型对调用请求中的各参数进行自动化校验。该方案可以实现实时性地、全面性地以及高效率地对前端的调用请求进行校验的目标。
在一种可能实现的方法中,所述前后端转换配置中任一接口的前端参数数据结构模型是通过对后端代码中的各数据结构模型文件和所述后端代码中的各接口定义文件进行解析生成的、所述接口的后端参数数据结构模型进行转换得到的,包括:根据对后端代码中的各数据结构模型文件的解析,获取各数据结构模型文件分别对应的数据结构模型文件对象;任一数据结构模型文件对象包括对外暴露类;根据对所述后端代码中的各接口定义文件的解析,获取各接口分别对应的对外暴露类;针对各接口中的任一接口,根据所述接口的对外暴露类,从各数据结构模型文件对象中确定出与所述接口的对外暴露类同名的数据结构模型文件对象;根据所述数据结构模型文件对象,生成所述接口的后端参数数据结构模型;对所述接口的后端参数数据结构模型进行前后端参数的转换,得到所述接口的前端参数数据结构模型。
上述方案中,由于后端代码在对前端接口进行定义时,分为了两部分,包括数据结构模型文件和接口定义文件,其中通过对各数据结构模型文件的解析,可以获取到对应的各数据结构模型文件对象,任一个数据结构模型文件对象中包括一个对外暴露类,以及通过对各接口定义文件的解析,可以获取到与接口对应对外暴露类,然后针对于任一个接口,通过该接口的对外暴露类,将可以从各数据结构模型文件对象中匹配出与之同名的一个数据结构模型文件对象,接着根据对匹配出数据结构模型文件对象的处理,就可以生成该接口的后端参数数据结构模型,最后通过将所生成的后端参数数据结构模型转换成前端可以认知的数据结构模型,从而就得到了该接口的前端参数数据结构模型。该方式实现了在由后端代码对前端的各接口作出定义的场景下,通过自动化解析后端代码中关于各接口的定义,如此可以避免背景技术中需要通过人工的方式来测试前端接口可用性的问题。
在一种可能实现的方法中,所述根据对后端代码中的各数据结构模型文件的解析,获取各数据结构模型文件分别对应的数据结构模型文件对象,包 括:针对各数据结构模型文件中的任一数据结构模型文件,通过javaparse工具建立所述数据结构模型文件的抽象语法树;所述抽象语法树包括JCImport节点和JCClassDecl节点;基于所述JCImport节点得到第一信息;所述第一信息包括各个变量的变量内容和导入路径;基于所述JCClassDecl节点得到第二信息;所述第二信息包括所述数据结构模型文件指示的对外暴露类和所述对外暴露类内部的各变量的变量信息;将所述第一信息和所述第二信息作为所述数据结构模型文件的数据结构模型文件对象。
上述方案中,描述了如何通过对一数据结构模型文件的解析而得到它的数据结构模型文件对象的过程,包括首先可通过javaparse工具建立该数据结构模型文件的抽象语法树,其中,通过该抽象语法树中的JCImport节点可以获取到的各个变量的变量内容以及它的导入路径,同时通过抽象语法树中的JCClassDecl节点可以获取到该数据结构模型文件指示的对外暴露类以及该对外暴露类内部的各变量的变量信息,从而可以将两方面得到的信息作为该数据结构模型文件的数据结构模型文件对象。该方式通过javaparse工具为建立任一数据结构模型文件建立对应的抽象语法树,从而通过对抽象语法树的解析,就可以建立该数据结构模型文件的数据结构模型文件对象。该方式实现了自动化解析后端代码中的、对接口进行定义时需要用到的数据结构模型文件,提升了接口参数校验的效率。
在一种可能实现的方法中,所述变量信息包括变量名称、变量类型和变量注解名;所述根据所述数据结构模型文件对象,生成所述接口的后端参数数据结构模型,包括:若所述接口的数据结构模型文件对象中包括至少一个变量类型为非自定义类型的第一变量,则将所述第一变量的变量信息作为所述接口在所述第一变量下的后端参数数据结构模型;若所述接口的数据结构模型文件对象中包括至少一个变量类型为自定义类型的第二变量,则将基于所述第二变量的导入路径获取到的、与所述第二变量同名的内容作为所述接口在所述第二变量下的后端参数数据结构模型。
上述方案中,在对各接口的接口定义文件进行解析后,针对任一个接口在解析后得到的对外暴露类,可以从解析得到的各数据结构模型文件对象中匹配出与之同名的一个数据结构模型文件对象;对于所匹配出的数据结构模型文件对象,其中在含有非自定义类型的变量的同时可能还含有自定义类型的变量,因此,对于非自定义类型的变量,直接可以将变量名对应的变量信息放在该变量下,而对于自定义类型的变量,则可以通过该变量对应的导入路径而获取到与该变量同名的内容,进而可以将所获取的内容放在该变量下。通过该方式,可以实现从数据结构模型文件对象到后端参数数据结构模型的过渡,最后通过将后端参数数据结构模型转换为前端能够识别的前端参数数据结构模型,就可以基于前端参数数据结构模型来对接口的调用请求中所设计的各参数快速进行准确校验了。
在一种可能实现的方法中,各接口包括前端向后端发送接口请求时所带数据的入参数据结构和后端接收到前端发送的接口请求时返回数据的出参数据结构;所述根据对所述后端代码中的各接口定义文件的解析,获取各接口 分别对应的对外暴露类,包括:针对各接口定义文件中的任一接口定义文件,获取所述接口定义文件指示的接口的入参数据结构和出参数据结构分别对应的第一对外暴露类和第二对外暴露类。
上述方案中,前后端在通过发送接口进行数据交互的过程中,其中包括前端向后端发送接口请求时携带的数据,即入参,以及后端接收到前端发送的接口请求时返回的数据,即出参;因此前端的接口校验包括对入参和出参的校验,对入参的校验可以基于入参数据结构,对出参的校验可以基于出参数据结构,因此在对后端代码中的接口定义文件进行解析时,可以基于任一个接口定义文件而获取到该接口定义文件指示的接口的入参数据结构和出参数据结构分别对应的第一对外暴露类和第二对外暴露类,如此的话,后续通过对外暴露类名称的匹配,可以获取到用于校验该接口的入参和出参正确性的入参数据结构和出参数据结构。
在一种可能实现的方法中,所述对所述接口的后端参数数据结构模型进行前后端参数的转换,得到所述接口的前端参数数据结构模型,包括:针对所述接口的后端参数数据结构模型中的任一参数,若所述参数的参数值符合基本数据类型,则基于基本数据类型映射表进行转化,得到所述参数在前端的表达;若所述参数的参数值不符合所述基本数据类型,则基于自定义数据类型映射表进行转化,得到所述参数在前端的表达,从而得到所述接口的前端参数数据结构模型。
上述方案中,由于前后端代码的差异性,在得到接口的后端参数数据结构模型后,仍需要将其转换为前端能够识别的前端参数数据结构模型,如此前端在通过接口向后端发送数据时,才能够校验前端接口参数的正确性。其中,在将一接口的后端参数数据结构模型转换为该接口在前端的表达的过程中,一种情况是,后端参数数据结构模型中的一参数的参数值采用的是基本数据类型的表达,那么仅需要基于基本数据类型映射表进行转化,以得到该参数在前端的表达,另一种情况是,该参数的参数值并非采用的是基本数据类型的表达,而是前后端人员预先已经商量好的自定义类型的数据类型,那么对此情况仅需要按照自定义数据类型映射表进行转化,以得到该参数在前端的表达,在完成对后端参数数据结构模型中的所有参数的转换以后,即可得到该接口在前端的参数数据结构模型。
在一种可能实现的方法中,所述基于所述第一接口的前端参数数据结构模型对所述调用请求中的各参数进行校验,确定所述调用请求的正确性,包括:根据所述第一接口的前端参数数据结构模型,对所述调用请求中的各参数进行递归遍历;若确定存在第一参数不满足所述第一参数在所述第一接口的前端参数数据结构模型中的要求,则确定所述第一参数错误并在第一接口参数错误记录池中记录所述错误;在遍历结束后,对所述第一接口参数错误记录池中的各错误进行输出。
上述方案中,在得到接口的前端参数数据结构模型之后,即可使用各前端参数数据结构模型来对相应的接口的调用请求进行校验,其中在对调用请求中的各参数进行校验时,可采用递归的方式对各待校验的参数进行遍历, 当遍历到某一参数时,确定该参数并不满足当前接口的前端参数数据结构模型中的要去,则可以确定该参数传输错误并在当前接口参数错误记录池中记录该错误,从而在遍历结束后,可以基于当前接口参数错误记录池中的各错误进行输出,如此便可以减少测试成本以及查错成本。
第二方面,本申请实施例提供一种接口参数校验装置,该装置包括:前端参数数据结构模型获取单元,用于针对前端接收到的对第一接口的调用请求,从前后端转换配置中获取所述第一接口的前端参数数据结构模型;所述前后端转换配置中任一接口的前端参数数据结构模型是通过对后端代码中的各数据结构模型文件和所述后端代码中的各接口定义文件进行解析生成的、所述接口的后端参数数据结构模型进行转换得到的;判断单元,用于基于所述第一接口的前端参数数据结构模型对所述调用请求中的各参数进行校验,确定所述调用请求的正确性。
第三方面,本申请实施例提供了一种计算设备,包括:
存储器,用于存储程序指令;
处理器,用于调用所述存储器中存储的程序指令,按照获得的程序执行如第一方面任一实现方法。
第四方面,本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行如第一方面任一实现方法。
附图说明
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简要介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域的普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1为本申请实施例提供的一种接口参数校验方法的示意图;
图2为本申请实施例提供的一种ast语法树的示意图;
图3为本申请实施例提供的一种接口校验的流程示意图;
图4为本申请实施例提供的一种接口参数校验装置的示意图;
图5为本申请实施例提供的一种计算设备的示意图。
具体实施方式
为了使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请作进一步地详细描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本申请保护的范围。
由于目前在对前端发送的接口参数进行校验时,是通过人工的方式进行的,也即由前端开发人员基于后端开发人员编写的接口文档中的数据结构说明来对每一个接口的入参出参进行校验。该过程中难免出现实际上接口参数 已经更新了,但是接口文档未及时更新至前端开发人员的情况,基于该种不同步性,将很容易发生大面积校验失败的情况,以及该人工校验的过程中,需要由前端开发人员根据接口文档为每一个接口的入参出参去编写具体的校验代码,这显然耗时耗力,同时还很难确保不出现漏检某些接口入参出参的问题。
针对上述技术问题,本申请实施例提供一种接口参数校验方法。如图1所示,为本申请实施例提供的一种接口参数校验方法的示意图,该方法包括以下步骤:
步骤101,针对前端接收到的对第一接口的调用请求,从前后端转换配置中获取所述第一接口的前端参数数据结构模型。
在本步骤中,所述前后端转换配置中任一接口的前端参数数据结构模型是通过对后端代码中的各数据结构模型文件和所述后端代码中的各接口定义文件进行解析生成的、所述接口的后端参数数据结构模型进行转换得到的。
步骤102,基于所述第一接口的前端参数数据结构模型对所述调用请求中的各参数进行校验,确定所述调用请求的正确性。
上述方案中,在前端接收到对第一接口的调用请求时,通过获取第一接口的前端参数数据结构模型,其中由于该前端参数数据结构模型是根据第一接口的后端参数数据结构模型进行转换得到的,又由于第一接口的后端参数数据结构模型是根据后端代码中的各数据结构模型文件和各接口定义文件进行解析得到的,由于经解析得到的第一接口的后端参数数据结构模型中包括校验参数是否必须、参数所属的类型等内容,因此通过将所解析得到的后端参数数据结构模型转换为前端可认知的数据结构模型,即前端在第一接口下的参数数据模型,如此就可以基于第一接口的前端参数数据模型对调用请求中的各参数进行自动化校验。该方案可以实现实时性地、全面性地以及高效率地对前端的调用请求进行校验的目标。
以下将结合示例分别对上述一些步骤进行详细说明。
在上述步骤101的一个实施中,所述前后端转换配置中任一接口的前端参数数据结构模型是通过对后端代码中的各数据结构模型文件和所述后端代码中的各接口定义文件进行解析生成的、所述接口的后端参数数据结构模型进行转换得到的,包括:根据对后端代码中的各数据结构模型文件的解析,获取各数据结构模型文件分别对应的数据结构模型文件对象;任一数据结构模型文件对象包括对外暴露类;根据对所述后端代码中的各接口定义文件的解析,获取各接口分别对应的对外暴露类;针对各接口中的任一接口,根据所述接口的对外暴露类,从各数据结构模型文件对象中确定出与所述接口的对外暴露类同名的数据结构模型文件对象;根据所述数据结构模型文件对象,生成所述接口的后端参数数据结构模型;对所述接口的后端参数数据结构模型进行前后端参数的转换,得到所述接口的前端参数数据结构模型。
在前端开发的过程中,可以通过发送接口的方式与后端进行数据交互。该过程中,为了达到数据传输的有效性,对各接口能够进行传输的数据作出 相应的规范显得尤为重要。其中,对接口能够进行传输的数据所作出的规范称为接口文档,一般而言,接口文档是由后端开发人员进行编写并维护的,其内容包括各数据结构模型文件和各接口定义文件。
基于此,本申请实施例首先可以从后端代码中获取接口文档。在获取到接口文档后,将可以对当中的各数据结构模型文件以及各接口定义文件分别进行如下处理:
1、对于各数据结构模型文件的处理如下:
说明的是,由于本申请实施例对各数据结构模型文件中的任一个数据结构模型文件的处理方式均相同,故接下来将以对各数据结构模型文件中的一个数据结构模型文件进行处理为例,进行举例说明。
针对各数据结构模型文件中的任一个数据结构模型文件,通过对该数据结构模型文件的解析,可以获取到它对应的数据结构模型文件对象。其中,可以通过下述方式得到与数据结构模型文件对应的数据结构模型文件对象:
在本申请的某些实施中,所述根据对后端代码中的各数据结构模型文件的解析,获取各数据结构模型文件分别对应的数据结构模型文件对象,包括:针对各数据结构模型文件中的任一数据结构模型文件,通过javaparse工具建立所述数据结构模型文件的抽象语法树;所述抽象语法树包括JCImport节点和JCClassDecl节点;基于所述JCImport节点得到第一信息;所述第一信息包括各个变量的变量内容和导入路径;基于所述JCClassDecl节点得到第二信息;所述第二信息包括所述数据结构模型文件指示的对外暴露类和所述对外暴露类内部的各变量的变量信息;将所述第一信息和所述第二信息作为所述数据结构模型文件的数据结构模型文件对象。
例如,对于各数据结构模型文件中的任一个数据结构模型文件,通过使用JavaParse工具,可为该数据结构模型文件生成与它相对应的ast(Abstract Syntax Tree,抽象语法树)语法树,ast语法树由JCTree的内部类(如JCCompilationUnit,JCClassDecl,JCVariableDecl等)作为语法节点而构成。整个ast语法树的根节点为JCCompilationUnit对象,JCCompilationUnit子节点分别为JCPackage、JCImport、JCClassDecl。在解析得到ast语法树后,可以基于下述各步骤获取该数据结构模型文件的数据结构模型文件对象:
步骤1、首先可获取JCImport的内容。具体可通过根节点JCCompilationUnit对象的imports方法获取到所有JCImport对象,并通过迭代循环JCImport对象,可取出每个JCImport对象中导入路径和导入变量的值。
步骤2、接着可获取JCClassDecl节点的数据结构,以得到当前的数据结构模型文件内所有类的数据结构。具体可通过JCTree的accept方法、以获取根节点对象JCCompilationUnit中的JCClassDecl子节点。其中,由于accept方法需要接收一个JCTree.Visitor的方法作为参数,因此,本申请实施例可实现一个JCTree.Visitor的子类,并将该子类作为参数传入JCCompilationUnit.accept方法,该子类内部覆写visitClassDef(访问类节点)方法,包括:该方法的注入参数即为JCClassDecl节点对象,这个对象的name值即为类名。同时,除了获取类的名称还需获得类内部定义的变量名称以及 变量类型。所以,本申请实施例还可再实现一个JCTree.Visitor子类,将该子类作为参数传入JCClassDecl.accept方法,该子类内部覆写visitVarDef(访问类节点)方法,该方法的注入参数即为JCVariableDecl节点对象,通过该对象的name值以及vartype值可获取到变量的名称以及类型。此外,通过JCVariableDecl的getAnnotations方法获取变量的注解列表的名称,便于通过约定好的注解名以及传入的参数、方便后续前端来判断变量是否是必须以及最大、最小值等,这样便可得到当前的数据结构模型文件的类以及类的数据结构定义。
步骤3、对当前的数据数据结构模型文件的路径进行字符串处理。具体可包括将路径中‘.’后面的内容去掉,然后将‘/’替换为‘.’,以经过该处理后得到的字符串作为key值,并将步骤1获取到的导入路径和导入变量的值、以及步骤2获取到的类的数据结构存入到缓存变量中,如此可以得到当前的数据结构模型文件对应的数据结构模型文件对象。
对于上述步骤1和步骤2,可以通过如下的例子进行说明。
设有一数据结构模型文件,名为Search.java,路径为cn/framework/dto/Search.java,内容为:
Figure PCTCN2022100674-appb-000001
对于上述Search.java这一数据结构模型文件,它的对外暴露类名为Search,其中含有2个变量:
1、名为channelProductId的变量属于String(字符串)这一数据类型;
2、名为user的变量属于USER这一数据类型,其中USER这一数据类型为自定义数据类型。
如图2所示,为本申请实施例提供的一种ast语法树的示意图,表示的是对上述Search.java这一数据结构模型文件应用JavaParse工具转化而来的JCCompilationUnit对象。
对于上述步骤3,可以通过如下的例子进行说明。
根据图2所示的JCCompilationUnit对象,对于上述Search.java这一数据结构模型文件,它的数据结构模型文件对象可以表示如下:
Figure PCTCN2022100674-appb-000002
Figure PCTCN2022100674-appb-000003
2、对于各接口定义文件的处理如下:
说明的是,由于本申请实施例对各接口定义文件中的任一个接口定义文件的处理方式均相同,故接下来将以对各接口定义文件中的一个接口定义文件进行处理为例,进行举例说明。
针对各接口定义文件中的任一个接口定义文件,该接口定义文件指示前端的一个接口,因此通过对该接口定义文件的解析,可以获取到该接口对应的对外暴露类。其中,可以通过下述方式得到接口定义文件指示的接口的对外暴露类:
在本申请的某些实施中,各接口包括前端向后端发送接口请求时所带数据的入参数据结构和后端接收到前端发送的接口请求时返回数据的出参数据结构;所述根据对所述后端代码中的各接口定义文件的解析,获取各接口分别对应的对外暴露类,包括:针对各接口定义文件中的任一接口定义文件,获取所述接口定义文件指示的接口的入参数据结构和出参数据结构分别对应的第一对外暴露类和第二对外暴露类。
前后端在通过发送接口进行数据交互的过程中,其中包括前端向后端发送接口请求时携带的数据,即入参,以及后端接收到前端发送的接口请求时返回的数据,即出参;因此前端的接口校验包括对入参和出参这两方面的校验,对入参的校验可以基于入参数据结构,对出参的校验可以基于出参数据结构。因此,对应到前端的接口在后端代码中的接口定义文件,本申请实施例可以对后端代码中的任一接口定义文件进行解析、转化为ast语法树,然后将需要用到的部分以该接口定义文件指示的接口的url作为key值、存储到一个临时变量中。对于对接口定义文件进行转化得到的ast语法树,本申请实施例可使用到的部分包含以下两项内容:
(1)、该接口入参的数据结构所对应的类的类名,即第一对外暴露类;
(2)、该接口出参的数据结构所对应的类的类名,即第二对外暴露类。
通过上述对接口文档中的各数据结构模型文件的处理,可以得到各数据结构模型文件对应的数据结构模型文件对象,以及对接口文档中的各接口定义文件的处理,可以得到各接口定义文件指示的接口的对外暴露类;在得到 这两方面内容之后,本申请实施例可以生成一个接口的后端参数数据结构模型。其中,可以通过以下方式生成接口的后端参数数据结构模型:
首先,针对各接口中的任一接口,根据该接口的对外暴露类,从各数据结构模型文件对象中确定出与该接口的对外暴露类同名的数据结构模型文件对象;接着,可以根据所匹配出的数据结构模型文件,生成该接口的后端参数数据结构模型。其中,可以通过以下方式生成接口的后端参数数据结构模型:
在本申请的某些实施中,所述变量信息包括变量名称、变量类型和变量注解名;所述根据所述数据结构模型文件对象,生成所述接口的后端参数数据结构模型,包括:若所述接口的数据结构模型文件对象中包括至少一个变量类型为非自定义类型的第一变量,则将所述第一变量的变量信息作为所述接口在所述第一变量下的后端参数数据结构模型;若所述接口的数据结构模型文件对象中包括至少一个变量类型为自定义类型的第二变量,则将基于所述第二变量的导入路径获取到的、与所述第二变量同名的内容作为所述接口在所述第二变量下的后端参数数据结构模型。
例如,对一接口而言,通过将该接口的类名作为key值,可从各数据结构模型文件对象中获取到这个类的数据结构。不过,由于在所获取的数据结构中,一些自定义类型(如上述例子中的USER类型)的变量的数据结构是没有在当前的数据结构模型文件中解析出来的,因此需要做一个递归来解析该些自定义类型变量的数据结构,包括:
遍历类中变量数据结构对象,当发现有自定义类型变量时,可先检查这个数据类型的类是否在当前的数据结构模型文件对象中有定义;如果没有,则确定是由外部引入的,所以可在JCImport找到对应的其它数据结构模型文件对象类,然后将此类的数据结构对象以key值为children放入到其对应的自定义类型中(注意,在这里自定义的类型的类内部结构还可能也会有更下一级的自定义类型的变量,所以这里要一直以同样的逻辑往下寻找直到没有自定义类型的变量为止,将这些解析好的类的数据结构存储到缓存中,在获取下一个接口出参入参数据结构的过程中,若发现自定义类型的变量时,则优先检查缓存中是否有之前已解析好的同名自定义类型的变量,可避免重复解析),然后以该接口对应的url为key值存储起来。
最后,所生成的后端参数数据结构模型包含:
1、参数名;
2、参数类型;
3、参数是否必须;
4、参数值的最大长度和最小长度,无则为空;
5、参数的子结构(当参数为复杂数据类型时,如对象、数组以及一些自定义数据类型,需要通过递归得到其具体的子结构)。
例如,设接口A的入参在后端的数据结构模型的内容如下:
Figure PCTCN2022100674-appb-000004
Figure PCTCN2022100674-appb-000005
其中,首先对上述接口A的入参在后端的参数数据结构模型中涉及的一些名词作出说明:
url:接口A的url值。
reqFields:接口A的请求参数数据结构模型,每一个子元素即为请求参数所需变量,子元素的name为参数名,mustFlag表示此参数是否为必须项(O为必须项、N为非必须项),fieldType为参数值的数据类型。
因此,上述接口A的入参在后端的参数数据结构模型表示的含义如下:
接口A的入参包括2个子元素/参数,分别为“size”和“params”;其中:
对于“size”这一子元素/参数,该参数为必须项,且参数值的数据类型为数值类型;
对于“params”子元素/参数,该参数为必须项,且参数值的数据类型为自定义类型,并包括2个子参数,分别为“name”和“id”;其中,对于“name”这一子参数,该子参数为必须项,且参数值的数据类型为字符串,对于“id”这一子参数,该子参数为非必须项,且参数值的数据类型为数值类型。
通过上述方式,对于前端的一个接口,本申请实施例可以生成该接口的后端参数数据结构模型。由于所生成的数据结构模型仍然属于后端的数据类 型,是无法被前端进行识别的。因此,本申请实施例可对接口的后端参数数据结构模型进行转换,转换为前端可以识别的表达。其中,可以通过以下方式对后端参数数据结构模型进行转换:
在本申请的某些实施中,所述对所述接口的后端参数数据结构模型进行前后端参数的转换,得到所述接口的前端参数数据结构模型,包括:针对所述接口的后端参数数据结构模型中的任一参数,若所述参数的参数值符合基本数据类型,则基于基本数据类型映射表进行转化,得到所述参数在前端的表达;若所述参数的参数值不符合所述基本数据类型,则基于自定义数据类型映射表进行转化,得到所述参数在前端的表达,从而得到所述接口的前端参数数据结构模型。
由于前后端代码在执行过程中,一方面是能够基于当前存在有的前后端进行转换的基本数据类型而进行的,同时为了满足不同业务需求,前后端的代码人员还可以提前商量好一些复杂的数据类型以及对应的转换方式。因此,在进行后端参数数据结构模型到前端参数数据结构模型的转换,可分如下两步:
1、对后端一些基本的数据类型,如char、int、byte等,可直接转化为前端对应的基本数据类型。比如,基本数据类型的映射表如下:
(1)char->string
(2)string->string
(3)boolean->boolean
(4)byte->number
(5)short->number
(6)double->number
(7)long->number
(8)float->number
(9)int->number
(10)integer->number
(11)bigDecimal->number
(12)bigInteger->number
(13)date->string
2、对一些后端自定义的数据类型进行转化的过程,相对来说会复杂一些,主要需要识别数组和对象,因此这里需要前端的开发人员去和后端的开发人员做一些基本约定。例如,在自定义数据类型为前端数组(array)时,其对应的申明方式可以为以下几种:
(1)List<ClassB>
(2)Array<ClassB>
(3)Collection<ClassB>
(4)ClassB[]
在对参数的数据类型进行了前后端的转换后,最后,还可转换一些后端对参数的注解(与后端约定好注解字段代表的含义即可):如当前参数是否 必须、当前参数的值最小长度和最大长度是多少等内容。至此,可以得到接口的前端参数数据结构模型(具体可以参见下文)。
在上述步骤102的一个实施中,所述基于所述第一接口的前端参数数据结构模型对所述调用请求中的各参数进行校验,确定所述调用请求的正确性,包括:根据所述第一接口的前端参数数据结构模型,对所述调用请求中的各参数进行递归遍历;若确定存在第一参数不满足所述第一参数在所述第一接口的前端参数数据结构模型中的要求,则确定所述第一参数错误并在第一接口参数错误记录池中记录所述错误;在遍历结束后,对所述第一接口参数错误记录池中的各错误进行输出。
接着前述的例子,在得到接口的前端参数数据结构模型之后,前端代码在编译时可将上述得到的前端参数数据结构模型的json文件转化为符合es6模块引入的文件,并在前端项目中引入该json文件。那么,前端代码运行时在发送接口请求入参时,通过此接口的url值、可在上述转化的json文件中拿到对应的入参数据结构模型,并以此递归循环比对具体的请求入参数据是否正确。
例如,现有一对前文例子中的接口A的入参数据结构进行调用的请求,请求内容如下:
Figure PCTCN2022100674-appb-000006
在发送接口A的时候,本申请实施例可从引入的json文件获取接口A的入参数据结构模型,其中,该入参数据结构模型的内容如下:
Figure PCTCN2022100674-appb-000007
Figure PCTCN2022100674-appb-000008
以下是对上述接口A的入参数据结构模型中涉及到的一些名词的说明:
name:为参数名;
mustFlag:此参数是否必须有(O为必须,N为非必须);
filedType:此参数的数据类型(包括string,number,boolen,object,array);
minSize:当参数数据类型为数字时表示其最小为多少,当参数数据类型为字符串时表示此字符串长度最小为多少,当参数数据类型为数组时,表示数组长度最小为多少;
maxSize:当参数数据类型为数字时表示其最大为多少,当参数数据类型为字符串时表示此字符串长度最大为多少,当参数数据类型为数组时,表示数组长度最大为多少;
children表示此参数的子集(引用类型数据如object,array会有子元素)的数据结构类型,其结构仍然是name、mustFlag、filedType、children、minSize、maxSize。
因此,可基于接口A的入参数据结构模型对请求调用中的各参数进行校验,其中如图3所示,为本申请实施例提供的一种接口校验的流程示意图,其中,对于“size”这一参数,由于其参数值“10”不符合数字最大值为8的要求,因此,可以将该错误记录到错误池中,另外对于“id”这一子参数,由于其参数值“test”属于字符串类型,并不符合数字类型,因此可以将该错误也记录到错误池中。当在本次校验完所有的参数后,可以将错误池的各错误进行输出,以减少测试及查错成本。
说明的是,对接口调用请求的出参进行校验可以参考上述对接口调用请求的入参进行校验的过程,不再赘述。
基于同样的构思,本申请实施例提供一种接口参数校验装置,如图4所示,为本申请实施例提供的一种接口参数校验装置的示意图,该装置包括前端参数数据结构模型获取单元401和判断单元402;
前端参数数据结构模型获取单元401,用于针对前端接收到的对第一接口 的调用请求,从前后端转换配置中获取所述第一接口的前端参数数据结构模型;所述前后端转换配置中任一接口的前端参数数据结构模型是通过对后端代码中的各数据结构模型文件和所述后端代码中的各接口定义文件进行解析生成的、所述接口的后端参数数据结构模型进行转换得到的;
判断单元402,用于基于所述第一接口的前端参数数据结构模型对所述调用请求中的各参数进行校验,确定所述调用请求的正确性。
进一步的,对于该装置,前端参数数据结构模型获取单元401,具体用于:根据对后端代码中的各数据结构模型文件的解析,获取各数据结构模型文件分别对应的数据结构模型文件对象;任一数据结构模型文件对象包括对外暴露类;根据对所述后端代码中的各接口定义文件的解析,获取各接口分别对应的对外暴露类;针对各接口中的任一接口,根据所述接口的对外暴露类,从各数据结构模型文件对象中确定出与所述接口的对外暴露类同名的数据结构模型文件对象;根据所述数据结构模型文件对象,生成所述接口的后端参数数据结构模型;对所述接口的后端参数数据结构模型进行前后端参数的转换,得到所述接口的前端参数数据结构模型。
进一步的,对于该装置,还包括数据结构模型文件对象确定单元403;数据结构模型文件对象确定单元403,用于:针对各数据结构模型文件中的任一数据结构模型文件,通过javaparse工具建立所述数据结构模型文件的抽象语法树;所述抽象语法树包括JCImport节点和JCClassDecl节点;基于所述JCImport节点得到第一信息;所述第一信息包括各个变量的变量内容和导入路径;基于所述JCClassDecl节点得到第二信息;所述第二信息包括所述数据结构模型文件指示的对外暴露类和所述对外暴露类内部的各变量的变量信息;将所述第一信息和所述第二信息作为所述数据结构模型文件的数据结构模型文件对象。
进一步的,对于该装置,还包括后端参数数据结构模型生成单元404;所述变量信息包括变量名称、变量类型和变量注解名;后端参数数据结构模型生成单元404,用于:若所述接口的数据结构模型文件对象中包括至少一个变量类型为非自定义类型的第一变量,则将所述第一变量的变量信息作为所述接口在所述第一变量下的后端参数数据结构模型;若所述接口的数据结构模型文件对象中包括至少一个变量类型为自定义类型的第二变量,则将基于所述第二变量的导入路径获取到的、与所述第二变量同名的内容作为所述接口在所述第二变量下的后端参数数据结构模型。
进一步的,对于该装置,还包括接口对外暴露类获取单元405;各接口包括前端向后端发送接口请求时所带数据的入参数据结构和后端接收到前端发送的接口请求时返回数据的出参数据结构;接口对外暴露类获取单元405,用于:针对各接口定义文件中的任一接口定义文件,获取所述接口定义文件指示的接口的入参数据结构和出参数据结构分别对应的第一对外暴露类和第二对外暴露类。
进一步的,对于该装置,还包括前后端数据结构模型转换单元406;前后端数据结构模型转换单元406,用于:针对所述接口的后端参数数据结构模型 中的任一参数,若所述参数的参数值符合基本数据类型,则基于基本数据类型映射表进行转化,得到所述参数在前端的表达;若所述参数的参数值不符合所述基本数据类型,则基于自定义数据类型映射表进行转化,得到所述参数在前端的表达,从而得到所述接口的前端参数数据结构模型。
进一步的,对于该装置,判断单元402,具体用于:根据所述第一接口的前端参数数据结构模型,对所述调用请求中的各参数进行递归遍历;若确定存在第一参数不满足所述第一参数在所述第一接口的前端参数数据结构模型中的要求,则确定所述第一参数错误并在第一接口参数错误记录池中记录所述错误;在遍历结束后,对所述第一接口参数错误记录池中的各错误进行输出。
本申请实施例还提供了一种计算设备,该计算设备具体可以为桌面计算机、便携式计算机、智能手机、平板电脑、个人数字助理(Personal Digital Assistant,PDA)等。该计算设备可以包括中央处理器(Center Processing Unit,CPU)、存储器、输入/输出设备等,输入设备可以包括键盘、鼠标、触摸屏等,输出设备可以包括显示设备,如液晶显示器(Liquid Crystal Display,LCD)、阴极射线管(Cathode Ray Tube,CRT)等。
存储器,可以包括只读存储器(ROM)和随机存取存储器(RAM),并向处理器提供存储器中存储的程序指令和数据。在本申请实施例中,存储器可以用于存储接口参数校验方法的程序指令;
处理器,用于调用所述存储器中存储的程序指令,按照获得的程序执行接口参数校验方法。
如图5所示,为本申请实施例提供的一种计算设备的示意图,该计算设备包括:
处理器501、存储器502、收发器503、总线接口504;其中,处理器501、存储器502与收发器503之间通过总线505连接;
所述处理器501,用于读取所述存储器502中的程序,执行上述接口参数校验方法;
处理器501可以是中央处理器(central processing unit,简称CPU),网络处理器(network processor,简称NP)或者CPU和NP的组合。还可以是硬件芯片。上述硬件芯片可以是专用集成电路(application-specific integrated circuit,简称ASIC),可编程逻辑器件(programmable logic device,简称PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complex programmable logic device,简称CPLD),现场可编程逻辑门阵列(field-programmable gate array,简称FPGA),通用阵列逻辑(generic array logic,简称GAL)或其任意组合。
所述存储器502,用于存储一个或多个可执行程序,可以存储所述处理器501在执行操作时所使用的数据。
具体地,程序可以包括程序代码,程序代码包括计算机操作指令。存储器502可以包括易失性存储器(volatile memory),例如随机存取存储器(random-access memory,简称RAM);存储器502也可以包括非易失性存储器(non-volatile memory),例如快闪存储器(flash memory),硬盘(hard disk  drive,简称HDD)或固态硬盘(solid-state drive,简称SSD);存储器502还可以包括上述种类的存储器的组合。
存储器502存储了如下的元素,可执行模块或者数据结构,或者它们的子集,或者它们的扩展集:
操作指令:包括各种操作指令,用于实现各种操作。
操作系统:包括各种系统程序,用于实现各种基础业务以及处理基于硬件的任务。
总线505可以是外设部件互连标准(peripheral component interconnect,简称PCI)总线或扩展工业标准结构(extended industry standard architecture,简称EISA)总线等。总线可以分为地址总线、数据总线、控制总线等。为便于表示,图5中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。
总线接口504可以为有线通信接入口,无线总线接口或其组合,其中,有线总线接口例如可以为以太网接口。以太网接口可以是光接口,电接口或其组合。无线总线接口可以为WLAN接口。
本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行接口参数校验方法。
本领域内的技术人员应明白,本申请的实施例可提供为方法、或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本申请是参照根据本申请实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
尽管已描述了本申请的优选实施例,但本领域内的技术人员一旦得知了 基本创造性概念,则可对这些实施例作出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本申请范围的所有变更和修改。
显然,本领域的技术人员可以对本申请进行各种改动和变型而不脱离本申请的精神和范围。这样,倘若本申请的这些修改和变型属于本申请权利要求及其等同技术的范围之内,则本申请也意图包含这些改动和变型在内。

Claims (10)

  1. 一种接口参数校验方法,其特征在于,包括:
    针对前端接收到的对第一接口的调用请求,从前后端转换配置中获取所述第一接口的前端参数数据结构模型;所述前后端转换配置中任一接口的前端参数数据结构模型是通过对后端代码中的各数据结构模型文件和所述后端代码中的各接口定义文件进行解析生成的、所述接口的后端参数数据结构模型进行转换得到的;
    基于所述第一接口的前端参数数据结构模型对所述调用请求中的各参数进行校验,确定所述调用请求的正确性。
  2. 如权利要求1所述的方法,其特征在于,
    所述前后端转换配置中任一接口的前端参数数据结构模型是通过对后端代码中的各数据结构模型文件和所述后端代码中的各接口定义文件进行解析生成的、所述接口的后端参数数据结构模型进行转换得到的,包括:
    根据对后端代码中的各数据结构模型文件的解析,获取各数据结构模型文件分别对应的数据结构模型文件对象;任一数据结构模型文件对象包括对外暴露类;
    根据对所述后端代码中的各接口定义文件的解析,获取各接口分别对应的对外暴露类;
    针对各接口中的任一接口,根据所述接口的对外暴露类,从各数据结构模型文件对象中确定出与所述接口的对外暴露类同名的数据结构模型文件对象;根据所述数据结构模型文件对象,生成所述接口的后端参数数据结构模型;对所述接口的后端参数数据结构模型进行前后端参数的转换,得到所述接口的前端参数数据结构模型。
  3. 如权利要求2所述的方法,其特征在于,
    所述根据对后端代码中的各数据结构模型文件的解析,获取各数据结构模型文件分别对应的数据结构模型文件对象,包括:
    针对各数据结构模型文件中的任一数据结构模型文件,通过javaparse工具建立所述数据结构模型文件的抽象语法树;所述抽象语法树包括JCImport节点和JCClassDecl节点;
    基于所述JCImport节点得到第一信息;所述第一信息包括各个变量的变量内容和导入路径;
    基于所述JCClassDecl节点得到第二信息;所述第二信息包括所述数据结构模型文件指示的对外暴露类和所述对外暴露类内部的各变量的变量信息;
    将所述第一信息和所述第二信息作为所述数据结构模型文件的数据结构模型文件对象。
  4. 如权利要求3所述的方法,其特征在于,所述变量信息包括变量名称、变量类型和变量注解名;
    所述根据所述数据结构模型文件对象,生成所述接口的后端参数数据结构模型,包括:
    若所述接口的数据结构模型文件对象中包括至少一个变量类型为非自定义类型的第一变量,则将所述第一变量的变量信息作为所述接口在所述第一变量下的后端参数数据结构模型;
    若所述接口的数据结构模型文件对象中包括至少一个变量类型为自定义类型的第二变量,则将基于所述第二变量的导入路径获取到的、与所述第二变量同名的内容作为所述接口在所述第二变量下的后端参数数据结构模型。
  5. 如权利要求2所述的方法,其特征在于,各接口包括前端向后端发送接口请求时所带数据的入参数据结构和后端接收到前端发送的接口请求时返回数据的出参数据结构;
    所述根据对所述后端代码中的各接口定义文件的解析,获取各接口分别对应的对外暴露类,包括:
    针对各接口定义文件中的任一接口定义文件,获取所述接口定义文件指示的接口的入参数据结构和出参数据结构分别对应的第一对外暴露类和第二对外暴露类。
  6. 如权利要求2所述的方法,其特征在于,
    所述对所述接口的后端参数数据结构模型进行前后端参数的转换,得到所述接口的前端参数数据结构模型,包括:
    针对所述接口的后端参数数据结构模型中的任一参数,若所述参数的参数值符合基本数据类型,则基于基本数据类型映射表进行转化,得到所述参数在前端的表达;
    若所述参数的参数值不符合所述基本数据类型,则基于自定义数据类型映射表进行转化,得到所述参数在前端的表达,从而得到所述接口的前端参数数据结构模型。
  7. 如权利要求1至6任一项所述的方法,其特征在于,
    所述基于所述第一接口的前端参数数据结构模型对所述调用请求中的各参数进行校验,确定所述调用请求的正确性,包括:
    根据所述第一接口的前端参数数据结构模型,对所述调用请求中的各参数进行递归遍历;
    若确定存在第一参数不满足所述第一参数在所述第一接口的前端参数数据结构模型中的要求,则确定所述第一参数错误并在第一接口参数错误记录池中记录所述错误;
    在遍历结束后,对所述第一接口参数错误记录池中的各错误进行输出。
  8. 一种接口参数校验装置,其特征在于,包括:
    前端参数数据结构模型获取单元,用于针对前端接收到的对第一接口的调用请求,从前后端转换配置中获取所述第一接口的前端参数数据结构模型;所述前后端转换配置中任一接口的前端参数数据结构模型是通过对后端代码中的各数据结构模型文件和所述后端代码中的各接口定义文件进行解析生成的、所述接口的后端参数数据结构模型进行转换得到的;
    判断单元,用于基于所述第一接口的前端参数数据结构模型对所述调用请求中的各参数进行校验,确定所述调用请求的正确性。
  9. 一种计算机设备,其特征在于,包括:
    存储器,用于存储计算机程序;
    处理器,用于调用所述存储器中存储的计算机程序,按照获得的程序执行如权利要求1-7任一项所述的方法。
  10. 一种计算机可读存储介质,其特征在于,所述存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行如权利要求1-7任一项所述的方法。
PCT/CN2022/100674 2021-12-03 2022-06-23 一种接口参数校验方法及装置 Ceased WO2023098043A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111463409.3A CN114116510A (zh) 2021-12-03 2021-12-03 一种接口参数校验方法及装置
CN202111463409.3 2021-12-03

Publications (1)

Publication Number Publication Date
WO2023098043A1 true WO2023098043A1 (zh) 2023-06-08

Family

ID=80367042

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/100674 Ceased WO2023098043A1 (zh) 2021-12-03 2022-06-23 一种接口参数校验方法及装置

Country Status (2)

Country Link
CN (1) CN114116510A (zh)
WO (1) WO2023098043A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117707653A (zh) * 2024-02-06 2024-03-15 天津医康互联科技有限公司 参数监控方法、装置、电子设备及计算机可读存储介质
CN118069539A (zh) * 2024-04-19 2024-05-24 建信金融科技有限责任公司 数据处理的方法、装置、电子设备和存储介质
CN121597445A (zh) * 2026-01-28 2026-03-03 济南浪潮数据技术有限公司 接口调用方法、电子设备及存储介质

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114116510A (zh) * 2021-12-03 2022-03-01 深圳前海微众银行股份有限公司 一种接口参数校验方法及装置
CN117573762B (zh) * 2024-01-15 2024-04-16 杭州数云信息技术有限公司 数据连接平台的数据处理方法及装置、存储介质、服务器

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10262095B1 (en) * 2017-09-28 2019-04-16 Cadence Design Systems, Inc. Conversion of real number modeling code to cycle-driven simulation interface code for circuit design in digital mixed signal environments
CN111064725A (zh) * 2019-12-12 2020-04-24 广州鲁邦通物联网科技有限公司 一种代码零入侵接口校验方法和校验装置
CN112395138A (zh) * 2020-11-20 2021-02-23 北京华胜天成科技股份有限公司 一种校验参数的方法和装置
CN113157256A (zh) * 2021-03-25 2021-07-23 北京达佳互联信息技术有限公司 接口代码的生成方法、装置、电子设备、存储介质及产品
CN114116510A (zh) * 2021-12-03 2022-03-01 深圳前海微众银行股份有限公司 一种接口参数校验方法及装置

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10262095B1 (en) * 2017-09-28 2019-04-16 Cadence Design Systems, Inc. Conversion of real number modeling code to cycle-driven simulation interface code for circuit design in digital mixed signal environments
CN111064725A (zh) * 2019-12-12 2020-04-24 广州鲁邦通物联网科技有限公司 一种代码零入侵接口校验方法和校验装置
CN112395138A (zh) * 2020-11-20 2021-02-23 北京华胜天成科技股份有限公司 一种校验参数的方法和装置
CN113157256A (zh) * 2021-03-25 2021-07-23 北京达佳互联信息技术有限公司 接口代码的生成方法、装置、电子设备、存储介质及产品
CN114116510A (zh) * 2021-12-03 2022-03-01 深圳前海微众银行股份有限公司 一种接口参数校验方法及装置

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117707653A (zh) * 2024-02-06 2024-03-15 天津医康互联科技有限公司 参数监控方法、装置、电子设备及计算机可读存储介质
CN117707653B (zh) * 2024-02-06 2024-05-10 天津医康互联科技有限公司 参数监控方法、装置、电子设备及计算机可读存储介质
CN118069539A (zh) * 2024-04-19 2024-05-24 建信金融科技有限责任公司 数据处理的方法、装置、电子设备和存储介质
CN121597445A (zh) * 2026-01-28 2026-03-03 济南浪潮数据技术有限公司 接口调用方法、电子设备及存储介质

Also Published As

Publication number Publication date
CN114116510A (zh) 2022-03-01

Similar Documents

Publication Publication Date Title
WO2023098043A1 (zh) 一种接口参数校验方法及装置
US9984152B2 (en) Data integration tool
CN104866426B (zh) 软件测试综合控制方法及系统
CN113238740B (zh) 代码生成方法、代码生成装置、存储介质及电子设备
CN113504900A (zh) 一种编程语言转换方法和装置
CN113050987B (zh) 一种接口文档的生成方法、装置、存储介质及电子设备
CN110688121A (zh) 代码补全方法、装置、计算机装置及存储介质
CN111694561A (zh) 一种接口管理方法、装置、设备及存储介质
CN111581920A (zh) 文档转换方法、装置、设备及计算机存储介质
CN114691143B (zh) 一种代码生成方法、装置、设备及计算机可读存储介质
CN113792138B (zh) 报表生成方法、装置、电子设备及存储介质
CN112035443A (zh) 基于Linux平台的大数据执行方法、系统、设备及存储介质
CN115641092A (zh) 实现数据核查计划导入自动生成逻辑核查的方法和系统
CN110543297A (zh) 用于生成源码的方法和装置
CN103955429A (zh) 确定回归测试范围的方法及装置
CN112416333A (zh) 软件模型训练方法、装置、系统、设备和存储介质
CN111626585B (zh) 脚本数据提取方法、装置、计算机设备和存储介质
CN117370242A (zh) 通过解析接口文档生成多语言sdk客户端的适配器和方法
CN106708475A (zh) 一种北向数据转换方法和装置
CN110175128B (zh) 一种相似代码案例获取方法、装置、设备和存储介质
CN113986381B (zh) 数据解析方法、装置、设备及存储介质
CN115640279A (zh) 一种数据血缘关系的构建方法和装置
CN114443484A (zh) 一种程序测试方法、装置、设备及存储介质
CN112799638B (zh) 无侵入式快速开发方法、平台、终端及存储介质
CN114020965A (zh) 数据转换方法、装置及存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22899863

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 23.09.2024)

122 Ep: pct application non-entry in european phase

Ref document number: 22899863

Country of ref document: EP

Kind code of ref document: A1