CN108108162B - Application programming interface generation method and device - Google Patents

Application programming interface generation method and device Download PDF

Info

Publication number
CN108108162B
CN108108162B CN201611050070.3A CN201611050070A CN108108162B CN 108108162 B CN108108162 B CN 108108162B CN 201611050070 A CN201611050070 A CN 201611050070A CN 108108162 B CN108108162 B CN 108108162B
Authority
CN
China
Prior art keywords
parameter
function
protocol
api
format
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201611050070.3A
Other languages
Chinese (zh)
Other versions
CN108108162A (en
Inventor
朱辉云
郭计伟
胡育辉
陈焕葵
陈云云
覃竞才
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201611050070.3A priority Critical patent/CN108108162B/en
Publication of CN108108162A publication Critical patent/CN108108162A/en
Application granted granted Critical
Publication of CN108108162B publication Critical patent/CN108108162B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms

Abstract

The invention relates to a method for generating an application programming interface, belonging to the technical field of software development. The method comprises the following steps: acquiring a protocol document of an Application Programming Interface (API); acquiring parameter information contained in the protocol document, and determining a function template of the API; and generating the API according to the parameter information and the function template. According to the method, the function template of the API is preset, when the API is developed, a developer only needs to input the protocol document of the API, the software development tool can automatically acquire the parameter information of the API according to the protocol document, the API is automatically generated by combining the parameter information and the function template of the API, the developer does not need to manually write the code of the API, the labor cost of API development is greatly reduced, the development time is shortened, and therefore the software development efficiency is improved.

Description

Application programming interface generation method and device
Technical Field
The invention relates to the technical field of software development, in particular to a method and a device for generating an application programming interface.
Background
An API (Application Programming Interface) is a predefined set of functions in a backend system that can provide applications and developers the ability to access a set of routines based on some software or hardware.
The development of APIs is an extremely important part of the development process of background systems. In the prior art, the development of the API is mainly completed by manual writing by a developer. For example, a developer writes codes of respective parts of functions in the corresponding API against a protocol document of the preset or written API.
At present, the API is written manually by developers, and writing codes of the API consumes a large amount of labor cost and consumes certain development time, so that the development efficiency of software is low.
Disclosure of Invention
In order to solve the problems that in the prior art, a large amount of labor cost and development time are consumed for manually writing codes of an API, and software development efficiency is affected, the embodiment of the invention provides a method and a device for generating an application programming interface, and the technical scheme is as follows:
in a first aspect, a method for generating an application programming interface is provided, where the method includes:
acquiring a protocol document of an Application Programming Interface (API);
acquiring parameter information contained in the protocol document, and determining a function template of the API, wherein the parameter information comprises at least one parameter and the type of the at least one parameter, or the parameter information comprises the at least one parameter, the type of the at least one parameter and a nesting relation among the at least one parameter;
and generating the API according to the parameter information and the function template.
In a second aspect, an application programming interface generating apparatus is provided, the apparatus comprising:
the first acquisition module is used for acquiring a protocol document of an Application Programming Interface (API);
a second obtaining module, configured to obtain parameter information included in the protocol document, where the parameter information includes at least one parameter and a type of the at least one parameter, or the parameter information includes the at least one parameter, the type of the at least one parameter, and a nesting relationship between the at least one parameter;
the template determining module is used for determining a function template of the API;
and the generating module is used for generating the API according to the parameter information and the function template.
The technical scheme provided by the embodiment of the invention has the following beneficial effects:
the method has the advantages that the function template of the API is preset, when the API is developed, developers only need to input the protocol document of the API, the software development tool can automatically obtain the parameter information of the API according to the protocol document, the API is automatically generated by combining the parameter information and the function template of the API, the developers do not need to manually write codes of the API, labor cost of API development is greatly reduced, development time is shortened, and accordingly software development efficiency is improved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention, as claimed.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
FIG. 1 is a schematic flow chart of an implementation of the scheme of the present invention;
FIG. 2 is a flowchart illustrating a method for application programming interface generation in accordance with an illustrative embodiment;
FIG. 3 is a schematic diagram of an API generation process to which the embodiment shown in FIG. 2 relates;
FIG. 4 is a flowchart illustrating a method for application programming interface generation in accordance with an illustrative embodiment;
FIG. 5 is a schematic diagram of a parameter selection interface according to the embodiment shown in FIG. 4;
FIG. 6 is a block diagram illustrating an application programming interface generation apparatus in accordance with an illustrative embodiment;
fig. 7 is a schematic structural diagram of an electronic device provided in accordance with an example embodiment.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the invention, as detailed in the appended claims.
The scheme shown in the embodiment of the invention can be applied to various software development platform devices. For example, the scheme can be applied to electronic equipment running with a software development tool based on a personal computer or a workstation.
In the solution shown in the embodiment of the present invention, when an API is developed, a software development tool only needs to acquire a protocol document of the API to be developed, and automatically acquire parameter information included in the protocol document, where the parameter information includes at least one parameter and a type of the at least one parameter, or the parameter information includes the at least one parameter, the type of the at least one parameter, and a nesting relationship between the at least one parameter; and generating the API according to the parameter information and a preset function template.
The software development tool in the embodiment of the invention can automatically extract the parameter information contained in the protocol document and required by the automatic generation of the API according to the content of the protocol document. Wherein, at least one parameter in the parameter information refers to a parameter which needs to be input when the API is called.
Referring to fig. 1, a schematic flow chart of implementation of the solution of the present invention is shown. As shown in fig. 1, when a developer develops an API, a protocol document of the API is selected to be opened by a software development tool, the software development tool reads the protocol document into a memory, and analyzes and obtains parameter information corresponding to the API included in the protocol document, and since most of function codes of other parts are the same or similar except for a part of functions related to parameters in the API, in an embodiment of the present invention, a function template of the API may be preset, and after the software development tool acquires the parameter information, the software development tool may generate function codes of each part in the API based on the parameter information and the preset function template, combine the generated function codes of each part, and finally obtain the API. In the process, developers only need to provide the protocol document of the API, so that the workload of the developers for manually writing codes is greatly simplified, the development time of the API is shortened, and the development efficiency is improved.
Generally, an API may be composed of a calling function and a called function, where the calling function is used to implement calling logic of the API, such as calling a specified function, or parsing a calling result, and the called function is used to implement functions of byte-order conversion, serialization, and deserialization of parameters when the calling function calls. In the embodiment of the present invention, the calling function in the API may be generated by applying the preset function template to the parameter information of the API, and the called function may be directly generated according to the parameter and the parameter type in the parameter information of the API, or directly generated by a compiling tool corresponding to the protocol document. A specific API generation method may be as shown in fig. 2 below.
FIG. 2 is a flow chart illustrating a method for application programming interface generation that may be used in an electronic device running a software development tool in accordance with an exemplary embodiment. As shown in fig. 2, the method for generating an application programming interface may include the following steps:
step 201, acquiring a protocol document of an Application Programming Interface (API).
The developer can input or store the protocol document into the electronic device running the software development tool, and open the protocol document through the software development tool, at this time, the software development tool reads the protocol document into the memory.
Specifically, in the embodiment of the present invention, a Protocol format of a Protocol document of the API may be divided into a fixed-length Protocol format and an indefinite-length Protocol format, where the fixed-length Protocol format may specifically be a structure (struct) format, and the indefinite-length Protocol format may specifically be a PB (Protocol buffers) format, a TLV (Type-length-value) format, or a PDU (Protocol Data Unit) format.
For example, when the protocol format is a structure format, the protocol document may be as follows:
Figure BDA0001160799490000041
alternatively, when the protocol format is the PB format, the protocol document may be as follows:
Figure BDA0001160799490000042
Figure BDA0001160799490000051
step 202, identifying the protocol format of the protocol document, determining the development language type, and determining the function name of the calling function of the API.
In identifying the protocol format, the software development tool may identify the protocol format by parsing a protocol header of the protocol document. For example, if the software development tool parses out the "struct" field in the protocol header, it may be determined that the protocol format of the protocol file is the structure format.
The solution shown in the embodiment of the present invention further supports generating corresponding APIs according to different development language types (such as C + +, Java, and Python). Specifically, when the development language type of the generated API is determined, the software development tool may present a development language selection interface, where the development language selection interface includes types of various development languages supported by the software development tool, the developer may select one or more development languages in the development language selection interface, and the software development tool determines the development language type corresponding to the subsequently generated API according to a selection operation of the developer on the development language type in the development language selection interface.
Alternatively, in another possible implementation manner, the software development tool may also determine the default development language type as the development language type corresponding to the subsequent generation API.
In addition, even if the corresponding parameters of different APIs are the same, the implemented functions of the different APIs may be different, and the functions of the APIs may be usually embodied by the function names of the calling functions in the APIs.
The function name of the calling function of the API may be set by a developer, for example, the software development tool may display a function name setting interface to the developer, and the software developer sets or fills the function name of the calling function of the API to be generated in the function name setting interface.
Specifically, after determining the protocol format and the development language type, the software development tool queries various function names of calling functions of the API corresponding to the protocol format and the development language type, and displays the queried various function names in a function name setting interface, when a developer selects a function name, the developer sets the function name by selecting (for example, checking or clicking a drop-down menu) in the function name setting interface, and the software development tool determines the function name of the calling function of the API to be generated according to the selection operation of the developer in the function name setting interface.
Step 203, determining a function template according to the development language type and the function name.
In the embodiment of the invention, a plurality of function templates, different development languages and function names of calling functions can be preset by the software development tool, the corresponding function templates are different, and when the development language type corresponding to the API and the function name of the calling function are determined by the software development tool, the corresponding function template can be inquired and determined according to the development language type and the function name.
Step 204, acquiring the parameter information contained in the protocol document according to the protocol format of the protocol document.
The parameter information includes at least one parameter and a type of the at least one parameter, or the parameter information includes the at least one parameter, the type of the at least one parameter and a nesting relation among the at least one parameter.
In the embodiment of the invention, the protocol document comprises various parameters and types of the parameters corresponding to the API to be generated, and when the API is generated, the software development tool can obtain at least one parameter and the type of the at least one parameter in the protocol document.
Optionally, if there is a nested relationship between at least one parameter obtained by the software development tool, the software development tool needs to further obtain the nested relationship between the at least one parameter when generating the API.
Optionally, for protocol documents in different protocol formats, methods for acquiring parameter information in the protocol documents by software development tools are different.
When the protocol format of the protocol document is a fixed-length protocol format (such as a structure format), the software development tool may parse the protocol document to obtain the parameter information.
For example, for a protocol document in a protocol body format, the software development tool may scan each field in the protocol document word by word, and obtain at least one parameter in the protocol document, a type of the at least one parameter, and a nesting relationship between the at least one parameter that may exist by parsing the field.
When the protocol format of the protocol document is an indefinite length protocol format (such as a PB format), the software development tool may compile the protocol document through a compilation tool corresponding to the indefinite length protocol format to obtain a compilation file of the protocol document; the parameter information is extracted from the compiled file.
For example, for a protocol document in the PB format, the software development tool may first invoke a compiling tool corresponding to the PB format to compile the protocol document, and obtain parameter information according to a compiling result. Specifically, the protocol document in the PB format may be a Proto file, and for the Proto file, the software development tool may invoke a compiling tool corresponding to the Proto file, and generate compiled files, that is, a pb.h file and a pb.cc file, for the Proto file. The pb.h file is a header file of a class related to an API corresponding to the protocol document, and the pb.cc file is an implementation file of a class defined in the pb.h file, and the software development tool can extract at least one parameter in the protocol document, a type of the at least one parameter, and a nesting relation between the at least one parameter, which may exist, from the pb.h file and the pb.cc file.
Step 205, the API is generated according to the parameter information and the function template.
In the embodiment of the present invention, when generating the API, the software development tool may generate a called function corresponding to the at least one parameter and the type of the at least one parameter, generate a calling function of the API based on the function template of the API according to the parameter information, and finally combine the called function and the calling function to generate the API.
For the calling function of the API, except for a part of function codes related to the parameters, most of codes of other parts are the same or similar, in the solution shown in the embodiment of the present invention, a function template corresponding to the calling function may be preset, when the API is generated, if there is no nesting relationship among at least one parameter in the parameter information, the calling function of the API is generated according to the at least one parameter, the type of the at least one parameter, and the function template combination, and if there is a nesting relationship among at least one parameter in the parameter information, the calling function of the API is generated according to the at least one parameter, the type of the at least one parameter, the nesting relationship among the at least one parameter, and the function template combination.
Specifically, the function template may be configured to indicate a parameter declaration statement and a parameter assignment statement related to the parameter information, and a fixed statement unrelated to the parameter information, and the function template is further configured to indicate a position relationship between the parameter declaration statement, the parameter assignment statement, the fixed statement, and a function call statement; the function call statement is a statement for calling a called function. When generating a calling function of the API according to the corresponding parameter information and template combination, the software development tool may complete a parameter declaration statement and a parameter assignment statement according to the parameter information (i.e., the at least one parameter, the type of the at least one parameter, and optionally, a nesting relationship between the at least one parameter), generate a corresponding function calling statement according to a protocol format of the protocol document, and generate a calling function of the API according to a position relationship combination between the parameter declaration statement, the parameter assignment statement, the fixed statement, and the function calling statement.
In embodiments of the present invention, a software development tool may generate a called function corresponding to at least one parameter and a type of the at least one parameter. For protocol documents with different protocol formats, the called functions of the corresponding APIs and the generation methods of the called functions are different. When the protocol format of the protocol document is a fixed-length protocol format, the software development tool can generate the called function according to at least one parameter and the type of the at least one parameter and the called function format corresponding to the protocol format; when the protocol format of the protocol document is the protocol format with indefinite length, the software development tool can compile the protocol document through the compiling tool to obtain a compiled file of the protocol document, and extract the called function from the compiled file.
Specifically, for a protocol document in a fixed-length protocol format (such as a structure format), a called function of the corresponding API is a byte-order transmutation function. Since the format of the endian transmutation function (i.e., the called function format described above) is generally fixed, for example, the following provides an example of an endian transmutation function:
Figure BDA0001160799490000081
in the above example of the endian conversion function, usLength and ulUin are parameters, ntohs and ntohl depend on corresponding parameter types, and the rest of codes are in a fixed format, so in the embodiment of the present invention, a software development tool only needs to acquire at least one parameter and the type of the at least one parameter included in a protocol document of the API, that is, the endian conversion function may be generated according to the fixed format according to the at least one parameter and the type of the at least one parameter, and be used as a called function of the API.
For a protocol document with an indefinite length format (such as a PB format), the called functions of the corresponding API are serialization and deserialization functions, and the serialization and deserialization functions can be directly obtained by compiling the protocol document through a compiling tool. For example, taking the format of the protocol document as PB format as an example, the software development tool may call a compiling tool corresponding to the Proto file (i.e., the protocol document), compile the Proto file to generate compiled files, i.e., pb.h file and pb.cc file, and directly extract serializtoarray () function and parsefrom array () function (i.e., serialization and deserialization functions) from the generated pb.h.h file and pb.cc file.
Specifically, please refer to fig. 3, which illustrates a schematic diagram of an API generating process according to an embodiment of the present invention, wherein a developer inputs or stores a protocol document of an API into an electronic device running a software development tool, and opens the protocol document through the software development tool, at this time, the software development tool reads contents of the protocol document into a memory. The software development tool analyzes the protocol format of the protocol document and determines the development language type and the function name according to the instruction of a developer or according to default setting, on one hand, the software development tool determines the function template of the API according to the analyzed and determined protocol format, development language type and the function name of the calling function of the API, on the other hand, the software development tool acquires parameter information (at least comprising parameters and parameter types and optionally comprising nesting relations among the parameters) in the protocol document according to the protocol format, generates the called function of the API according to a fixed format or a compiling tool by combining the parameters and the parameter types in the parameter information, generates the calling function of the API by combining the parameters, the parameter types (optionally comprising nesting relations among the parameters) in the parameter information and the calling function template of the API, and finally combines the called function and the calling function of the API, and generating the API.
Alternatively, due to the particularity of the protocol itself, which does not have a fixed length protocol format, the length of the parameters contained therein is not fixed, in the call function of the API, in order to facilitate the serialization and deserialization of the parameters, the corresponding code statement of the fixed-length parameter may be deployed before the corresponding code statement of the non-fixed-length parameter, and therefore, when the protocol document contains both a protocol document in a fixed-length protocol format and a protocol document in an indefinite-length protocol format, the software development tool may first generate a function code corresponding to the call function of the API based on a protocol document in a fixed-length protocol format (e.g., a struct format), then generate a function code corresponding to the call function of the API based on a protocol document in an indefinite-length protocol format (e.g., a PB format), and finally perform comprehensive calculation to obtain a total length of the packet, and perform serialization according to the total length and a length of a field in the fixed-length protocol format.
For example, taking the formats of the protocol documents including the structure format and the PB format as examples, after the software development tool reads a plurality of protocol documents into the memory, the protocol type of each protocol document is determined; if the protocol type of each protocol document is the structure format, generating a function code of each protocol document corresponding to the calling function of the API according to a function generation mode corresponding to the structure format; if the protocol type of each protocol document is in a PB format, generating a function code of each protocol document, which corresponds to the calling function of the API, according to a function generation mode corresponding to the PB format; if part of the documents in each protocol document are in a structural body format and in a PB format, firstly generating function codes of the protocol documents corresponding to the structural body format in the calling function of the API, and after the function codes of the protocol documents corresponding to the structural body format in the calling function of the API are generated, regenerating the function codes of the protocol documents corresponding to the PB format in the calling function of the API.
In summary, according to the method shown in the embodiment of the present invention, by presetting the calling function template corresponding to the protocol format, the development language, and the function name of the calling function of the API, when developing the API, a developer only needs to input the protocol document of the API, and the software development tool can automatically obtain the parameter information of the API according to the protocol document, and automatically generate the calling function and the called function in the API by combining the parameter information and the corresponding function template, without manually writing function codes by the developer, which greatly reduces the labor cost of API development, shortens the development time, and thus improves the software development efficiency.
In addition, according to the method shown in the embodiment of the present invention, when the protocol document includes both the protocol document in the fixed-length protocol format and the protocol document in the indefinite-length protocol format, the function code corresponding to the calling function of the API is generated based on the protocol document in the fixed-length protocol format, and then the function code corresponding to the calling function of the API is generated based on the protocol document in the indefinite-length protocol format, so that the same API can be generated according to the protocol documents in different protocol formats.
FIG. 4 is a flowchart illustrating a method for generating an application programming interface that may be used in an electronic device running a software development tool in accordance with an exemplary embodiment. As shown in fig. 4, the method for generating an application programming interface may include the following steps:
step 401, acquiring a protocol document of an Application Programming Interface (API).
Step 402, identifying the protocol format of the protocol document, determining the development language type, and determining the function name of the calling function of the API.
Step 403, determining a function template according to the development language type and the function name.
The implementation process of steps 401 to 403 may refer to steps 201 to 203 in the corresponding embodiment of fig. 2, and is not described herein again.
Step 404, a parameter selection interface is displayed, and the parameter selection interface includes each parameter included in the protocol document.
Step 405, obtaining the parameter information included in the protocol document according to the selection operation of the at least one parameter in the parameter selection interface.
The parameter information includes at least one parameter and a type of the at least one parameter, or the parameter information includes the at least one parameter, the type of the at least one parameter and a nesting relation among the at least one parameter.
In practical applications, when a developer develops an API based on a protocol document of the API, the development of the API may only need to be performed according to some of the parameters. In contrast, the scheme shown in the embodiment of the invention can support a developer to select partial parameters and automatically generate the API according to the selected partial parameters. For example, after the software development tool determines each parameter in the protocol document according to the protocol format, a parameter selection interface may be popped up, where the parameter selection interface includes the above parameters, and a developer may select a part of the parameters from the parameter selection interface as at least one parameter for generating the API.
For example, referring to fig. 5, a schematic diagram of a parameter selection interface according to an embodiment of the present invention is shown, as shown in fig. 5, the parameter selection interface 501 includes several parameters 502, which are shown as parameter a, parameter B, parameter C, parameter D and parameter E in fig. 5, wherein, the parameter A is nested with the parameter B and the parameter C, the parameter D and the parameter E are mutually independent parameters, each parameter corresponds to a hook item 503, wherein, each hook option 503 defaults to complete hook selection, and the developer can choose to cancel the hook selection of the hook options corresponding to some parameters, for example, in fig. 5, the developer selects to cancel the checking of the parameter E, and after the developer selects to cancel the part or not to cancel the checking, the parameter of the parameter selection interface in which the check item is in the check state is at least one parameter selected by the developer (i.e., parameters a to D in fig. 5). The parameter selection interface 501 further includes a determination button 504, and after the developer clicks the determination button 504, the software development tool determines the parameters a to D as the at least one parameter, and obtains the types of the parameters a to D and the nesting relationship between the parameters a to D.
Step 406, generating the API according to the parameter information and the function template.
The implementation process of step 406 may refer to the description under step 205 in the embodiment shown in fig. 2, and is not described herein again.
In summary, in the method shown in the embodiment of the present invention, by presetting the function template corresponding to the protocol format, the development language, and the function name of the calling function of the API, when developing the API, a developer only needs to input the protocol document of the API, and the software development tool can automatically obtain the parameter information of the API according to the protocol document, and automatically generate the calling function and the called function in the API by combining the parameter information and the function template, without manually writing function codes by the developer, which greatly reduces the labor cost of API development, shortens the development time, and thus improves the software development efficiency.
In addition, the method disclosed by the embodiment of the invention can also support that a developer selects part of parameters in the protocol document to generate the corresponding API, thereby improving the flexibility of automatic generation of the API.
The following are embodiments of the apparatus of the present invention that may be used to perform embodiments of the method of the present invention. For details which are not disclosed in the embodiments of the apparatus of the present invention, reference is made to the embodiments of the method of the present invention.
Referring now to FIG. 6, shown is a block diagram of an application programming interface generation apparatus in accordance with an illustrative embodiment. The api generating apparatus may be implemented as all or part of an electronic device in hardware or a combination of hardware and software. The application programming interface generating means may include:
a first obtaining module 601, configured to obtain a protocol document of an application programming interface API;
a second obtaining module 602, configured to obtain parameter information included in the protocol document, where the parameter information includes at least one parameter and a type of the at least one parameter, or the parameter information includes the at least one parameter, the type of the at least one parameter, and a nesting relationship between the at least one parameter;
a template determining module 603, configured to determine a function template of the API;
a generating module 604, configured to generate the API according to the parameter information and the function template.
Optionally, the generating module includes:
a first generating unit, configured to generate a calling function of the API based on the function template according to the parameter information, where the calling function is used to implement a calling logic of the API;
a second generating unit, configured to generate a called function corresponding to the at least one parameter and a type of the at least one parameter, where the called function is used to be called by the calling function to implement at least one of byte order conversion, serialization, and deserialization of the parameter;
and the combining unit is used for combining the calling function and the called function to generate the API.
Optionally, the template determining module includes:
the format identification unit is used for identifying the protocol format of the protocol document, and the protocol format is a fixed-length protocol format or an indefinite-length protocol format;
a type determination unit for determining a development language type;
a function name determining unit for determining a function name of a calling function of the API;
and the template determining unit is used for determining the function template according to the protocol format, the development language type and the function name.
Optionally, the function name determining unit includes:
the interface display subunit is used for displaying a function name setting interface;
and the determining subunit is used for determining the function name according to the setting operation executed in the function name setting interface.
Optionally, the second obtaining module includes:
the syntactic analysis unit is used for carrying out syntactic analysis on the protocol document to obtain the parameter information when the protocol format of the protocol document is the structural body format;
the compiling unit is used for calling a compiling tool to compile the protocol document when the protocol format of the protocol document is a PB format, and obtaining a compiled file of the protocol document;
an extracting unit configured to extract the parameter information from the compiled file obtained by the compiling unit.
Optionally, the second obtaining module includes:
the interface display unit is used for displaying a parameter selection interface, and the parameter selection interface comprises all parameters contained in the protocol document;
and the acquisition unit is used for acquiring the parameter information according to the selection operation of the at least one parameter in the parameter selection interface.
Optionally, the second generating unit includes:
the first generating subunit is configured to, when the protocol format of the protocol document is a fixed-length protocol format, generate the called function according to the called function format corresponding to the protocol format according to the at least one parameter and the type of the at least one parameter;
and the compiling subunit is used for compiling the protocol document through a compiling tool to obtain a compiled file of the protocol document when the protocol format of the protocol document is the indefinite-length protocol format, and extracting the called function from the compiled file.
In summary, in the apparatus shown in the embodiment of the present invention, by presetting the function template corresponding to the parameter information (including the parameter and the type of the parameter, and optionally including the nesting relationship between the parameters) of the API, when developing the API, a developer only needs to input the protocol document of the API, and the software development tool can automatically obtain the parameter information of the API according to the protocol document and automatically generate the API in combination with the function template corresponding to the parameter information, without manually writing the function code by the developer, which greatly reduces the labor cost of API development, shortens the development time, and thus improves the software development efficiency.
In addition, the device shown in the embodiment of the invention also supports that a developer selects part of parameters in the protocol document to generate the corresponding API, thereby improving the flexibility of automatic generation of the API.
Embodiments of the present invention also provide a non-transitory computer-readable storage medium, such as a memory, including instructions executable by a processor of a database management device to perform the methods of application programming interface generation shown in the various embodiments of the present invention. For example, the non-transitory computer readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
Fig. 7 is a schematic structural diagram of an electronic device according to an exemplary embodiment. The electronic device may be implemented as a device running a software development tool in the above-described aspect of the present invention. The electronic device 700 includes a Central Processing Unit (CPU)701, a system memory 704 including a Random Access Memory (RAM)702 and a Read Only Memory (ROM)703, and a system bus 705 connecting the system memory 704 and the central processing unit 701. The electronic device 700 also includes a basic input/output system (I/O system) 706 that facilitates transfer of information between devices within the computer, and a mass storage device 707 for storing an operating system 713, application programs 714, and other program modules 715.
The basic input/output system 706 comprises a display 708 for displaying information and an input device 709, such as a mouse, keyboard, etc., for a user to input information. Wherein the display 708 and input device 709 are connected to the central processing unit 701 through an input output controller 710 coupled to the system bus 705. The basic input/output system 706 may also include an input/output controller 710 for receiving and processing input from a number of other devices, such as a keyboard, mouse, or electronic stylus. Similarly, input-output controller 710 may also provide output to a display screen, a printer, or other type of output device.
The mass storage device 707 is connected to the central processing unit 701 through a mass storage controller (not shown) connected to the system bus 705. The mass storage device 707 and its associated computer-readable media provide non-volatile storage for the electronic device 700. That is, the mass storage device 707 may include a computer-readable medium (not shown), such as a hard disk or CD-ROM drive.
Without loss of generality, the computer-readable media may comprise computer storage media and communication media. Computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Computer storage media includes RAM, ROM, EPROM, EEPROM, flash memory or other solid state memory technology, CD-ROM, DVD, or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices. Of course, those skilled in the art will appreciate that the computer storage media is not limited to the foregoing. The system memory 704 and mass storage device 707 described above may be collectively referred to as memory.
The electronic device 700 may also operate as a remote computer connected to a network via a network, such as the internet, in accordance with various embodiments of the present invention. That is, the electronic device 700 may be connected to the network 712 through the network interface unit 711 connected to the system bus 705, or may be connected to another type of network or a remote computer system (not shown) using the network interface unit 711.
The memory further includes one or more programs, the one or more programs are stored in the memory, and the central processing unit 701 implements the api generating method shown in fig. 2 or 4 by executing the one or more programs.
Other embodiments of the invention will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the invention and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the invention being indicated by the following claims.
It will be understood that the invention is not limited to the precise arrangements 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 invention is limited only by the appended claims.

Claims (14)

1. A method for generating an application programming interface, the method comprising:
acquiring a protocol document of an Application Programming Interface (API);
acquiring parameter information contained in the protocol document, and determining a function template of the API, wherein the parameter information comprises at least one parameter and the type of the at least one parameter, or the parameter information comprises the at least one parameter, the type of the at least one parameter and a nesting relation among the at least one parameter;
generating a calling function of the API based on the function template according to the parameter information, wherein the calling function is used for realizing calling logic of the API;
generating a called function corresponding to the at least one parameter and the type of the at least one parameter, wherein the called function is used for realizing at least one of byte order conversion, serialization and deserialization of the parameter under the calling of the calling function;
and combining the calling function and the called function to generate the API.
2. The method of claim 1, wherein determining the function template for the API comprises:
determining a development language type and determining a function name of a calling function of the API;
and determining the function template according to the development language type and the function name.
3. The method of claim 2, wherein determining a function name of a calling function of the API comprises:
displaying a function name setting interface;
and determining the function name according to the setting operation executed in the function name setting interface.
4. The method according to any one of claims 1 to 3, wherein the obtaining the parameter information includes:
when the protocol format of the protocol document is a fixed-length protocol format, performing syntax analysis on the protocol document to obtain the parameter information;
when the protocol format of the protocol document is the protocol format with indefinite length, compiling the protocol document through a compiling tool to obtain a compiled file of the protocol document, and extracting the parameter information from the compiled file.
5. The method according to any one of claims 1 to 3, wherein the obtaining the parameter information includes:
displaying a parameter selection interface, wherein the parameter selection interface comprises each parameter contained in the protocol document;
and acquiring the parameter information according to the selection operation of the at least one parameter in the parameter selection interface.
6. The method of claim 1, wherein generating the called function corresponding to the at least one parameter and the type of the at least one parameter comprises:
when the protocol format of the protocol document is a fixed-length protocol format, generating the called function according to the at least one parameter and the type of the at least one parameter and a called function format corresponding to the protocol format;
when the protocol format of the protocol document is the protocol format with indefinite length, compiling the protocol document through a compiling tool to obtain a compiled file of the protocol document, and extracting the called function from the compiled file.
7. An apparatus for generating an application programming interface, the apparatus comprising:
the first acquisition module is used for acquiring a protocol document of an Application Programming Interface (API);
a second obtaining module, configured to obtain parameter information included in the protocol document, where the parameter information includes at least one parameter and a type of the at least one parameter, or the parameter information includes the at least one parameter, the type of the at least one parameter, and a nesting relationship between the at least one parameter;
the template determining module is used for determining a function template of the API;
a generation module comprising:
a first generating unit, configured to generate a calling function of the API based on the function template according to the parameter information, where the calling function is used to implement a calling logic of the API;
a second generating unit, configured to generate a called function corresponding to the at least one parameter and a type of the at least one parameter, where the called function is used to implement at least one of byte order conversion, serialization, and deserialization of the parameter under the call of the calling function;
and the combining unit is used for combining the calling function and the called function to generate the API.
8. The apparatus of claim 7, wherein the template determination module comprises:
a type determination unit for determining a development language type;
a function name determining unit for determining a function name of a calling function of the API;
and the template determining unit is used for determining the function template according to the development language type and the function name.
9. The apparatus of claim 8, wherein the function name determining unit comprises:
the interface display subunit is used for displaying a function name setting interface;
and the determining subunit is used for determining the function name according to the setting operation executed in the function name setting interface.
10. The apparatus according to any one of claims 7 to 9, wherein the second obtaining module comprises:
the syntactic analysis unit is used for carrying out syntactic analysis on the protocol document to obtain the parameter information when the protocol format of the protocol document is the structural body format;
the compiling unit is used for calling a compiling tool to compile the protocol document when the protocol format of the protocol document is a PB format, and obtaining a compiled file of the protocol document;
an extracting unit configured to extract the parameter information from the compiled file obtained by the compiling unit.
11. The apparatus according to any one of claims 7 to 9, wherein the second obtaining module comprises:
the interface display unit is used for displaying a parameter selection interface, and the parameter selection interface comprises all parameters contained in the protocol document;
and the acquisition unit is used for acquiring the parameter information according to the selection operation of the at least one parameter in the parameter selection interface.
12. The apparatus of claim 7, wherein the second generating unit comprises:
the first generating subunit is configured to, when the protocol format of the protocol document is a fixed-length protocol format, generate the called function according to the called function format corresponding to the protocol format according to the at least one parameter and the type of the at least one parameter;
and the compiling subunit is used for compiling the protocol document through a compiling tool to obtain a compiled file of the protocol document when the protocol format of the protocol document is the indefinite-length protocol format, and extracting the called function from the compiled file.
13. An electronic device, comprising a memory and a central processing unit, wherein the memory stores one or more programs, and the programs are loaded and executed by the central processing unit to implement the application programming interface generating method according to any one of claims 1 to 6.
14. A computer-readable storage medium having stored thereon instructions which are loaded and executed by a processor to implement the application programming interface generation method of any of claims 1 to 6.
CN201611050070.3A 2016-11-24 2016-11-24 Application programming interface generation method and device Active CN108108162B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201611050070.3A CN108108162B (en) 2016-11-24 2016-11-24 Application programming interface generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611050070.3A CN108108162B (en) 2016-11-24 2016-11-24 Application programming interface generation method and device

Publications (2)

Publication Number Publication Date
CN108108162A CN108108162A (en) 2018-06-01
CN108108162B true CN108108162B (en) 2020-05-12

Family

ID=62204916

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611050070.3A Active CN108108162B (en) 2016-11-24 2016-11-24 Application programming interface generation method and device

Country Status (1)

Country Link
CN (1) CN108108162B (en)

Families Citing this family (18)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109062564A (en) * 2018-06-23 2018-12-21 上海泽阳智能科技有限公司 While a kind of programmed process device towards hardware and data
CN108920135B (en) * 2018-06-27 2021-09-10 杭州贝店科技有限公司 User-defined service generation method and device, computer equipment and storage medium
CN110795147A (en) * 2018-08-01 2020-02-14 北京京东尚科信息技术有限公司 Interface protocol file management method and device
CN109270846A (en) * 2018-10-22 2019-01-25 赵永存 Automation equipment software rapid development system based on flow chart
CN109976746A (en) * 2018-11-28 2019-07-05 四川商通实业有限公司 A kind of visual configuration application interface method
CN110083384B (en) * 2019-03-21 2020-09-15 平安国际智慧城市科技股份有限公司 Application programming interface creating method and device
CN110262783B (en) * 2019-05-22 2023-08-08 深圳华科云动力科技有限公司 Interface generation method and device and terminal equipment
CN110471654A (en) * 2019-07-17 2019-11-19 深圳文理子科技有限公司 The cloud development system and computer software program product of communication protocol
CN112286510A (en) * 2019-07-24 2021-01-29 深圳市应该科技有限公司 Method and device for realizing automatic programming based on API (application program interface)
CN110688099B (en) * 2019-09-12 2022-10-14 成都西达瑞电子科技有限公司 Microprocessor development method for long-distance radio integrated programmable system on chip
CN110781082B (en) * 2019-10-14 2022-05-20 腾讯科技(深圳)有限公司 Method, device, medium and equipment for generating test case of interface
CN111142877B (en) * 2019-12-19 2023-10-27 无锡中感微电子股份有限公司 Automatic extracting method, system and storage medium for interface function and parameter type of ROM chip patch
CN111338637A (en) * 2020-02-26 2020-06-26 腾讯科技(深圳)有限公司 Code generation method and device
CN111638875B (en) * 2020-06-05 2023-09-22 中国银行股份有限公司 Opposite terminal generation method and system
CN112463261A (en) * 2020-11-20 2021-03-09 北京达佳互联信息技术有限公司 Interface calling method and device
CN114691464A (en) * 2020-12-25 2022-07-01 中兴通讯股份有限公司 Interface testing method, computer equipment and computer readable storage medium
CN113766030B (en) * 2021-09-13 2023-05-26 城云科技(中国)有限公司 Automatic parameter entering method and device for interface constant parameters
CN113703880B (en) * 2021-10-22 2022-02-22 北京百度网讯科技有限公司 Application program starting method and device, electronic equipment and readable storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103049271A (en) * 2012-12-27 2013-04-17 微梦创科网络科技(中国)有限公司 Method and device for automatically generating description document of API (application program interface)
CN104298534A (en) * 2014-10-23 2015-01-21 广州华多网络科技有限公司 Programming method and device based on Lua language
CN105117233A (en) * 2015-09-14 2015-12-02 百度在线网络技术(北京)有限公司 API calling method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103049271A (en) * 2012-12-27 2013-04-17 微梦创科网络科技(中国)有限公司 Method and device for automatically generating description document of API (application program interface)
CN104298534A (en) * 2014-10-23 2015-01-21 广州华多网络科技有限公司 Programming method and device based on Lua language
CN105117233A (en) * 2015-09-14 2015-12-02 百度在线网络技术(北京)有限公司 API calling method and device

Also Published As

Publication number Publication date
CN108108162A (en) 2018-06-01

Similar Documents

Publication Publication Date Title
CN108108162B (en) Application programming interface generation method and device
KR101314949B1 (en) Integration environment generator
US20140372970A1 (en) Method to auto generate jax-rs rest service implementation classes from existing interfaces
WO2022002030A1 (en) Data processing method, apparatus, and device, and computer readable storage medium
US11003835B2 (en) System and method to convert a webpage built on a legacy framework to a webpage compatible with a target framework
CN111221521A (en) Method and device for generating log code, computer system and readable storage medium
CN111061464B (en) Analysis code generation method, device, equipment and storage medium
CN110727429B (en) Front-end page generation method, device and equipment
CN112765023A (en) Test case generation method and device
US7970779B2 (en) Application interface including dynamic transform definitions
CN109783752A (en) Page loading method and device, electronic equipment and computer readable storage medium
US7385927B2 (en) Methods and structure for improved testing of embedded systems
CN104049974A (en) Dynamic control assembly method and system
US7530075B2 (en) System and method for employing object-based pipelines
CN106919374B (en) Script generation method and device
US8112500B2 (en) Technique of relaying communications between client apparatus and server apparatus
CN107239265B (en) Binding method and device of Java function and C function
CN110554857A (en) JavaBean generation method, device and system and readable storage medium
CN111596905A (en) Method, device, storage medium and terminal for generating java object
CN111488731A (en) File generation method and device, computer equipment and storage medium
CN108874387B (en) Data serialization method and related equipment thereof
CN115543324A (en) Method, device, equipment and medium for generating interactive interface
US8108828B2 (en) System for generating optimized computer data field conversion routines
CN107644007B (en) Font providing system, meta font providing apparatus, and control method thereof
CN110780983A (en) Task exception handling method and device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant