Interface calling method and device, equipment, storage medium and program product

The interface calling method automates the process of determining and generating response data using a simulation interface library, addressing the inefficiencies of manual code writing in traditional interface testing, thereby improving testing efficiency and flexibility.

CN119149140APending Publication Date: 2024-12-17MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410832277.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-25
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

Traditional interface testing requires manual code writing to simulate mock interfaces, which is time-consuming and error-prone, especially when backend interfaces are not yet developed or unstable.

Method used

An interface calling method that determines a target simulation interface and generates response data automatically by using a preset simulation interface library, eliminating the need for manual code writing by testers.

Benefits of technology

Improves the efficiency and accuracy of interface testing by allowing front-end developers to simulate interface calls without relying on real interfaces, enhancing flexibility and practicality during development and testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149140A_ABST
    Figure CN119149140A_ABST
Patent Text Reader

Abstract

The invention provides an interface calling method and device, equipment, a storage medium and a program product. The interface calling method comprises the following steps: determining a target simulation interface corresponding to an interface calling request in a preset simulation interface library according to a request method and a request path in the interface calling request of a sending end; determining a response data class according to the interface definition of the target simulation interface, and generating response data according to the response data class; and sending the response data to the sending end, so that interface calling can be realized without depending on a real interface and without manually writing codes by testers.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to computer technology, and in particular to an interface calling method, device, equipment, storage medium and program product. Background Art

[0002] As the complexity of software development increases, interface testing becomes an important part of ensuring software quality. Traditional interface testing usually requires testers to manually write code to simulate mock interfaces. When the backend interface is not yet developed or is unstable, front-end developers or testers cannot implement interface calls by simulating interfaces. Summary of the invention

[0003] The present application provides an interface calling method, apparatus, device, storage medium and program product, so as to achieve the technical effect of interface calling without relying on a real interface and without the need for testers to manually write code.

[0004] On the one hand, the present application provides an interface calling method, comprising:

[0005] Determine, according to the request method and request path in the interface call request, a target simulation interface in a preset simulation interface library corresponding to the interface call request;

[0006] Determine a response data class according to an interface definition of the target simulation interface, and generate response data according to the response data class;

[0007] The response data is sent to the sending end of the interface call request.

[0008] On the other hand, the present application provides an interface calling device, comprising:

[0009] A determination unit, configured to determine a target simulation interface corresponding to the interface call request in a preset simulation interface library according to a request method and a request path in the interface call request;

[0010] A generating unit, configured to determine a response data class according to an interface definition of the target simulation interface, and generate response data according to the response data class;

[0011] The sending unit is used to send the response data to the sending end of the interface call request.

[0012] On the other hand, the present application provides an electronic device, comprising: a processor, and a memory connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement any of the above methods.

[0013] On the other hand, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement any of the above methods.

[0014] On the other hand, the present application provides a computer program product, including a computer program, which implements any of the above methods when executed by a processor.

[0015] The interface calling method, device, equipment, storage medium and program product provided by the present application, the method, firstly, according to the request method and request path in the interface calling request of the sending end, determines the target simulation interface corresponding to the interface calling request in the preset simulation interface library; because the simulation interface library is pre-created and configured, covering various possible simulation interfaces of request methods and request paths, the system can directly match and search from the simulation interface library when processing the interface calling request, without connecting and relying on the real interface. Secondly, the response data class is determined according to the interface definition of the target simulation interface, and the response data is generated according to the response data class. By automatically determining the target simulation interface according to the request method and request path, and then automatically determining the response data class according to the interface definition and generating the response data. It can be seen that the tester does not need to manually write code for each specific interface call to process the request and generate the response, but can automatically find the corresponding target simulation interface from the simulation interface library according to the established rules and processes. Finally, the response data is sent to the sending end, so that the technical effect of the interface call is achieved without relying on the real interface and without the need for the tester to manually write code, thereby improving the efficiency of development and testing. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0017] Figure 1 It is a flowchart of an interface calling method provided in an embodiment of the present application;

[0018] Figure 2 A flowchart of an optional interface calling method provided in an embodiment of the present application;

[0019] Figure 3 It is a flowchart of an optional interface calling method provided in an embodiment of the present application;

[0020] Figure 4 A flowchart of an optional interface calling method provided in an embodiment of the present application;

[0021] Figure 5It is a flowchart of an optional interface calling method provided in an embodiment of the present application;

[0022] Figure 6 A structural block diagram of an interface calling device provided in an embodiment of the present application;

[0023] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0024] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0025] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0026] First, the terms involved in this application are explained:

