Interface document generation method and device, electronic equipment, medium and program product

By generating the call chain of interface class methods and detecting exceptions, the problem of lack of exception description in interface documents is solved, interface documentation for exception handling is provided, and the success rate of interface calls and test coverage are improved.

CN120704734APending Publication Date: 2025-09-26BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510881071.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-27
Publication Date
2025-09-26

AI Technical Summary

Technical Problem

The existing interface documentation only describes normal response situations and fails to cover abnormal situations, resulting in the interface users being unable to handle abnormal situations.

Method used

By scanning the code files of the target project, the call chain of the interface class method is generated, and the abnormal situations in the interface class method are detected according to the preset abnormality detection rules, and the interface abnormality return document is generated.

Benefits of technology

The generated interface document contains exceptions, making it easier for the caller to handle exceptions, improving the success rate of interface calls, reducing user experience risks, and supporting comprehensive coverage regression testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120704734A_ABST
    Figure CN120704734A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an interface document generation method and device, electronic equipment, a medium and a program product, and relates to the technical field of computers. The method comprises the steps that a code file of a target project is scanned, calling chains corresponding to all interface class methods in the code file are generated, and the calling chains are used for representing the relation between methods called by the interface class methods in the code file; detecting an abnormal condition existing in the code file according to a preset abnormal detection rule and a calling relation indicated by the calling chain; and generating an interface exception return document according to exceptions existing in the interface class method. According to the method, abnormal conditions possibly occurring in the code file of the target project are written into the interface exception return document, so that a calling party can access conveniently, and convenience is provided for automatic case writing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an interface document generation method, device, electronic equipment, medium and program product. Background Art

[0002] Interface documentation is a descriptive document used to describe various interfaces in a software system, allowing callers to perform corresponding actions based on the document's content. During code development, developers manually add annotations and instructions to the interface code, generating the corresponding interface documentation from these annotations. However, currently, annotation-based interface documentation only describes normal interface responses, not exceptions. This prevents interface users from handling these exceptions. For example, an interface takes an ID number as an input parameter and user information as an output parameter. When using this interface to query the user information corresponding to a specific ID number, the interface normally returns the corresponding user information. However, due to an internal server exception or an incorrectly entered ID number, the interface may not return the user information. The interface documentation only describes the interface's return of identity information, not the absence of information. Consequently, when no user information is returned, the interface user is unable to handle the situation. Summary of the Invention

[0003] To solve the above technical problems or at least partially solve the above technical problems, embodiments of the present invention provide an interface document generation method, device, electronic device, medium, and program product.

[0004] In a first aspect, an embodiment of the present invention provides a method for generating an interface document, comprising:

[0005] Scan the code files of the target project and generate a call chain corresponding to each interface class method in the code file, wherein the call chain is used to represent the relationship between the methods called by the interface class method in the code file;

[0006] Detecting abnormalities in the interface class methods in the code file according to preset abnormality detection rules and the call relationship indicated by the call chain;

[0007] Generate an interface exception return document based on the exception situation existing in the interface class method.

[0008] In an optional embodiment, the preset exception detection rule includes a null pointer exception detection rule;

[0009] The detecting anomalies existing in the interface class method in the code file according to the preset anomaly detection rules and the call relationship indicated by the call chain includes:

[0010] The methods in the call chain are traversed according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, whether there is a null pointer situation in the method is detected according to the null pointer exception detection rule.

[0011] In an optional embodiment, the preset anomaly detection rule includes a network anomaly detection rule;

[0012] The detecting anomalies existing in the interface class method in the code file according to the preset anomaly detection rules and the call relationship indicated by the call chain includes:

[0013] The methods in the call chain are traversed according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, whether there is a network anomaly in the method is detected according to the network anomaly detection rule.

[0014] In an optional embodiment, the preset anomaly detection rule includes an array out-of-bounds anomaly detection rule;

[0015] The detecting anomalies existing in the interface class method in the code file according to the preset anomaly detection rules and the call relationship indicated by the call chain includes:

[0016] The methods in the call chain are traversed according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, whether there is an array out-of-bounds situation in the method is detected according to the array out-of-bounds exception detection rule.

[0017] In an optional embodiment, the preset exception detection rule includes a keyword for identifying an interface class method that actively throws an exception;

[0018] The detecting abnormalities existing in the interface class methods in the code file according to the preset abnormality detection rules and the calling relationship indicated by the call chain of each interface class method includes:

[0019] Traversing the methods in the call chain according to the call relationship indicated by the call chain, and detecting whether the keyword exists in the method according to the keyword indicated by the preset exception detection rule when traversing the methods in the call chain;

[0020] When the keyword exists in the method, determining whether the interface class method has an exception that is actively thrown;

[0021] In an optional embodiment, generating an interface exception return document according to an exception situation existing in the interface class method includes:

[0022] When it is determined that the interface class method has an exception situation that is actively thrown, an interface exception return document is generated according to the error code and prompt information corresponding to the exception situation actively thrown by the interface class method.

[0023] In an optional embodiment, scanning the code file of the target project to generate a call chain corresponding to each interface class method in the code file includes:

[0024] From the code files of the target project, search for the controller class code file in the startup class directory of the target project;

[0025] Searching for the interface class method in the controller class code file, and determining the method of calling the interface class method according to the code corresponding to the interface class method;

[0026] According to the method and calling sequence of the interface class method, a call chain corresponding to the interface class method is generated.

[0027] In an optional embodiment, the method further includes: generating an interface description document based on the annotations of each interface class method in the code file of the target project; merging the interface exception return document and the interface description document to generate an interface document corresponding to the target project.

[0028] In a second aspect, an embodiment of the present invention provides an interface document generation device, comprising:

[0029] A scanning module is used to scan the code files of the target project and generate a call chain corresponding to each interface class method in the code file, wherein the call chain is used to represent the relationship between the methods called by the interface class method in the code file;

[0030] A detection module, configured to detect abnormal situations existing in the interface class method in the code file according to preset abnormality detection rules and the call relationship indicated by the call chain;

[0031] The generation module is used to generate an interface exception return document according to the abnormal situation existing in the interface class method.

[0032] In an optional embodiment, the preset exception detection rule includes a null pointer exception detection rule;

[0033] The detection module is also used to: traverse the methods in the call chain according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, detect whether there is a null pointer situation in the method according to the null pointer exception detection rule.

[0034] In an optional embodiment, the preset anomaly detection rule includes a network anomaly detection rule;

[0035] The detection module is further used to: traverse the methods in the call chain according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, detect whether there is a network anomaly in the method according to the network anomaly detection rule.

[0036] In an optional embodiment, the preset anomaly detection rule includes an array out-of-bounds anomaly detection rule;

[0037] The detection module is also used to: traverse the methods in the call chain according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, detect whether there is an array out-of-bounds situation in the method according to the array out-of-bounds exception detection rule.

[0038] In an optional embodiment, the preset exception detection rule includes a keyword for identifying an interface class method that actively throws an exception;

[0039] The detection module is used to: traverse the methods in the call chain according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, detect whether the keyword exists in the method according to the keyword indicated by the preset exception detection rule; if the keyword exists in the method, determine whether the interface class method has an exception that is actively thrown.

[0040] In an optional embodiment, the generation module is further used to generate an interface exception return document based on the error code and prompt information corresponding to the exception actively thrown by the interface class method when it is determined that the interface class method has an exception actively thrown.

[0041] In an optional embodiment, the scanning module is used to: search for the controller class code file under the startup class directory of the target project from the code file of the target project; search for the interface class method in the controller class code file, and determine the method called by the interface class method based on the code corresponding to the interface class method; and generate a call chain corresponding to the interface class method based on the method called by the interface class method and the calling order.

[0042] In an optional embodiment, the generation module is also used to: generate an interface description document based on the annotations of each interface class method in the code file of the target project; merge the interface exception return document and the interface description document to generate an interface document corresponding to the target project.

