API difference comparison method and device based on tree structure, equipment and medium

Through the tree-based API difference comparison method, the problem of the existing technology being unable to deal with the difference comparison between complex API structures and large-scale API documents is solved, and efficient and accurate API difference display and change impact analysis are achieved.

CN119271527APending Publication Date: 2025-01-07SHANGHAI SHUHE INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411334556.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-24
Publication Date
2025-01-07

Smart Images

  • Figure CN119271527A_ABST
    Figure CN119271527A_ABST
Patent Text Reader

Abstract

The invention relates to an API difference comparison method and device based on a tree structure, equipment and a medium. The method comprises the following steps: an API acquisition step: acquiring APIs needing to be compared; a conversion step: converting the API document into a tree structure; a comparison step: comparing the APIs needing to be compared through the tree structure; a recording step: recording difference information of the parameters and a hierarchical path of each parameter at a tree node according to a comparison result; and a tree reconstruction step: reconstructing a tree carrying API difference information according to the hierarchical path. According to the method, difference comparison of parameters and attributes of a complex API structure is supported, the difference of the API is visually displayed on a tree structure, and a clear basis is provided for API change influence analysis.
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 a tree-structure-based API difference comparison method, device, equipment and medium. Background Art

[0002] In the process of software system development and maintenance, due to the continuous evolution and change of API, how to effectively compare and analyze the differences between APIs has become an important issue. At present, the demand for API difference comparison is mainly reflected in: 1. Version control: With the upgrade of software version, different versions of API may change, and a method is needed to compare the differences between different versions of API. 2. Compatibility detection: When integrating multiple systems, it is necessary to ensure that the new version of API is compatible with the old version of API. Difference comparison helps to find incompatibilities. 3. Change impact analysis: When the API changes, it is necessary to analyze the possible impact of these changes, such as whether it affects the front-end page, API use case, and upstream system call. For API difference comparison, the commonly used methods currently include: 1. Text comparison: Use text comparison tools (such as diff) to compare API documents line by line. This method is simple and direct, but it is only suitable for small-scale and simple API documents. When the content of the API document is large and the structure is complex, the text comparison method seems to be unable to cope with it and it is difficult to intuitively reflect the changes in the API structure. 2. Tool comparison: Use specialized API comparison tools (such as Swagger Diff, OpenAPIDiff) to compare API definition files (such as Swagger, OpenAPI). This method can automatically compare API differences and is highly efficient, but is limited by the tool's functionality and the format of the API description file.

[0003] It can be seen that the existing solutions have certain functional limitations and cannot handle complex API structures. In addition, for large-scale API documents, the comparison process is cumbersome and time-consuming and cannot meet usage requirements.

[0004] To address the above problems, no effective solution has been proposed yet. Summary of the invention

[0005] Based on this, it is necessary to provide a method, device, equipment and medium for API difference comparison based on tree structure for the above technical problems. The present invention supports the difference comparison of parameters and attributes of complex API structures, intuitively displays the differences of APIs in the tree structure, and provides a clear basis for API change impact analysis.

[0006] According to a first aspect of the present invention, a tree-structure-based API difference comparison method is provided, comprising:

[0007] API acquisition steps: obtain the API that needs to be compared;

[0008] The conversion step converts the API document into a tree structure;

[0009] A comparison step, comparing the APIs to be compared through the tree structure;

[0010] Recording steps: Record the difference information of parameters according to the comparison results, as well as the hierarchical path of each parameter in the tree node;

[0011] In the tree reconstruction step, a tree carrying API difference information is reconstructed according to the hierarchical path.

[0012] In some embodiments, between the API acquisition step and the conversion step, the method further includes:

[0013] The parsing step is to parse the model referenced in the API parameter definition into specific parameters.

[0014] In some embodiments, when the referenced model is a data model of parent-child recursive references, only the first level of reference relationship is parsed.

[0015] In some embodiments, between the converting step and the comparing step, the method further comprises:

[0016] A noise removal step, checking the tree structure and removing attributes irrelevant to the difference comparison;

[0017] In some embodiments, it further includes:

[0018] A difference query step, wherein the API difference is viewed by filtering the tree carrying the API difference information under a filtering condition;

[0019] The filtering conditions include: showing only differences, showing only destructive changes.

[0020] In some embodiments, the tree structure is a JsonNode tree.

[0021] In some embodiments, the node types in the JsonNode tree include: object type, array type, value type;

[0022] Different node types are processed separately.

[0023] According to a second aspect of the present invention, there is provided a tree-structured API difference comparison device, comprising:

[0024] API acquisition module, used to obtain the API that needs to be compared;

[0025] The conversion module is used to convert the API document into a tree structure;

[0026] A comparison module, used for comparing the APIs to be compared through the tree structure;

[0027] The recording module is used to record the difference information of the parameters according to the comparison results, as well as the hierarchical path of each parameter in the tree node;

[0028] The tree reconstruction module is used to rebuild a tree carrying API difference information according to the hierarchical path.

[0029] According to a third aspect of the present invention, there is provided a computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any of the above-mentioned method embodiments when executing the computer program.