[0027] Interface mock: It is a method of simulating the real behavior of a system in software development and testing to ensure that testing or development can continue without actual components or services. A mock object is a special object that simulates the behavior of a real object, but internally provides the developer or tester with full control over that behavior. This means that using a mock object, you can preset the expected behavior and output, and you can also check its internal behavior to verify that it is operating as expected.

[0028] JSONSchema: is a standardized language for describing the structure and validation rules of JSON formatted data. Its core purpose is to provide clear, detailed and machine-readable definitions for JSON data formatting. It specifies how to describe the properties of objects, elements of arrays, data types of values, string patterns, digital restrictions, etc. in JSON data. Furthermore, JSONSchema can not only be used to verify whether data meets specific structures and conditions, but also supports annotations, default values, semantic validation, and a variety of complex structural relationships (for example, data polymorphism, references, and recursive definitions). Therefore, it provides powerful support for application scenarios such as ensuring data consistency, generating documents, and automatically generating code and user interfaces.

[0029] OpenAPI Specification (OAS): is an open source, standardized, machine-readable format designed specifically for RESTful APIs to describe their overall structure and behavior. The OpenAPI specification allows developers to clearly define the details of the API in a structured manner, including but not limited to: endpoint description, which defines all endpoints (or paths) provided by the API and the HTTP methods supported on these endpoints (such as GET, POST, PUT, and DELETE); request and response formats, which define possible input parameters, request body formats, response bodies, HTTP status codes, and possible error messages for each API call; data models, which describe the structure of the simulated interface handled by the API, such as users, orders, or any other entities. These structures are usually defined through JSONSchema; authentication and authorization, which specifies how the API handles authentication and authorization, including supported authentication mechanisms (such as API keys, OAuth tokens, etc.) and permission requirements for each endpoint; version information, licensing, and other metadata, which provide additional descriptive information for the API, such as its creator, current version, license, etc. The definition of OpenAPI not only provides developers with clear API design documents, but also enables various tools and systems to automatically generate code, test scripts, simulation servers or production-level services, thereby greatly improving the efficiency of development and deployment.

[0030] As the complexity of software development increases, interface testing becomes an important part of ensuring software quality. However, traditional interface testing usually requires testers to manually write code to simulate mock interfaces, which is time-consuming and error-prone. Therefore, how to quickly and efficiently generate interface mock data has become a problem that needs to be solved.

[0031] There are several main ways to mock existing interfaces: 1) Code writing: directly write code to mock interfaces and return parameters, which is not suitable for widespread use. It takes a long time to write code and requires a certain threshold, requiring front-end personnel to have programming skills. 2) Fixed configuration method: just request a certain interface and directly configure the return value, and the return value is fixed. This method is relatively simple, but the return value is fixed. In many cases, we request the same interface to return different values. This method is suitable for scenarios with relatively low requirements and has great limitations. 3) Configuration method with programming: that is, you can write js scripts or python scripts in the configuration interface to dynamically return parameters. You can also do configuration, which is similar to the method in 2), and you can also use scripts to solve the problem of returning different values ​​according to different requests. This method solves the rigidity of fixed configuration. However, although the scripting language is relatively simple, it still requires front-end personnel to have programming skills and has a certain threshold. 4) Mock.js syntax method: You need to master the mock.js syntax and then configure the mock according to the rules. It is a popular method that can directly fix the configuration and does not have as high a threshold as writing scripts. However, the syntax is more complicated. If you really use it, it is similar to writing scripts, which requires front-end personnel to have programming skills.

[0032] The interface calling method provided by the present application is intended to solve the above technical problems of the prior art. The technical solution of the present application and how the technical solution of the present application solves the above technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0033] Figure 1 is a flowchart of an interface calling method provided in an embodiment of the present application, such as Figure 1 As shown, the method includes:

[0034] S101, determining a target simulation interface corresponding to the interface call request in a preset simulation interface library according to a request method and a request path in the interface call request.

[0035] In the above steps, the sender can be understood as the party that initiates the communication or request, for example, it can be various types of applications, devices, system components, etc.

[0036] In the above steps, the interface call request can be understood as a specific request sent by the sender to a responder in the hope of obtaining specific data, performing specific operations or obtaining certain services. For example, a request sent by a mobile application to a server to obtain a user's friend list can be understood as an interface call request.

[0037] It should be understood that in this application example, specifically, this request usually contains some key information:

[0038] Request methods, such as GET (get data), POST (submit data), PUT (update data), DELETE (delete data), etc., are used to indicate the type of operation requested.

[0039] The request path specifies the specific location or address of the interface to be called, for example, it can be a URL path, which is used to define the location of the requested resource on the server.

