Method, device, electronic device and storage medium for calling application program interface

By parsing API documents and generating client code files and entry executable files, the problem of high programming skills and difficulty in code maintenance of API calls is solved, and higher reliability and convenience of API calls are achieved.

CN119759457APending Publication Date: 2025-04-04SANGFOR TECH INC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411716064.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-04-04

AI Technical Summary

Technical Problem

In the prior art, API calls require developers to have high programming skills, and as system complexity increases, code maintenance and update becomes difficult.

Method used

By parsing the target API document, the client code files and entry executable files for each API interface are automatically generated, which reduces the programming threshold and code maintenance complexity.

Benefits of technology

It realizes the need to write code manually, reduces the requirements for developers' programming skills, improves the reliability and convenience of API calls, and avoids inaccurate or incomplete API call code caused by human errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119759457A_ABST
    Figure CN119759457A_ABST
Patent Text Reader

Abstract

The present application provides a method, device, electronic device and storage medium for calling an application program interface, the method comprising: parsing a target API document to obtain description information of each of the multiple APIs in the target API document, wherein the target API document is obtained according to the API specification definition; generating a client code file of the API based on the description information of each API, and an entry executable file for calling the client code file; storing the client code file and entry executable file of each API in a target file directory; and sending the target file directory to an operation and maintenance client, so that the operation and maintenance client calls the API based on the target file directory. By adopting the above method, it is possible to automatically generate client code files and entry executable files for each API interface in the target API document, which not only reduces the programming threshold and the complexity of code maintenance, but also improves the reliability and convenience of API calls.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for calling an application program interface. Background Art

[0002] With the development of cloud computing environment, openness has become one of the key factors to promote technological innovation and improve service quality. Many cloud service providers open API (application programming interface) and related documents to allow users to conduct secondary development or realize automated operation and maintenance.

[0003] However, in the related art, although directly calling the API is highly flexible, it also requires developers to have high programming skills. In addition, since the API is usually not used in isolation, but works with other services or libraries, and different programmers have different programming methods for different APIs, based on this, the API calls in the related art will increase with the increase of system complexity, and the maintenance and update of the corresponding code may also become very difficult. Summary of the invention

[0004] In view of the above problems, the present application provides a method, device, electronic device and storage medium for calling an application program interface, which can automatically generate client code files and entry executable files for each API interface in the target API document, which not only reduces the programming threshold and the complexity of code maintenance, but also improves the reliability and convenience of API calls.

[0005] The embodiment of the present application is implemented by adopting the following technical solutions:

[0006] In the first aspect, an embodiment of the present application provides a method for calling an application program interface, comprising: parsing a target API document to obtain description information of each of multiple APIs in the target API document, wherein the target API document is obtained according to an API specification definition; generating a client code file of the API based on the description information of each API, and an entry executable file that calls the client code file; storing the client code file and the entry executable file of each of the APIs in a target file directory; and sending the target file directory to an operation and maintenance client, so that the operation and maintenance client calls the API based on the target file directory.

[0007] In the second aspect, the embodiment of the present application provides a device for calling an application program interface, the device comprising: a parsing module, used to parse a target API document to obtain description information of each of the multiple APIs in the target API document, wherein the target API document is obtained according to the API specification definition; a file generation module, used to generate a client code file of the API based on the description information of each API, and an entry executable file for calling the client code file; a file storage module, used to store the client code file and the entry executable file of each of the APIs in a target file directory; a directory sending module, used to send the target file directory to an operation and maintenance client, so that the operation and maintenance client calls the API based on the target file directory. .

[0008] In a third aspect, an embodiment of the present application provides an electronic device, comprising: one or more processors; a memory; and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the calling method of the above-mentioned application program interface.

[0009] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a program code, and the program code can be called by a processor to execute a calling method of the above-mentioned application program interface.