[0030] According to a fourth aspect of the present invention, there is provided a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the method of any of the above embodiments are implemented.

[0031] Beneficial effects of the present invention:

[0032] 1. The API version comparison is abstracted into the comparison of two tree structures, and the tree node paths and node data types are compared one by one to ensure the consistency and stability of the algorithm. In addition, the noise data of some parameters or attributes that do not need to be involved in the comparison is removed to improve the processing efficiency.

[0033] 2. Supports data model detection and automatic parsing to ensure the consistency of comparison and entry. Supports detection of recursive references in data models to avoid system stack overflow caused by repeated comparisons due to recursive references.

[0034] 3. Reconstruct a tree that carries API difference information. You can intuitively see the difference between one version and another based on the details of an API. By screening destructive changes, you can intuitively determine whether the API change will affect the upstream caller. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 is a flowchart of some embodiments of the tree-structure-based API difference comparison method of the present invention;

[0036] Figure 2 is a schematic diagram of an interface showing only differences in the present invention;

[0037] Figure 3 is a schematic diagram of an interface showing only destructive changes in the present invention;

[0038] Figure 4 It is a schematic diagram of an interface showing complete details of an API in the present invention;

[0039] Figure 5 It is a schematic diagram of the structure of some embodiments of the tree-structure-based API difference comparison device of the present invention;

[0040] Figure 6 It is a diagram of the internal structure of a computer device used to implement some embodiments of the present invention. DETAILED DESCRIPTION

[0041] Embodiments of the present invention will be described more fully below with reference to the accompanying drawings, in which embodiments of the present invention are shown. However, the present invention can be embodied in many different forms and should not be construed as limited to the embodiments set forth herein.

[0042] The terms used herein are used only for the purpose of describing specific embodiments and are not intended to limit the present disclosure. As used herein, the singular forms "a", "an", "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that when used herein, the term "comprising" specifies the presence of the claimed features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof.

[0043] Unless otherwise defined, the terms (including technical and scientific terms) used herein have the same meanings as commonly understood by those of ordinary skill in the art to which the present disclosure belongs. The terms used herein should be interpreted as having the meanings consistent with their meanings in the context of this specification and in the relevant field, and should not be interpreted in an idealized or overly formal sense, unless specifically defined as such herein.

[0044] Before describing the specific details of the present application, the meanings of the terms used in the present application will be briefly explained.

[0045] Hierarchical path: refers to the complete path from the root node to a specific node in the API tree structure. It reflects the specific location and hierarchical relationship of the node in the entire API document.

[0046] API: The interface of the application, mainly including Request parameters, Response parameters and other information. The Request parameters are subdivided into "Query parameters", "Path parameters", "Header parameters", and "RequestBody parameters". The Response parameter supports returning multiple response bodies. Different response bodies are distinguished by http status codes and are managed by the API platform.

[0047] Data model: encapsulates the request parameters or response parameters of the API, representing a set of parameters. For example, the User model contains a combination of parameters such as userId, userName, and address that represent user information.

[0048] Reference data model: When designing API parameters, you can reference predefined data models to improve design efficiency and achieve reuse.

[0049] Recursive reference: A data model references itself, such as a Node model parameter that references its own List <node>chilren.

[0050] JsonNode: Jackson is a popular Java library for processing JSON data. JsonNode allows developers to operate JSON data in a tree structure, thus achieving flexible and efficient JSON parsing and generation.

[0051] Compatibility changes: Changes to API request / response parameters will not affect the normal use of the upstream requester.

[0052] Destructive changes: Changes to API request / response parameters can cause upstream requests to fail, resulting in accidents or impacts.

[0053] Figure 1 The flowcharts of some embodiments of the tree-structure-based API difference comparison method of the present invention are shown.

[0054] like Figure 1 As shown, the method includes:

[0055] API acquisition step S102, acquiring the API to be compared;

[0056] Query the two API versions involved in the comparison, such as: V1.0 and V2.0.

[0057] In some embodiments, a parsing step is also included to parse and flatten the API model. If there is a reference model in the API parameter, it is parsed as a specific parameter replacement.

[0058] Conversion step S104, converting the API document into a tree structure;

[0059] Convert API document into JsonNode tree object.

[0060] In some embodiments, it also includes a noise removal step, recursively detecting JsonNode, removing attributes that are not of interest, and improving comparison efficiency.

[0061] Comparison step S106, comparing the APIs to be compared using the tree structure;

[0062] Use the first version (V1.0) as a reference to detect the changes made to the second version (V2.0) based on the former.

[0063] Recording step S108, recording the difference information of the parameters and the hierarchical path of each parameter in the tree node according to the comparison result;

[0064] Difference information, including: addition, deletion, modification, etc. If it is a modification, it will be reflected as a change in parameter attributes, such as: data type, default value, minimum value, maximum value, enumeration value, precision / multiple, regularization, uniqueness, etc.

[0065] In the tree reconstruction step S110, a tree carrying API difference information is reconstructed according to the hierarchical path.

