CN114489603A - Code generation method, apparatus, electronic device, medium, and product - Google Patents
Code generation method, apparatus, electronic device, medium, and product Download PDFInfo
- Publication number
- CN114489603A CN114489603A CN202210142411.9A CN202210142411A CN114489603A CN 114489603 A CN114489603 A CN 114489603A CN 202210142411 A CN202210142411 A CN 202210142411A CN 114489603 A CN114489603 A CN 114489603A
- Authority
- CN
- China
- Prior art keywords
- interface
- code
- target
- template
- generation method
- 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.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 67
- 238000004891 communication Methods 0.000 claims description 24
- 238000004590 computer program Methods 0.000 claims description 6
- 238000007726 management method Methods 0.000 description 15
- 230000008569 process Effects 0.000 description 12
- 230000006870 function Effects 0.000 description 11
- 238000010586 diagram Methods 0.000 description 4
- 238000012545 processing Methods 0.000 description 4
- 238000011161 development Methods 0.000 description 3
- 230000003993 interaction Effects 0.000 description 3
- 230000004044 response Effects 0.000 description 2
- 238000012546 transfer Methods 0.000 description 2
- 239000000470 constituent Substances 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 238000012795 verification Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Information Transfer Between Computers (AREA)
Abstract
Description
技术领域technical field
本申请涉及软件技术领域,更具体的说,是涉及代码生成方法、装置、电子设备、介质和产品。The present application relates to the field of software technology, and more specifically, to a code generation method, apparatus, electronic device, medium and product.
背景技术Background technique
前端客户端与后台服务器需要通过接口进行数据交互,即开发人员需要编写接口对应的接口代码,前端客户端通过调用接口代码以实现通过接口与后台服务器进行交互的目的。由于前端客户端的种类繁多,所以需要开发人员一一针对不同的接口编写相应的接口代码,操作繁琐。The front-end client and the back-end server need to exchange data through the interface, that is, the developer needs to write the interface code corresponding to the interface, and the front-end client can interact with the back-end server through the interface by calling the interface code. Due to the wide variety of front-end clients, developers are required to write corresponding interface codes for different interfaces one by one, which is cumbersome to operate.
发明内容SUMMARY OF THE INVENTION
有鉴于此,本申请提供了一种代码生成方法、装置、电子设备、介质和产品。In view of this, the present application provides a code generation method, apparatus, electronic device, medium and product.
为实现上述目的,本申请提供如下技术方案:To achieve the above purpose, the application provides the following technical solutions:
根据本公开实施例的第一方面,提供一种代码生成方法,包括:According to a first aspect of the embodiments of the present disclosure, a code generation method is provided, including:
获取接口对应的接口信息,所述接口信息包括多个字段以及多个字段分别对应的字段值,所述多个字段包括:后台服务器的通讯地址、向所述后台服务器发送的报文携带的参数名称、所述报文的结构以及所述报文的请求方式;Obtain interface information corresponding to the interface, where the interface information includes multiple fields and field values corresponding to the multiple fields respectively, and the multiple fields include: the communication address of the background server, the parameters carried in the message sent to the background server the name, the structure of the message, and the request method of the message;
控制显示用户界面,所述用户界面用于指示用户选择接口代码模板,所述接口代码模板包括待填写字段值的多个字段;Controlling and displaying a user interface, the user interface is used to instruct the user to select an interface code template, and the interface code template includes a plurality of fields of field values to be filled;
获取通过所述用户界面确定的所述接口对应的接口代码模板;Obtain the interface code template corresponding to the interface determined by the user interface;
从所述接口信息中查找所述接口代码模板包含的字段的字段值,并填入所述接口代码模板,以生成所述接口对应的目标接口代码。The field value of the field included in the interface code template is searched from the interface information, and the interface code template is filled in to generate the target interface code corresponding to the interface.
在第一方面的第一种可能实现方式中,还包括:In a first possible implementation manner of the first aspect, it further includes:
基于预先设置的接口代码与文件位置的对应关系中,查找所述目标接口代码对应的目标文件位置;Based on the preset correspondence between the interface code and the file location, search for the target file location corresponding to the target interface code;
将所述目标接口代码插入预构建的前端客户端的代码文件的所述目标文件位置。Inserting the target interface code into the target file location of the code file of the pre-built front-end client.
在第一方面的第二种可能实现方式中,所述获取接口对应的接口信息包括:In a second possible implementation manner of the first aspect, the obtaining interface information corresponding to the interface includes:
获取所述接口对应的接口文档;Obtain the interface document corresponding to the interface;
解析所述接口文档,以获得所述接口信息。Parse the interface document to obtain the interface information.
在第一方面的第三种可能实现方式中,所述获取接口对应的接口信息包括:In a third possible implementation manner of the first aspect, the obtaining interface information corresponding to the interface includes:
建立与在线接口管理工具的通信连接,所述在线接口管理工具包含所述接口对应的接口信息;establishing a communication connection with an online interface management tool, where the online interface management tool includes interface information corresponding to the interface;
通过所述在线接口管理工具获得所述接口对应的接口信息。Obtain interface information corresponding to the interface through the online interface management tool.
根据本公开实施例的第二方面,提供一种代码生成装置,包括:According to a second aspect of the embodiments of the present disclosure, there is provided a code generation apparatus, comprising:
第一获取模块,用于获取接口对应的接口信息,所述接口信息包括多个字段以及多个字段分别对应的字段值,所述多个字段包括:后台服务器的通讯地址、向所述后台服务器发送的报文携带的参数名称、所述报文的结构以及所述报文的请求方式;The first obtaining module is used to obtain interface information corresponding to the interface, the interface information includes multiple fields and field values corresponding to the multiple fields respectively, and the multiple fields include: the communication address of the background server, the communication address to the background server The parameter name carried in the sent message, the structure of the message, and the request method of the message;
控制模块,用于控制显示用户界面,所述用户界面用于指示用户选择接口代码模板,所述接口代码模板包括待填写字段值的多个字段;a control module, configured to control and display a user interface, the user interface is used to instruct the user to select an interface code template, and the interface code template includes a plurality of fields of field values to be filled;
第二获取模块,用于获取通过所述用户界面确定的所述接口对应的接口代码模板;A second acquisition module, configured to acquire the interface code template corresponding to the interface determined by the user interface;
生成模块,用于从所述接口信息中查找所述接口代码模板包含的字段的字段值,并填入所述接口代码模板,以生成所述接口对应的目标接口代码。The generating module is configured to search the field value of the field included in the interface code template from the interface information, and fill in the interface code template to generate the target interface code corresponding to the interface.
在第二方面的第一种可能实现方式中,还包括:In a first possible implementation manner of the second aspect, it further includes:
查找模块,用于基于预先设置的接口代码与文件位置的对应关系中,查找所述目标接口代码对应的目标文件位置;a search module for searching the target file position corresponding to the target interface code based on the preset correspondence between the interface code and the file position;
插入模块,用于将所述目标接口代码插入预构建的前端客户端的代码文件的所述目标文件位置。an inserting module, configured to insert the target interface code into the target file location of the code file of the pre-built front-end client.
在第二方面的第二种可能实现方式中,所述第一获取模块包括:In a second possible implementation manner of the second aspect, the first obtaining module includes:
第一获取单元,用于获取所述接口对应的接口文档;a first obtaining unit, configured to obtain an interface document corresponding to the interface;
解析单元,用于解析所述接口文档,以获得所述接口信息。A parsing unit, configured to parse the interface document to obtain the interface information.
在第二方面的第三种可能实现方式中,所述第一获取模块包括:In a third possible implementation manner of the second aspect, the first obtaining module includes:
建立连接单元,用于建立与在线接口管理工具的通信连接,所述在线接口管理工具包含所述接口对应的接口信息;establishing a connection unit for establishing a communication connection with an online interface management tool, where the online interface management tool includes interface information corresponding to the interface;
第二获取单元,用于通过所述在线接口管理工具获得所述接口对应的接口信息。The second obtaining unit is configured to obtain the interface information corresponding to the interface through the online interface management tool.
根据本公开实施例的第三方面,提供一种电子设备包括:According to a third aspect of the embodiments of the present disclosure, there is provided an electronic device comprising:
处理器;processor;
用于存储所述处理器可执行指令的存储器;a memory for storing the processor-executable instructions;
其中,所述处理器被配置为执行所述指令,以实现如第一方面所述的代码生成方法。Wherein, the processor is configured to execute the instructions to implement the code generation method according to the first aspect.
根据本公开实施例的第四方面,提供一种计算机可读存储介质,当所述存储介质中的指令由电子设备的处理器执行时,使得所述电子设备能够执行如第一方面所述的代码生成方法。According to a fourth aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, when instructions in the storage medium are executed by a processor of an electronic device, enabling the electronic device to execute the method described in the first aspect Code generation method.
根据本公开实施例的第五方面,提供一种计算机程序产品,可直接加载到计算机的内部存储器,所述存储器为第三方面所示的所述电子设备包含的存储器中,并含有软件代码,所述计算机程序经由计算机载入并执行后能够实现如第一方面所述的代码生成方法。According to a fifth aspect of the embodiments of the present disclosure, a computer program product is provided, which can be directly loaded into an internal memory of a computer, where the memory is a memory included in the electronic device shown in the third aspect, and contains software codes, The computer program can implement the code generation method described in the first aspect after being loaded and executed by the computer.
经由上述的技术方案可知,本申请提供的代码生成方法中,无需开发人员人为编写接口代码,而是预先构建接口代码模板,从得到的接口信息中查找接口代码模板包含的字段的字段值,并填入接口代码模板,从而得到接口对应的目标接口代码,在这过程中,需要用户选择接口对应的接口代码模板,后续接口代码自动生成,无需开发人员针对每一接口编写接口代码,所以占用开发人员的时间大大减少,且提高了接口代码的生成效率。As can be seen from the above technical solutions, in the code generation method provided by this application, it is not necessary for developers to manually write interface codes, but to pre-build an interface code template, and find the field values of the fields contained in the interface code template from the obtained interface information, and Fill in the interface code template to obtain the target interface code corresponding to the interface. In this process, the user needs to select the interface code template corresponding to the interface, and the subsequent interface code is automatically generated. There is no need for developers to write interface code for each interface, so it takes up development The time of personnel is greatly reduced, and the generation efficiency of interface code is improved.
附图说明Description of drawings
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据提供的附图获得其他的附图。In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only It is an embodiment of the present application. For those of ordinary skill in the art, other drawings can also be obtained according to the provided drawings without any creative effort.
图1为本申请实施例提供的代码生成方法的流程图;1 is a flowchart of a code generation method provided by an embodiment of the present application;
图2为本申请实施例提供的代码生成装置的结构图;2 is a structural diagram of a code generation device provided by an embodiment of the present application;
图3是根据一示例性实施例示出的一种用于电子设备的装置的框图。Fig. 3 is a block diagram of an apparatus for an electronic device according to an exemplary embodiment.
具体实施方式Detailed ways
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
本申请实施例提供了一种代码生成方法、装置、电子设备、介质及产品,在介绍本申请提供的技术方案之前,先对本申请涉及的硬件架构进行说明。Embodiments of the present application provide a code generation method, apparatus, electronic device, medium and product. Before introducing the technical solutions provided by the present application, the hardware architecture involved in the present application is described.
本申请实施例涉及的硬件架构包括:电子设备。The hardware architecture involved in the embodiments of the present application includes: an electronic device.
示例性的,电子设备可以是任何一种可与用户通过键盘、触摸板、触摸屏、遥控器、语音交互或手写设备等一种或多种方式进行人机交互的电子产品,例如,手机、笔记本电脑、平板电脑、掌上电脑、个人计算机、可穿戴设备、智能电视、PAD等。Exemplarily, the electronic device can be any electronic product that can interact with the user in one or more ways, such as a keyboard, a touchpad, a touchscreen, a remote control, a voice interaction, or a handwriting device, for example, a mobile phone, a notebook, etc. Computers, Tablets, Palmtops, Personal Computers, Wearables, Smart TVs, PADs, etc.
电子设备中可以运行有前端客户端,前端客户端可以为应用程序客户端或网页版客户端或小程序。A front-end client may run in the electronic device, and the front-end client may be an application client or a web client or a small program.
前端客户端与各服务器进行交互的接口对应的接口代码都可以通过本申请提供的代码生成方法生成,从而无需开发人员一一编写各接口的接口代码,操作简便,且提高了效率。The interface codes corresponding to the interfaces where the front-end client interacts with each server can be generated by the code generation method provided in the present application, so that developers do not need to write the interface codes of each interface one by one, the operation is simple, and the efficiency is improved.
可以理解的是,在生成各接口对应的接口代码后,将接口代码插入前端客户端的代码文件的相应位置,从而开发完毕前端客户端,前端客户端即可投入使用。It can be understood that, after generating the interface code corresponding to each interface, insert the interface code into the corresponding position of the code file of the front-end client, so that the front-end client can be put into use after the development of the front-end client is completed.
本领域技术人员应能理解上述电子设备仅为举例,其他现有的或今后可能出现的电子设备如可适用于本公开,也应包含在本公开保护范围以内,并在此以引用方式包含于此。Those skilled in the art should understand that the above-mentioned electronic devices are only examples, and other existing or future electronic devices, if applicable to the present disclosure, should also be included within the protection scope of the present disclosure, and are incorporated herein by reference. this.
下面结合上述硬件架构对本申请实施例提供的代码生成方法进行说明。The code generation method provided by the embodiments of the present application will be described below with reference to the above hardware architecture.
如图1所示,为本申请实施例提供的代码生成方法的流程图,该方法包括以下步骤S11至步骤S14。As shown in FIG. 1 , which is a flowchart of a code generation method provided by an embodiment of the present application, the method includes the following steps S11 to S14 .
步骤S11:获取接口对应的接口信息,所述接口信息包括多个字段以及多个字段分别对应的字段值,所述多个字段包括:后台服务器的通讯地址、向所述后台服务器发送的报文携带的参数名称、所述报文的结构以及所述报文的请求方式。Step S11: Obtain interface information corresponding to the interface, where the interface information includes multiple fields and field values corresponding to the multiple fields respectively, and the multiple fields include: the communication address of the background server, the message sent to the background server The parameter name carried, the structure of the packet, and the request mode of the packet.
可以理解的是,在前端客户端开发过程中,开发人员会根据前端客户端的业务拆解各个功能,然后针对每一功能,确定若实现该功能,前端客户端需要进行交互的后台服务器,从而确定该功能对应的接口。所以接口与前端客户端的功能相关。It is understandable that in the development process of the front-end client, developers will disassemble each function according to the business of the front-end client, and then, for each function, determine the back-end server that the front-end client needs to interact with if the function is implemented, so as to determine the The interface corresponding to this function. So the interface is related to the function of the front-end client.
接口信息是生成接口代码的基础,下面说明为何接口信息需要包括上述多个字段。The interface information is the basis for generating the interface code. The following explains why the interface information needs to include the above-mentioned multiple fields.
可以理解的是,前端客户端在与后台服务器进行交互的过程中,是通过Http(HyperText Transfer Protocol,超文本传输协议)协议通信的。前端客户端可以向后台服务器发送报文,例如,Http报文,报文包含报文头和报文体。It can be understood that the front-end client communicates through the Http (HyperText Transfer Protocol, hypertext transfer protocol) protocol in the process of interacting with the back-end server. The front-end client can send a message to the back-end server, for example, an Http message, and the message includes a message header and a message body.
报文中携带有接口相关的参数名称和参数名称对应的字段值。后台服务器在接收到报文后,会核实报文中携带的参数名称是否与该接口的功能相符,若相符则会向前端客户端反馈响应报文。The packet carries the parameter name related to the interface and the field value corresponding to the parameter name. After receiving the message, the backend server will verify whether the parameter name carried in the message matches the function of the interface. If it matches, it will send a response message back to the front-end client.
下面以前端客户端包含的功能为登录功能为例进行说明。前端客户端可以接收用户输入的用户名和密码(报文中携带的参数名称包括用户名和密码),前端客户端通过登录接口向后台服务器发送登录请求报文,后台服务器接收到登录请求报文后,会核实该请求报文是否携带用户名和密码,若携带,则进行验证用户名和密码的字段值是否满足要求,并返回验证是否通过的响应报文。The following takes the function included in the front-end client as the login function as an example for description. The front-end client can receive the user name and password entered by the user (the parameter name carried in the message includes the user name and password). The front-end client sends a login request message to the backend server through the login interface. After the backend server receives the login request message, It will verify whether the request packet carries the user name and password. If so, it will verify whether the field values of the user name and password meet the requirements, and return a response packet indicating whether the verification is passed.
报文中携带后台服务器的通讯地址,示例性的,通讯地址可以为IP地址(InternetProtocol Address,又译为网际协议地址)和端口号。报文中携带的目的地址即为后台服务器的通讯地址。The message carries the communication address of the background server. Exemplarily, the communication address may be an IP address (Internet Protocol Address, also translated as an Internet Protocol address) and a port number. The destination address carried in the message is the communication address of the background server.
报文的请求方式包括但不限于:GET请求方式、POST请求方式、PUT请求方式、Delete请求方式。请求方式表征了前端客户端与后台服务器的交互方式。The message request methods include but are not limited to: GET request method, POST request method, PUT request method, and Delete request method. The request mode characterizes the interaction between the front-end client and the back-end server.
在前端客户端与后台服务器进行交互的过程中,需要知道对方的报文的结构,否则无法从报文中解析出字段和字段值。所以需要报文的结构这一参数。In the process of interaction between the front-end client and the back-end server, it is necessary to know the structure of the other party's message, otherwise the fields and field values cannot be parsed from the message. Therefore, the parameter of the structure of the message is required.
步骤S12:控制显示用户界面,所述用户界面用于指示用户选择接口代码模板,所述接口代码模板包括待填写字段值的多个字段。Step S12: Control to display a user interface, the user interface is used to instruct the user to select an interface code template, and the interface code template includes a plurality of fields of field values to be filled.
接口代码模板是预先构建的,不同类型的接口对应的接口代码模板不同。每一接口对应的接口代码模板中只包含该接口所需要的各字段,各字段对应的字段值未填写,示例性的,字段对应的字段值可以用占位符表示。Interface code templates are pre-built, and interface code templates corresponding to different types of interfaces are different. The interface code template corresponding to each interface contains only the fields required by the interface, and the field value corresponding to each field is not filled in. Exemplarily, the field value corresponding to the field can be represented by a placeholder.
示例性的,接口代码模板至少包括以下字段:请求方式、参数名称、后台服务器的通讯地址。Exemplarily, the interface code template includes at least the following fields: request method, parameter name, and communication address of the background server.
步骤S13:获取通过所述用户界面确定的所述接口对应的接口代码模板。Step S13: Obtain an interface code template corresponding to the interface determined through the user interface.
示例性的,每个接口代码模板对应一个模板名称,用户可以通过模板名称确定接口对应的接口代码模板,所以用户可以不是开发人员。Exemplarily, each interface code template corresponds to a template name, and the user can determine the interface code template corresponding to the interface through the template name, so the user may not be a developer.
示例性的,用户界面可以显示接口代码模板包含的字段,用户可以通过接口代码模板显示的字段,从中选择与接口的功能相对应的接口代码模板。Exemplarily, the user interface may display the fields included in the interface code template, and the user may select the interface code template corresponding to the function of the interface from the fields displayed by the interface code template.
步骤S14:从所述接口信息中查找所述接口代码模板包含的字段的字段值,并填入所述接口代码模板,以生成所述接口对应的目标接口代码。Step S14: Search the interface information for the field value of the field included in the interface code template, and fill in the interface code template to generate the target interface code corresponding to the interface.
示例性的,若接口代码模板中包含的字段的字段值均被填充,就得到了目标接口代码。Exemplarily, if the field values of the fields included in the interface code template are all filled, the target interface code is obtained.
示例性的,若接口代码模板中一个或多个字段的字段值未从接口信息中查找到,则可以控制显示提示框,以提示用户人为写入。Exemplarily, if the field value of one or more fields in the interface code template is not found from the interface information, a prompt box can be controlled to be displayed to prompt the user to manually write it.
本申请实施例提供的代码生成方法中,无需开发人员人为编写接口代码,而是预先构建接口代码模板,从得到的接口信息中查找接口代码模板包含的字段的字段值,并填入接口代码模板,从而得到接口对应的目标接口代码,在这过程中,需要用户选择接口对应的接口代码模板,后续接口代码自动生成,无需开发人员针对每一接口编写接口代码,所以占用开发人员的时间大大减少,且提高了接口代码的效生成率。In the code generation method provided by the embodiments of the present application, developers do not need to manually write interface codes, but pre-build an interface code template, search for field values of fields included in the interface code template from the obtained interface information, and fill in the interface code template , so as to obtain the target interface code corresponding to the interface. In this process, the user needs to select the interface code template corresponding to the interface, and the subsequent interface code is automatically generated. There is no need for developers to write interface code for each interface, so the time occupied by developers is greatly reduced. , and improve the efficient generation rate of interface code.
可以理解的是,接口代码需要插入前端客户端对应的代码文件的相应位置,在运行前端客户端对应的代码文件的过程中,http请求库会自动调用代码文件中相应位置的接口代码。在一可选实现方式中,上述方法还包括以下步骤A1至步骤A2。It is understandable that the interface code needs to be inserted into the corresponding position of the code file corresponding to the front-end client. During the process of running the code file corresponding to the front-end client, the http request library will automatically call the interface code in the corresponding position in the code file. In an optional implementation manner, the above method further includes the following steps A1 to A2.
步骤A1:基于预先设置的接口代码与文件位置的对应关系中,查找所述目标接口代码对应的目标文件位置。Step A1: Based on the preset correspondence between the interface code and the file location, search for the target file location corresponding to the target interface code.
示例性的,可以变更接口代码与文件位置的对应关系。Exemplarily, the corresponding relationship between the interface code and the file location can be changed.
步骤A2:将所述目标接口代码插入预构建的前端客户端的代码文件的所述目标文件位置。Step A2: Insert the target interface code into the target file location of the code file of the pre-built front-end client.
本申请中通过接口代码模板的方式生成接口代码,并插入至代码文件的目标文件位置,所以本申请是将接口代码作为模块的方式使用,避免了代码文件过于臃肿,在后续开发人员阅读代码文件时思路也比较清晰。In this application, the interface code is generated by the interface code template, and inserted into the target file location of the code file, so the application uses the interface code as a module, which avoids the code file being too bloated, and the subsequent developers read the code file. The thinking is also clearer.
在一可选实现方式中,步骤S11的实现方式有多种,本申请实施例提供但不限于以下三种。In an optional implementation manner, there are multiple implementation manners of step S11, and the embodiments of the present application provide but are not limited to the following three.
第一种步骤S11的实现方式包括以下步骤B1至步骤B2。The implementation of the first step S11 includes the following steps B1 to B2.
步骤B1:获取所述接口对应的接口文档。Step B1: Obtain an interface document corresponding to the interface.
示例性的,接口文档是由开发人员编写并上传至电子设备中的。Exemplarily, the interface document is written by the developer and uploaded to the electronic device.
接口文档包括前端客户端的开发人员和后台服务器的开发人员共同定义的接口信息。前端客户端的开发人员和后台服务器的开发人员在开发前端客户端和后台服务器的过程中是基于接口文档进行开发的。The interface document includes the interface information jointly defined by the developer of the front-end client and the developer of the back-end server. The developers of the front-end client and the back-end server develop based on the interface document in the process of developing the front-end client and the back-end server.
步骤B2:解析所述接口文档,以获得所述接口信息。Step B2: Parse the interface document to obtain the interface information.
接口文档包括多个字段以及多个字段分别对应的字段值。接口文档的结构是固定的,所以可以基于接口文档的结构定义解析接口文档的方式。The interface document includes multiple fields and field values corresponding to the multiple fields. The structure of the interface document is fixed, so the way to parse the interface document can be defined based on the structure of the interface document.
第二种步骤S11的实现方式包括以下步骤C1至步骤C2。The implementation manner of the second step S11 includes the following steps C1 to C2.
步骤C1:建立与在线接口管理工具的通信连接,所述在线接口管理工具包含所述接口对应的接口信息。Step C1: Establish a communication connection with an online interface management tool, where the online interface management tool includes interface information corresponding to the interface.
示例性的,在线接口管理工具可以为:Swagger、RAP、APIDOC、Spring REST Docs。Exemplarily, the online interface management tools can be: Swagger, RAP, APIDOC, Spring REST Docs.
开发人员可以在在线接口管理工具中设置一个或多个接口分别对应的接口信息。Developers can set the interface information corresponding to one or more interfaces in the online interface management tool.
示例性的,在线接口管理工具可以位于其他电子设备中,运行有前端客户端的电子设备可以与其他电子设备建立远程连接。Exemplarily, the online interface management tool may be located in other electronic devices, and the electronic device running the front-end client may establish a remote connection with other electronic devices.
步骤C2:通过所述在线接口管理工具获得所述接口对应的接口信息。Step C2: Obtain interface information corresponding to the interface through the online interface management tool.
第三种步骤S11的实现方式包括:解析工程源代码,以得到接口信息。The implementation manner of the third step S11 includes: parsing the project source code to obtain interface information.
在一可选实现方式中,本申请实施例提供的代码生成方法支持常用的插件,例如,IDE插件。可以通过IDE插件调用本申请提供的代码生成方法,以实现接口代码的更新。In an optional implementation manner, the code generation method provided by the embodiments of the present application supports commonly used plug-ins, for example, IDE plug-ins. The code generation method provided by this application can be invoked through the IDE plug-in to update the interface code.
上述本申请公开的实施例中详细描述了方法,对于本申请的方法可采用多种形式的装置实现,因此本申请还公开了一种装置,下面给出具体的实施例进行详细说明。The above-mentioned embodiments disclosed in the present application describe the method in detail, and the method of the present application can be implemented by various forms of devices. Therefore, the present application also discloses a device, and specific embodiments are given below for detailed description.
如图2所示,为本申请实施例提供的代码生成装置的结构图,该装置包括:第一获取模块21、控制模块22、第二获取模块23以及生成模块24,其中:As shown in FIG. 2 , which is a structural diagram of a code generation device provided by an embodiment of the present application, the device includes: a
第一获取模块21,用于获取接口对应的接口信息,所述接口信息包括多个字段以及多个字段分别对应的字段值,所述多个字段包括:后台服务器的通讯地址、向所述后台服务器发送的报文携带的参数名称、所述报文的结构以及所述报文的请求方式;The
控制模块22,用于控制显示用户界面,所述用户界面用于指示用户选择接口代码模板,所述接口代码模板包括待填写字段值的多个字段;a
第二获取模块23,用于获取通过所述用户界面确定的所述接口对应的接口代码模板;A second obtaining
生成模块24,用于从所述接口信息中查找所述接口代码模板包含的字段的字段值,并填入所述接口代码模板,以生成所述接口对应的目标接口代码。The generating
在一可选实现方式中,还包括:In an optional implementation, it also includes:
查找模块,用于基于预先设置的接口代码与文件位置的对应关系中,查找所述目标接口代码对应的目标文件位置;a search module for searching the target file position corresponding to the target interface code based on the preset correspondence between the interface code and the file position;
插入模块,用于将所述目标接口代码插入预构建的前端客户端的代码文件的所述目标文件位置。an inserting module, configured to insert the target interface code into the target file location of the code file of the pre-built front-end client.
在一可选实现方式中,所述第一获取模块包括:In an optional implementation, the first obtaining module includes:
第一获取单元,用于获取所述接口对应的接口文档;a first obtaining unit, configured to obtain an interface document corresponding to the interface;
解析单元,用于解析所述接口文档,以获得所述接口信息。A parsing unit, configured to parse the interface document to obtain the interface information.
在一可选实现方式中,所述第一获取模块包括:In an optional implementation, the first obtaining module includes:
建立连接单元,用于建立与在线接口管理工具的通信连接,所述在线接口管理工具包含所述接口对应的接口信息;establishing a connection unit for establishing a communication connection with an online interface management tool, where the online interface management tool includes interface information corresponding to the interface;
第二获取单元,用于通过所述在线接口管理工具获得所述接口对应的接口信息。The second obtaining unit is configured to obtain the interface information corresponding to the interface through the online interface management tool.
关于上述实施例中的装置,其中各个模块执行操作的具体方式已经在有关该方法的实施例中进行了详细描述,此处将不做详细阐述说明。Regarding the apparatus in the above-mentioned embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment of the method, and will not be described in detail here.
图3是根据一示例性实施例示出的一种用于电子设备的装置的框图。Fig. 3 is a block diagram of an apparatus for an electronic device according to an exemplary embodiment.
电子设备包括但不限于:处理器31、存储器32、网络接口33、I/O控制器34以及通信总线35。The electronic devices include, but are not limited to: a
需要说明的是,本领域技术人员可以理解,图3中示出的电子设备的结构并不构成对电子设备的限定,电子设备可以包括比图3所示更多或更少的部件,或者组合某些部件,或者不同的部件布置。It should be noted that those skilled in the art can understand that the structure of the electronic device shown in FIG. 3 does not constitute a limitation on the electronic device, and the electronic device may include more or less components than those shown in FIG. Some components, or different component arrangements.
下面结合图3对电子设备的各个构成部件进行具体的介绍:Below in conjunction with Fig. 3, each constituent element of the electronic device is introduced in detail:
处理器31是电子设备的控制中心,利用各种接口和线路连接整个电子设备的各个部分,通过运行或执行存储在存储器32内的软件程序和/或模块,以及调用存储在存储器32内的数据,执行电子设备的各种功能和处理数据,从而对电子设备进行整体监控。处理器31可包括一个或多个处理单元;示例性的,处理器31可集成应用处理器和调制解调处理器,其中,应用处理器主要处理操作系统、用户界面和应用程序等,调制解调处理器主要处理无线通信。可以理解的是,上述调制解调处理器也可以不集成到处理器31中。The
处理器31可能是一个中央处理器(Central Processing Unit,CPU),或者是特定集成电路ASIC(Application Specific Integrated Circuit),或者是被配置成实施本发明实施例的一个或多个集成电路等;The
存储器32可能包含内存,例如高速随机存取存储器(Random-Access Memory,RAM)321和只读存储器(Read-Only Memory,ROM)322,也可能还包括大容量存储设备323,例如至少1个磁盘存储器等。当然,该电子设备还可能包括其他业务所需要的硬件。The
其中,上述的存储器32,用于存储上述处理器31可执行指令。上述处理器31具有以下功能:获取接口对应的接口信息,所述接口信息包括多个字段以及多个字段分别对应的字段值,所述多个字段包括:后台服务器的通讯地址、向所述后台服务器发送的报文携带的参数名称、所述报文的结构以及所述报文的请求方式;The above-mentioned
控制显示用户界面,所述用户界面用于指示用户选择接口代码模板,所述接口代码模板包括待填写字段值的多个字段;Controlling and displaying a user interface, the user interface is used to instruct the user to select an interface code template, and the interface code template includes a plurality of fields of field values to be filled;
获取通过所述用户界面确定的所述接口对应的接口代码模板;Obtain the interface code template corresponding to the interface determined by the user interface;
从所述接口信息中查找所述接口代码模板包含的字段的字段值,并填入所述接口代码模板,以生成所述接口对应的目标接口代码。Find the field value of the field included in the interface code template from the interface information, and fill in the interface code template to generate the target interface code corresponding to the interface.
一个有线或无线网络接口33被配置为将电子设备连接到网络。A wired or
处理器31、存储器32、网络接口33和I/O控制器34可以通过通信总线35相互连接,该通信总线可以是ISA(Industry Standard Architecture,工业标准体系结构)总线、PCI(Peripheral Component Interconnect,外设部件互连标准)总线或EISA(ExtendedIndustry Standard Architecture,扩展工业标准结构)总线等。所述总线可以分为地址总线、数据总线、控制总线等。The
在示例性实施例中,电子设备可以被一个或多个应用专用集成电路(ASIC)、数字信号处理器(DSP)、数字信号处理设备(DSPD)、可编程逻辑器件(PLD)、现场可编程门阵列(FPGA)、控制器、微控制器、微处理器或其他电子元件实现,用于执行上述代码生成方法。In an exemplary embodiment, the electronic device may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable A gate array (FPGA), controller, microcontroller, microprocessor, or other electronic component implementation is implemented for performing the above-described code generation method.
在示例性实施例中,本公开实施例提供了一种包括指令的存储介质,例如包括指令的存储器32,上述指令可由电子设备的处理器31执行以完成上述方法。可选地,存储介质可以是非临时性计算机可读存储介质,例如,所述非临时性计算机可读存储介质可以是ROM、随机存取存储器(RAM)、CD-ROM、磁带、软盘和光数据存储设备等。In an exemplary embodiment, an embodiment of the present disclosure provides a storage medium including instructions, such as a
在示例性实施例中,还提供了一种计算机可读存储介质,可直接加载到计算机的内部存储器,例如上述存储器32中,并含有软件代码,该计算机程序经由计算机载入并执行后能够实现上述代码生成方法任一实施例所示步骤。In an exemplary embodiment, a computer-readable storage medium is also provided, which can be directly loaded into the internal memory of a computer, such as the above-mentioned
在示例性实施例中,还提供一种计算机程序产品,可直接加载到计算机的内部存储器,例如所述电子设备包含的存储器中,并含有软件代码,该计算机程序经由计算机载入并执行后能够实现上述所述代码生成方法任一实施例所示步骤。In an exemplary embodiment, a computer program product is also provided, which can be directly loaded into the internal memory of a computer, such as the memory contained in the electronic device, and contains software codes, the computer program can be loaded and executed by the computer. The steps shown in any embodiment of the above-mentioned code generation method are implemented.
需要说明的是,本发明提供的代码生成方法、装置、电子设备、介质及产品可用于金融领域或其他领域,例如,可用于金融领域中的代码生成应用场景。其他领域为除金融领域之外的任意领域,例如,电力领域。上述仅为示例,并不对本发明提供的代码生成方法、装置、电子设备、介质及产品的应用领域进行限定。It should be noted that the code generation method, device, electronic device, medium and product provided by the present invention can be used in the financial field or other fields, for example, can be used in code generation application scenarios in the financial field. The other fields are any fields other than the financial field, for example, the electric power field. The above is only an example, and does not limit the application fields of the code generation method, device, electronic device, medium and product provided by the present invention.
需要说明的是,本说明书中的各个实施例中记载的特征可以相互替换或者组合。对于装置或系统类实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。It should be noted that the features described in each embodiment in this specification may be replaced or combined with each other. As for the apparatus or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for related parts, please refer to the partial description of the method embodiment.
还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。It should also be noted that in this document, relational terms such as first and second are used only to distinguish one entity or operation from another, and do not necessarily require or imply those entities or operations There is no such actual relationship or order between them. Moreover, the terms "comprising", "comprising" or any other variation thereof are intended to encompass non-exclusive inclusion such that a process, method, article or device comprising a list of elements includes not only those elements, but also includes not explicitly listed or other elements inherent to such a process, method, article or apparatus. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in a process, method, article or apparatus that includes the element.
结合本文中所公开的实施例描述的方法或算法的步骤可以直接用硬件、处理器执行的软件模块,或者二者的结合来实施。软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的存储介质中。The steps of a method or algorithm described in connection with the embodiments disclosed herein may be directly implemented in hardware, a software module executed by a processor, or a combination of the two. A software module can be placed in random access memory (RAM), internal memory, read only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other in the technical field. in any other known form of storage medium.
对所公开的实施例的上述说明,使本领域专业技术人员能够实现或使用本申请。对这些实施例的多种修改对本领域的专业技术人员来说将是显而易见的,本文中所定义的一般原理可以在不脱离本申请的精神或范围的情况下,在其它实施例中实现。因此,本申请将不会被限制于本文所示的这些实施例,而是要符合与本文所公开的原理和新颖特点相一致的最宽的范围。The above description of the disclosed embodiments enables any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, this application is not intended to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210142411.9A CN114489603A (en) | 2022-02-16 | 2022-02-16 | Code generation method, apparatus, electronic device, medium, and product |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210142411.9A CN114489603A (en) | 2022-02-16 | 2022-02-16 | Code generation method, apparatus, electronic device, medium, and product |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114489603A true CN114489603A (en) | 2022-05-13 |
Family
ID=81479515
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210142411.9A Pending CN114489603A (en) | 2022-02-16 | 2022-02-16 | Code generation method, apparatus, electronic device, medium, and product |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114489603A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116339703A (en) * | 2023-05-24 | 2023-06-27 | 北京蓝天航空科技股份有限公司 | Bus interface code generation method and device, electronic equipment and medium |
CN118034652A (en) * | 2023-12-22 | 2024-05-14 | 北京谷器数据科技有限公司 | Method for automatically generating service codes |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110515608A (en) * | 2019-08-30 | 2019-11-29 | 网易(杭州)网络有限公司 | A kind of generation method and device, electronic equipment, storage medium of interface code |
CN111930363A (en) * | 2020-08-07 | 2020-11-13 | 北京字节跳动网络技术有限公司 | Block interface code generation method and device |
CN113138757A (en) * | 2021-05-11 | 2021-07-20 | 中国工商银行股份有限公司 | Method, device, server, system and medium for automatically generating front-end code |
CN113918308A (en) * | 2021-11-05 | 2022-01-11 | 杭州安恒信息技术股份有限公司 | Interface calling method, system, readable storage medium and computer device |
-
2022
- 2022-02-16 CN CN202210142411.9A patent/CN114489603A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110515608A (en) * | 2019-08-30 | 2019-11-29 | 网易(杭州)网络有限公司 | A kind of generation method and device, electronic equipment, storage medium of interface code |
CN111930363A (en) * | 2020-08-07 | 2020-11-13 | 北京字节跳动网络技术有限公司 | Block interface code generation method and device |
CN113138757A (en) * | 2021-05-11 | 2021-07-20 | 中国工商银行股份有限公司 | Method, device, server, system and medium for automatically generating front-end code |
CN113918308A (en) * | 2021-11-05 | 2022-01-11 | 杭州安恒信息技术股份有限公司 | Interface calling method, system, readable storage medium and computer device |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116339703A (en) * | 2023-05-24 | 2023-06-27 | 北京蓝天航空科技股份有限公司 | Bus interface code generation method and device, electronic equipment and medium |
CN116339703B (en) * | 2023-05-24 | 2023-08-15 | 北京蓝天航空科技股份有限公司 | Bus interface code generation method and device, electronic equipment and medium |
CN118034652A (en) * | 2023-12-22 | 2024-05-14 | 北京谷器数据科技有限公司 | Method for automatically generating service codes |
CN118034652B (en) * | 2023-12-22 | 2024-10-08 | 北京谷器数据科技有限公司 | A method for automatically generating service codes |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111414407A (en) | Data query method, device, computer equipment and storage medium for database | |
CN111767095A (en) | Microservice generation method, apparatus, terminal device and storage medium | |
CN102843413B (en) | Screen generation system, screen generation method, and screen generation program | |
CN110858172A (en) | A kind of automatic test code generation method and device | |
CN114489603A (en) | Code generation method, apparatus, electronic device, medium, and product | |
CN113761588A (en) | Data verification method and device, terminal equipment and storage medium | |
CN110704200A (en) | Methods and devices for converting invocation interfaces | |
CN114189553B (en) | Flow playback method, system and computing device | |
CN114489736A (en) | Interface code updating method, device, system, medium and product | |
CN116561013B (en) | Test methods, devices, electronic equipment and media based on the target service framework | |
CN112732547B (en) | Service testing method and device, storage medium and electronic equipment | |
CN112905990A (en) | Access method, client, server and access system | |
CN112732468A (en) | Data processing method, data interaction system and computing equipment | |
CN113055348A (en) | Cross-platform data request method and device and electronic equipment | |
CN113760703B (en) | A method, device, equipment and storage medium for generating mock data | |
WO2024051195A1 (en) | Data calling method and apparatus, and serving gateway and storage medium | |
CN114936151A (en) | Display method, device, equipment, storage medium and communication system of debugging page | |
WO2019052170A1 (en) | Method, apparatus and device for implementing user login avoidance, and computer storage medium | |
CN112637254B (en) | Data processing method and device, electronic equipment and computer readable storage medium | |
CN114722108A (en) | Customer service data processing method and device, electronic equipment and storage medium | |
CN114417318A (en) | Method, device and electronic device for jumping to third-party pages | |
CN113242306B (en) | Block chain consensus method and device | |
CN113608996B (en) | A mirror compilation test method, system, device and readable storage medium | |
CN118694550A (en) | A cross-domain access method and device | |
CN115633080A (en) | Proxy-based verification method and device, storage medium, and computer equipment |
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 |