[0010] The calling method, device, electronic device and storage medium of the application program interface provided in the embodiment of the present application can reduce the need for manual code writing by parsing the target API document, obtaining the description information of each of the multiple APIs in the target API document, and generating the client code file of the API based on the description information of each API, as well as the entry executable file for calling the client code file, thereby reducing the requirement for developers' programming skills, so that developers no longer need to deeply understand every detail of the API, but only need to pay attention to the description information provided in the document. In addition, it can also reduce inaccurate or incomplete API calling codes caused by human errors, and ensure that the generated code is consistent with the description information of the API; store the client code files and entry executable files of each of the APIs in the target file directory; send the target file directory to the operation and maintenance client, so that the operation and maintenance client calls the API based on the target file directory. This allows the operation and maintenance personnel to directly use these files to call the API without having to worry about the specific implementation of the API. In this way, even if the API changes, such as adding new endpoints, changing parameter formats or return value structures, etc., since these changes are encapsulated in new client code files and entry executable files, operation and maintenance personnel do not need to understand the specific content of these changes, nor do they need to modify the code. They only need to use the updated file directory and new files. This avoids the problem that developers need to have high programming skills when calling APIs in related technologies and the difficulty of code maintenance and updating in related technologies.

[0011] These and other aspects of the present application will become more clearly understood in the description of the following embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0013] Figure 1 It is a flowchart of a method for calling an application program interface provided in an embodiment of the present application.

[0014] Figure 2 It is a flowchart of a method for calling an application program interface provided in an embodiment of the present application.

[0015] Figure 3 yes Figure 1 Schematic diagram of the process of step S120.

[0016] Figure 4This is a schematic diagram of the storage results of a client code file and an entry executable file provided in an embodiment of the present application.

[0017] Figure 5 It is a schematic diagram of selecting an application program interface to be called provided in an embodiment of the present application.

[0018] Figure 6 This is another flowchart of a method for calling an application program interface provided in an embodiment of the present application.

[0019] Figure 7 It is a connection block diagram of a device for calling an application program interface provided in an embodiment of the present application.

[0020] Figure 8 It is a schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0021] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be understood as limiting the present application.

[0022] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present application.

[0023] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0024] Please refer to Figure 1 and Figure 2 , a method for calling an application program interface provided in an embodiment of the present application. The method can be applied to an electronic device, and the electronic device can be a server, wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.

[0025] The method comprises the following steps:

[0026] Step S110: Parse the target API document to obtain description information of each of the multiple APIs in the target API document.

[0027] The target API document is defined according to the API specification.

[0028] API (Application Programming Interface) is a set of rules that define the interaction between software components. In other words, API specifies how software modules communicate with each other, including how to call functions, methods, classes, etc., as well as the format and transmission method of data.

[0029] An API specification refers to a set of rules that define the behavior, format, security, etc. of an API. The API specification may be an OpenAPI specification (OpenAPI Specification) or an AsyncAPI specification (AsyncAPI Specification).

[0030] Take the OpenAPI specification as an example. OpenAPI is a specification and complete framework for describing, producing, consuming and visualizing the life cycle of Web services based on the REST architecture (REST, Representational State Transfer, a software architecture style). OpenAPI is designed to help developers and teams design, build, document and use REST APIs. The OpenAPI specification defines a standard, language-independent interface that enables both humans and computers to discover and understand the functions of a service without accessing source code, documentation or inspecting network traffic. It includes the following description of the API: Basic information: such as the title, description, version and contact information of the API. Server information: URL (Uniform Resource Locator) of the API service. Path: The specific path of the API, that is, the URL of various operations. Operation: The HTTP method corresponding to the API path, such as get, submit, replace and delete. Parameter: Input parameter, which can be a path parameter, query parameter, header parameter or request body. Response: Various possible responses, including success and error codes and returned data structures. Security scheme: Authentication and authorization scheme, such as API key, OAuth (OpenAuthorization), etc.