[0066] In the process of building the API tree that carries the difference information, the change type of the parent node is calculated by summarizing the change types of the child nodes, and the nodes are labeled according to the rules of [destructive changes].

[0067] In some embodiments, it also includes a difference query step, viewing the API difference by filtering the tree carrying the API difference information with a filtering condition;

[0068] The filtering conditions include: showing only differences, showing only destructive changes.

[0069] Supports filtering API tree nodes by showing only differences, showing only destructive changes, showing unchanged, etc. Figure 2 It is a schematic diagram of the interface that only shows the differences in the present invention. Figure 3 This is a schematic diagram of an interface that only displays destructive changes in the present invention. Figure 4 This is a schematic diagram of the interface showing the complete details of the API in the present invention; changes will be marked with special color labels.

[0070] In some embodiments of the present invention, before comparing API versions, it is necessary to ensure that a unified standard Schema structure is used. When there is a referenced data model, the model needs to be parsed to avoid misjudgment. When there is a parent-child recursive reference data model scenario in the API parameters, only the first layer is parsed, and the second and subsequent layers are not parsed repeatedly, and a corresponding brief description is added to avoid stack overflow.

[0071] In the present invention, the scenarios of destructive changes include: 1. Method and URL are changed; 2. A [required] request parameter is added; 3. The data type of a parameter is modified; 4. A response parameter is deleted.

[0072] Figure 5 It is a schematic diagram of the structure of some embodiments of the tree-structure-based API difference comparison device of the present invention.

[0073] The API acquisition module 100 is used to acquire the API that needs to be compared;

[0074] A conversion module 200, used to convert the API document into a tree structure;

[0075] A comparison module 300, used to compare the APIs to be compared through the tree structure;

[0076] A recording module 400, used to record the difference information of the parameters and the hierarchical path of each parameter in the tree node according to the comparison result;

[0077] The tree reconstruction module 500 is used to reconstruct a tree carrying API difference information according to the hierarchical path.

[0078] For the specific definition of a tree-structure-based API difference comparison device, please refer to the definition of a tree-structure-based API difference comparison method above, which will not be repeated here. Each module in the above-mentioned tree-structure-based API difference comparison device can be implemented in whole or in part through 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.

[0079] The present invention also provides a computer device, which may be a terminal, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected via 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 and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. 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, the above-mentioned tree-structure-based API difference comparison method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse, etc. Those skilled in the art can understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention 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.

[0080] The present invention also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned tree-structure-based API difference comparison method is implemented.

[0081] Those skilled in the art can understand that all or part of the processes in the above method embodiments 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 methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus), direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0082] So far, the embodiments of the present invention have been described in detail. In order to avoid obscuring the concept of the present invention, some details known in the art are not described. Based on the above description, those skilled in the art can fully understand how to implement the technical solutions disclosed herein.

[0083] Although some specific embodiments of the present invention have been described in detail by way of examples, it should be understood by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the present invention. It should be understood by those skilled in the art that the above embodiments may be modified or some technical features may be replaced by equivalents without departing from the scope and spirit of the present invention. The scope of the present invention is defined by the appended claims.< / node>

Claims

1. A tree-structured API difference comparison method, characterized in that: include: API acquisition steps: obtain the API that needs to be compared; The conversion step converts the API document into a tree structure; A comparison step, comparing the APIs to be compared through the tree structure; Recording steps: Record the difference information of parameters according to the comparison results, as well as the hierarchical path of each parameter in the tree node; In the tree reconstruction step, a tree carrying API difference information is reconstructed according to the hierarchical path.

2. The tree-structured API difference comparison method according to claim 1, characterized in that: Between the API acquisition step and the conversion step, it also includes: The parsing step is to parse the model referenced in the API parameter definition into specific parameters.

3. The tree-structure-based API difference comparison method according to claim 2, characterized in that: When the referenced model is a data model that is recursively referenced by a parent and a child, only the first level of reference relationship is parsed.

4. The tree-structure-based API difference comparison method according to claim 1, characterized in that: Between the conversion step and the comparison step, it also includes: The noise removal step examines the tree structure and removes attributes that are not relevant to the difference comparison.

5. The tree-structure-based API difference comparison method according to claim 1, characterized in that: Also includes, A difference query step, wherein the API difference is viewed by filtering the tree carrying the API difference information under a filtering condition; The filtering conditions include: showing only differences, showing only destructive changes.

6. The tree-structure-based API difference comparison method according to claim 1, characterized in that: The tree structure is a JsonNode tree.

7. The API difference comparison method according to claim 6, characterized in that: The node types in the JsonNode tree include: object type, array type, and value type; Different node types are processed separately.

8. A tree-structured API difference comparison device, characterized in that: include: API acquisition module, used to obtain the API that needs to be compared; The conversion module is used to convert the API document into a tree structure; A comparison module, used for comparing the APIs to be compared through the tree structure; The recording module is used to record the difference information of the parameters according to the comparison results, as well as the hierarchical path of each parameter in the tree node; The tree reconstruction module is used to rebuild a tree carrying API difference information according to the hierarchical path.

9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, 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 7 are implemented.