[0040] In addition, it may also contain a request header to pass some additional metadata, such as authentication information, the format of the request, etc. The request body (in some request methods) is used to carry specific data, such as form data submitted in a POST request, and so on.

[0041] In the above steps, the preset simulation interface library contains multiple predefined simulation interfaces, each of which has its specific request method and request path. Therefore, the responder can search for the target simulation interface corresponding to the interface call request in the preset simulation interface library according to the extracted request method and path.

[0042] S102, determining a response data class according to an interface definition of a target simulation interface, and generating response data according to the response data class.

[0043] In the above steps, the response data class refers to a set of data attributes determined according to the interface definition of the simulation interface, which define the data structure and data type of the response data. It can be understood that the fields that the response data should contain and the data types of these fields are specified according to the interface definition.

[0044] In the above steps, the interface definition of the target simulation interface specifically includes detailed information such as the format, type, structure, etc. of the data expected to be returned by the simulation interface.

[0045] In the above steps, the response data class can be understood as a pre-set data template or model, which specifies the data attributes and data format (or rules and structure) that the response data should have. After the response data class corresponding to the target simulation interface is determined, the response end will generate specific response data according to the data attributes and data format specified by the response data class.

[0046] For example, if the interface definition of the target simulation interface indicates that for a certain interface call request, the response data class should contain the user's name, age and address information. When the response end generates the response data, it will assign values ​​to the name, age and address attributes according to this response data class, thus forming a complete response data.

[0047] For another example, in the interface definition of an e-commerce website, for a request to query product details, the response data class may include information such as product name, price, inventory quantity, product description, etc. The responder will obtain the corresponding values ​​from the preset data storage or calculation logic based on this response data class, and combine them to generate accurate response data and return it to the sender.

[0048] S103, sending the response data to the sending end of the interface call request.

[0049] In the above steps, after generating response data that meets the interface definition and requirements according to the previous steps, it is necessary to accurately transmit the response data back to the sender who originally initiated the interface call request through a predetermined communication method and channel, thereby completing a complete interface interaction.

[0050] For example, in the interaction between a mobile application and a server, the mobile application, as the sender, sends an API call request to the server to obtain product recommendations. The server generates response data for product recommendations based on relevant rules, such as a series of product names, pictures, prices, and other information. Then, the server will send these response data back to the mobile application in a specific data format (such as JSON, XML, etc.) through a network connection, so that the mobile application can receive and perform subsequent processing and display.

[0051] In this application example, after the responder determines the target simulation interface, the response data class to be returned can be determined based on the interface definition of the target simulation interface. When response data needs to be generated, the data instance is created with reference to this response data class to ensure that each field conforms to the predetermined data type and contains all necessary information. In this way, when an interface call request is received, the responder can generate response data that conforms to the interface definition based on this response data class and send it to the sender of the request.

[0052] The interface calling method provided in the embodiment of the present application is suitable for interface testing scenarios, can be implemented using an interface testing system, and can be used in project development and testing with front-end and back-end separation. When the back-end interface has not been completed or is unstable, the front-end developer or tester can verify the functions and performance of the front-end by simulating the interface without waiting for the completion or deployment of the back-end interface.

[0053] Taking interface testing in the development phase to verify whether the behavior of the interface meets the design requirements as an example, first, according to the request method and request path in the interface call request of the sender, determine the target simulation interface corresponding to the interface call request in the preset simulation interface library; since the simulation interface library is created and configured in advance, covering simulation interfaces of various possible request methods and request paths, the system can directly match and search from the simulation interface library when processing interface call requests, without connecting and relying on the real interface, and without caring about the specific implementation details of the real interface.

[0054] Secondly, the response data class is determined according to the interface definition of the target simulation interface, and the response data is generated according to the response data class. By automatically determining the target simulation interface according to the request method and request path, and then automatically determining the response data class and generating the response data according to the interface definition, it can be seen that the tester does not need to manually write code for each specific interface call to process the request and generate the response, but can automatically find the corresponding target simulation interface from the simulation interface library according to the established rules and processes.

[0055] Finally, the response data is sent to the sender, so that the technical effect of the interface call can be achieved without relying on the real interface and without the need for testers to manually write code, thereby improving the efficiency of development and testing. Without affecting the services and data of the real interface, the behavior and results of the real interface can be simulated to verify the logic and effect of the interface test, thereby enhancing the flexibility and practicality of the interface test.

[0056] In an optional embodiment, Figure 2 As shown, before obtaining the request method and the request path from the interface call request in response to the interface call request, the method further includes:

[0057] S201, configuring a preset analog interface library, wherein each analog interface in the analog interface library is configured with an interface definition.

