Method and system for generating template function corresponding to interface request parameter, terminal and medium
By generating template functions corresponding to interface request parameters, the problem that service providers in the OpenAPI management platform need to write code to process interface request parameters is solved, which simplifies the registration process and reduces the difficulty, and expands the applicability of the platform.
Patent Information
- Application Number
- CN202411941393.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-05-23
AI Technical Summary
In the OpenAPI management platform, service providers need to write code themselves to process interface request parameters, which increases the difficulty of interface registration and the threshold for platform use.
提供一种生成接口请求参数对应模板函数的方法,通过获取和解析接口相关信息的文档,提取模板参数的计算规则,并基于此生成模板函数,简化接口请求参数的处理。
The service registration process is simplified, the difficulty of service providers registering services is reduced, the details of template parameter processing are blocked, and the applicability of the service engine is expanded.
Smart Images

Figure CN120029587A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, system, terminal and medium for generating a template function corresponding to an interface request parameter. Background Art
[0002] The OpenAPI management platform is a software solution designed to help developers and enterprises manage and use the OpenAPI specification to build, publish, maintain and use APIs. Service providers register their APIs on the platform and submit them for review. The platform will then conduct a detailed review of the submitted APIs from multiple dimensions, including functional integrity, security, stability, and compliance with platform specifications, based on a series of established strict standards. After the review is successful, users with interface requirements can easily find and efficiently use these interfaces with the help of the convenient search and filtering functions provided by the platform. From this perspective, whether a simple, convenient and smooth experience of accessing and calling APIs on the OpenAPI platform can be created for users is undoubtedly of vital importance to whether the platform can stand out in the fierce market competition and achieve widespread promotion and use.
[0003] Specifically, when a service provider registers an API on the platform, it needs to define the various request parameters required when calling the interface. Considering the security of data transmission, preventing malicious attacks, and meeting complex logical requirements in specific business scenarios, service registrants usually take a series of complex and critical processing measures when editing the request parameters required for calling these interfaces on the platform. For example, sensitive data is encrypted to ensure the confidentiality of data during transmission and storage; certain specific parameters are converted to uppercase and lowercase to adapt to the strict requirements of different systems or business rules.
[0004] However, as far as the current status of the OpenAPI platform is concerned, for these key processing links of request parameters, such as encryption and adding accurate timestamps, the service provider still needs to rely on its own technical capabilities and programming knowledge to strictly follow the complicated specifications given by the platform and write its own code to implement them. This situation undoubtedly increases the difficulty coefficient of interface registration to a large extent, making those users with relatively weak technical strength or who have just come into contact with the platform face many obstacles during use, thereby raising the overall usage threshold of the platform and, to a certain extent, limiting the rapid development and widespread popularity of the platform. Summary of the invention
[0005] In order to solve the technical problem that service providers need to encode interface request parameters by themselves when registering APIs in the OpenAPI management platform, which increases the difficulty coefficient of interface registration, the present invention provides a method for generating a template function corresponding to interface request parameters, and also provides a system, a terminal and a medium for generating a template function corresponding to interface request parameters.
[0006] To achieve the above-mentioned purpose, in a first aspect, a technical solution adopted by a method for generating a template function corresponding to an interface request parameter in the present invention is: A method for generating a template function corresponding to an interface request parameter comprises the following steps: Obtain a document describing information related to the interface, parse the document describing information related to the interface, and extract calculation rules for template parameters based on the parsing results; Key information is extracted from the calculation rule of the template parameter, and a template function corresponding to the calculation rule of the template parameter is generated based on the key information.
[0007] As a preferred implementation of a method for generating a template function corresponding to an interface request parameter, parsing a document for describing interface related information includes the following steps: A corresponding parsing tool is selected based on the type of the document used to describe the interface related information, and the document used to describe the interface related information is parsed based on the corresponding parsing tool.
[0008] As a preferred implementation of a method for generating a template function corresponding to an interface request parameter, the document used to describe the interface-related information is an API document or a WSDL document.
[0009] As a preferred implementation of a method for generating a template function corresponding to an interface request parameter, extracting key information from a calculation rule of the template parameter includes the following steps: The calculation rules of the template parameters are preprocessed, and the preprocessed calculation rules of the template parameters are segmented and tagged based on the natural language processing library, and key information is extracted using a grammar analysis tool based on the POS tagging results.
[0010] As a preferred implementation of a method for generating a template function corresponding to an interface request parameter, key information includes parameter names, operators, and operation order.
[0011] As a preferred implementation of a method for generating a template function corresponding to an interface request parameter, generating a template function corresponding to a calculation rule of the template parameter based on key information includes the following steps: Build an AST structure based on key information, build the function body code based on the AST structure, and output the template function.
[0012] As a preferred implementation of a method for generating a template function corresponding to an interface request parameter, a parsing tool for parsing a document describing interface-related information includes a first parsing tool and a second parsing tool, the first parsing tool is used to parse an API document, and the second parsing tool is used to parse a WSDL document; the first parsing tool includes Swagger Parser, Postman or APIMatic, and the second parsing tool includes Apache CXF, SoapUI or WSDL4J.
[0013] In the second aspect, the technical solution adopted by a system for generating a template function corresponding to an interface request parameter in the present invention is: A system for generating a template function corresponding to an interface request parameter includes a calculation rule extraction module and a function generation module, wherein: The calculation rule extraction module is configured to obtain a document describing information related to the interface, parse the document describing information related to the interface, and extract calculation rules of template parameters based on the parsing result; The function generation module is configured to extract key information from the calculation rule of the template parameter, and generate a template function corresponding to the calculation rule of the template parameter based on the key information.
[0014] In a third aspect, a technical solution adopted by a terminal in the present invention is: A terminal comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any one of the above-mentioned methods for generating a template function corresponding to an interface request parameter are implemented.
[0015] In a fourth aspect, a technical solution adopted by a medium in the present invention is: A storage medium stores a computer program thereon, and when the computer program is executed by a processor, the steps of any one of the methods for generating a template function corresponding to an interface request parameter as described above are implemented.
[0016] The beneficial effects of the present invention include: After generating a template function corresponding to the calculation rule of the template parameter according to a method for generating a template function corresponding to an interface request parameter proposed in the present invention, the service provider who registers the API can directly fill in the value of the template parameter in the interface request parameter as the template function, and can complete the service registration without complicated parameter definition editing operations, thereby simplifying the service registration process, standardizing the definition editing operations of the interface parameters during interface registration, reducing the difficulty of service provider registration of services, shielding the details of the template parameter processing implementation, reducing the difficulty of developers understanding the service, and expanding the applicability of the service engine. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solution of the present invention, the accompanying drawings required for use in the description will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0018] Figure 1 It is a flowchart of a method for generating a template function corresponding to an interface request parameter in a specific implementation mode of the present invention; Figure 2 It is a structural diagram of a system for generating a template function corresponding to an interface request parameter in a specific implementation manner of the present invention. DETAILED DESCRIPTION
[0019] The current OpenAPI platform still requires service providers to encode and process request parameters such as encryption and adding timestamps according to the platform's given specifications. This greatly increases the difficulty of interface registration and raises the threshold for platform use. Especially for complex HTTP services and WebService services, professional terminology and API-related concepts are involved when registering and calling APIs on the platform, making it impossible for users to self-register and call services in many cases. In addition, the current API service proxy engine is difficult to expand. When service registration users have new processing operations on API request parameters, the platform needs to modify a large amount of code to support the new operations.
[0020] A simple and easy-to-use API management platform should complete the processing of interface request parameters for users. When users register interfaces with the platform, they do not need to encode the request parameters. At the same time, its service proxy engine should be extensible. When users have new processing requirements for interface request parameters, it can simply and efficiently complete the registration, provision and use of services without changing any service proxy engine code.
[0021] Before describing the technical content of the specific embodiments of the present invention, the professional knowledge involved in the present invention is first introduced: API (Application Programming Interface) is a set of rules and protocols that define how different software components interact with each other. In simple terms, it is like a bridge for communication between software, allowing one software system (client) to access the functions and data provided by another software system (server). For example, when you check weather information in a mobile app, the app obtains weather data by calling the API of the weather service provider.
[0022] API documentation is a detailed description of the application programming interface (API), and its purpose is to help developers understand how to use the API correctly. It is like a user manual, covering key information such as the API's functions, usage methods, parameter requirements, and return values, so that developers can effectively call the API to implement their own application functions without understanding the internal implementation details of the API.
[0023] WSDL is an XML (Extensible Markup Language)-based language used to describe Web services. It is mainly used for Web services with SOAP (Simple Object Access Protocol) architecture. Its purpose is to accurately define the service interface, including the operations, message formats, transmission protocols, etc. provided by the service, so that clients of different platforms and languages can understand and call Web services.
[0024] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical scheme of the present invention will be clearly and completely described below in conjunction with the drawings in this specific embodiment. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0025] Reference Figure 1 A method for generating a template function corresponding to an interface request parameter proposed in this embodiment includes the following steps: S1. Obtain a document describing information related to the interface, parse the document describing information related to the interface, and extract calculation rules for template parameters based on the parsing results; S2. Extract key information from the calculation rule of the template parameter, and generate a template function corresponding to the calculation rule of the template parameter based on the key information.
[0026] In this embodiment, the document used to describe interface-related information is uploaded by the service provider who registers the API. After generating a template function corresponding to the calculation rule of the template parameter according to a method for generating a template function corresponding to an interface request parameter proposed in this embodiment, the service provider who registers the API can directly fill in the value of the template parameter in the interface request parameter as the template function. The service registration can be completed without the need for complex parameter definition editing operations, which simplifies the service registration process, standardizes the definition editing operations of the interface parameters during interface registration, reduces the difficulty of service providers registering services, shields the details of the template parameter processing implementation, reduces the difficulty for developers to understand the service, and expands the applicability of the service engine.
[0027] In addition, the template parameters implemented in this embodiment are easy to expand. When there are new parameter processing requirements for the template parameters, there is no need to modify the service proxy engine code. Instead, only the corresponding function implementation needs to be added to the implementation script of the template parameters.
[0028] In some embodiments, after parsing the document for describing interface-related information, the method for generating the template function corresponding to the interface request parameters further includes the following steps: Extract the names, positions, and values of the required parameters, optional parameters, constant parameters, and template parameters in the request parameters based on the parsing result, and generate a table based on the extraction result. After generating the template function corresponding to the calculation rule of the template parameter based on the key information, modify the value of the corresponding template parameter in the table to the template function.
[0029] Adopting the above steps to generate a table and modify the value of the corresponding template parameter in the table to the template function can facilitate the service provider registering the API to view all request parameters more clearly and conveniently, and at the same time facilitate manual verification of whether the template function is correct.
[0030] Among the required parameters, optional parameters, constant parameters, and template parameters, the constant parameters and template parameters do not need to be passed in by the interface requirement user.
[0031] In some embodiments, parsing the document for describing interface-related information includes the following steps: Select the corresponding parsing tool based on the type of the document for describing interface-related information, and parse the document for describing interface-related information based on the corresponding parsing tool.
[0032] Different parsing tools can parse different documents for describing interface-related information. In some embodiments, the document for describing interface-related information is an API document or a WSDL document.
[0033] In order to be able to parse the API document or the WSDL document, further, the parsing tools for parsing the document for describing interface-related information include a first parsing tool and a second parsing tool. The first parsing tool is used to parse the API document, and the second parsing tool is used to parse the WSDL document; the first parsing tool includes Swagger Parser, Postman, or APIMatic, and the second parsing tool includes Apache CXF, SoapUI, or WSDL4J.
[0034] Among them, Swagger is a set of open source tools for describing, designing, building and using RESTful APIs. Swagger Parser is one of the tools, which can parse Swagger / OpenAPI specification documents and automatically extract various types of parameter information in the API, such as path parameters, query parameters, request body parameters, etc. These parameters may include template parameters. It can also parse detailed properties such as parameter data type, whether it is required, and default value.
[0035] Postman is a popular API development and testing tool. It can import API documents (such as Swagger format) and clearly display API endpoints, request methods, parameters and other information on the interface. For automatic parameter extraction, it provides a visual way to view and manage parameters. Although it is mainly a manual operation tool, it can achieve a certain degree of automated parameter extraction through its built-in scripting functions (such as JavaScript scripts).
[0036] APIMatic is an API management platform that provides powerful API document parsing and conversion capabilities. It can process API documents in multiple formats, including Swagger, RAML, etc., and convert them into a unified format for easy management and analysis. It can automatically extract various parameters in the API, including complex nested parameter structures. It can also generate code examples, test cases, etc. These features help to deeply understand the usage scenarios of parameters, so as to better identify and process template parameters.
[0037] Apache CXF is an open source Web service framework that provides a wealth of tools and functions to handle Web service-related tasks, including WSDL parsing. It supports multiple Web service standards, such as SOAP, REST, etc. In terms of WSDL parsing, it can read WSDL files and generate corresponding Java code to represent service interfaces and data types. In this way, it indirectly helps to understand the parameter information in WSDL, including template parameters.
[0038] SoapUI is a widely used tool for testing Web services. It also provides powerful WSDL parsing capabilities. It can parse WSDL files and display information such as the service's operations, request and response structures. It can not only help you understand the content of WSDL, but also use its testing capabilities to send requests and observe responses, thereby better inferring the calculation rules and functions of template parameters.
[0039] WSDL4J is a Java library specifically for parsing WSDL documents. It can parse WSDL documents into Java objects, facilitating developers to programmatically access and process various elements in WSDL, such as service definitions, port types, messages, etc.
[0040] In some embodiments, extracting key information from the calculation rules of template parameters includes the following steps: Preprocess the calculation rules of template parameters, perform word segmentation on the preprocessed calculation rules of template parameters based on a natural language processing library, and perform part-of-speech tagging. Based on the part-of-speech tagging results, use a syntax analysis tool to extract key information.
[0041] Among them, the natural language processing library can be NLTK (Natural Language Toolkit). NLTK is a Python library that provides simple and easy-to-use interfaces for processing various natural language processing tasks. It contains a large number of corpora, lexical resources, and various text processing tools, and has functions such as word segmentation, part-of-speech tagging, named entity recognition, stemming, and lemmatization.
[0042] Furthermore, the key information includes parameter names, operators, and operation orders.
[0043] In this embodiment, generating a template function corresponding to the calculation rules of template parameters based on the key information includes the following steps: Construct an AST structure based on the key information, construct function body code based on the AST structure, and output the template function.
[0044] AST is a tree structure constructed by the compiler after performing syntax analysis on the source code during program compilation. It represents the syntax structure of the program code in an abstract way, eliminating some irrelevant details in the source code, such as spaces, comments, etc.
[0045] In a specific embodiment, the code of the AST structure and the code that can generate the function body code according to the AST structure are first constructed. The code of the AST structure can obtain the parameter name, operator and the operation order corresponding to the operator, and construct the corresponding AST structure according to the parameter name, operator and the operation order corresponding to the operator. It gradually combines the parameters and operators into a syntax tree from high to low according to the operation order. The code that generates the function body code according to the AST structure can obtain the AST structure, recursively traverse the AST structure, convert it into the corresponding Python function body code representation, and perform corresponding code generation processing for different node types (parameter nodes or binary expression nodes, etc.). For example, the binary expression node will concatenate the corresponding arithmetic operation expression according to the operator to generate a complete Python function code string, that is, a template function, and then output it.
[0046] The following are two examples of using a method of generating a template function corresponding to an interface request parameter in this embodiment: (1) Assume that there is an interface A. There is a template parameter checkSign in the calling parameters of interface A. The calculation rule is to connect version and orderNo together and use MD5 operation to obtain the signature value. The signature is in uppercase. OrderNo and version are parameters passed in by the user. Then, through this embodiment, the MD5 encryption function and the uppercase conversion function are implemented in the service proxy engine. When registering interface A to the platform, its value is upper(md5Hex(version+orderNo)) when editing the template parameters.
[0047] (2) Assume that there is a unified credit code query service, which is a WebService service. After parsing its WSDL, extract the names, positions and values of the required parameters, optional parameters, constant parameters and template parameters in the request parameters, and generate the following Table 1 based on the extraction results.
[0048]
[0049] Table 1 The value of the template parameter security is: <arguments> <unitname>XXX< / unitname> < / arguments> + KEY's MD5 value, extracts the calculation rules of template parameters based on the parsing results, extracts key information from the calculation rules of template parameters, and generates the template function md5Hex(arguments+key) corresponding to the calculation rules of template parameters based on the key information. When calling a service, the service caller only needs to provide the required unitname parameter and the necessary authentication parameters to implement the service call, without having to worry about the interface parameter requirements.
[0050] like Figure 2As shown below, a system for generating a template function corresponding to an interface request parameter provided by an embodiment of the present disclosure, a system for generating a template function corresponding to an interface request parameter and a method for generating a template function corresponding to an interface request parameter in the above-mentioned embodiments belong to the same inventive concept, and details not described in detail in the embodiment of a system for generating a template function corresponding to an interface request parameter can be referred to the embodiment of the above-mentioned method for generating a template function corresponding to an interface request parameter.
[0051] A system for generating a template function corresponding to an interface request parameter includes a calculation rule extraction module and a function generation module, wherein: The calculation rule extraction module is configured to obtain a document describing information related to the interface, parse the document describing information related to the interface, and extract calculation rules of template parameters based on the parsing result; The function generation module is configured to extract key information from the calculation rule of the template parameter, and generate a template function corresponding to the calculation rule of the template parameter based on the key information.
[0052] An embodiment of the present application also proposes a terminal, including a memory, a processor, a communication unit, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of a method for generating a template function corresponding to an interface request parameter when executing the program; the memory, the processor, and the communication unit communicate via one or more buses.
[0053] The processor may include one or more processing units, for example, the processor may include a central processing unit (CPU), an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor and / or a neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0054] The processor can be the nerve center and command center of the terminal. The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.
[0055] The memory is used to store the execution instructions of the processor. The memory can be implemented by any type of volatile or non-volatile storage terminal or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. When the execution instructions in the memory are executed by the processor, the terminal can execute some or all of the steps in the above method embodiments of generating a template function corresponding to the interface request parameters.
[0056] The wireless communication function of the electronic device can be implemented by an antenna, a wireless communication module, a modulation and demodulation processor, a baseband processor, etc.
[0057] The wireless communication module can provide solutions for wireless communication including wireless local area network, Bluetooth, global navigation satellite system, frequency modulation, near field communication technology, infrared technology, etc. applied to the electronic device.
[0058] This embodiment also proposes a storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the steps of any one of the above methods of generating a template function corresponding to the interface request parameters.
[0059] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for generating a template function corresponding to an interface request parameter, characterized in that: The following steps are involved: Obtain a document describing information related to the interface, parse the document describing information related to the interface, and extract calculation rules for template parameters based on the parsing results; Key information is extracted from the calculation rule of the template parameter, and a template function corresponding to the calculation rule of the template parameter is generated based on the key information.
2. A method for generating a template function corresponding to an interface request parameter according to claim 1, characterized in that: Parsing a document describing interface-related information involves the following steps: A corresponding parsing tool is selected based on the type of the document used to describe the interface related information, and the document used to describe the interface related information is parsed based on the corresponding parsing tool.
3. A method for generating a template function corresponding to an interface request parameter according to claim 2, characterized in that: The document used to describe interface-related information is an API document or a WSDL document.
4. A method for generating a template function corresponding to an interface request parameter according to claim 1, characterized in that: Extracting key information from the calculation rules of template parameters includes the following steps: The calculation rules of the template parameters are preprocessed, and the preprocessed calculation rules of the template parameters are segmented and tagged based on the natural language processing library, and key information is extracted using a grammar analysis tool based on the POS tagging results.
5. A method for generating a template function corresponding to an interface request parameter according to claim 1, characterized in that: Key information includes parameter names, operators, and order of operations.
6. A method for generating a template function corresponding to an interface request parameter according to claim 1 or 5, characterized in that: Generating a template function corresponding to the calculation rule of the template parameter based on the key information includes the following steps: Build an AST structure based on key information, build the function body code based on the AST structure, and output the template function.
7. A method for generating a template function corresponding to an interface request parameter according to claim 3, characterized in that: The parsing tools for parsing documents describing interface-related information include a first parsing tool and a second parsing tool, the first parsing tool is used to parse API documents, and the second parsing tool is used to parse WSDL documents; the first parsing tool includes SwaggerParser, Postman or APIMatic, and the second parsing tool includes Apache CXF, SoapUI or WSDL4J.
8. A system for generating a template function corresponding to an interface request parameter, characterized in that: It includes a calculation rule extraction module and a function generation module, where: The calculation rule extraction module is configured to obtain a document describing information related to the interface, parse the document describing information related to the interface, and extract calculation rules of template parameters based on the parsing result; The function generation module is configured to extract key information from the calculation rule of the template parameter, and generate a template function corresponding to the calculation rule of the template parameter based on the key information.
9. A terminal comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of a method for generating a template function corresponding to an interface request parameter as described in any one of claims 1 to 7 are implemented.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of a method for generating a template function corresponding to an interface request parameter as described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Application program interface calling method and device, equipment, storage medium and program
CN120832253A
Calling method, device and equipment of application program interface, storage medium and program
CN120832253B