[0043] In a third aspect, an embodiment of the present invention provides an electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; the memory is used to store computer programs; and the processor is used to implement the interface document generation method of any embodiment of the present invention when executing the program stored in the memory.

[0044] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the interface document generation method of any embodiment of the present invention.

[0045] In a fifth aspect, an embodiment of the present invention provides a computer program product, which, when running on a computer, enables the computer to execute the interface document generation method of any embodiment of the present invention.

[0046] The technical solution provided by the present disclosure brings at least the following beneficial effects:

[0047] The interface document generation method provided by the embodiment of the present invention scans the code file of the target project and generates a call chain corresponding to each interface class method in the code file. The call chain is used to characterize the relationship between the methods called by the interface class method in the code file; according to the preset exception detection rules and the call relationship indicated by the call chain, the abnormal situation existing in the interface class method in the code file is detected; according to the abnormal situation existing in the interface class method, an interface abnormal return document is generated. The method writes the abnormal situation that may appear in the code file of the target project into the interface abnormal return document, which is convenient for the caller to access and provides convenience for the writing of automated cases. In addition, the method provided by the embodiment of the present invention can be applied when the project code is completed to generate the corresponding interface document. The tester uses the interface document to build a test case for the project in order to perform a comprehensive coverage regression test on the interface; the method can also be applied again when the project is updated or modified (for example, when exception handling such as the retry timeout time of certain interfaces is added, and the original interface return is not modified) to update the interface document, so that the tester can use the updated interface document to understand the update of the project code, thereby building a more complete test case for comprehensive coverage regression testing of the interface. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for describing the embodiments or the prior art.

[0049] Figure 1 A schematic diagram showing a flow chart of a method for generating an interface document according to an embodiment of the present invention;

[0050] Figure 2A schematic diagram showing a call chain generated by the interface document generation method according to an embodiment of the present invention;

[0051] Figure 3 A schematic diagram showing a flow chart of a method for generating an interface document according to another embodiment of the present invention;

[0052] Figure 4 A schematic diagram showing the structure of an interface document generating device provided by an embodiment of the present invention is shown;

[0053] Figure 5 A schematic structural diagram of an electronic device according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0054] The following description of exemplary embodiments of the present invention is made in conjunction with the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding. These details should be considered as merely exemplary. Therefore, it should be appreciated by those skilled in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0055] The terms "first," "second," and the like in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of this application can be implemented in an order other than that illustrated or described herein, and that the objects distinguished by "first," "second," and the like are generally of the same type, and do not limit the number of objects; for example, the first object can be one or more. In addition, the term "and / or" in the specification and claims refers to at least one of the connected objects, and the character " / " generally indicates that the objects connected are in an "or" relationship.

[0056] Figure 1 FIG. 1 is a flow chart showing a method for generating an interface document according to an embodiment of the present invention. Figure 1 As shown, the interface document generation method includes:

[0057] Step S101: Scan the code file of the target project and generate a call chain corresponding to each interface class method in the code file, wherein the call chain is used to represent the relationship between methods called by the interface class method in the code file.

[0058] An interface can be an interface between different software systems or between different modules within the same system. At the code level, an interface is implemented through a method or function. An interface method is a method that implements the corresponding functionality of the interface, and this method may call one or more other methods. The target project is the project for which interface documentation needs to be generated.

[0059] Scan the target project's code files and identify the interface class methods in the code files based on the annotations in the code files. Scan the code corresponding to the interface class methods to identify the method names included in the code corresponding to the interface class methods. The methods corresponding to the method names are the methods called by the interface class methods. Based on the order in which the method names appear in the code corresponding to the interface class methods and the calling relationships between the methods, a call chain corresponding to the interface class methods is generated. This call chain is used to indicate the methods called by the interface class methods and the order in which they are called. For example, scan the code corresponding to interface class method 1 and determine that the code corresponding to interface class method 1 includes method A, method A's code includes method B, method C1, and method D, and method B's code includes the method name of method C2. Then, it is determined that the methods called by interface class method 1 include method A, method B, method C1, method C2, and method D. Interface class method 1 calls method A, which in turn calls method B (which in turn calls method C2), method C1, and method D. The call chain corresponding to interface class method 1 is: interface class method 1 -> method A -> method B -> method C2 -> method C1 -> method D. Annotations are a way to add metadata to code, providing a mechanism for adding supplementary information to source code. They can be used to describe the characteristics and behaviors of program elements such as classes, methods, and fields. Annotations are defined using a special syntax, typically starting with the "@" symbol and followed by the annotation name.