[0058] In the above method steps, the interface definition includes at least one of the request method type, request path, request body and response body. The simulation interface library includes multiple simulation interfaces, each of which has its own interface definition, which details the behavior of the interface and the expected data structure to ensure that the simulation interface can correctly respond to various different interface call requests.

[0059] It should be understood that the request method type (such as GET, POST, etc.) determines the way of data interaction; the request path indicates the specific location of the interface; the request body contains the data sent to the interface; and the response body specifies the format and content of the data returned by the interface.

[0060] S202, converting the interface definition into a target protocol format, and saving the interface definition in the target protocol format.

[0061] In the above method steps, the target protocol format may be HTTP, SOAP or other network communication protocol formats.

[0062] It should be understood that S201 and S202 describe the configuration steps that need to be performed before processing an interface call request. Before actually receiving and processing an interface call request, the responding end must first configure a simulation interface library. For example, an interface definition platform can be used to configure a corresponding interface definition for each simulation interface, that is, each simulation interface has a detailed description and specification. In addition, the interface definition is converted into a specific protocol format for storage, such as the format of HTTP, SOAP or other network communication protocols, so that the interface definition can be stored and used in a unified format that can be recognized and processed by the responding end. In the example of the present application, the interface definition after formatting will be saved in the simulation interface library in the target protocol format, realizing unified management and standardization of the simulation interface, and improving the compatibility and maintainability of the simulation interface.

[0063] For example, assuming that the target protocol format is JSON, the interface definition originally described in XML format will be converted to JSON and saved so that the system can quickly read and understand these interface definitions during subsequent interface calls.

[0064] For another example, in the simulation interface library of an e-commerce platform, for the simulation interface of "getting product details", its interface definition includes the request method type of "GET", the request path of " / goods / detail", possible request bodies (such as product ID) and detailed response bodies (various information about the product). These definitions are converted into the specified target protocol format for storage and management.

[0065] Before the interface call, the above preparation steps of configuring and standardizing the simulation interface library can prepare for the subsequent interface call to be carried out smoothly and accurately. In addition, the sender does not need to care about the specific implementation method and details of the simulation interface, but only needs to write and store the interface definition according to the target protocol format, such as the OpenAPI protocol format, so that the simulation interface can be seamlessly connected with different senders and real interfaces, reducing the complexity and risk of the simulation interface.

[0066] In one example, the OpenAPI protocol specification can be used to accurately, detailed, and intuitively describe an interface definition. However, it should be noted that the OpenAPI protocol specification is used when storing the interface definition, but a set of interface description protocols can also be completely customized and are not strongly dependent on the OpenAPI protocol.

[0067] This application example avoids the need for testers to manually write code by configuring interface definitions, greatly improving the efficiency of interface testing. By using the interface definition platform to configure the corresponding interface definition for each simulated interface, the resulting response data can meet the requirements of the actual application, thereby more accurately reflecting the actual application scenario.

[0068] In an optional example, the response data class includes: data attributes of the request body and response body of the target simulation interface; Figure 3 As shown, the response data class is determined according to the interface definition of the target simulation interface, and response data is generated according to the response data class, including:

[0069] S301, determining data attributes of a request body and a response body of a target simulation interface according to an interface definition of the target simulation interface, wherein the data attributes include a data structure and a data type.

[0070] As shown above, the response data class refers to the definition of the data structure and type used to generate the response data. Optionally, the data structure can be, for example, an object, an array, etc., and the data type can include any one of the following: integer int, string string, floating point number number, Boolean value boolean, null value NULL, array array, object object.

[0071] S302, generating response data corresponding to the interface definition according to the data structure and data type.

[0072] In one example, first, the responder determines the data attributes of the request body and the response body according to the interface definition of the target simulation interface. These data attributes include the structure of the data (e.g., object, array, etc.) and the data type (e.g., string, number, Boolean value, etc.).

[0073] After determining the data attributes of the request body and response body of the target simulation interface, that is, the data structure and data type, the corresponding response data can be generated according to the data structure and data type. Specifically, a data instance that matches the interface definition can be generated or created. This instance contains all necessary data fields and corresponding data types.

[0074] The interface definition can clarify the specific organization method (data structure) and type of data (data type) in the request body and response body, and then create specific response data content according to the clear data structure and data type.

[0075] For example, the data structure of the request body may be a form with multiple fields, each field has a specific data type, such as string, integer, or Boolean. The data structure of the response body may be an object containing product details, including product name (string type), price (float type), etc.