[0031] The OpenAPI specification is usually written in YAML format (a human-readable data serialization format) or JSON format (a lightweight data exchange format), which can be read by various tools that can automatically generate documents, client libraries, server stubs, etc. As shown in Table 1, an example of an OpenAPI specification is provided, which is as follows:

[0032]

[0033] In one possible implementation, the API specification includes an OpenAPI specification, and the target API document obtained according to the API specification definition includes description information of multiple APIs. By using the API specification to define the API, the cloud service provider can ensure that the description information of each API in the target API document follows the same specification, ensuring that the format of the document is unified, which is convenient for developers to understand and use. The format of the target API document can be YAML format or JSON format, etc.

[0034] The description information of each API may include basic information (such as the title name, version, description of the API), server information (such as the base address and available environment of the API service), path, supported HTTP methods, request parameters (such as path parameters, query parameters, etc.), response data format (such as JSON or XML, etc.), security mechanisms (such as authentication and authorization, etc.) and external links, etc.

[0035] The above step S110 may specifically be: calling a parser to parse the target API document, and converting the description information corresponding to each of the APIs obtained by the parsing into a specified data structure.

[0036] Among them, different API specifications can correspond to different parsers, that is, the parser can be determined according to the specifications adopted by the target API document. The parser is responsible for reading the target API document and converting it into a specified data structure that is easy to read, such as a Python dictionary, list, or class data structure.

[0037] It is worth mentioning that when parsing the target API document, the parser can also check whether the target API document meets the requirements of the API specification, such as checking whether all required fields are provided and whether the field values ​​are valid. If it is determined that the target API document meets the requirements of the API specification, the above steps of parsing the target API document with the parser and converting the description information corresponding to each of the APIs obtained by the parsing into a specified data structure are executed.

[0038] Step S120: Generate a client code file of each API based on the description information of the API, and an entry executable file for calling the client code file.

[0039] Among them, the client code file contains all the logic required to call the corresponding API, which is used to implement the interaction logic with the API, such as building requests, sending requests, processing responses, etc. These files are usually abstract encapsulations of API endpoints, making API calls more concise and consistent.

[0040] The entry executable file is the specific implementation of the Ansible module. Each entry executable file is an executable Python script, representing an independent functional module. It calls the corresponding client code file to implement the business logic to complete the corresponding function, that is, call the client code file to complete a specific task. When using the entry executable file, it is necessary to process input parameters, call the client code, process the results, and return the correct Ansible format output. That is, the Ansible module relies on the client code file in module_utils to complete specific tasks. For example, if an Ansible module needs to interact with the cloud service provider's API to create or delete resources, it will rely on the corresponding client library in module_utils to perform these operations.

[0041] Among them, Ansible is an open source automation platform for configuration management, application deployment, task automation, etc. It can use an agentless architecture, which means that no specific client software needs to be installed on the remotely managed machine.

[0042] The above step S120 can be to use a code generator to generate an API client code file according to the API description information, and an entry executable file that calls the client code file; it can also be to use a template engine to generate an API client code file according to the API description information, and an entry executable file that calls the client code file.

[0043] Please refer to FIG. 3 . In one possible implementation, the above step S120 includes:

[0044] Step S122: calling the template engine to generate a client code file of the API based on the description information of the API and the first predefined code template.

[0045] The first predefined code template is a template for generating a client code file, which includes the basic structure of the client code, such as class definition, method definition, request construction logic, etc.

[0046] Specifically, the above step S122 may be calling the template engine to perform the following steps: performing lexical analysis on the first predefined code template to obtain multiple tags of the first predefined code template; performing syntax analysis on the multiple tags of the first predefined code template to obtain a first template tree; replacing the placeholders in the first template tree according to the description information of the API to obtain a first abstract syntax tree of the API; and converting the first abstract syntax tree of the API into a client code file of the API.