[0060] As an optional example, Figure 2 The diagram shows the call chain corresponding to the interface class method. Figure 2As shown, the call chain corresponding to the interface method GET-m1 (denoted as call chain 1) is: GET-m1->serviceA-ma1->serviceA-ma2->serviceB-mb1. The call chain corresponding to the interface method GET-m2 (denoted as call chain 2) is: GET-m2->serviceA-ma1->serviceC-mc1->serviceD-md1. The interface method GET-m1 calls the methods serviceA-ma1, serviceA-ma2, and serviceB-mb1 in the order indicated by call chain 1. The interface method GET-m2 calls the methods serviceA-ma1, serviceC-mc1, and serviceD-md1 in the order indicated by call chain 2.

[0061] Step S102: detecting abnormal situations existing in the interface class methods in the code file according to preset abnormality detection rules and the calling relationship indicated by the calling chain.

[0062] Preset exception detection rules are used to detect possible exceptions that may occur in interface methods. These exceptions include those thrown by interface methods themselves, as well as those that may arise due to special circumstances, such as null pointer exceptions caused by using a method that has not been instantiated before, or array out-of-bounds exceptions. Exceptions thrown by interface methods are those manually thrown by program developers in the corresponding code of interface methods based on business logic or specific conditions. Developers can customize these exceptions based on business needs, so that they can throw exceptions that are meaningful to the business in specific situations.

[0063] In this step, the methods in the code file are traversed according to the call relationship indicated by the call chain. When traversing the methods in the call chain, the exception detection rules are used to check the code of the method, such as the input parameters and output parameters of the method, to detect any exceptions in the code corresponding to the method. Exceptions in the code corresponding to the method called by the interface class method are considered exceptions of the interface class method.

[0064] Step S103: Generate an interface exception return document based on the exception situation in the interface class method, wherein the interface exception return document includes the exception situation that may occur in the interface class method.

[0065] The interface document generation method provided by the embodiment of the present invention scans the code file of the target project and generates a call chain corresponding to each interface class method in the code file. The call chain is used to indicate the relationship between the methods called by the interface class method in the code file; according to the preset exception detection rules and the call relationship indicated by the call chain, it is determined whether the interface class method in the code file will have an exception; if it is determined that the interface class method in the code file will have an exception, an interface exception return document is generated. The method writes the exceptions that may occur in the code file of the target project into the interface exception return document, which is convenient for the caller to access and provides convenience for the writing of automated cases. In addition, the method provided by the embodiment of the present invention can be applied when the project code is completed to generate the corresponding interface document. The tester uses the interface document to build a test case for the project to perform comprehensive coverage regression testing on the interface; the method can also be applied again when the project is updated or modified (for example, when exception handling such as the retry timeout of certain interfaces is added, and the original interface return is not modified) to update the interface document, so that the tester can use the updated interface document to understand the update of the project code, thereby building a more complete test case for comprehensive coverage regression testing of the interface.

[0066] In an optional embodiment, the preset exception detection rules include one or more possible exception types of null pointer exception, network exception and array out of bounds exception. Null pointer exception refers to an exception caused by attempting to access or operate an uninitialized object. Array Index Out Of Bounds Exception means that when accessing an array, the index value used exceeds the actual range of the array, causing the program to be abnormal. Array out of bounds exception usually occurs when trying to access an element that does not exist in the array. Network exception refers to an exception that occurs when accessing the network.

[0067] In some optional embodiments, step S102 of detecting anomalies in the interface class method according to a preset anomaly detection rule includes:

[0068] The methods in the call chain are traversed based on the call relationship indicated by the call chain. When traversing the methods in the call chain, the null pointer exception detection rules are used to detect whether there are null pointer situations in the methods. For example, the null pointer exception detection rules are used to detect whether there is a possibility of accessing or operating an uninitialized object in the method. If there is a possibility of accessing or operating an uninitialized object in the method, it is determined that a null pointer exception exists in the interface class method that calls the method.

[0069] In some other optional embodiments, step S102 of detecting anomalies in the interface class method according to a preset anomaly detection rule includes:

[0070] The methods in the call chain are traversed based on the call relationships indicated by the call chain. While traversing the methods in the call chain, network anomaly detection rules are used to detect whether any network anomalies exist within the methods. For example, the network anomaly detection rules are used to detect whether the method accesses the network and further detect whether a network access anomaly is likely to occur. If a network access anomaly is likely to occur within the method, a network anomaly is determined to exist within the interface class method that calls the method.

[0071] In some other optional embodiments, step S102 of detecting anomalies in the interface class method according to a preset anomaly detection rule includes:

[0072] Traverse the methods in the call chain according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, detect whether there is an array out-of-bounds situation in the method according to the array out-of-bounds exception detection rules. For example, detect whether an array is used in the method according to the array out-of-bounds exception detection rules, and further detect whether an array out-of-bounds situation may occur (for example, determine whether an array out-of-bounds situation may occur based on the input parameters, output parameters and functions of the method). If an array out-of-bounds situation may occur in the method, determine that an array out-of-bounds exception exists in the interface class method that calls the method.

[0073] In some other optional embodiments, the preset exception detection rules include keywords for identifying interface class methods that actively throw exceptions. Step S102 detects exceptions in the interface class method according to the preset exception detection rules, including:

[0074] According to the keyword indicated by the preset exception detection rule, traverse the methods in the call chain according to the call relationship indicated by the call chain, and determine whether the keyword exists in the code corresponding to the interface class method in the code file; when the keyword exists in the code corresponding to the interface class method, determine whether the interface class method has an exception that is actively thrown.

[0075] As an optional example, the keyword indicated by the exception detection rule is "throws." An interface method throwing an exception means that the method contains the "throws" keyword, for example, public String add(DisplaySpaceVo request) throwsBizException. Finding methods that throw exceptions involves checking whether the "throws" keyword is present in the method declaration. If the "throws" keyword is present in the method declaration, the interface method actively throws an exception.

[0076] When it is determined that an exception is actively thrown by an interface class method, an interface exception return document is generated according to the error code and prompt information corresponding to the active exception thrown by the interface class method, for example, the error code and prompt information corresponding to the active exception thrown are written into the interface exception return document. Among them, the exception actively thrown by the interface class method refers to the exception manually thrown by the program developer in the code corresponding to the interface class method according to business logic or specific conditions. The developer can customize the exception actively thrown according to business needs, so as to throw exceptions with business significance under specific circumstances. In the code file corresponding to the interface class method, there are error codes and prompt information corresponding to the exception actively thrown by the interface class method, wherein the error code is a group of numbers or a combination of letters and numbers, and the prompt information is used to indicate the relevant information indicated by the error code, which is used to explain the error code. In the embodiment of the present application, the error code and prompt information corresponding to the actively thrown exception are written into the interface exception return document, and the actively thrown exception, error code and prompt information are associated to facilitate the identification of specific problems in the code.

[0077] Figure 3 A schematic flow chart of an interface document generation method provided by another embodiment of the present invention is shown.

[0078] like Figure 3 As shown, the method includes:

[0079] Step S301: Search for the controller class code file in the startup class directory of the target project.

[0080] The default startup class directory for a code file is determined based on the code file's development framework. The @RestController and @Controller annotations identify a file as a controller class, which handles HTTP (Hypertext Transfer Protocol) requests and returns corresponding HTTP responses. Therefore, code files containing the @RestController and @Controller annotations are searched for in the target project's startup class directory. Code files containing these annotations are controller class code files.

