CN117034900A - Automatic generation method of API (application program interface) code file, terminal equipment and storage medium - Google Patents

Automatic generation method of API (application program interface) code file, terminal equipment and storage medium Download PDF

Info

Publication number
CN117034900A
CN117034900A CN202311253971.2A CN202311253971A CN117034900A CN 117034900 A CN117034900 A CN 117034900A CN 202311253971 A CN202311253971 A CN 202311253971A CN 117034900 A CN117034900 A CN 117034900A
Authority
CN
China
Prior art keywords
api
address
mock
type
code file
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.)
Granted
Application number
CN202311253971.2A
Other languages
Chinese (zh)
Other versions
CN117034900B (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.)
Xiamen Yeastar Digital Technology Co ltd
Original Assignee
Xiamen Yeastar Digital Technology 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 Xiamen Yeastar Digital Technology Co ltd filed Critical Xiamen Yeastar Digital Technology Co ltd
Priority to CN202311253971.2A priority Critical patent/CN117034900B/en
Publication of CN117034900A publication Critical patent/CN117034900A/en
Application granted granted Critical
Publication of CN117034900B publication Critical patent/CN117034900B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/186Templates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Artificial Intelligence (AREA)
  • Data Mining & Analysis (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention relates to an automatic generation method of an API code file, terminal equipment and a storage medium, wherein the method comprises the following steps: identifying a corresponding project ID and an API ID according to a document address of the API to be analyzed, and acquiring document content; generating a type code based on the type template according to the input parameter, the output parameter and the naming prefix; generating Mock data and a storage address thereof based on a Mock template; and generating a service code based on the service template according to the type name of the input participation output parameter and the Mock data storage address in the type code. The invention can automatically complete the generation work of the API related code file.

Description

Automatic generation method of API (application program interface) code file, terminal equipment and storage medium
Technical Field
The present invention relates to the field of software development, and in particular, to an API code file automatic generation method, terminal device, and storage medium.
Background
In the software development process, the generation of the interface Mock and the type file is an important work, so that the communication cost in the development can be greatly reduced, and the development efficiency is improved. Traditional methods require manually writing Mock code and type definition files, which are often cumbersome and error-prone.
Disclosure of Invention
In order to solve the problems, the invention provides an automatic generation method of an API code file, a terminal device and a storage medium.
The specific scheme is as follows:
an automatic generation method of an API code file comprises the following steps:
s1: configuring a type template, a Mock template and a service template of the API;
s2: identifying a corresponding project ID and an API ID according to a document address of the API to be analyzed, and acquiring document content of the API; the document content of the API comprises an input parameter, an output parameter, a request address and a Method of the API;
s3: generating a naming prefix of the API according to the request address and the Method of the API;
s4: generating a type code of the API based on the type template according to the input parameter, the output parameter and the naming prefix of the API;
s5: generating the Mock data of the API based on a Mock template according to the type of the input parameter, the output parameter and the input parameter of the API, generating a Mock data storage address based on a request address of the API, a Method and a Mock prefix generated based on an item ID, and storing the generated Mock data into the Mock data storage address;
s6: and generating a service code of the API based on the service template according to the type name of the input and output parameters in the type code and the Mock data storage address.
Further, the generation mode of the document address of the API is as follows: creating an item in the YAPI platform to obtain a YAPI address and an item ID corresponding to the item; and importing the document content of the API to be analyzed into YAPI according to the YAPI address and the project ID to obtain the document address of the API.
Further, the document address of the API is mapped in the following manner: logging in to http:// api.com/based on YAPI simulation, requesting http:// api.com/project ID, and searching the document content of the API according to the project ID, the Method and the request address.
Further, the naming prefix of the API is a concatenation of the request address and the Method.
An automatic generation terminal device of an API code file comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the steps of the method according to the embodiment of the invention are realized when the processor executes the computer program.
A computer readable storage medium storing a computer program which, when executed by a processor, implements the steps of the method described above for embodiments of the present invention.
The invention adopts the technical scheme and has the beneficial effects that:
(1) The method can automatically generate the Mock data and the type file, avoids the complicated work of manual writing, automatically generates the Mock data by the script, can be directly used in projects without modifying any code, and has the advantages of standard, unified and easily understood code format, self-contained notes and high maintainability.
(2) The API document and the Mock data can be stored in a database to realize automatic management and maintenance, support different projects and versions and support configuration custom parameters and templates.
(3) Parameters can be set, mock data can be generated in real time to support joint debugging requirements of various complex parameter adjustment, various scenes such as various states of payment and the like are manufactured, and problems are reproduced and developed on the premise that databases of development, testing, production and the like are not changed.
Drawings
Fig. 1 is a flowchart of a first embodiment of the present invention.
Detailed Description
For further illustration of the various embodiments, the invention is provided with the accompanying drawings. The accompanying drawings, which are incorporated in and constitute a part of this disclosure, illustrate embodiments and together with the description, serve to explain the principles of the embodiments. With reference to these matters, one of ordinary skill in the art will understand other possible embodiments and advantages of the present invention.
The invention will now be further described with reference to the drawings and detailed description.
Embodiment one:
the embodiment of the invention provides an automatic generation method of an API code file, as shown in figure 1, comprising the following steps:
s1: the type template, the Mock template and the service template of the API are configured.
S2: and identifying the corresponding project ID and the API ID according to the document address of the API to be analyzed, and acquiring the document content of the API.
The document contents of the setting API in this embodiment include: method of API, in-parameter, out-parameter, request address, etc.
The generation mode of the document address of the API is as follows: creating an item in the YAPI platform to obtain a YAPI address and an item ID corresponding to the item; according to the YAPI address, the project ID and the YAPI platform login credentials, a third-party plug-in is used for importing the document content of the API to be analyzed into the YAPI to obtain the document address of the API, such as http:// api.com/project/430/interface/API/171401, wherein 430 is the project ID, and 171401 is the API ID.
Further, when the document content of the API is changed, the API ID will change accordingly, and if the API ID is changed to 171402, the document address of the API will be changed, which is not desired by the user, and in order to avoid the defect, address mapping is performed in this embodiment, so that the address pointing is always opposite. The mapping address corresponding to the document address of the API is as follows:
http://192.168.22.42:8001/yapi/jump. Phppid=430 & method=get & path=/user/API/bilising/v 1/list, the way to GET the document address of the API based on the mapped address is: creating an item in the YAPI platform to obtain a YAPI address and an item ID corresponding to the item; and importing the document content of the API to be analyzed into YAPI according to the YAPI address and the project ID to obtain the document address of the API.
S3: and generating a naming prefix of the API according to the request address and the Method of the API.
In this embodiment, the naming prefix of the API is set as concatenation of the request address and the Method, if the request address is/user/API/bridging/v 1/list and the Method is GET, the naming prefix is: userpibillingv 1ListGet.
S4: and generating the type code of the API based on the type template according to the input parameter, the output parameter and the naming prefix of the API.
An example of a generated type code is listed below.
/**
* List of biling 3.0.1
* get request parameter type
* http://192.168.22.42:8001/yapi/jump.phppid=430&method=GET&path=/user/api/billing/v1/list
*/
export type TUserApiBillingV1ListGetParams = {
/***/
ucId?: string;
}
/**
* List of biling 3.0.1
* response body type
* http://192.168.22.42:8001/yapi/jump.phppid=430&method=GET&path=/user/api/billing/v1/list
*/
export type TUserApiBillingV1ListGetRes = {
Self-increasing ID
id?: number;
Contact mail
contactEmail?: string;
Name/(
firstName?: string;
/(last name
lastName?: string;
Company
company?: string;
/** country */
country?: string;
/** province */
province?: string;
/** city */
city?: string;
/** street */
street?: string;
/** zipCode */
zipCode?: string;
/** phone */
phone?: string;
TAX information in the format TAX 3243/VAT EWER
taxNum?: string;
Whether or not default 0 is +.1
defaulted?: number;
Remarks/(
remark?: string;
}
Generating a type code, wherein the entry corresponds to a type name, such as TUserApiBillingV1ListGetParams in the example, wherein 'T' represents a type, 'UserApiBillingV 1 ListGet' is a naming prefix, and Params represents the entry; the references are given corresponding to a type name, such as TUserApiBillingV1ListGetREs in the above example, where "T" represents the type, "UserApiBillingV1ListGet" is the naming prefix, and Res represents the reference.
S5: generating the Mock data of the API based on the Mock template according to the type of the input parameter, the output parameter and the input parameter of the API, generating a Mock data storage address based on the request address of the API, the Method and the Mock prefix generated based on the item ID, and storing the generated Mock data in the Mock data storage address.
S6: and generating a service code of the API based on the service template according to the type name of the input and output parameters in the type code and the Mock data storage address.
An example of the generated service code is listed below.
import request from '@/utils/request';
import getMockPrefix from '@/utils/getMockPrefix';
const MOCK_PREFIX = getMockPrefix('/mock/430');
// const MOCK_PREFIX = "";
/**
* List of biling 3.0.1
* http://192.168.22.42:8001/yapi/jump.phppid=430&method=GET&path=/user/api/billing/v1/list
*/
export const apiUserApiBillingV1ListGet = (params: TUserApiBillingV1ListGetParams) =>{
return request<TUserApiBillingV1ListGetRes>(`${MOCK_PREFIX}/user/api/billing/v1/list`, {
method: 'GET',
params
});
};
Where mock_prefix represents a MOCK PREFIX whose content "/MOCK/430" is generated based on the item ID.
The Mock data storage address is obtained by splicing a Mock PREFIX and a request address, such as 'mock_prefix }/user/api/biasing/v 1/list'.
Further, in order to enable the generated code file to be better understood by different users, corresponding annotations are further added in the generation of the type code, the Mock data and the service code in the embodiment, and the annotations are acquired based on the document content of the API in step S2.
Based on the generated code file, the front-end personnel can continue to develop the front-end interactive function after copying, and the development of most or even all functions of the front-end test can be independently completed under the condition that no back-end personnel participates in the front-end test.
Embodiment two:
the invention also provides a terminal device for automatically generating the API code file, which comprises a memory, a processor and a computer program stored in the memory and capable of running on the processor, wherein the steps in the method embodiment of the first embodiment of the invention are realized when the processor executes the computer program.
Further, as an executable scheme, the automatic generation terminal device of the API code file may be a computing device such as a desktop computer, a notebook computer, a palm computer, and a cloud server. The automatic generation of the API code file by the terminal device may include, but is not limited to, a processor, a memory. It will be appreciated by those skilled in the art that the above-described configuration of the API code file automatic generation terminal device is merely an example of the API code file automatic generation terminal device, and does not constitute limitation of the API code file automatic generation terminal device, and may include more or less components than those described above, or may combine some components, or different components, for example, the API code file automatic generation terminal device may further include an input/output device, a network access device, a bus, and the like, which is not limited by the embodiment of the present invention.
Further, as an executable scheme, the processor may be a central processing unit (Central Processing Unit, CPU), other general purpose processor, digital signal processor (Digital Signal Processor, DSP), application specific integrated circuit (Application Specific Integrated Circuit, ASIC), field programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic device, etc. The general processor may be a microprocessor or the processor may be any conventional processor, etc., and the processor is a control center of the terminal device for automatically generating the API code file, and the various parts of the terminal device are automatically generated by connecting the whole API code file with various interfaces and lines.
The memory may be used to store the computer program and/or module, and the processor may implement various functions of the terminal device by running or executing the computer program and/or module stored in the memory and invoking data stored in the memory. The memory may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, at least one application program required for a function; the storage data area may store data created according to the use of the cellular phone, etc. In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as a hard disk, memory, plug-in hard disk, smart Media Card (SMC), secure Digital (SD) Card, flash Card (Flash Card), at least one disk storage device, flash memory device, or other volatile solid-state storage device.
The present invention also provides a computer readable storage medium storing a computer program which when executed by a processor implements the steps of the above-described method of an embodiment of the present invention.
The API code file automatically generating terminal device integrated modules/units may be stored in a computer readable storage medium if implemented in the form of software functional units and sold or used as a stand alone product. Based on such understanding, the present invention may implement all or part of the flow of the method of the above embodiment, or may be implemented by a computer program to instruct related hardware, where the computer program may be stored in a computer readable storage medium, and when the computer program is executed by a processor, the computer program may implement the steps of each of the method embodiments described above. Wherein the computer program comprises computer program code which may be in source code form, object code form, executable file or some intermediate form etc. The computer readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a software distribution medium, and so forth.
While the invention has been particularly shown and described with reference to a preferred embodiment, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the invention as defined by the appended claims.

Claims (6)

1. An automatic generation method of an API code file is characterized by comprising the following steps:
s1: configuring a type template, a Mock template and a service template of the API;
s2: identifying a corresponding project ID and an API ID according to a document address of the API to be analyzed, and acquiring document content of the API; the document content of the API comprises an input parameter, an output parameter, a request address and a Method of the API;
s3: generating a naming prefix of the API according to the request address and the Method of the API;
s4: generating a type code of the API based on the type template according to the input parameter, the output parameter and the naming prefix of the API;
s5: generating the Mock data of the API based on a Mock template according to the type of the input parameter, the output parameter and the input parameter of the API, generating a Mock data storage address based on a request address of the API, a Method and a Mock prefix generated based on an item ID, and storing the generated Mock data into the Mock data storage address;
s6: and generating a service code of the API based on the service template according to the type name of the input and output parameters in the type code and the Mock data storage address.
2. The API code file automatic generation method of claim 1, wherein: the generation mode of the document address of the API is as follows: creating an item in the YAPI platform to obtain a YAPI address and an item ID corresponding to the item; and importing the document content of the API to be analyzed into YAPI according to the YAPI address and the project ID to obtain the document address of the API.
3. The API code file automatic generation method of claim 1, wherein: the document address of the API is mapped in the following way: logging in to http:// api.com/based on YAPI simulation, requesting http:// api.com/project ID, and searching the document content of the API according to the project ID, the Method and the request address.
4. The API code file automatic generation method of claim 1, wherein: the naming prefix of the API is the concatenation of the request address and the Method.
5. An API code file automatic generation terminal device, characterized in that: comprising a processor, a memory and a computer program stored in the memory and running on the processor, the processor implementing the steps of the method according to any one of claims 1 to 4 when the computer program is executed.
6. A computer-readable storage medium storing a computer program, characterized in that: the computer program, when executed by a processor, implements the steps of the method according to any one of claims 1 to 4.
CN202311253971.2A 2023-09-27 2023-09-27 Automatic generation method of API (application program interface) code file, terminal equipment and storage medium Active CN117034900B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311253971.2A CN117034900B (en) 2023-09-27 2023-09-27 Automatic generation method of API (application program interface) code file, terminal equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311253971.2A CN117034900B (en) 2023-09-27 2023-09-27 Automatic generation method of API (application program interface) code file, terminal equipment and storage medium

Publications (2)

Publication Number Publication Date
CN117034900A true CN117034900A (en) 2023-11-10
CN117034900B CN117034900B (en) 2023-12-26

Family

ID=88632046

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311253971.2A Active CN117034900B (en) 2023-09-27 2023-09-27 Automatic generation method of API (application program interface) code file, terminal equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117034900B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111581920A (en) * 2020-05-12 2020-08-25 深圳前海微众银行股份有限公司 Document conversion method, device, equipment and computer storage medium
WO2020173128A1 (en) * 2019-02-27 2020-09-03 平安科技(深圳)有限公司 Method and device for generating software development kit, and terminal device
CN113672204A (en) * 2021-07-22 2021-11-19 北京明略昭辉科技有限公司 Interface document generation method, system, electronic equipment and storage medium
CN114741070A (en) * 2022-04-12 2022-07-12 中国联合网络通信集团有限公司 Code generation method and device, electronic equipment and storage medium
CN116432624A (en) * 2023-04-21 2023-07-14 上海微盟企业发展有限公司 Micro-service API document generation method, device, equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2020173128A1 (en) * 2019-02-27 2020-09-03 平安科技(深圳)有限公司 Method and device for generating software development kit, and terminal device
CN111581920A (en) * 2020-05-12 2020-08-25 深圳前海微众银行股份有限公司 Document conversion method, device, equipment and computer storage medium
CN113672204A (en) * 2021-07-22 2021-11-19 北京明略昭辉科技有限公司 Interface document generation method, system, electronic equipment and storage medium
CN114741070A (en) * 2022-04-12 2022-07-12 中国联合网络通信集团有限公司 Code generation method and device, electronic equipment and storage medium
CN116432624A (en) * 2023-04-21 2023-07-14 上海微盟企业发展有限公司 Micro-service API document generation method, device, equipment and storage medium

Also Published As

Publication number Publication date
CN117034900B (en) 2023-12-26

Similar Documents

Publication Publication Date Title
CN112052242B (en) Data query method, device, electronic equipment and storage medium
US20200380624A1 (en) Smart contract template meta-programming system and method
CN112650533B (en) Interface document generation method and device and terminal equipment
CN108279987A (en) The method for edition management and device of application program
CN111767704B (en) Excel form template generation method and device
CN102567436A (en) Multi-Tenant system
CN102880683B (en) The automatic network of a kind of feasibility study report generates system and the method for generation thereof
CN109558525A (en) A kind of generation method of test data set, device, equipment and storage medium
US20150293948A1 (en) Converting Data Objects from Single- to Multi-Source Database Environment
WO2022134583A1 (en) Insurance data information generation method, apparatus, server, and storage medium
CN109726295A (en) Brand knowledge map display methods, device, figure server and storage medium
CN110738038A (en) Contract text generation method, device, equipment and computer readable storage medium
CN113626223A (en) Interface calling method and device
CN110298692A (en) Method, system and the storage medium of customer data unified management by all kinds of means
CN111898351B (en) Automatic Excel data importing method and device based on Aviator, terminal equipment and storage medium
CN117034900B (en) Automatic generation method of API (application program interface) code file, terminal equipment and storage medium
CN101763340A (en) Business bill conversion method, device and system
CN111090976A (en) Method and device for generating inspection document based on dynamic data
CN116400914A (en) Method for quickly constructing web application based on data model
CN115543428A (en) Simulated data generation method and device based on strategy template
CN115114321A (en) Dynamic query method and system
CN111027302B (en) Electricity selling contract generation method and system based on settlement model
CN113177059A (en) Method and device for generating matching platform SQL script
CN108228688B (en) Template generation method, system and server based on XBRL
CN116755684B (en) OAS Schema generation method, device, equipment and 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