[0047] Exemplarily, the placeholder may specifically include a placeholder {{.Name}} representing the name of the API, a placeholder {{.Description}} representing the description of the API, a placeholder {{.version}} representing the version of the API, etc. After obtaining the description information of the API, the placeholder in the first template tree may be replaced according to the information indicated by the placeholder and the description information of the API to obtain the first abstract syntax tree of the API. Exemplarily, if the name of the API is create-sever and the version is 1.0.0, the placeholder {{.Name}} indicating the name of the API in the code may be replaced with create-sever, and the placeholder {{.version}} indicating the version of the API in the code may be replaced with 1.0.0.

[0048] Among them, by performing lexical analysis on the first predefined code template, the character sequence in the first predefined code template can be decomposed into a series of meaningful tags, which can be keywords, identifiers, operators, constants, strings, the start and end of actions, etc. The first template tree is obtained by performing syntax analysis on multiple tags. The first template tree records the hierarchical relationship of each element in the template, that is, actions and expressions. By replacing the placeholders in the syntax tree according to the specific content in the API description information (thereby replacing the actions and expressions in the first template tree), a first abstract syntax tree that already includes the specific implementation details of the API is generated. Finally, the first abstract syntax tree is traversed and converted into an actual code file (that is, the client code file of the API).

[0049] It is worth mentioning that before replacing the placeholders in the first template tree according to the description information of the API, the description information can be processed so that the client code file obtained after replacing the placeholders in the first template tree according to the processed description information of the API can be compatible with different programming languages. For example, the description information CreateServer can be converted into create_server to be compatible with the python language.

[0050] The above-mentioned template engine can be a GO template engine, a text / template template engine, etc., and can be set according to actual needs. For example, taking the template engine as a GO template engine, the Go template engine supports a variety of actions and expressions, including: {{.}}: represents the current object. {{.FieldName}}: represents the field of the object. {{range.Slice}}...{{end}}: traverse a slice or array. {{if.Condition}}...{{else}}...{{end}}: conditional judgment. {{with.Context}}...{{end}}: set the current context. {{template"name".}}: include other templates. {{define"name"}}...{{end}}: define a template. {{block"name".}}...{{end}}: define an overridable template block.

[0051] By adopting the above process, it is possible to use templates and automated tools to quickly generate API client code files, greatly shortening the development cycle, ensuring the consistency of client codes corresponding to each API, and reducing problems caused by differences in personal coding habits.

[0052] The above step S122 may also be: extracting target information matching the information indicated by each placeholder in the first code template from the description information of the API according to the information indicated by the placeholder in the first code template, and replacing each placeholder in the first code template with the target information matching it.

[0053] Step S124: The template engine is called to generate an entry executable file of the client code file that calls the API based on the description information of the API, the second predefined code template and the file name of the client code file.

[0054] Among them, the second predefined code template is a template for generating an entry executable file, which includes a main function, parameter processing logic, client code file call, etc.

[0055] Specifically, the above step S124 may be: calling the template engine to execute the following steps: performing lexical analysis on the second predefined code template to obtain multiple tags of the second predefined code template; performing syntax analysis on the multiple tags of the second predefined code template to obtain a second template tree; replacing the placeholders in the second template tree according to the description information of the API and the file name of the client code file to obtain a second abstract syntax tree of the API; converting the second abstract syntax tree of the API into an entry executable file of the API.

[0056] For the above process, please refer to the detailed description of the above step S122, which will not be repeated here.

[0057] The above step S124 can also be, according to the information indicated by the placeholder in the first code template, extracting the target information matching the information indicated by the placeholder from the description information of the API and the file name of the client code file, and replacing each placeholder in the second code template with the target information matching it.

[0058] In another possible implementation, the above step S120 may be: calling a code generation tool to generate a client code file and an entry executable file of the API based on the description information of each API.

[0059] It is worth mentioning that the code generation tool can first generate the client code file of the API, and the generated entry executable file can be directly used to write the entry executable file, that is, the code generation tool is used to generate the client code file of the API based on the description information of each API, and generate the entry executable file of the API based on the generated client code file of the API.