[0081] Step S302: Searching for the interface class method in the controller class code file, and determining the method to be called by the interface class method according to the code corresponding to the interface class method.

[0082] In this embodiment, the interface class method in the controller class code file is a method annotated with @RequestMapping, @GetMapping, or @PostMapping. Among them, @RequestMapping is an annotation in SpringMVC used to map web requests (such as URL paths) to specific methods. It can be annotated on classes or methods. When annotated on a class, it means that all methods in the class that respond to requests have the class path as the parent path. @PostMapping is a composite annotation, which is an abbreviation of @RequestMapping(method=RequestMethod.POST). It is used to process HTTP POST requests and can only be annotated on methods. Methods annotated with @PostMapping will only respond to POST requests. @GetMapping is also a composite annotation, which is an abbreviation of @RequestMapping(method=RequestMethod.GET). It is used to process HTTP GET requests and can only be annotated on methods. Methods annotated with @GetMapping will only respond to GET requests.

[0083] Step S303: Generate a call chain corresponding to the interface class method according to the method and calling sequence of the interface class method.

[0084] Identify the method contained in the code corresponding to the interface class method. The method contained in the code corresponding to the interface class method is the method called by the interface class method, and then generate a call chain corresponding to the interface class method.

[0085] Step S304: according to the multiple possible exception types indicated by the preset exception detection rules and the call relationship indicated by the call chain, traverse the methods in the call chain to detect the exceptions existing in the interface class methods in the code file.

[0086] Step S305: According to the keywords indicated by the preset exception detection rules and the call relationship indicated by the call chain, the methods in the call chain are traversed to detect exceptions in the interface class methods in the code file.

[0087] A method throws an exception if it contains the throws keyword, for example, public String add(DisplaySpaceVo request) throws BizException. To find a method that throws an exception, check whether the method declaration contains the throws keyword.

[0088] Actively thrown exceptions are those that contain the throws keyword in the method declaration. Interface class methods may cause exceptions, including null pointer exceptions, network-related exceptions, and array out-of-bounds exceptions caused by instantiating objects in the method's inner class or when accessing the network.

[0089] Generally, exceptions thrown proactively are business exceptions, requiring the caller to handle them accordingly based on business needs. Most of the possible exceptions can be resolved by retrying.

[0090] Step S306: Generate an interface exception return document based on the possible exception types that may occur in the interface class method and the error code and prompt information corresponding to the exception situation actively thrown.

[0091] The exception type thrown refers to the code that actively throws an exception. The type of this exception is determined when the code is written. It will contain the business code, and there is a special file record for the corresponding business code. The error code thrown is clearly defined in the code, and the corresponding error description can be found according to the error code. As an optional example, the error code is as follows:

[0092] SUCCESS("A00000","success","success"),

[0093] REPEAT_REQUEST("A00001","Repeat Request","Benefits are very popular, please try again later~"),

[0094] NO_DATA("A00002","No data","Benefits are very popular, please try again later~").

[0095] Step S307: Generate an interface description document based on the annotations of each interface class method in the code file of the target project. The interface description document may include, but is not limited to, a detailed description of the interface address, interface input parameter field name and explanation, interface output parameter field name and explanation, calling method, etc.

[0096] Step S308: Merge the interface exception return document and the interface description document to generate an interface document corresponding to the target project.

[0097] Step S309: Convert the interface document into a specified format and output it.

[0098] The interface document generation method provided by the embodiment of the present invention analyzes the call chain corresponding to the interface class method through code scanning, and records all possible exceptions of the interface class method. Compared with the interface document generated by the prior art, which only includes input and output parameters, it has more descriptions of exceptions, which makes it convenient for the interface party to understand the return result of the interface more accurately, improves access efficiency, and reduces the risk of reduced user experience due to unhandled interface exceptions. In addition, it provides convenience for the writing of automated test cases. After the project code is updated or modified, for example, certain exception handling may be added to the code, such as adding exception handling such as the retry timeout time of certain interfaces, and the original interface return is not modified. The interface document can be updated by rescanning the project code using the method of the embodiment of the present invention, which makes it convenient for testers to use the updated interface document to understand the update of the project code, thereby building a more complete test case for comprehensive coverage regression testing of the interface.