[0076] For another example, if the data structure of the response body is determined to be an object containing "name" (string), "age" (integer), and "gender" (string), then when generating the response data, each attribute will be assigned a corresponding type and a reasonable value according to this structure, such as "Zhang San" (name), 25 (age), and "male" (gender).

[0077] Through the above method steps, the example of this application can achieve that the generated response data can accurately reflect the interface definition of the simulated interface, so that the front-end application can be effectively tested and verified without the back-end service. This method is particularly suitable for the early stages of software development, when the back-end service has not yet been implemented, and the front-end developer can use simulated data for development and testing.

[0078] In this application example, a standardized description language can be used to uniformly represent and standardize the interface definition, thereby improving the compatibility and maintainability of the interface definition. The subsequent sender does not need to worry about the specific implementation method and details of the data structure, but only needs to write and store the data structure according to the standardized description language, such as JSON Schema, XML Schema, Protobuf, etc., so that the interface definition can be seamlessly connected with different data formats and data sources, reducing the complexity and risk of the interface definition.

[0079] It should be noted that in the embodiment of the present application, JSONSchema is used to describe the data structure of the interface request body and response body, which can accurately describe the Json data structure in the request body and response body, but a set of Json description formats can also be completely customized, and it is not strongly dependent on JSONSchema.

[0080] Afterwards, by generating the response data class mockStyleJson corresponding to the above interface definition according to the standardized description language JSONSchema, the automatic conversion and encapsulation of the interface definition is realized, and the operability and scalability of the interface definition are improved. The subsequent sender does not need to manually write and modify the code of the response data class, but only needs to automatically generate the response data class according to the standardized description language, so that the interface definition can be seamlessly connected with different programming languages ​​and development environments, improving the efficiency and flexibility of the interface definition.

[0081] Finally, the embodiments of the present application do not need to rely on the generation and transmission of real data. They only need to use simulation tools, such as Mockito, EasyMock, Wi reMock, etc., to instantiate the response data class, so that the interface definition can generate simulated response data mockedJson, thereby realizing the simulation implementation and verification of the interface definition, and improving the reliability and testability of the interface definition.

[0082] It should be noted that in the embodiment of the present application, mockStyleJson is generated by JSONSchema and stored in the interface definition as a sample template of the response. When the interface mock is subsequently implemented, the desired specific mockedJson data can be generated very conveniently without having to parse the data structure of the response content again.

[0083] As an optional embodiment, Figure 4 As shown, according to the data structure and data type, the response data corresponding to the interface definition is generated, including:

[0084] S401, determining a method for generating response data according to a request method type in an interface definition;

[0085] S402, generating response data according to the generation method, data structure and data type.

[0086] In the above method steps, the responder first needs to determine how to generate response data according to the request method type specified in the interface definition (such as GET, POST, PUT, etc.). Different request methods may require different response data generation logic. For example, for a GET request, it may be mainly to obtain data from an existing database or a preset data set as a response; while for a POST request, it may be necessary to calculate, process, or combine the submitted data with other data to generate a response.

[0087] After determining the generation method, the responder generates response data according to the generation method, data structure and data type. It can be understood that the specific response data is actually created by comprehensively considering the determined generation method, as well as the clear data structure (such as array, object, etc.) and data type (such as integer, string, Boolean value, etc.).

[0088] For example, if the request method type is GET, the data structure is an array containing product information, and the data types include product ID (integer), product name (string), and product price (floating point number), then when generating response data, the product information array that conforms to this structure and type will be obtained from the data source in the usual way of GET request.

[0089] For example, if the request method type is POST, the submitted data is the user's order information, the data structure includes the order number (string), product list (array) and total amount (floating point number), and the data types match accordingly. When generating the response data, the discount amount may be calculated based on the order information, and the final response data is generated according to the specified structure and type combination.

[0090] In one example, if the above-mentioned response data satisfies the language format of the standardized description language, the above-mentioned interface definition is determined to be valid. That is, the embodiment of the present application can determine the validity of the interface definition on the premise of ensuring that the format of the response data is correct and consistent, and store the response data in the interface definition, so that the interface definition can be synchronized and consistent with the response data, thereby enhancing the completeness and accuracy of the interface definition.

[0091] In another example, if the above-mentioned response data does not meet the language format of the standardized description language, the above-mentioned interface definition is determined to be wrong, thereby achieving effective feedback and prompts on the interface definition. Moreover, when the format of the response data is found to be wrong or inconsistent, the writing and storage of the interface definition can be modified and optimized according to the error information, so that the interface definition can be kept compliant and consistent with the standardized description language, thereby reducing the complexity and risk of the interface definition.

[0092] As an optional embodiment, for example, a front-end developer of an e-commerce platform needs to call the back-end search interface to implement the product search and display functions, but the back-end search interface is still under development and cannot be provided to the front-end. At this time, the front-end developer can use the simulation interface method to create an interface definition that is the same as the back-end search interface, including the request method, request path, request body, and response body, etc., and then generate some simulated response data based on the interface definition to simulate the behavior and results of the back-end search interface, so that the front-end development and testing work can be carried out without relying on the back-end interface.

[0093] To realize the function of such a simulated interface, the specific method steps are as follows: First, on the interface definition platform, pre-configure the interface definition of the simulated interface to be called, wherein the interface definition is used to describe at least one of the following contents of the simulated interface: request method type, request path, request body and response body. Then, process the interface definition into the target protocol format OpenAPI, and store the interface definition in the target protocol format OpenAPI, so that the interface definition can be seamlessly connected with different sending ends and real interfaces. After that, obtain the data structures corresponding to the request body and the response body in the interface definition, obtain the standardized description language for describing the data structures corresponding to the request body and the response body, generate the response data class mockStyleJson corresponding to the interface definition according to the standardized description language, and use this mockStyleJson class to conveniently and quickly use the simulation tool to instantiate the response data class to generate the response data mockedJson corresponding to the simulated interface. Finally, check whether the response data meets the language format of the standardized description language JSONSchema. If the response data meets the language format of the standardized description language, the interface definition is determined to be valid, and the response data is stored in the interface definition. If the response data does not meet the language format of the standardized description language, the interface definition is determined to be wrong.

[0094] As an optional embodiment, Figure 5 As shown, according to the generation method, data structure and data type, at least one response data satisfying the response data class is determined, including:

[0095] S501: If the generation method is a random generation method, randomly select at least one existing response data from the simulation interface library according to the data structure and data type.

[0096] In the above steps, the response data may be determined according to different generation methods, which are divided into two types: random generation and non-random generation.

[0097] In the example of this application, if the random generation method is selected, at least one response data can be randomly selected from the simulation interface library according to the defined data structure and data type. It can be understood that in the random generation method, the response data will not be fixed, but based on the specified data structure (such as an object containing multiple fields) and data type (such as some fields are integers and some are strings), at least one response data is randomly selected as the final response data from the multiple response data prepared in advance by the simulation interface library.

[0098] S502: If the generation method is a non-random generation method, assign values ​​to the data attributes of the request body and the response body according to the data structure and data type, and generate response data according to the assignment result.

[0099] In the example of this application, if a non-random generation method is selected, specific assignment operations can be performed according to the data attributes of the request body and the response body. For each data attribute in the request body and the response body, a corresponding value is assigned according to its data structure and type, thereby generating response data that meets the interface definition. The specific assignment process has rules and basis, which can be based on a preset algorithm, real data in a database, or other deterministic logic. It should be understood that non-random generation methods are generally used in scenarios that require specific data output, such as in scenarios for testing specific functions or logic.

[0100] Through the above method steps, when generating response data, you can choose a suitable generation method according to different needs. Whether it is to test the robustness of the interface or to verify specific business logic, it can be achieved through this flexible data generation strategy.

[0101] In the example of this application, there is also an optional embodiment, which uses the following method steps to configure an interface definition for each analog interface:

[0102] At least one of a real request method type, a real request path, a real request body, and a real response body is extracted from the interface definition of the real interface.

[0103] An interface definition of a simulation interface corresponding to the real interface is generated according to at least one of a real request method type, a real request path, a real request body, and a real response body.

[0104] In the above method steps, first, key information is extracted from the existing real interface, for example, it may include at least one of the elements such as request method type (such as GET, POST, etc.), request path (i.e., URL of API), request body (data sent to the responding end) and response body (data returned by the responding end). These element information are the basis for constructing the simulated interface.

[0105] Then, based on the extracted element information of the real interface, a complete interface definition of the simulated interface is created. For example, the extracted elements are adjusted, supplemented, or recombined to form an interface definition that can be used in a simulated environment and meets specific requirements and rules. For example, based on the extracted request method and path of the real interface, combined with some preset simulation data and rules, the format and content of the request body and response body of the simulated interface are determined, thereby generating a complete simulation interface definition.

[0106] Through the above method and steps, it can be ensured that the simulated interface can reflect the behavior of the real interface as much as possible, so that developers can still carry out front-end development and testing work when the back-end interface is not yet completed, thereby speeding up the development cycle.

[0107] As an optional example, determining a target simulation interface corresponding to the interface call request in a preset simulation interface library according to the request method and the request path may include the following method steps:

[0108] Traverse the simulation interfaces of the simulation interface library, and match the request method and request path of the simulation interface with the request method and request path in the interface call request;

[0109] The target simulation interface corresponding to the interface call request is determined according to the matching result.

[0110] It should be understood that the above method steps describe a specific method for determining a target simulation interface corresponding to an interface call request in a simulation interface library.

[0111] First, by traversing the simulation interface library, each simulation interface in the simulation interface library can be checked. For example, each simulation interface in the simulation interface library is checked one by one. For each simulation interface, its own set request method (such as GET, POST, etc.) and request path (such as a specific URL path) are compared with the request method and request path in the currently received interface call request.

[0112] Afterwards, the request method and request path of each simulation interface in the simulation interface library can be matched with the request method and path in the interface call request. After the above-mentioned one-by-one matching process, if the request method and request path of a simulation interface are exactly the same as the interface call request, then this simulation interface will be identified as the target simulation interface corresponding to the request, and the target simulation interface will be used to generate response data.

[0113] Through the above method steps, the correct simulation interface can be accurately identified to respond to the interface call request, thereby improving the accuracy and effectiveness of the interface call during the testing phase of software development.

[0114] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0115] According to one or more embodiments of the present application, an interface calling device is provided. Figure 6 A structural block diagram of an interface calling device provided in an embodiment of the present application, such as Figure 6 As shown, the above device comprises:

[0116] The determination unit 601 is used to determine the target simulation interface corresponding to the interface call request in the preset simulation interface library according to the request method and request path in the interface call request of the sending end;

[0117] A generating unit 602, configured to determine a response data class according to the interface definition of the target simulation interface, and generate response data according to the response data class;

[0118] The sending unit 603 is used to send the above response data to the above sending end.

[0119] According to one or more embodiments of the present application, the above device further includes:

[0120] A configuration unit is used to configure a preset simulation interface library, wherein each simulation interface in the simulation interface library is configured with an interface definition, and the interface definition includes at least one of a request method type, a request path, a request body, and a response body.

[0121] The format conversion unit is used to convert the above interface definition into a target protocol format and save the above interface definition in the above target protocol format.

[0122] According to one or more embodiments of the present application, the above-mentioned response data class includes: data attributes of the request body and response body of the target simulation interface; the above-mentioned generation unit includes:

[0123] The first determination subunit is used to determine the data attributes of the request body and the response body of the target simulation interface according to the interface definition of the target simulation interface, wherein the data attributes include data structure and data type.

[0124] The generating subunit is used to generate the above-mentioned response data corresponding to the above-mentioned interface definition according to the above-mentioned data structure and data type.

[0125] According to one or more embodiments of the present application, the above-mentioned generating subunit is further used for:

[0126] The method for generating the above response data is determined according to the above request method type in the above interface definition.

[0127] The response data is generated according to the generation method, data structure and data type.

[0128] According to one or more embodiments of the present application, the above-mentioned generating subunit is further used for:

[0129] If the above generation method is a random generation method, then at least one existing response data is randomly selected from the above simulation interface library according to the above data structure and the above data type.

[0130] If the above generation method is a non-random generation method, then according to the above data structure and data type, the data attributes of the above request body and the above response body are assigned values, and response data is generated according to the assignment results.

[0131] According to one or more embodiments of the present application, the apparatus is further configured to configure an interface definition for each analog interface using the following unit modules:

[0132] The extraction unit is used to extract at least one of a real request method type, a real request path, a real request body and a real response body from the interface definition of the real interface.

[0133] The interface definition generating unit is used to generate the interface definition of the simulation interface corresponding to the real interface according to at least one of the real request method type, the real request path, the real request body and the real response body.

[0134] According to one or more embodiments of the present application, the above-mentioned determination unit includes:

[0135] The second determination unit is used to traverse the simulation interface of the simulation interface library, and match the request method and request path of the simulation interface with the request method and request path in the interface call request.

[0136] The third determining unit is used to determine the target simulation interface corresponding to the interface calling request according to the matching result.

[0137] In an exemplary embodiment, the present application also provides an electronic device, including: a processor, and a memory connected to the processor;

[0138] The memory stores computer-executable instructions;

[0139] The processor executes the computer-executable instructions stored in the memory to implement any of the above methods.

[0140] In an exemplary embodiment, the embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement any of the above methods.

[0141] In an exemplary embodiment, the present application also provides a computer program product, including a computer program, which implements any of the above methods when executed by a processor.