[0060] Step S130: Store the client code files and entry executable files of each of the APIs into the target file directory.

[0061] Among them, the API client code file and entry executable file can be stored in the same target file directory or in different target file directories.

[0062] In one possible implementation of the present application, after generating the client code files and entry executable files of the API, the client code files of each API can be stored in the module_utils directory (a directory for storing module auxiliary tools) so that they can be called to reduce duplicate code and facilitate maintenance. And the entry executable files of the API are stored in the modules directory, by storing the entry program code files in the modules directory, such as creating a server, deleting a server, etc.

[0063] Exemplarily, the multiple APIs include an API for creating an image (create_image), an API for creating a network (create_network), an API for deleting a network (delete_network), an API for deleting a server (delete_server), an API for obtaining an image (get_image), an API for obtaining a server (get_server), and an API for creating a server (create_server). Figure 4The file structure under the plugins / directory is shown in FIG. 1 , which includes two subdirectories (i.e., the modules directory and the module_utils directory), wherein the modules directory stores the entry executable files of the above-mentioned APIs, and a schematic diagram of the client code files under the module_utils directory. It is worth mentioning that the content of client.py under the module_utils directory is fixed. It is an http client implemented based on the built-in httplib module of python, which is used to send various HTTP requests. Among them, the entry executable file under the modules directory and the client code file under the module_utils directory are one-to-one corresponding, because the entry executable files are all implemented by relying on the corresponding client code files. The exemplary entry executable file create_server.py under the modules directory relies on the client code file create_server.py under the module_utils directory to implement.

[0064] Step S140: Send the target file directory to the operation and maintenance client, so that the operation and maintenance client calls an API based on the target file directory.

[0065] By adopting the above steps S110-S140 of the present application, by parsing the target API document, obtaining the description information of each of the multiple APIs in the target API document, and generating the client code file of the API based on the description information of each API, and the entry executable file for calling the client code file, it is possible to reduce the need for manual code writing, thereby reducing the requirements for developers' programming skills, so that developers no longer need to deeply understand every detail of the API, but only need to pay attention to the description information provided in the document. In addition, it is also possible to reduce inaccurate or incomplete API call codes caused by human errors, and ensure that the generated code is consistent with the description information of the API; the client code files and entry executable files of each of the APIs are stored in the target file directory; the target file directory is sent to the operation and maintenance client, so that the operation and maintenance client calls the API based on the target file directory. The operation and maintenance personnel can directly use these files to call the API without having to care about the specific implementation of the API. In this way, even if the API changes, such as adding new endpoints, changing parameter formats or return value structures, etc., since these changes are encapsulated in new client code files and entry executable files, operation and maintenance personnel do not need to understand the specific content of these changes, nor do they need to modify the code. They only need to use the updated file directory and new files. This avoids the problem that developers need to have high programming skills when calling APIs in related technologies and the difficulty of code maintenance and updating in related technologies.

[0066] It should be noted that, by adopting the above-mentioned step S140, when a download request for the target API is received from the operation and maintenance client based on the target file directory, the client code file and the entry executable file of the target API can be packaged and compressed to obtain a compressed package file; the compressed package file is sent to the operation and maintenance client, so that the operation and maintenance client decompresses and installs the compressed package file and then calls the target API.

[0067] For example, Figure 5 As shown, the operation and maintenance client can display the APIs to which the client code files and entry executable files available for download belong based on the target file directory on the product page. The operation and maintenance personnel can check the APIs to be called based on their needs (such as creating an image, obtaining image information, creating a network, deleting a network, creating a cloud host, and deleting a cloud host) and click the confirmation control to have the operation and maintenance client return a download request to the electronic device. After receiving the download request, the electronic device can obtain the target API to generate the corresponding client code files and entry executable files to generate a compressed package and send it to the operation and maintenance client for the operation and maintenance personnel to call.