[0099] Figure 4 FIG. 1 shows a schematic diagram of the structure of the interface document generating device provided by an embodiment of the present invention. Figure 4 As shown, the interface document generating device 400 includes:

[0100] Scanning module 401 is used to scan the code files of the target project and generate a call chain corresponding to each interface class method in the code file, wherein the call chain is used to represent the relationship between the methods called by the interface class method in the code file;

[0101] Detection module 402, configured to detect abnormalities in the interface class methods in the code file according to preset abnormality detection rules and the call relationship indicated by the call chain;

[0102] The generation module 403 is used to generate an interface exception return document according to the abnormal situation existing in the interface class method.

[0103] In an optional embodiment, the preset exception detection rule includes a null pointer exception detection rule;

[0104] The detection module is also used to: traverse the methods in the call chain according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, detect whether there is a null pointer situation in the method according to the null pointer exception detection rule.

[0105] In an optional embodiment, the preset anomaly detection rule includes a network anomaly detection rule;

[0106] The detection module is further used to: traverse the methods in the call chain according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, detect whether there is a network anomaly in the method according to the network anomaly detection rule.

[0107] In an optional embodiment, the preset anomaly detection rule includes an array out-of-bounds anomaly detection rule;

[0108] The detection module is also used to: traverse the methods in the call chain according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, detect whether there is an array out-of-bounds situation in the method according to the array out-of-bounds exception detection rule.

[0109] In an optional embodiment, the preset exception detection rule includes a keyword for identifying an interface class method that actively throws an exception;

[0110] The detection module is used to: traverse the methods in the call chain according to the call relationship indicated by the call chain, and determine whether the keyword exists in the code corresponding to the method when traversing the methods in the call chain; when the keyword exists in the code corresponding to the method, determine whether the interface class method has an exception that is actively thrown.

[0111] In an optional embodiment, the generation module is further used to generate an interface exception return document based on the error code and prompt information corresponding to the exception actively thrown by the interface class method when it is determined that the interface class method has an exception actively thrown.

[0112] In an optional embodiment, the scanning module is used to: search for the controller class code file under the startup class directory of the target project from the code file of the target project; search for the interface class method in the controller class code file, and determine the method called by the interface class method based on the code corresponding to the interface class method; and generate a call chain corresponding to the interface class method based on the method called by the interface class method and the calling order.

[0113] In an optional embodiment, the generation module is also used to: generate an interface description document based on the annotations of each interface class method in the code file of the target project; merge the interface exception return document and the interface description document to generate an interface document corresponding to the target project.

[0114] The above device can execute the method provided by the embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not fully described in this embodiment, please refer to the interface document generation method provided by the embodiment of the present invention.

[0115] Figure 5 FIG. 1 shows a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Figure 5 As shown, the electronic device includes:

[0116] Processor 501, communication interface 502, memory 503 and communication bus 504, wherein the processor 501, communication interface 502, memory 503 communicate with each other via the communication bus 504.

[0117] Memory 503, used for storing computer programs;

[0118] The processor 501 is configured to execute the program stored in the memory 503, and implement the following steps:

[0119] Scan the code files of the target project and generate a call chain corresponding to each interface class method in the code file, wherein the call chain is used to indicate the relationship between methods called by the interface class method in the code file;

[0120] Determine whether an exception occurs in the interface class method in the code file according to a preset exception detection rule and the call relationship indicated by the call chain;

[0121] When it is determined that an exception occurs in the interface class method in the code file, an interface exception return document is generated.

[0122] The communication bus mentioned in the terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not mean that there is only one bus or only one type of bus.

[0123] The communication interface is used for communication between the above terminal and other devices.

[0124] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.

[0125] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.

[0126] In another embodiment provided by the present invention, a computer-readable storage medium is also provided, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes the interface document generation method described in any one of the above embodiments.