[0142] In order to implement the above embodiment, the present application embodiment also provides an electronic device. Figure 7, which shows a schematic diagram of the structure of an electronic device 700 suitable for implementing an embodiment of the present application, and the electronic device 700 may be a terminal device or a server. The terminal device may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, message transceiver devices, game consoles, medical devices, fitness equipment, personal digital assistants (PDAs), tablet computers (PADs), portable multimedia players (PMPs), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0143] like Figure 7 As shown, the electronic device 700 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage device 708 to a random access memory (RAM) 703. Various programs and data required for the operation of the electronic device 700 are also stored in the RAM 703. The processing device 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.

[0144] Typically, the following devices may be connected to the I / O interface 705: an input device 706 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 707 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 708 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 709. The communication device 709 may allow the electronic device 700 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 7 The electronic device 700 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0145] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 709, or installed from the storage device 708, or installed from the ROM 702. When the computer program is executed by the processing device 701, the above-mentioned functions defined in the method of the embodiment of the present application are executed.

[0146] It should be noted that the computer-readable medium mentioned above in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0147] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0148] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the method shown in the above embodiment.

[0149] The computer program code for performing the operation of the present application can be written in one or more programming languages ​​or a combination thereof, and the above-mentioned programming languages ​​include object-oriented programming languages, such as Java, Smalltalk, C++, and also include conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed completely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., using an Internet service provider to connect through the Internet).

[0150] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0151] The units involved in the embodiments described in the present application may be implemented by software or hardware. The name of the unit does not limit the unit itself in some cases. For example, the first acquisition unit may also be described as a "unit for acquiring at least two Internet Protocol addresses".

[0152] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0153] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0154] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0155] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. An interface calling method, It is characterized in that The method comprises: Determine, according to the request method and request path in the interface call request, a target simulation interface in a preset simulation interface library corresponding to the interface call request; Determine a response data class according to an interface definition of the target simulation interface, and generate response data according to the response data class; The response data is sent to the sending end of the interface call request.

2. The method according to claim 1, It is characterized in that The method further comprises: Configuring the preset simulation interface library, wherein each simulation interface in the simulation interface library is configured with an interface definition, and the interface definition includes at least one of a request method type, a request path, a request body, and a response body; The interface definition is converted into a target protocol format, and the interface definition is saved in the target protocol format.

3. The method according to claim 2, It is characterized in that The response data class includes data attributes of the request body and the response body of the target simulation interface; the step of determining the response data class according to the interface definition of the target simulation interface and generating response data according to the response data class includes: Determine data attributes of a request body and a response body of the target simulation interface according to the interface definition of the target simulation interface, wherein the data attributes include a data structure and a data type; According to the data structure and data type, the response data corresponding to the interface definition is generated.

4. The method according to claim 3, It is characterized in that The step of generating the response data corresponding to the interface definition according to the data structure and the data type includes: Determining a method for generating the response data according to the request method type in the interface definition; The response data is generated according to the generation method, the data structure and the data type.

5. The method according to claim 4, It is characterized in that The step of generating the response data according to the generating method, the data structure and the data type includes: If the generating method is a random generating method, randomly selecting at least one existing response data from the simulation interface library according to the data structure and the data type; If the generation method is a non-random generation method, the data attributes of the request body and the response body are assigned values ​​according to the data structure and data type, and response data is generated according to the assignment results.

6. The method according to claim 2, It is characterized in that The following method steps are used to configure the interface definition for each analog interface: Extracting at least one of a real request method type, a real request path, a real request body, and a real response body from an interface definition of a real interface; An interface definition of the simulation interface corresponding to the real interface is generated according to at least one of the real request method type, the real request path, the real request body, and the real response body.

7. The method according to any one of claims 1 to 6, It is characterized in that The step of determining, according to the request method and the request path, a target simulation interface in a preset simulation interface library corresponding to the interface call request comprises: Traversing the simulation interfaces of the simulation interface library, and matching the request method and request path of the simulation interface with the request method and request path in the interface call request; The target simulation interface corresponding to the interface call request is determined according to the matching result.

8. An interface calling device, It is characterized in that The device comprises: A determination unit, configured to determine a target simulation interface corresponding to the interface call request in a preset simulation interface library according to a request method and a request path in the interface call request; A generating unit, configured to determine a response data class according to an interface definition of the target simulation interface, and generate response data according to the response data class; The sending unit is used to send the response data to the sending end of the interface call request.

9. An electronic device, It is characterized in that include: A processor, and a memory connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the interface calling method according to any one of claims 1 to 7.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer-executable instructions, which are used to implement the interface calling method according to any one of claims 1 to 7 when executed by a processor.

11. A computer program product, It is characterized in that The invention comprises a computer program, which implements the interface calling method according to any one of claims 1 to 7 when executed by a processor.