[0068] To ensure the reliability of the generated API client code files and entry executable files, thereby improving the reliability of subsequent API calls, in one possible implementation of this application, please refer to Figure 6 Before executing step S140, the method further includes:

[0069] Step S150: Obtain the client code files and entry executable files of each of the APIs in the target file directory as files to be tested, and obtain a test configuration file.

[0070] The test configuration file defines how to perform the test, including the test data set to be used, the test environment requirements, etc. It is a file used to guide the test framework or test tool on how to perform the test.

[0071] Step S160: Parse the test scenario file to obtain a test case, wherein the test case includes input parameters and expected output results.

[0072] A test scenario file is a file that specifically describes how a certain function or business process works. It contains detailed test case information, which usually includes input data, operation steps, expected results, etc. Its main function is to define the behavior of each test case in detail, ensure that the test covers all functional requirements, and verify whether the software works as expected.

[0073] The test scenario file contains specific test logic and data. By parsing the test scenario file, the input data and expected results of at least one test case can be obtained.

[0074] Step S170: Initialize the test environment according to the test configuration file, and execute the test file in the test environment based on the input parameters to obtain the test output result.

[0075] Specifically, the purpose of initializing the test environment is to ensure that the test is performed under controlled and consistent conditions. Initializing the test environment according to the test configuration file may specifically include configuring the test environment according to the parameters in the test configuration file, such as configuring a database connection string, an external service endpoint, etc. Afterwards, obtaining input parameters, constructing test data according to the input parameters, which may include request parameters, environment variable settings, etc., and obtaining the test output results generated after the test file is executed based on the test data.

[0076] Step S180: obtaining a test result of the file to be tested based on the test output result and the expected output result.

[0077] If the test output exactly matches the expected output, the test passes. If there are any differences, the test fails.

[0078] If the test result indicates that the test passes, step S140 is executed: sending the target file directory to the operation and maintenance client.

[0079] By adopting the calling method of the application program interface of the present application, it is possible to automatically parse the API document and generate the client code file and the entry executable file, so that the developer does not need to manually write complex Ansible module code. In addition, since these client code files and entry executable texts are automatically generated according to the API specification, when the API specification changes, the module can be automatically updated by regeneration, reducing the maintenance workload. Further, since the generated client code files and entry executable texts are generated based on the general API description information calling the predefined code template, the client code files and entry executable texts have high versatility. This means that the client code files and entry executable texts can be reused in different environments, and only some specific configuration parameters need to be adjusted to adapt to the new environment. In addition, since the client code files and entry executable texts corresponding to different APIs follow a unified coding specification and structure, the client code files and entry executable texts of different APIs can be packaged into independent components for distribution, which is convenient for the integrated use of other projects, thereby not only improving the automation level of cloud services, reducing human errors, but also making the maintenance of modules easier, while enhancing the portability and reusability of modules.

[0080] like Figure 7 As shown, a device 200 for calling an application program interface provided in an embodiment of the present application is shown, which is applied to an electronic device, and the device 200 for calling an application program interface includes: a parsing module 210, which is used to parse a target API document to obtain description information of each of a plurality of APIs in the target API document, wherein the target API document is obtained according to an API specification definition; a file generating module 220, which is used to generate a client code file of the API based on the description information of each API, and an entry executable file for calling the client code file; a file storing module 230, which is used to store the client code file and the entry executable file of each of the APIs in a target file directory; a directory sending module 240, which is used to send the target file directory to an operation and maintenance client, so that the operation and maintenance client calls the API based on the target file directory.

[0081] In one embodiment, the file generation module 220 includes a first file generation submodule and a second file generation submodule. The first file generation submodule is used to call the template engine based on the description information of the API and the first predefined code template to generate a client code file of the API; the second file generation submodule is used to call the template engine based on the description information of the API, the second predefined code template and the file name of the client code file to generate an entry executable file that calls the client code file of the API.

