Interface document generation method, device, computer equipment and storage medium
By extracting interface parameters in business code carrying decorative functions and generating interface description files, the problems of interface omission and repeated definitions in traditional interface document generation are solved, and the automatic generation and accuracy of interface documents are achieved, which promotes front-end communication and improvement of software project development efficiency.
Patent Information
- Application Number
- CN202010951067.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-11
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2040-09-11
AI Technical Summary
During the software project development process, traditional interface document generation methods have omissions or repeated definitions, resulting in inaccurate interface documents, which affects the communication between front and back ends and the development efficiency of software projects.
By obtaining the business code carrying the decorative function, extracting interface parameters according to the data definition rules of the decorative function, generating interface description files, and synchronizing them to the interface management platform, and generating interface documents from the platform.
It realizes automatic extraction of interface parameters and automatic generation of interface documents, improves the accuracy of interface documents, promotes efficient communication between the front and back ends, and thus improves the efficiency of software project development.
Smart Images

Figure CN114168190B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an interface document generation method, apparatus, computer equipment and storage medium. Background Art
[0002] In the process of software project development, a front-end and back-end separation development model is generally adopted to improve development efficiency. However, this development model requires close communication between front-end developers, back-end developers and testers. For example, front-end development depends on the interface data of the back-end, and the back-end developers need to provide complete interface documentation to the front-end developers.
[0003] In traditional technology, each interface in the business code needs to define interface descriptions such as properties and parameters, and write the interface descriptions into a document to obtain an interface document. The interface document exists independently of the business code. After the business code is updated, it is necessary to redefine each interface not in the interface document based on the updated business code. When writing or updating the interface descriptions of each interface into the interface document, there are cases where the interface is omitted or repeatedly defined, resulting in inaccurate information in the interface document, which is not conducive to communication between the front-end and the back-end, thereby affecting the development efficiency of the software project. Summary of the invention
[0004] Based on this, it is necessary to provide an interface document generation method, device, computer equipment and storage medium that can improve the accuracy of interface documents to improve the efficiency of software project development in response to the above technical problems.
[0005] A method for generating an interface document, the method comprising:
[0006] Get the business code with the decorated function;
[0007] According to the data definition rules corresponding to the decorated function, the interface parameters defined in the business code are extracted;
[0008] Generate interface description file according to interface parameters;
[0009] The interface description file is synchronized to the interface management platform, and the interface management platform generates the interface document.
[0010] In one embodiment, synchronizing the interface description file to the interface management platform, and generating the interface document by the interface management platform includes:
[0011] The interface description file is synchronized to the interface management platform, so that when the interface management platform detects the existence of an initial interface document corresponding to the business code, it updates the initial interface document according to the interface description file.
[0012] An interface document generating device, the device comprising:
[0013] Business code acquisition module, used to obtain business codes carrying decorated functions;
[0014] The interface parameter extraction module is used to extract the interface parameters defined in the business code according to the data definition rules corresponding to the decorated function;
[0015] An interface description file generation module is used to generate an interface description file according to interface parameters;
[0016] The interface document generation module is used to synchronize the interface description file to the interface management platform, and the interface management platform generates the interface document.
[0017] A computer device includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0018] Get the business code with the decorated function;
[0019] According to the data definition rules corresponding to the decorated function, the interface parameters defined in the business code are extracted;
[0020] Generate interface description file according to interface parameters;
[0021] The interface description file is synchronized to the interface management platform, and the interface management platform generates the interface document.
[0022] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0023] Get the business code with the decorated function;
[0024] According to the data definition rules corresponding to the decorated function, the interface parameters defined in the business code are extracted;
[0025] Generate interface description file according to interface parameters;
[0026] The interface description file is synchronized to the interface management platform, and the interface management platform generates the interface document.
[0027] The above-mentioned interface document generation method, device, computer equipment and storage medium, based on the business code carrying the decorated function, can quickly and conveniently extract the interface parameters in the business code according to the data definition rules of the decorated function, thereby realizing the automatic extraction of the interface parameters, and generating an interface description file recognizable by the interface management platform according to the interface parameters, and then generating the interface document through the interface management platform. By utilizing the data definition rules of the decorated function, the automatic extraction of the interface parameters can be realized directly based on the business code, and the interface document can be automatically generated with the help of the interface management platform, thereby realizing the coupling of the interface document and the business code, and improving the accuracy of the interface document. Accurate interface documents are conducive to efficient communication between the front and back ends during the software development process, thereby effectively improving the efficiency of software project development. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 An application environment diagram of an interface document generation method in an embodiment;
[0029] Figure 2 A schematic diagram of a flow chart of a method for generating an interface document in one embodiment;
[0030] Figure 3 A schematic diagram of a flow chart of a method for generating an interface document in another embodiment;
[0031] Figure 4 A schematic diagram of a flow chart of a method for generating an interface document in yet another embodiment;
[0032] Figure 5 A schematic diagram of a flow chart of a method for generating an interface document in yet another embodiment;
[0033] Figure 6 A flowchart of a method for generating an interface document in another embodiment;
[0034] Figure 7 A schematic diagram of an interface information query interface of an interface document generation method in an embodiment;
[0035] Figure 8 A schematic diagram of a flow chart of a method for generating an interface document in one embodiment;
[0036] Fig. 9 A schematic diagram of a flow chart of a method for generating an interface document in yet another embodiment;
[0037] Fig.10 It is a structural block diagram of an interface document generating device in one embodiment;
[0038] Fig.11 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0039] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0040] The interface document generation method provided in this application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network, and the server 104 communicates with the interface management platform 106 through the network. The server 104 obtains the business code with the decoration function written by the developer on the terminal 102, extracts the interface parameters defined in the business code according to the data definition rules corresponding to the decoration function, generates an interface description file according to the interface parameters, and synchronizes the interface description file to the interface management platform 106 to generate an interface document through the interface management platform 106. Among them, the terminal 102 can be but not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices, and the server 104 can be implemented with an independent server or a server cluster composed of multiple servers.
[0041] In one embodiment, Figure 2 As shown, a method for generating an interface document is provided, and the method is applied to Figure 1 The server in is taken as an example to illustrate, including the following steps 202 to 208.
[0042] Step 202, obtaining the business code carrying the decorated function.
[0043] Decorative functions, also known as decorators, refer to dynamically extending the functionality of an object without having to change the original class file or use inheritance. It wraps the real object by creating a wrapper object, that is, a decorator. Business code refers to code that can be run directly in the development environment to implement business logic.
[0044] The business code with the decoration function written by the developer through the development terminal does not change the original business logic in essence. The interface parameters in the code are packaged through the decoration function to facilitate the identification of the interface parameters. In the application process, through the decorator mode, the interface input parameters, output parameters, http status code, parameter type and other data can be customized on the technology stack that the developer is familiar with, so as to reduce the learning cost of the developer.
[0045] Step 204: extract the interface parameters defined in the business code according to the data definition rules corresponding to the decorated function.
[0046] The data definition rules of the decorated function are the writing rules that the decorated function needs to follow. That is to say, in the process of writing business code, it is necessary to define the interface parameters according to the writing rules of the decorated function. After obtaining the business code, the interface parameters defined in the business code can be quickly and accurately identified and extracted based on the data definition rules corresponding to the decorated function.
[0047] Step 206: Generate an interface description file according to the interface parameters.
[0048] In the embodiment, the interface description file is generated by performing parameter standardization and format conversion on the interface parameters. Parameter standardization refers to the process of processing the interface parameters according to certain parameter format specifications, and format conversion refers to the process of converting the standardized interface parameters into file formats in accordance with the format requirements of the interface management platform, so that the generated interface description file can be imported into the corresponding interface management platform.
[0049] In one embodiment, Figure 3 As shown, according to the interface parameters, generating the interface description file, that is, step 206, includes steps 302 to 306.
[0050] Step 302, obtaining a parameter format specification corresponding to the interface parameter file;
[0051] Step 304: perform parameter standardization processing on the interface parameters according to the parameter format specification to generate an interface parameter file.
[0052] The interface parameter file is a file with standard parameter format specifications. The interface parameters are sorted according to the standard parameter format specifications and updated to the initial interface parameter file, so as to obtain an interface parameter file containing various interface parameters and conforming to the parameter format specifications. Specifically, the main purpose of the business code is to implement code logic for data processing, and there is no unified format requirement for the interface parameters defined in the code file. Based on the standard parameter format specifications of the interface parameter file, the interface parameters are filled with relevant information and data format adjustment according to the standard parameter format specifications, and updated to the initial interface parameter file, so as to achieve the purpose of writing the interface parameters into the interface parameter file, and the interface parameters in the interface parameter file conform to the standard parameter format specifications. In an embodiment, the interface parameter file can be a swagger file, which is a standardized and complete framework for generating, describing, calling and visualizing RESTful-style Web services. Specifically, the swagger file is a standard specification file with a standardized and complete framework. The extracted interface parameters are defined according to the specifications of the swagger file for the interface and the interface-related information, and a swagger file including various interface parameters is obtained.
[0053] Step 306: convert the interface parameter file into an interface description file according to a preset file conversion logic.
[0054] The preset file conversion logic refers to the processing logic that utilizes the differences in data expressions in different files and the representations of the same data in different files to convert data A in file 1 into data a that conforms to the data expression of file 2, wherein the substantive content of data A is the same as that of data a. An interface description file refers to a file having a specific format recognized by an interface management platform. In an embodiment, the interface description file may be a YAML (YAML Ain't a Markup Language, a markup language) file. YAML is a highly readable format for expressing data serialization. The syntax of YAML is similar to other high-level languages, and can simply express data forms such as lists, hash tables, and scalars.
[0055] Since the interface parameter file itself is a file generated strictly in accordance with the parameter format specification, the data actually contained in the interface parameter file and the interface description file are all extracted interface parameters, but the two are based on different file rules for data recording. According to the pre-configured file conversion logic between the interface parameter file and the interface description file, the interface parameter file is converted into an interface description file.
[0056] Step 208: synchronize the interface description file to the interface management platform, and the interface management platform generates an interface document.
[0057] The interface management platform refers to a data management platform that manages interface data in a unified manner. The interface management platform can import files in a specific format, obtain interface parameters, and generate corresponding interface documents based on the obtained interface parameters, thereby realizing the automatic generation of interface documents.
[0058] In one embodiment, the interface document can be quickly generated by importing the interface description file into the interface management platform. In other embodiments, the developer can directly write the interface description file and import it into the interface management platform to obtain the description file. However, since the interface description file has specific format requirements, the syntax learning cost is high, the entry threshold is high, and manual writing of the interface description file is time-consuming. Through file conversion, the participation of developers can be reduced, which can not only improve efficiency, but also avoid the occurrence of human errors in the writing process of the interface description file.
[0059] The above-mentioned interface document generation method, based on the business code carrying the decorated function, can quickly and conveniently extract the interface parameters in the business code according to the data definition rules of the decorated function, realize the automatic extraction of the interface parameters, and generate an interface description file recognizable by the interface management platform according to the interface parameters, and then generate the interface document through the interface management platform. By utilizing the data definition rules of the decorated function, the automatic extraction of the interface parameters can be realized directly based on the business code, and the interface document can be automatically generated with the help of the interface management platform, realizing the coupling of the interface document and the business code, and improving the accuracy of the interface document. Accurate interface documents are conducive to efficient communication between the front and back ends during the software development process, thereby effectively improving the efficiency of software project development.
[0060] In one embodiment, if Figure 4 As shown, after performing parameter standardization processing on the interface parameters according to the parameter format specification to generate an interface parameter file, that is, step 304, steps 402 to 404 are also included.
[0061] Step 402: Generate an interface parameter verification file according to the interface parameter file.
[0062] Step 404: When an interface debugging request initiated by the client is received, the interface parameters corresponding to the interface debugging request are verified according to the interface parameter verification file.
[0063] Step 208 , synchronizing the interface description file to the interface management platform, and the interface management platform generates the interface document including step 406 .
[0064] Step 406: When the verification passes, the interface description file is synchronized to the interface management platform, and the interface management platform generates an interface document.
[0065] The interface parameter verification file refers to the data specification file of the interface parameter verification environment. During the interface debugging process, based on the interface parameter verification file, the legality of the parameters of the interface sent by the client request can be verified. By verifying the interface parameters corresponding to the interface debugging request sent by the client, the correctness of the business code can be further verified.
[0066] In one embodiment, the interface file generation process mainly includes three processes, the first is the business code development stage, the second is the online interface debugging stage, and the third is the interface development completion stage, that is, the interface file generation stage. The client interface parameter verification is implemented in the interface debugging stage.
[0067] In other embodiments, during the operation, the interface parameter verification file can also ensure the legality of the interface parameters during operation, and avoid the intrusion of illegal interfaces. Specifically, during the debugging and verification process, if there is no problem with the interface verification of the client, it means that there is no problem with the interface of the client. In this process, based on the same interface parameter verification file, all interfaces that have been verified to be legal can directly input and output parameters. Once an illegal interface is invaded, since the invading interface has not been debugged and verified, when the verification conditions of the interface parameter verification file are not met, the request through the interface will be intercepted to avoid entering the business code, thereby ensuring security during the operation process.
[0068] In one embodiment, the interface parameter verification file includes a jsonschema file. The method further includes: in response to a node process restart operation, loading the jsonschema file into the node process. When an interface debugging request initiated by a client is received, the interface parameters corresponding to the interface debugging request are verified according to the interface parameter verification file, including: when an interface debugging request initiated by a client is received, the jsonschema file is called from the node process, and the interface parameters corresponding to the interface debugging request are verified.
[0069] The interface parameter verification file includes the jsonschema file. Jsonschema is a data format that describes json. The Node process is used to execute the specified task. By restarting the node process, the file loaded in the original node process is interrupted to update the loaded file. Ensure that the file loaded in the process is the latest interface parameter verification file to ensure the accuracy of the verification result of the client interface.
[0070] In one embodiment, if Figure 5 As shown, when an interface debugging request initiated by a client is received, the interface parameters corresponding to the interface debugging request are verified according to the interface parameter verification file, that is, step 404 includes steps 502 to 508.
[0071] Step 502: When an interface debugging request initiated by the client is received, input parameters in the interface debugging request are extracted.
[0072] Step 504: Verify the input parameters according to the input parameter definition specification in the interface parameter verification file.
[0073] Step 506: When the input parameter verification passes, the output parameter corresponding to the input parameter is obtained according to the business logic in the business code.
[0074] Step 508: Verify the output parameters according to the output parameter definition specification in the interface parameter verification file.
[0075] When the verification passes, the interface description file is synchronized to the interface management platform, and the interface management platform generates an interface document, that is, step 406 includes step 510.
[0076] Step 510: When the output parameter verification passes, the interface description file is synchronized to the interface management platform, and the interface management platform generates an interface document.
[0077] In one embodiment, the interface parameters that need to be verified include input parameters and output parameters. Specifically, the input parameters are first verified. When the input parameter verification passes, the output parameters are obtained based on the input parameters and the business logic, and then the output parameters are verified. Only when both the input parameters and the output parameters pass the verification can the verification result be obtained. Among them, the input parameter passing the verification means that the input parameters in the interface debugging request meet the input parameter definition specifications in the interface parameter verification file, and the output parameter passing the verification means that the output parameters in the interface debugging request meet the output parameter definition specifications in the interface parameter verification file.
[0078] The interface parameter verification file includes input parameter definition specifications and output parameter definition specifications. For example, the input parameter definition specifications may include the data type of the input parameter, whether a required field is missing, etc. The input parameters and output parameters are verified respectively through the input parameter definition specifications and the output parameter definition specifications. By verifying the input parameters and output parameters of the client corresponding interface, the legitimacy of the interface parameters can be verified. Furthermore, the connection between the business code and the client interface can be used to infer whether there is a problem with the business code based on the parameter verification results of the interface, thereby realizing the detection of the business code.
[0079] In one embodiment, if Figure 6 As shown, when an interface debugging request initiated by a client is received, the interface parameters corresponding to the interface debugging request are verified according to the interface parameter verification file, that is, after step 404, step 602 is also included.
[0080] Step 602: When the interface parameter verification fails, the interface parameter illegality information is fed back to the client, so that the client updates the service code according to the interface parameter illegality information.
[0081] After the service code is updated, return to step 204.
[0082] In the embodiment, the interface debugging request sent by the client is initiated based on the business code. When the interface parameter verification fails, the server will feedback the interface parameter illegal information carrying the verification failure reason to the client. The client locates the problem data in the business code according to the verification failure reason in the interface parameter illegal information, thereby updating the business code. After the business code is updated, the interface parameters will also change. At this time, by re-extracting and updating the interface parameters defined in the business code, the interface parameter file, the interface parameter verification file, and the interface description file are all updated to ensure the accuracy of the generated interface file.
[0083] It can be understood that the verification of output parameters is performed after the verification of input parameters. When the input parameter verification fails, the verification will be terminated and the result of the verification failure will be fed back to the customer order. The business logic will not be executed based on the input parameters, and the output parameters corresponding to the input parameters will not be obtained, thereby reducing the amount of data processing.
[0084] In one embodiment, synchronizing the interface description file to the interface management platform, and generating the interface document by the interface management platform includes:
[0085] The interface description file is synchronized to the interface management platform, so that when the interface management platform detects the existence of an initial interface document corresponding to the business code, it updates the initial interface document according to the interface description file.
[0086] In order to meet the application of business scenarios that require real-time updates of business codes, the interface documents in the interface management platform can be updated to achieve synchronous updates of data. Specifically, before generating the interface document, the interface management platform detects whether there is an initial interface document corresponding to the business code. If so, the initial interface document is updated. If not, a new interface document is directly generated, thus avoiding the duplication of interface documents and causing confusion in the data structure of the interface document.
[0087] In one embodiment, the method further includes: sending an interface information viewing request to an interface management platform, receiving interface information fed back by the interface management platform, and pushing the interface information to an interface information display interface, wherein the interface information includes basic interface information, request parameter information, and return data information.
[0088] like Figure 7 As shown, taking the interface of the financial system as an example, based on the interface management platform, the interface information of each interface in the interface document can be obtained in a visual way. The interface information display interface displays an interface list including various interfaces in the interface document. In response to the touch operation of an interface in the interface list, the detailed interface information of the interface can be further obtained and displayed, including basic interface information, request parameter information and return data information, so as to realize the convenient viewing of interface information.
[0089] If you click on an interface in the interface list whose name is an interface of a transaction record, the basic information, request parameters and return data of the interface will be displayed. The basic information includes the interface name, creator, status, update time, interface path and mock address. The request parameters include the parameter name, whether it is required, examples and remarks. The return data includes the name, type, whether it is required, default value and remarks.
[0090] The present application also provides an application scenario, and the application scenario applies the above-mentioned interface document generation method. Specifically, the application of the interface document generation method in the application scenario is as follows:
[0091] See also Figure 8 ,The generation process of interface documentation is mainly divided into three stages.
[0092] The first stage is the local development stage. Developers define the interface input parameters, output parameters, http status code, parameter type and other data through custom decorators. During local development, the decorator analysis engine will automatically analyze the current interface related data and assemble it into swagger files and jsonschema files, which are provided to the interface documentation and parameter verification respectively.
[0093] Specifically, developers write business codes with decorators in the development client, check whether the parameter definitions in the declaration file meet the definition specifications of the decorator, extract interface parameters, generate a swagger file, that is, an interface parameter file, and then use the conversion tool provided by swagger to convert the swagger file into a jsonschema file. By restarting the node process, the jsonschema file is loaded into the node process. In addition, the engine tool will convert the swagger file into a YAML file to prepare for the second stage of interface parameter verification.
[0094] The second stage is the interface debugging stage, which is suitable for online processing. When the client initiates an http / https request, the parameter verification plug-in analysis engine will automatically analyze the input and output parameters of the current interface, and verify the parameters in combination with the jsonschema file in the first stage to ensure the legitimacy of the input and output parameters.
[0095] Specifically, the client initiates a request to the server based on the business code. The server verifies the input parameters in the request according to the jsonschema file in the node process. When the input parameter verification fails, the abnormal data is fed back to the client and reported. When the input parameter verification succeeds, the output parameters corresponding to the input parameters are obtained according to the business logic, that is, the return parameters. The output parameters in the request are verified according to the jsonschema file in the node process. When the output parameter verification fails, the abnormal data is fed back to the client and reported. When the output parameters of each interface are verified successfully, the third stage begins.
[0096] The third stage is the interface development completion stage, which is also the interface document generation stage. During the code submission process, the YAML file converted from the swagger file in the first stage is automatically synchronized to the yapi platform, and the interface document is finally generated or updated.
[0097] Specifically, during the submission of the business code and the swagger file, the YAML file is synchronized to the yapi platform. The yapi platform generates or updates the interface document based on the YAML file.
[0098] Through the above processing, not only can the decorator mode solve the problem of automatic generation of interface documents, but also the developer's development efficiency is greatly improved and the developer's learning cost is reduced; in addition, combined with the relevant parameter verification plug-in, the legality of the input parameters and output parameters of the interface can be ensured during operation, avoiding the access of illegal ports.
[0099] It should be understood that, although the steps in the above-mentioned flowcharts are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the above-mentioned flowcharts may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0100] In one embodiment, Fig. 9 As shown, a method for generating an interface document is provided, including the following steps 902 to 930.
[0101] Step 902, obtaining the business code carrying the decorated function.
[0102] Step 904: extract the interface parameters defined in the business code according to the data definition rules corresponding to the decorated function.
[0103] Step 906, obtain the swagger file parameter format specification, standardize the interface parameters according to the swagger file parameter format specification, and generate a swagger file.
[0104] Step 908, generate a jsonschema file according to the swagger file, and convert the swagger file into a yaml file according to the preset file conversion logic.
[0105] Step 910, in response to the node process restart operation, the jsonschema file is loaded into the node process.
[0106] Step 912: When an interface debugging request initiated by the client is received, input parameters in the interface debugging request are extracted.
[0107] Step 914, calling the jsonschema file from the node process.
[0108] Step 916, verify the input parameters according to the input parameter definition specification in the jsonschema file.
[0109] Step 918, when the input parameter verification fails, the interface parameter illegality information is fed back to the client, so that the client updates the service code according to the interface parameter illegality information, and returns to step 904.
[0110] Step 920: When the input parameter verification passes, the output parameter corresponding to the input parameter is obtained according to the business logic in the business code.
[0111] Step 922, verify the output parameters according to the output parameter definition specification in the jsonschema file.
[0112] Step 924 , when the output parameter check fails, the interface parameter illegality information is fed back to the client, so that the client updates the service code according to the interface parameter illegality information, and returns to step 904 .
[0113] Step 926, when the output parameter verification passes, the yaml file is synchronized to the interface management platform, and the interface management platform generates an interface document.
[0114] Step 928: Send an interface information viewing request to the interface management platform.
[0115] Step 930, receiving the interface information fed back by the interface management platform, and pushing the interface information to the interface information display interface, the interface information includes basic interface information, request parameter information and return data information.
[0116] In one embodiment, Fig.10 As shown, an interface document generation device 1000 is provided. The device can adopt a software module or a hardware module, or a combination of the two to become a part of a computer device. The device specifically includes: a business code acquisition module 1002, an interface parameter extraction module 1004, an interface description file generation module 1006 and an interface document generation module 1008, wherein:
[0117] The business code acquisition module 1002 is used to acquire the business code carrying the decorated function.
[0118] The interface parameter extraction module 1004 is used to extract the interface parameters defined in the business code according to the data definition rules corresponding to the decorated function.
[0119] The interface description file generating module 1006 is used to generate an interface description file according to the interface parameters.
[0120] The interface document generation module 1008 is used to synchronize the interface description file to the interface management platform, and the interface management platform generates the interface document.
[0121] In one embodiment, the interface description file generation module includes an interface parameter file generation module and a file conversion module. The interface parameter file generation module is used to obtain a parameter format specification corresponding to the interface parameter file, perform parameter standardization processing on the interface parameters according to the parameter format specification, and generate an interface parameter file. The file conversion module is used to convert the interface parameter file into an interface description file according to a preset file conversion logic.
[0122] In one of the embodiments, the interface document generation device also includes an interface parameter verification module, which is used to generate an interface parameter verification file based on the interface parameter file. When an interface debugging request initiated by the client is received, the interface parameters corresponding to the interface debugging request are verified according to the interface parameter verification file; the interface document generation module is also used to synchronize the interface description file to the interface management platform when the verification passes, and the interface management platform generates an interface document.
[0123] In one of the embodiments, the interface parameter verification file includes a jsonschema file; the interface document generation device also includes a file loading module, which is used to respond to the node process restart operation and load the jsonschema file into the node process; the interface parameter verification module is also used to call the jsonschema file from the node process when receiving an interface debugging request initiated by the client, and verify the interface parameters corresponding to the interface debugging request.
[0124] In one of the embodiments, the interface parameter verification module is also used to extract the input parameters in the interface debugging request initiated by the client when receiving the interface debugging request; verify the input parameters according to the input parameter definition specifications in the interface parameter verification file; when the input parameter verification passes, obtain the output parameters corresponding to the input parameters according to the business logic in the business code; verify the output parameters according to the output parameter definition specifications in the interface parameter verification file; the interface document generation module is also used to synchronize the interface description file to the interface management platform when the output parameter verification passes, and the interface management platform generates the interface document.
[0125] In one of the embodiments, the interface document generating device further includes an information feedback module, which is used to feedback interface parameter illegality information to the client when the interface parameter verification fails, so that the client updates the service code according to the interface parameter illegality information.
[0126] In one of the embodiments, the interface document generation module is also used to synchronize the interface description file to the interface management platform, so that when the interface management platform detects the existence of an initial interface document corresponding to the business code, it updates the initial interface document according to the interface description file.
[0127] In one of the embodiments, the interface document generation device also includes an interface information viewing module, which is used to send an interface information viewing request to the interface management platform; receive interface information feedback from the interface management platform, and push the interface information to the interface information display interface, the interface information includes basic interface information, request parameter information and return data information.
[0128] The above-mentioned interface document generation device, based on the business code carrying the decorated function, can quickly and conveniently extract the interface parameters in the business code according to the data definition rules of the decorated function, thereby realizing the automatic extraction of the interface parameters, and generating an interface description file recognizable by the interface management platform according to the interface parameters, and then generating the interface document through the interface management platform. By utilizing the data definition rules of the decorated function, the interface parameters can be automatically extracted directly based on the business code, and the interface document can be automatically generated with the help of the interface management platform, thereby realizing the coupling of the interface document and the business code, and improving the accuracy of the interface document. Accurate interface documents are conducive to efficient communication between the front and back ends during the software development process, thereby effectively improving the efficiency of software project development.
[0129] For the specific definition of the interface document generation device, please refer to the definition of the interface document generation method above, which will not be repeated here. Each module in the above-mentioned interface document generation device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0130] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.11 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store interface document generation data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an interface document generation method is implemented.
[0131] Those skilled in the art will understand that Fig.11 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0132] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0133] In one embodiment, a computer-readable storage medium is provided, storing a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0134] In one embodiment, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps in the above-mentioned method embodiments.
[0135] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0136] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0137] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A method for generating an interface document, characterized in that: The method includes a local development phase, an interface debugging phase, and an interface document generation phase which are performed in sequence: In the local development stage, the business code carrying the decoration function is obtained from the developer's terminal; according to the data definition rule corresponding to the decoration function, the interface parameters defined in the business code are extracted; the interface parameters are subjected to parameter standardization processing to generate an interface parameter file; according to the preset file conversion logic, the interface parameter file is converted into an interface description file that meets the format requirements of the interface management platform, and the interface description file is a YAML file with a specific format recognized by the interface management platform; Generate an interface parameter verification file according to the interface parameter file, wherein the interface parameter verification file includes a jsonschema file; In the interface debugging stage, in response to the node process restart operation, the file loaded in the original node process is interrupted, and the jsonschema file is loaded into the node process, so that the file loaded in the process is the latest interface parameter verification file; when an interface debugging request initiated by the client is received, the jsonschema file is called from the node process, and based on the jsonschema file, the interface parameters corresponding to the interface debugging request are verified through the parameter verification plug-in, wherein the interface parameters include input parameters and output parameters; When the verification of the input parameter fails, feedback of verification failure is sent to the client, and the verification is terminated; When the verification of the input parameter passes, and the verification of the output parameter fails, feedback of verification failure is sent to the client; During the interface document generation stage, when the input parameter verification passes and the output parameter verification passes, the YAML file is synchronized to the interface management platform, and the interface management platform imports the YAML file in the specific format, obtains the interface parameters from the YAML file to generate the interface document, or, when it is detected that there is an initial interface document corresponding to the business code, updates the initial interface document according to the YAML.
2. The method according to claim 1, characterized in that The performing parameter standardization processing on the interface parameters to generate an interface parameter file comprises: Get the parameter format specification corresponding to the interface parameter file; According to the parameter format specification, the interface parameters are subjected to parameter standardization processing to generate an interface parameter file.
3. The method according to claim 1, characterized in that The verifying the interface parameters corresponding to the interface debugging request through the parameter verification plug-in based on the jsonschema file includes: Extracting input parameters in the interface debugging request through a parameter verification plug-in; Verify the input parameters according to the input parameter definition specification in the jsonschema file; When the input parameter verification passes, the output parameter corresponding to the input parameter is obtained according to the business logic in the business code; Verify the output parameters according to the output parameter definition specification in the jsonschema file; When the verification of the input parameters passes and the verification of the output parameters passes, synchronizing the YAML file to the interface management platform, the interface management platform imports the YAML file in the specific format, and obtaining the interface parameters from the YAML file to generate the interface document includes: When the output parameter verification passes, the YAML file is synchronized to the interface management platform, the interface management platform imports the YAML file in the specific format, and obtains the interface parameters from the YAML file to generate an interface document.
4. The method according to claim 1, characterized in that After verifying the interface parameters corresponding to the interface debugging request through the parameter verification plug-in based on the jsonschema file, the method further includes: When the interface parameter verification fails, interface parameter illegality information is fed back to the client, so that the client updates the service code according to the interface parameter illegality information.
5. The method according to claim 1, characterized in that The method further comprises: Sending an interface information viewing request to the interface management platform; The interface information fed back by the interface management platform is received, and the interface information is pushed to the interface information display interface, wherein the interface information includes basic interface information, request parameter information, and return data information.
6. An interface document generating device, characterized in that: The device comprises: The business code acquisition module is used to obtain the business code with the decorated function from the developer's terminal during the local development stage; An interface parameter extraction module, used to extract the interface parameters defined in the business code according to the data definition rules corresponding to the decoration function; The interface parameter file generation module is used to perform parameter standardization processing on the interface parameters and generate an interface parameter file An interface description file generation module is used to convert the interface parameter file into an interface description file that meets the format requirements of the interface management platform according to a preset file conversion logic, wherein the interface description file is a YAML file having a specific format recognized by the interface management platform; and to generate an interface parameter verification file according to the interface parameter file, wherein the interface parameter verification file includes a jsonschema file; The interface parameter verification module is used to respond to the node process restart operation in the interface debugging stage, interrupt the file loaded in the original node process, and load the jsonschema file into the node process, so that the file loaded in the process is the latest interface parameter verification file; when receiving the interface debugging request initiated by the client, call the jsonschema file from the node process, and verify the interface parameters corresponding to the interface debugging request through the parameter verification plug-in based on the jsonschema file, wherein the interface parameters include input parameters and output parameters; when the verification of the input parameters fails, feedback the verification failure to the client and terminate the verification; when the verification of the input parameters passes and the verification of the output parameters fails, feedback the verification failure to the client; An interface document generation module, used for synchronizing the YAML interface description file to the interface management platform during the interface document generation phase when the verification of the input parameters passes and the verification of the output parameters passes, and the interface management platform imports the YAML file in the specific format, obtains the interface parameters from the YAML file to generate the interface document, or, when it is detected that there is an initial interface document corresponding to the business code, updates the initial interface document according to the YAML; Among them, the local development stage, the interface debugging stage and the interface document generation stage are performed in sequence.
7. The device according to claim 6, characterized in that The interface parameter file generation module is also used to obtain a parameter format specification corresponding to the interface parameter file; perform parameter standardization processing on the interface parameters according to the parameter format specification to generate an interface parameter file.
8. The device according to claim 6, characterized in that The interface parameter verification module is also used to extract the input parameters in the interface debugging request through the parameter verification plug-in when receiving the interface debugging request initiated by the client; verify the input parameters according to the input parameter definition specification in the jsonschema file; when the input parameter verification passes, obtain the output parameters corresponding to the input parameters according to the business logic in the business code; verify the output parameters according to the output parameter definition specification in the jsonschema file; The interface document generation module is also used to synchronize the YAML interface description file to the interface management platform when the output parameter verification passes, and the interface management platform imports the YAML file in the specific format, obtains the interface parameters from the YAML file to generate the interface document.
9. The device according to claim 6, characterized in that The interface document generating device also includes an information feedback module, which is used to feedback interface parameter illegality information to the client when the interface parameter verification fails, so that the client updates the service code according to the interface parameter illegality information.
10. The device according to claim 6, characterized in that The interface document generating device also includes an interface information checking module, which is used to feed back interface parameter illegal information to the client when the interface parameter verification fails, so that the client can update the service code according to the interface parameter illegal information.
11. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
12. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
13. A computer program product comprising computer instructions, characterized in that: When the computer instructions are executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Interface document generation method and device and computer readable storage medium
CN107766040A
Code generation method and device
CN111338637A