[0127] In another embodiment provided by the present invention, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the interface document generation method described in any one of the above embodiments.

[0128] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).

[0129] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0130] Each embodiment in this specification is described in a related manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiment is generally similar to the method embodiment, so the description is relatively simple. For related parts, refer to the description of the method embodiment.

[0131] The above description is only a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention are included in the scope of protection of the present invention.

Claims

1. A method for generating an interface document, characterized in that: include: Scan the code files of the target project and generate a call chain corresponding to each interface class method in the code file, wherein the call chain is used to represent the relationship between other methods called by the interface class method in the code file; Detecting abnormalities in the interface class methods in the code file according to preset abnormality detection rules and the call relationship indicated by the call chain; Generate an interface exception return document based on the exception situation existing in the interface class method.

2. The method according to claim 1, characterized in that The preset exception detection rules include null pointer exception detection rules; The detecting anomalies existing in the interface class method in the code file according to the preset anomaly detection rules and the call relationship indicated by the call chain includes: The methods in the call chain are traversed according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, whether there is a null pointer situation in the method is detected according to the null pointer exception detection rule.

3. The method according to claim 1, characterized in that The preset anomaly detection rules include network anomaly detection rules; The detecting anomalies existing in the interface class method in the code file according to the preset anomaly detection rules and the call relationship indicated by the call chain includes: The methods in the call chain are traversed according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, whether there is a network anomaly in the method is detected according to the network anomaly detection rule.

4. The method according to claim 1, wherein The preset anomaly detection rules include array out-of-bounds anomaly detection rules; The detecting anomalies existing in the interface class method in the code file according to the preset anomaly detection rules and the call relationship indicated by the call chain includes: The methods in the call chain are traversed according to the call relationship indicated by the call chain, and when traversing the methods in the call chain, whether there is an array out-of-bounds situation in the method is detected according to the array out-of-bounds exception detection rule.

5. The method according to any one of claims 1 to 4, characterized in that The preset exception detection rules include keywords for identifying interface class methods that actively throw exceptions; The detecting abnormalities existing in the interface class methods in the code file according to the preset abnormality detection rules and the calling relationship indicated by the call chain of each interface class method includes: Traversing the methods in the call chain according to the call relationship indicated by the call chain, and detecting whether the keyword exists in the method according to the keyword indicated by the preset exception detection rule when traversing the methods in the call chain; When the keyword exists in the method, it is determined that the interface class method has an exception that is actively thrown.

6. The method according to claim 5, characterized in that The generating of an interface exception return document according to an exception situation existing in the interface class method includes: When it is determined that the interface class method has an exception situation that is actively thrown, an interface exception return document is generated according to the error code and prompt information corresponding to the exception situation actively thrown by the interface class method.

7. The method according to claim 1, characterized in that Scanning the code files of the target project and generating a call chain corresponding to each interface class method in the code files includes: From the code files of the target project, search for the controller class code file in the startup class directory of the target project; Searching for the interface class method in the controller class code file, and determining the method of calling the interface class method according to the code corresponding to the interface class method; According to the method and calling sequence of the interface class method, a call chain corresponding to the interface class method is generated.

8. The method according to claim 1, characterized in that The method further comprises: Generate an interface description document based on the annotations of each interface class method in the code file of the target project; The interface exception return document and the interface description document are merged to generate an interface document corresponding to the target project.

9. An interface document generating device, characterized in that: include: A scanning module is used to scan the code files of the target project and generate a call chain corresponding to each interface class method in the code file, wherein the call chain is used to represent the relationship between the methods called by the interface class method in the code file; A detection module, configured to detect abnormal situations existing in the interface class method in the code file according to preset abnormality detection rules and the call relationship indicated by the call chain; The generation module is used to generate an interface exception return document according to the abnormal situation existing in the interface class method.

10. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory for storing computer programs; A processor, configured to implement the method according to any one of claims 1 to 8 when executing a program stored in a memory.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.

12. A computer program product, when running on a computer, causes the computer to execute the method according to any one of claims 1 to 8.