[0082] In one possible implementation, the first file generation submodule is also used to call the template engine to execute the following steps: perform lexical analysis on the first predefined code template to obtain multiple tags of the first predefined code template; perform syntactic analysis on the multiple tags of the first predefined code template to obtain a first template tree; replace the placeholders in the first template tree according to the description information of the API to obtain a first abstract syntax tree of the API; and convert the first abstract syntax tree of the API into a client code file of the API.

[0083] In one possible implementation, the second file generation submodule is also used to call the template engine to execute the following steps: perform lexical analysis on the second predefined code template to obtain multiple tags of the second predefined code template; perform syntax analysis on the multiple tags of the second predefined code template to obtain a second template tree; replace the placeholders in the second template tree according to the description information of the API and the file name of the client code file to obtain a second abstract syntax tree of the API; and convert the second abstract syntax tree of the API into an entry executable file of the API.

[0084] In one possible implementation, the parsing module is further used to call a parser to parse the target API document, and convert the description information corresponding to each of the APIs obtained by the parsing into a specified data structure.

[0085] In one possible implementation, the application program interface calling device 200 also includes a file processing module and a file sending module. The file processing module is used to package and compress the client code file and entry executable file of the target API to obtain a compressed package file after receiving a download request for the target API sent by the operation and maintenance client based on the target file directory; the file sending module is used to send the compressed package file to the operation and maintenance client, so that the operation and maintenance client decompresses and installs the compressed package file and then calls the target API.

[0086] In one embodiment, the calling device 200 of the application program interface also includes a test module, which is used to call the integrated test framework to perform the following steps: obtain the client code file and entry executable file of each API under the target file directory as the file to be tested, and obtain the test configuration file; parse the test scenario file to obtain the test case, which includes input parameters and expected output results; initialize the test environment according to the test configuration file, and execute the file to be tested based on the input parameters in the test environment to obtain the test output result; obtain the test result of the file to be tested based on the test output result and the expected output result; the directory sending module is also used to send the target file directory to the operation and maintenance client when the test result indicates that the test passed.

[0087] Each module in the above-mentioned device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each of the above modules. It should be noted that the device embodiment in this application corresponds to the aforementioned method embodiment. The specific principles in the device embodiment can be found in the contents of the aforementioned method embodiment, which will not be repeated here.

[0088] The following will be combined Figure 8 An electronic device provided by the present application is described.

[0089] like Figure 8 The embodiment of the present application further provides an electronic device 300, which may be a server. The electronic device 300 may include one or more processors 310, a memory 320, and one or more applications, wherein the one or more applications are stored in the memory 320 and configured to be executed by the one or more processors 310, and the one or more applications are configured to execute the calling method of the above-mentioned application program interface.

[0090] It can be understood that the processor 310 and the memory 320 are connected through a communication bus to complete the communication between them. The processor 320 can call the logic instructions in the memory 320 to execute the speech template generation method in any of the above embodiments. Exemplarily, the processor 310 can be implemented in a general CPU, a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit. ASIC), or one or more integrated circuits, etc., for executing related programs to implement the technical solution provided in this application. The memory can include ROM (Read 0nl yMemory, read-only memory), RAM (Random Access Memory, random access memory) static storage devices, dynamic storage devices, etc.

[0091] Correspondingly, an embodiment of the present application further provides a computer-readable storage medium, in which program code is stored. The program code can be called by a processor to execute the calling method of the above-mentioned application program interface.

[0092] It can be understood that the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.

[0093] Part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of various embodiments of the present invention. The aforementioned storage medium includes: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0094] The above are only preferred embodiments of the present application, and are not intended to limit the present application in any form. Although the present application has been disclosed as above with preferred embodiments, it is not intended to limit the present application. Any technical personnel in the field can make some changes or modify the technical contents disclosed above into equivalent embodiments without departing from the scope of the technical solution of the present application. However, any brief modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present application without departing from the content of the technical solution of the present application are still within the scope of the technical solution of the present application.

Claims

1. A method for calling an application program interface, characterized in that: The method comprises: Parsing a target API document to obtain description information of each of multiple APIs in the target API document, wherein the target API document is obtained according to an API specification definition; Generate the client code file of each API based on the description information of the API, and the entry executable file that calls the client code file; Store the client code files and entry executable files of each of the APIs in the target file directory; The target file directory is sent to the operation and maintenance client, so that the operation and maintenance client calls the API based on the target file directory.

2. The method according to claim 1, characterized in that The generation of the client code file of the API based on the description information of each API, and the entry executable file for calling the client code file, include: Calling a template engine to generate a client code file of the API based on the description information of the API and a first predefined code template; The calling template engine generates an entry executable file of the client code file that calls the API based on the description information of the API, the second predefined code template and the file name of the client code file.

3. The method according to claim 2, characterized in that The calling template engine generates a client code file of the API based on the description information of the API and the first predefined code template, including: calling the template engine to perform the following steps: Performing lexical analysis on the first predefined code template to obtain multiple tags of the first predefined code template; Performing grammatical analysis on multiple tags of the first predefined code template to obtain a first template tree; Replacing the placeholders in the first template tree according to the description information of the API to obtain a first abstract syntax tree of the API; The first abstract syntax tree of the API is converted into a client code file of the API.

4. The method according to claim 2, characterized in that: The calling template engine generates an entry executable file of the client code file that calls the API based on the description information of the API, the second predefined code template, and the file name of the client code file, including: calling the template engine to perform the following steps: Performing lexical analysis on the second predefined code template to obtain multiple tags of the second predefined code template; Performing grammatical analysis on multiple tags of the second predefined code template to obtain a second template tree; Replacing the placeholders in the second template tree according to the description information of the API and the file name of the client code file to obtain a second abstract syntax tree of the API; The second abstract syntax tree of the API is converted into an entry executable file of the API.

5. The method according to claim 1, characterized in that The target API document is parsed to obtain description information of each of the multiple APIs in the target API document, including: The parser is called to parse the target API document, and the description information corresponding to each of the APIs obtained by parsing is converted into a specified data structure.

6. The method according to claim 1, characterized in that After sending the target file directory to the operation and maintenance client, the method further includes: If a download request for the target API is received from the operation and maintenance client based on the target file directory, the client code file and the entry executable file of the target API are packaged and compressed to obtain a compressed package file; The compressed package file is sent to the operation and maintenance client, so that the operation and maintenance client decompresses and installs the compressed package file and then calls the target API.

7. The method according to claim 1, characterized in that Before sending the target file directory to the operation and maintenance client, the method further includes: calling the integrated test framework to perform the following steps: Obtain the client code files and entry executable files of each of the APIs in the target file directory as files to be tested, and obtain the test configuration files; Parsing the test scenario file to obtain a test case, wherein the test case includes input parameters and expected output results; Initialize the test environment according to the test configuration file, and execute the test file in the test environment based on the input parameters to obtain the test output result; Obtaining the test result of the file to be tested based on the test output result and the expected output result; If the test result indicates that the test passes, the step of sending the target file directory to the operation and maintenance client is executed.

8. A device for calling an application program interface, characterized in that: The device comprises: A parsing module, used to parse a target API document to obtain description information of each of multiple APIs in the target API document, wherein the target API document is obtained according to an API specification definition; A file generation module, used to generate a client code file of each API based on the description information of the API, and an entry executable file for calling the client code file; A file storage module, used to store the client code files and entry executable files of each of the APIs in a target file directory; The directory sending module is used to send the target file directory to the operation and maintenance client, so that the operation and maintenance client calls the API based on the target file directory.

9. An electronic device, characterized in that: include: one or more processors; Memory; One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program codes, and the program codes can be called by a processor to execute the method according to any one of claims 1 to 7.

11. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.