Interface document synchronization method, device, electronic device and storage medium
The interface document synchronization method addresses inefficiencies in software development by synchronizing interface documents to a management platform, enabling efficient retrieval and management, thus enhancing project development efficiency.
Patent Information
- Application Number
- CN202111537760.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-15
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2041-12-15
AI Technical Summary
Developers face inefficiencies in software project development due to the need to consult various interface codes with different coding styles and large amounts of code content, which hinders effective management and understanding of interface functions.
An interface document synchronization method that involves receiving synchronization parameters, determining an interface identifier, reading interface documents based on annotation information, and synchronizing these documents to an interface management platform for user access, allowing standardized management and efficient retrieval of interface information.
This method enables developers to efficiently obtain and manage interface documents without consulting extensive code, improving software project development efficiency by facilitating standardized interface document management.
Smart Images

Figure CN114201213B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to an interface document synchronization method, device, electronic device and storage medium. Background Art
[0002] With the development of computer technology, the complexity of system development is increasing, and a project requires multiple developers to work together.
[0003] In the related art, developers usually need to understand the functions of various interfaces by consulting the interface codes of various interfaces for subsequent development. However, due to the different coding styles of various interface codes and the large amount of code content, developers usually need to spend a lot of time consulting the interface codes of various interfaces, which is not conducive to improving the development efficiency of software projects. Summary of the invention
[0004] The present disclosure provides an interface document synchronization method, device, electronic device and storage medium to at least solve the problem of improving the efficiency of software project development in the related art. The technical solution of the present disclosure is as follows:
[0005] According to a first aspect of an embodiment of the present disclosure, there is provided an interface document synchronization method, comprising:
[0006] Receiving interface synchronization parameters passed in when the interface document synchronization interface is accessed, and determining the interface identifier in the interface synchronization parameters;
[0007] Determine, according to the preloaded document synchronization configuration information, a document scanning directory for the interface type corresponding to the interface identifier;
[0008] Reading the interface document of the interface corresponding to the interface identifier in the document scanning directory; wherein the interface document is generated according to the interface annotation information of the interface; the interface annotation information is determined by reading the interface code of the interface;
[0009] The interface document is synchronized to an interface management platform; the interface management platform is used to present the interface document to the user account.
[0010] In one possible implementation, synchronizing the interface document to the interface management platform includes: obtaining a target synchronization directory for the interface document; the target synchronization directory is a file directory in the interface management platform for storing the interface document; generating a document synchronization instruction based on the target synchronization directory and the interface document; sending the document synchronization instruction to an interface document import interface of the interface management platform; the interface document import interface is used to respond to the document synchronization instruction and import the interface document into the target synchronization directory.
[0011] In one possible implementation, obtaining the target synchronization directory for the interface document includes: reading the interface code of the interface to determine the synchronization directory annotation information of the interface; parsing the synchronization directory annotation information to determine the child synchronization directory for the interface document, and parsing the document synchronization configuration information to determine the parent synchronization directory for the interface document; and constructing the target synchronization directory based on the parent synchronization directory and the child synchronization directory.
[0012] In one possible implementation, after the step of sending the document synchronization instruction to the interface document import interface of the interface management platform, the method further includes: receiving the document import result returned by the interface document import interface; parsing the document import result to determine the quantity information of the interface documents that have been imported into the interface management platform.
[0013] In one possible implementation, the method also includes: loading the document synchronization configuration information, initializing a preset interface document generation program, and obtaining an initialized interface document generation program; wherein the initialized interface document generation program is used to read the interface code of the interface, determine the interface annotation information of the interface, and generate an interface description file with a preset format based on the interface annotation information; and is also used to save the interface description file as the interface document corresponding to the interface in the document scanning directory.
[0014] In one possible implementation, the step of loading the document synchronization configuration information, initializing the preset interface document generation program, and obtaining the initialized interface document generation program includes: obtaining the current business environment; if the current business environment satisfies the preset business environment, executing the step of loading the document synchronization configuration information, initializing the preset interface document generation program, and obtaining the initialized interface document generation program; wherein the preset business environment includes at least one of a business testing environment and a business development environment.
[0015] According to a second aspect of an embodiment of the present disclosure, there is provided an interface document synchronization device, including:
[0016] A receiving unit configured to receive interface synchronization parameters passed in when an interface document synchronization interface is accessed, and determine an interface identifier in the interface synchronization parameters;
[0017] A determination unit configured to determine a document scanning directory for an interface type corresponding to the interface identifier according to preloaded document synchronization configuration information;
[0018] A reading unit, configured to read an interface document of an interface corresponding to the interface identifier in the document scanning directory; wherein the interface document is generated according to interface annotation information of the interface; and the interface annotation information is determined by reading an interface code of the interface;
[0019] The synchronization unit is configured to execute synchronization of the interface document to an interface management platform; the interface management platform is used to present the interface document to a user account.
[0020] In one possible implementation, the synchronization unit is specifically configured to execute acquisition of a target synchronization directory for the interface document; the target synchronization directory is a file directory in the interface management platform for storing the interface document; a document synchronization instruction is generated based on the target synchronization directory and the interface document; the document synchronization instruction is sent to an interface document import interface of the interface management platform; the interface document import interface is used to respond to the document synchronization instruction and import the interface document into the target synchronization directory.
[0021] In one possible implementation, the synchronization unit is specifically configured to execute reading the interface code of the interface to determine the synchronization directory annotation information of the interface; parsing the synchronization directory annotation information to determine the child synchronization directory for the interface document, and parsing the document synchronization configuration information to determine the parent synchronization directory for the interface document; and constructing the target synchronization directory based on the parent synchronization directory and the child synchronization directory.
[0022] In one possible implementation, the device also includes: a parsing unit configured to execute and receive a document import result returned by the interface document import interface; parse the document import result to determine the quantity information of the interface documents that have been imported into the interface management platform.
[0023] In one possible implementation, the device also includes: an initialization unit, configured to execute loading of the document synchronization configuration information, initialize a preset interface document generation program, and obtain an initialized interface document generation program; wherein the initialized interface document generation program is used to read the interface code of the interface, determine the interface annotation information of the interface, and generate an interface description file with a preset format based on the interface annotation information; and is also used to save the interface description file as the interface document corresponding to the interface in the document scanning directory.
[0024] In one possible implementation, the initialization unit is specifically configured to execute the acquisition of the current business environment; if the current business environment satisfies the preset business environment, the step of loading the document synchronization configuration information, initializing the preset interface document generation program, and obtaining the initialized interface document generation program is executed; wherein the preset business environment includes at least one of a business testing environment and a business development environment.
[0025] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the interface document synchronization method as described in the first aspect or any possible implementation method of the first aspect is implemented.
[0026] According to a fourth aspect of an embodiment of the present disclosure, a storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the interface document synchronization method as described in the first aspect or any possible implementation of the first aspect is implemented.
[0027] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, the program product comprising a computer program, the computer program being stored in a readable storage medium, at least one processor of a device reading and executing the computer program from the readable storage medium, so that the device executes the interface document synchronization method described in any possible implementation of the first aspect.
[0028] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects: by receiving the interface synchronization parameters passed in when the interface document synchronization interface is accessed, and determining the interface identifier in the interface synchronization parameters; then, according to the preloaded document synchronization configuration information, determining the document scanning directory for the interface type corresponding to the interface identifier; then, reading the interface document of the interface corresponding to the interface identifier in the document scanning directory; wherein the interface document is generated according to the interface annotation information of the interface, and the interface annotation information of the interface is determined by reading the interface code of the interface; thereby, the interface document of the corresponding interface can be obtained based on the interface identifier without directly consulting the interface code of the interface, and the corresponding interface information can be obtained through the interface document of the interface, thereby avoiding users from wasting a lot of time to consult the interface code with a lot of content; at the same time, by synchronizing the interface document to the interface management platform for presenting the interface document to the user account, the user can directly consult the interface document of the interface corresponding to each interface identifier through the interface identifier on the interface management platform, and efficiently determine the information and function of each interface through each interface document, thereby avoiding the problem of being unable to perform standardized management of a large number of interface documents, thereby improving the efficiency of software project development. It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0030] Figure 1 The present invention is an application environment diagram of an interface document synchronization method according to an exemplary embodiment.
[0031] Figure 2 The present invention is a flowchart of an interface document synchronization method according to an exemplary embodiment.
[0032] Figure 3 The figure is a flowchart of another interface document synchronization method according to an exemplary embodiment.
[0033] Figure 4 A flowchart of a synchronization tool initialization method is shown according to an exemplary embodiment.
[0034] Figure 5 The invention is a block diagram of an interface document synchronization device according to an exemplary embodiment.
[0035] Figure 6 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0036] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0037] The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0038] It should also be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.
[0039] Figure 1 is a schematic diagram of an implementation environment provided by an embodiment of the present disclosure. Figure 1, the implementation environment includes an electronic device 102 and an interface management platform 104. The electronic device 102 and the interface management platform 104 are connected via a wireless or wired network. Exemplarily, the electronic device 102 is a server. Exemplarily, the interface management platform 104 is an interface management platform that is secondary packaged based on the open source framework Yapi (an open source interface visualization management platform).
[0040] In the embodiment of the present disclosure, the electronic device 102 receives the interface synchronization parameters passed in when the interface document synchronization interface is accessed, and determines the interface identifier in the interface synchronization parameters; then, the electronic device 102 determines the document scanning directory for the interface type corresponding to the interface identifier based on the preloaded document synchronization configuration information; then, the electronic device 102 reads the interface document of the interface corresponding to the interface identifier in the document scanning directory; then, the electronic device 102 synchronizes the interface document to the interface management platform 104 through the interface document import interface of the interface management platform 104; the interface management platform 104 is used to present the interface document to the user account, and send the document import result to the interface document import interface to return the document import result to the electronic device 102.
[0041] Figure 2 is a flowchart of an interface document synchronization method according to an exemplary embodiment. Figure 2 As shown, the interface document synchronization method is used in the electronic device 102 and includes the following steps.
[0042] In step S210, the interface synchronization parameters input when the interface document synchronization interface is accessed are received, and the interface identifier in the interface synchronization parameters is determined.
[0043] Among them, the interface document synchronization interface is an interface for receiving interface document synchronization requests.
[0044] The interface synchronization parameters include the interface type and the interface identifier.
[0045] The interface identifier may be a parameter value of an interface synchronization parameter.
[0046] The interface identifier may include a partial interface identifier and a full interface identifier.
[0047] Specifically, the electronic device can receive an interface document synchronization request at the interface document synchronization interface, and determine the target address, i.e., URL (Uniform Resource Locator), according to the interface document synchronization request. The URL carries interface synchronization parameters, and the interface synchronization parameter name and interface synchronization parameter value can be determined according to the interface synchronization parameters. The interface type is determined by the interface synchronization parameter name, and the interface synchronization parameter value is used as the interface identifier; wherein, the interface identifier may include a local interface identifier and a full interface identifier. When the interface identifier is a local interface identifier, the number of interface synchronization parameter values is at least one; when the interface identifier is a full interface identifier, the interface synchronization parameter value may be "all". For example, if the URL of the interface document synchronization interface is http: / / ip:port / swagger / kapi / autoImport? controllerNames=xxx controller; then the interface synchronization parameter can be determined to be controllerNames=xxxcontroller, then the interface synchronization parameter value xxx controller can be used as the interface identifier, and the interface identifier is determined to be a local interface identifier; and the interface type is determined to be a Controller class (control class).
[0048] In step S220, a document scanning directory for an interface type corresponding to the interface identifier is determined according to the preloaded document synchronization configuration information.
[0049] The document synchronization configuration information includes the path of the document scanning directory corresponding to the interface type of the interface identifier.
[0050] The document scanning directory is a file directory on the local side for storing interface documents.
[0051] Specifically, the document synchronization configuration information includes the path of the document scanning directory of each interface type on the local side. The electronic device can determine the path of the document scanning directory on the local side for the interface type corresponding to the interface identifier based on the pre-loaded document synchronization configuration information, and determine the document scanning directory for the interface type corresponding to the interface identifier based on the path of the document scanning directory. For example, if the interface type corresponding to the interface identifier is the Controller class, the pre-loaded document synchronization configuration information includes the path of the document scanning directory of the Controller class interface, such as controllerScanPath:com.kuaishou.controller, and the electronic device can determine the document scanning directory of the Controller class corresponding to the interface identifier based on the path of the above document scanning directory.
[0052] In step S230, the interface document of the interface corresponding to the interface identifier in the document scanning directory is read.
[0053] The interface document is generated based on the interface annotation information of the interface.
[0054] The interface annotation information is determined by reading the interface code of the interface.
[0055] Among them, the document scanning directory stores all interface documents belonging to the interface type corresponding to the interface identifier.
[0056] Specifically, after the electronic device determines the document scanning directory for the interface type corresponding to the interface identifier, all interface documents belonging to the interface type corresponding to the interface identifier are stored in the document scanning directory, and the electronic device can read the interface document of the interface corresponding to the interface identifier in the above document scanning directory according to the interface identifier. For example, if the document scanning directory for the interface type corresponding to the interface identifier is the document scanning directory of the Controller class, the electronic device can find the interface document corresponding to xxx controller in the document scanning directory of the Controller class based on the interface identifier xxx controller; wherein, in step S210, if the electronic device determines that the interface identifier in the interface synchronization parameter is a full document identifier, the electronic device will read all interface documents in the document scanning directory for the interface type corresponding to the interface identifier.
[0057] Among them, the electronic device can pre-acquire the interface code of the interface corresponding to the interface identifier, read the above interface code, determine the annotation information of the interface corresponding to the interface identifier, and finally generate the interface document of the interface corresponding to the interface identifier based on the annotation information of the interface.
[0058] In step S240, the interface document is synchronized to the interface management platform.
[0059] Among them, the interface management platform is used to present interface documents to user accounts.
[0060] Specifically, the electronic device can synchronize the interface document of the interface corresponding to the interface identifier to the interface management platform based on the document synchronization instruction; wherein, if the interface identifier is a partial interface identifier, the interface document of the interface corresponding to the interface identifier read in step S230 is a partial interface document in the document scanning directory, and this interface document synchronization operation is a partial synchronization mode; if the interface identifier is a full interface identifier, the interface document of the interface corresponding to the interface identifier read in step S230 is all interface documents in the document scanning directory, and this interface document synchronization operation is a full synchronization mode.
[0061] After receiving the interface document, the interface management platform will convert the format of the data in the interface document according to the preset data format and store it to obtain the converted interface document, so that the data format of the converted interface document is the preset data format; wherein, the format of the data in the interface document can be but is not limited to Json (JavaScript Object Notation, a lightweight data exchange format based on JavaScript programming language) and other formats; in this way, the interface management platform can present the interface document of the interface corresponding to each interface identifier to the user account.
[0062] In the above-mentioned interface document method, the interface synchronization parameters passed in when the interface document synchronization interface is accessed are received, and the interface identifier in the interface synchronization parameters is determined; then, according to the preloaded document synchronization configuration information, the document scanning directory for the interface type corresponding to the interface identifier is determined; then, the interface document of the interface corresponding to the interface identifier in the document scanning directory is read; wherein, the interface document is generated according to the interface annotation information of the interface, and the interface annotation information of the interface is determined by reading the interface code of the interface; thereby, the interface document of the corresponding interface can be obtained based on the interface identifier without directly consulting the interface code of the interface, and the corresponding interface information can be obtained through the interface document of the interface, thereby avoiding users from wasting a lot of time to consult the interface code with a lot of content; at the same time, by synchronizing the interface document to the interface management platform used to present the interface document to the user account, the user can directly consult the interface document of the interface corresponding to each interface identifier through the interface identifier on the interface management platform, and efficiently determine the information and functions of each interface through each interface document, thereby avoiding the problem of being unable to standardize the management of a large number of interface documents, thereby improving the efficiency of software project development.
[0063] In an exemplary embodiment, synchronizing an interface document to an interface management platform includes: obtaining a target synchronization directory for the interface document; generating a document synchronization instruction based on the target synchronization directory and the interface document; and sending the document synchronization instruction to the interface document import interface of the interface management platform.
[0064] The target synchronization directory is a file directory in the interface management platform for storing interface documents.
[0065] Among them, the interface document import interface is used to respond to the document synchronization instruction and import the interface document into the target synchronization directory.
[0066] Among them, the interface document import interface is a part of the interface management platform and is used to interact with external electronic devices.
[0067] Among them, the interface management platform is used to present interface documents to user accounts.
[0068] Specifically, the electronic device can obtain the target synchronization directory for the interface document by parsing the synchronization directory annotation information and the document synchronization configuration information; then, the electronic device generates a document synchronization instruction based on the target synchronization directory for the interface document and the interface document; then, the electronic device sends the document synchronization instruction to the interface document import interface of the interface management platform; after receiving the document synchronization instruction sent by the electronic device, the interface document import interface will receive the interface document and determine the target synchronization directory of the interface document, that is, the interface document import interface can determine the file directory where the interface document is to be stored after being synchronized to the interface management platform, and import the interface document into the corresponding file directory in the interface management platform.
[0069] The technical solution of this embodiment, when synchronizing the interface document to the interface management platform, obtains the target synchronization directory for the interface document, and generates a document synchronization instruction based on the target synchronization directory and the interface document, and then sends the document synchronization instruction to the interface document import interface of the interface management platform; in this way, the interface document import interface can respond to the document synchronization instruction, determine the target synchronization directory of the interface document, that is, determine the file directory for storing the interface document in the interface management platform, and import the interface document into the corresponding file directory in the interface management platform, so that users can view each interface document under the specific file directory of the interface management platform, thereby realizing standardized management of the interface documents, thereby improving the efficiency of obtaining the interface documents of each interface.
[0070] In an exemplary embodiment, obtaining a target synchronization directory for an interface document includes: reading the interface code of the interface to determine the synchronization directory annotation information of the interface; parsing the synchronization directory annotation information to determine the child synchronization directory for the interface document, and parsing the document synchronization configuration information to determine the parent synchronization directory for the interface document; and constructing a target synchronization directory based on the parent synchronization directory and the child synchronization directory.
[0071] The interface code can be, but is not limited to, Java code.
[0072] The synchronization directory annotation information is the synchronization directory annotation information in the interface annotation information, which may be @Api annotation information.
[0073] The document synchronization configuration information includes the name of the parent synchronization directory for the interface document.
[0074] The sub-level synchronization directory is a sub-level directory in the file directory for storing interface documents in the interface management platform, and may be a secondary directory.
[0075] The parent synchronization directory is a parent directory in a file directory for storing interface documents in the interface management platform, and may be a first-level directory.
[0076] Specifically, after reading the interface code of the interface, the electronic device can determine the interface annotation information of the interface, and determine the synchronization directory annotation information from the interface annotation information; by parsing the synchronization directory annotation information, the description information of the interface is determined, and the description information includes the name of the sub-level synchronization directory for the interface document; thereby, based on the description information of the interface, the sub-level synchronization directory of the interface document of the interface can be determined, that is, the sub-level directory in the file directory for storing interface documents in the interface management platform can be determined. Among them, the synchronization directory annotation information can be @Api annotation information. @Api annotation information acts on the class and indicates the description of the class, such as it can act on the interface type Controller class; @API annotation information has two attributes: value and tags. The tags attribute can be used to describe the corresponding class, so as to determine the sub-level synchronization directory. If the @Api annotation information is @Api (tags = {"xxx test interface document directory"}), then by parsing the @Api annotation information, it is determined that the sub-level synchronization directory where the interface document is synchronized to the interface management platform is "xxx test interface document directory". If the tags values in the two synchronization directory annotation information are the same, the two interface documents generated according to the above two synchronization directory annotation information will be synchronized to the same sub-level directory in the interface management platform.
[0077] At the same time, the document synchronization configuration information includes the name of the parent synchronization directory for the interface document. The electronic device can also determine the parent synchronization directory for the interface document by parsing the preloaded document synchronization configuration information, that is, determine the parent directory in the file directory for storing the interface document in the interface management platform. In this way, by determining the child synchronization directory for the interface document and the parent synchronization directory for the interface document, a target synchronization directory for the interface document is constructed, so that the file directory where the interface document is stored after being synchronized to the interface management platform can be determined; wherein, the parent synchronization directory can be a first-level directory in the target synchronization directory, and the child synchronization directory can be a second-level directory in the target synchronization directory, that is, the target synchronization directory consists of a first-level directory and a second-level directory.
[0078] The technical solution of this embodiment determines the synchronization directory annotation information of the interface by reading the interface code of the interface; then, by parsing the synchronization directory annotation information, the child synchronization directory for the interface document is determined, and by parsing the document synchronization configuration information, the parent synchronization directory for the interface document is determined; finally, a target synchronization directory is constructed according to the parent synchronization directory and the child synchronization directory; in this way, through the target synchronization directory, the file directory to be stored after the interface document of the interface is synchronized to the interface management platform can be determined, and the target synchronization directory is composed of the parent synchronization directory and the child synchronization directory, so that the interface documents can be stored in different child directories in the interface management platform, which is convenient for the management and classification of the interface documents, and when the user consults the interface document through the interface management platform, the interface document required by the user can be quickly queried, thereby improving the efficiency of obtaining the interface document.
[0079] In an exemplary embodiment, after the step of sending a document synchronization instruction to the interface document import interface of the interface management platform, the method also includes: receiving the document import result returned by the interface document import interface; parsing the document import result to determine the quantity information of the interface documents that have been imported into the interface management platform.
[0080] Among them, the document import results may include the number information of interface documents successfully imported in this interface document import operation, the number information of interface documents stored in the target synchronization directory of the interface management platform after this interface document import operation, the number information of interface documents that failed to be imported in this interface document import operation, and the number information of interface documents stored in the target synchronization directory before this interface document import operation.
[0081] Among them, the number information of interface documents imported into the interface management platform includes the number information of interface documents successfully imported in this interface document import operation and the number information of interface documents stored in the target synchronization directory of the interface management platform after this interface document import operation.
[0082] Specifically, after the electronic device sends a document synchronization instruction to the interface document import interface of the interface management platform, the interface document import interface can respond to the document synchronization instruction and import the interface document into the target synchronization directory, so that the interface management platform can receive and store the interface document; thereafter, the interface management platform will summarize the information of the received interface documents, determine the number of interface documents successfully imported in this interface document import operation and the number of interface documents stored in the target synchronization directory after this interface document import operation, and may also include the number of interface documents that failed to be imported in this interface document import operation and / or the number of interface documents stored in the target synchronization directory before this interface document import operation. ; Afterwards, the interface management platform will send the document import result to the interface document import interface, and the interface document import interface will return the above document import result to the electronic device. The electronic device will determine the quantity information of the interface documents that have been imported into the interface management platform by parsing the document import result, that is, the quantity information of the interface documents that have been successfully imported in this interface document import operation, and the quantity information of the interface documents that have been stored in the target synchronization directory of the interface management platform after this interface document import operation; in addition, the electronic device can also determine the quantity information of the interface documents that have failed to be imported in this interface document import operation and the quantity information of the interface documents that have been stored in the target synchronization directory before this interface document import operation.
[0083] The technical solution of this embodiment determines the quantity information of the interface documents imported into the interface management platform by receiving the document import result returned by the interface document import interface and parsing the document import result, so as to determine whether the interface management platform has received the interface document, avoid the occurrence of interface document synchronization and repeated synchronization of interface documents, and improve the reliability of interface document synchronization.
[0084] In an exemplary embodiment, the method further includes: loading document synchronization configuration information, initializing a preset interface document generation program, and obtaining an initialized interface document generation program;
[0085] Among them, the initialized interface document generation program is used to read the interface code of the interface, determine the interface annotation information of the interface, and generate an interface description file with a preset format based on the interface annotation information; it is also used to save the interface description file as the interface document corresponding to the interface in the document scanning directory.
[0086] The file storing the document synchronization configuration information is in yml format (a readable data serialization format).
[0087] Among them, the document synchronization configuration information includes at least one of the path of the document scanning directory corresponding to the interface type of the interface identifier, confirmation information on whether to enable the interface document synchronization overlay function, project name, project description, the name of the parent synchronization directory for the interface document, and confirmation information on whether to enable the interface management platform synchronization function.
[0088] The parent synchronization directory is a parent directory in a file directory for storing interface documents in the interface management platform.
[0089] The interface code may be, but is not limited to, Java code.
[0090] Specifically, the electronic device can load document synchronization configuration information and read the document synchronization configuration information, wherein the document synchronization configuration information includes at least one of the path of the document scanning directory corresponding to the interface type of the interface identifier, confirmation information on whether to enable the interface document synchronization overwrite function, the project name, project description information, the name of the parent synchronization directory for the interface document, and confirmation information on whether to enable the interface management platform synchronization function; initialize the preset interface document generation program through the document synchronization configuration information to obtain the initialized interface document generation program, so that the initialized interface document generation program contains the document synchronization configuration information; then, read the interface code of the interface through the initialized interface document generation program, and determine the interface annotation information of the interface; wherein, The interface annotation information includes the class name, method name, input parameter quantity, output parameter quantity, input parameter type, output parameter type, etc.; among which, the class name of the interface annotation information can be used as the name of the sub-level synchronization directory for the interface document; then, the path, project name and project description information of the document scanning directory corresponding to the interface type in the interface annotation information and the interface identifier in the document synchronization configuration information can be added to the preset interface document template. The preset interface document template has a unified data format, such as JSON format, so that the interface description file corresponding to the interface code can be generated according to the preset interface document template to which the interface annotation information and part of the document synchronization configuration information are added, and the above interface description file can be saved as the interface document corresponding to the interface in the document scanning directory located on the local side.
[0091] Among them, the electronic device can read the interface code based on Springfox-Swagger, determine the interface annotation information of the interface, and automatically generate an interface description file in JSON format according to the interface annotation information of the interface, and use the interface description file as the interface document corresponding to the interface; among them, Springfox is an open source API (Application Programming Interface))doc (Document) framework; Swagger is an open source, standardized and complete framework for generating, describing, calling and visualizing RESTful (Representational State Transfer, a design style and development method for network applications) style Web (World Wide Web, Global Wide Area Network) services; and Springfox-Swagger integrates Springfox with Swagger. Based on the Swagger specification, Springfox can automatically generate a description file in JSON format from the project code based on SpringMVC (a java framework) and Spring Boot (an open source application framework) projects.
[0092] The technical solution of this embodiment initializes the preset interface document generation program by loading the document synchronization configuration information to obtain the initialized interface document generation program; in this way, the interface code of the interface can be read based on the initialized interface document generation program containing the document synchronization configuration information, and the interface annotation information of the interface can be determined, and according to the interface annotation information, an interface description file with a preset format can be generated, and the interface description file will serve as the interface document corresponding to the interface; thereby, the interface document can be generated based on the interface annotation information, and the interface annotation information is determined by reading the interface code of the interface through the initialized interface document generation program containing the document synchronization configuration information; thereby, the consistency of the interface document with the interface information of the corresponding interface is ensured, and the problem of low efficiency in manually writing interface documents is avoided, thereby improving the generation efficiency of interface documents.
[0093] In an exemplary embodiment, document synchronization configuration information is loaded, a preset interface document generation program is initialized, and an initialized interface document generation program is obtained, including: obtaining a current business environment; if the current business environment meets the preset business environment, loading document synchronization configuration information is executed, initializing the preset interface document generation program, and obtaining the initialized interface document generation program.
[0094] The preset business environment includes at least one of a business test environment and a business development environment.
[0095] The current business environment may include, but is not limited to, a business test environment, a business development environment, and a business production environment.
[0096] Specifically, the electronic device determines the current business environment through environmental configuration information; the environment may be, but is not limited to, a business test environment, a business development environment, and a business production environment; if the current business environment is any one of the preset business environments, such as a business test environment or a business development environment, the steps of loading the document synchronization configuration information, initializing the preset interface document generation program, and obtaining the initialized interface document generation program are executed; if the current business environment is not the preset business environment, such as the current business environment is a business production environment, the subsequent steps are no longer executed, and the interface document cannot be synchronized to the interface management platform.
[0097] The technical solution of this embodiment obtains the current business environment and makes a judgment on the current business environment; if the current business environment is any one of a business test environment and a business development environment, the steps of loading document synchronization configuration information, initializing a preset interface document generation program, and obtaining the initialized interface document generation program are executed; thereby ensuring that the interface document is only effective in the business test environment and the business development environment, and will not be exposed to the business production environment, thereby improving the security of the interface document.
[0098] Figure 3 is a flowchart of another interface document synchronization method according to an exemplary embodiment. Figure 3 As shown, this method is used to Figure 1 In the electronic device 102, the following steps are included.
[0099] In step S310, the interface synchronization parameters input when the interface document synchronization interface is accessed are received, and the interface identifier in the interface synchronization parameters is determined.
[0100] In step S320, a document scanning directory for the interface type corresponding to the interface identifier is determined according to the preloaded document synchronization configuration information.
[0101] In step S330, the interface document of the interface corresponding to the interface identifier in the document scanning directory is read; wherein the interface document is generated based on the interface annotation information of the interface; and the interface annotation information is determined by reading the interface code of the interface.
[0102] In step S340, a target synchronization directory for the interface document is obtained; the target synchronization directory is a file directory in the interface management platform for storing the interface document.
[0103] In step S350, a document synchronization instruction is generated based on the target synchronization directory and the interface document.
[0104] In step S360, the document synchronization instruction is sent to the interface document import interface of the interface management platform; the interface document import interface is used to respond to the document synchronization instruction and import the interface document into the target synchronization directory.
[0105] In step S370, the document import result returned by the interface document import interface is received.
[0106] In step S380, the document import result is parsed to determine the quantity information of the interface documents that have been imported into the interface management platform.
[0107] It should be noted that the specific limitations of the above steps can be found in the above specific limitations of an interface document synchronization method, which will not be repeated here.
[0108] In another embodiment, the electronic device may implement the above-mentioned interface document synchronization method through a synchronization tool based on the Swagger framework and the interface management platform. To facilitate the understanding of those skilled in the art, Figure 4 A flowchart of a method for initializing a synchronization tool in another embodiment is provided, including the following steps.
[0109] In step S410, after starting the program by running the main method of the annotated startup class (equivalent to SpringBootApplication), the automatic equipment annotation (equivalent to KapiEnableAutoconFiguration) is loaded.
[0110] In step S420, the environment configuration class information (EnableSwaggerCondition) is activated to determine the current business environment. If the current business environment meets the preset business environment, step S430 is executed. If not, the initialization of the synchronization tool ends. The preset business environment includes at least one of a business test environment and a business development environment.
[0111] In step S430, the document synchronization configuration information (equivalent to KapiProperties) is loaded and the document synchronization configuration information is read.
[0112] The document synchronization configuration information includes at least the following:
[0113] config:controllerScanPath:com.kuaishou.xxx.controller (the full path of the Controller file, for the synchronization tool to determine the path of the document scanning directory on the local side)
[0114] dataSync: true (dataSync is used to control whether to enable data overwriting if the same interface name already exists during automatic synchronization)
[0115] projectDesc: Project description
[0116] projectName: project name
[0117] token:token is a parameter provided by the interface document import interface of the interface management platform, which is used to uniquely identify a specific directory of the interface management platform. This parameter specifies that the interface document is synchronized to the parent synchronization directory in the file directory for storing interface documents on the interface management platform.
[0118] enableSwitch: If true is filled in, the synchronization function of the interface management platform will take effect. If false is filled in, the synchronization function of the interface management platform can be forcibly disabled.
[0119] In step S440, part of the document synchronization configuration information is loaded (equivalent to loading KapiConfiguraiton), and the initialization of the preset interface document generation program is completed (equivalent to initializing Springfox-swagger).
[0120] In step S450, the interface annotation information on the Controller class is loaded (equivalent to loading KapiSwaggerSynController), the interface synchronization path is initialized, and the synchronization tool initialization is completed.
[0121] The interface annotation information includes:
[0122] 1.@Api(tags={"xxx test interface document directory"})
[0123] Applied to the requested class, the tags attribute corresponds to the sub-level synchronization directory in the file directory where the interface document is stored after the interface document is synchronized to the interface management platform.
[0124] 2.@ApiOperation(value="Get xxx")
[0125] It acts on the requested method to explain the purpose and function of the method. The value represents the Chinese comment of the method.
[0126] 3.@ApiImplicitParams&@ApiImplicitParams,
[0127] Acts on the request method and is used to annotate the meaning of each parameter in the method. If the input parameter is a Vo (View Object, displaying the view model), you can use the @ApiModel and @ApiModelProperty annotations
[0128] 4.@ApiModel and @ApiModelProperty
[0129] It acts on the method output parameters and is used to describe the actual meaning of each parameter in the method output parameters.
[0130] In this way, the synchronization tool that has completed initialization can execute the above-mentioned interface document synchronization method.
[0131] It should be understood that although Figure 2-Figure 4 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2-Figure 4 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.
[0132] It can be understood that the same / similar parts between the various embodiments of the above method in this specification can refer to each other, and each embodiment focuses on the differences from other embodiments. For related points, please refer to the description of other method embodiments.
[0133] Figure 5 is a block diagram of an interface document synchronization device according to an exemplary embodiment. Figure 5 The device includes a receiving unit 510, a determining unit 520, a reading unit 530 and a synchronization unit 540.
[0134] The receiving unit 510 is configured to receive the interface synchronization parameters transmitted when the interface document synchronization interface is accessed, and determine the interface identifier in the interface synchronization parameters.
[0135] The determination unit 520 is configured to determine a document scanning directory for the interface type corresponding to the interface identifier according to the preloaded document synchronization configuration information.
[0136] The reading unit 530 is configured to execute reading of the interface document of the interface corresponding to the interface identifier in the document scanning directory; wherein the interface document is generated based on the interface annotation information of the interface; and the interface annotation information is determined by reading the interface code of the interface.
[0137] The synchronization unit 540 is configured to execute synchronization of the interface document to an interface management platform; the interface management platform is used to present the interface document to a user account.
[0138] In an exemplary embodiment, the synchronization unit is specifically configured to execute acquisition of a target synchronization directory for the interface document; the target synchronization directory is a file directory in the interface management platform for storing the interface document; a document synchronization instruction is generated based on the target synchronization directory and the interface document; the document synchronization instruction is sent to an interface document import interface of the interface management platform; the interface document import interface is used to respond to the document synchronization instruction and import the interface document into the target synchronization directory.
[0139] In an exemplary embodiment, the synchronization unit is specifically configured to execute reading the interface code of the interface to determine the synchronization directory annotation information of the interface; parsing the synchronization directory annotation information to determine the child synchronization directory for the interface document, and parsing the document synchronization configuration information to determine the parent synchronization directory for the interface document; and constructing the target synchronization directory based on the parent synchronization directory and the child synchronization directory.
[0140] In an exemplary embodiment, the device also includes: a parsing unit configured to execute receiving a document import result returned by the interface document import interface; parsing the document import result to determine the quantity information of the interface documents that have been imported into the interface management platform.
[0141] In an exemplary embodiment, the device also includes: an initialization unit, configured to execute loading of the document synchronization configuration information, initialize a preset interface document generation program, and obtain an initialized interface document generation program; wherein the initialized interface document generation program is used to read the interface code of the interface, determine the interface annotation information of the interface, and generate an interface description file with a preset format based on the interface annotation information; and is also used to save the interface description file as the interface document corresponding to the interface in the document scanning directory.
[0142] In an exemplary embodiment, the initialization unit is specifically configured to execute the acquisition of the current business environment; if the current business environment satisfies the preset business environment, the step of loading the document synchronization configuration information, initializing the preset interface document generation program, and obtaining the initialized interface document generation program is executed; wherein the preset business environment includes at least one of a business testing environment and a business development environment.
[0143] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0144] Figure 6 is a block diagram of an electronic device 600 for executing the above-mentioned interface document synchronization method according to an exemplary embodiment. For example, the electronic device 600 may be a server. Figure 6 , the electronic device 600 includes a processing component 620, which further includes one or more processors, and a memory resource represented by a memory 622 for storing instructions executable by the processing component 620, such as an application. The application stored in the memory 622 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 620 is configured to execute the instructions to perform the above method.
[0145] The electronic device 600 may further include a power supply component 624 configured to perform power management of the electronic device 600, a wired or wireless network interface 626 configured to connect the electronic device 600 to a network, and an input / output (I / O) interface 628. The electronic device 600 may operate based on an operating system stored in the memory 622, such as Windows 66erver, Mac O6X, Unix, Linux, FreeB6D or the like.
[0146] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory 622 including instructions, and the above instructions can be executed by a processor of the electronic device 600 to perform the above method. The storage medium can be a computer-readable storage medium, for example, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0147] In an exemplary embodiment, a computer program product is further provided. The computer program product includes instructions. The instructions can be executed by a processor of the electronic device 600 to complete the above method.
[0148] It should be noted that the above-mentioned devices, electronic devices, computer-readable storage media, computer program products, etc. may also include other implementation methods according to the description of the method embodiments. The specific implementation methods can refer to the description of the relevant method embodiments, which will not be described one by one here.
[0149] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.
[0150] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. An interface document synchronization method, characterized in that: include: Receiving interface synchronization parameters passed in when the interface document synchronization interface is accessed, and determining the interface identifier in the interface synchronization parameters; Determine, according to the preloaded document synchronization configuration information, a document scanning directory for the interface type corresponding to the interface identifier; Reading the interface document of the interface corresponding to the interface identifier in the document scanning directory; wherein the interface document is generated according to the interface annotation information of the interface; the interface annotation information is determined by reading the interface code of the interface; Synchronizing the interface document to an interface management platform; the interface management platform is used to present the interface document to a user account; The method comprises: obtaining a target synchronization directory for the interface document; the target synchronization directory is a file directory in the interface management platform for storing the interface document; specifically comprising: reading the interface code of the interface to determine the synchronization directory annotation information of the interface; parsing the synchronization directory annotation information to determine the child synchronization directory for the interface document, and parsing the document synchronization configuration information to determine the parent synchronization directory for the interface document; constructing the target synchronization directory according to the parent synchronization directory and the child synchronization directory; Generate a document synchronization instruction based on the target synchronization directory and the interface document; The document synchronization instruction is sent to the interface document import interface of the interface management platform to respond to the document synchronization instruction and import the interface document into the target synchronization directory.
2. The interface document synchronization method according to claim 1, characterized in that: After the step of sending the document synchronization instruction to the interface document import interface of the interface management platform, the method further includes: Receive the document import result returned by the interface document import interface; The document import result is parsed to determine the quantity information of the interface documents that have been imported into the interface management platform.
3. The interface document synchronization method according to any one of claims 1 to 2, characterized in that: The method further comprises: Loading the document synchronization configuration information, initializing a preset interface document generation program, and obtaining an initialized interface document generation program; Among them, the initialized interface document generation program is used to read the interface code of the interface, determine the interface annotation information of the interface, and generate an interface description file with a preset format based on the interface annotation information; it is also used to save the interface description file as the interface document corresponding to the interface in the document scanning directory.
4. The interface document synchronization method according to claim 3, characterized in that: The step of loading the document synchronization configuration information and initializing a preset interface document generation program to obtain an initialized interface document generation program includes: Get the current business environment; If the current business environment satisfies the preset business environment, the steps of loading the document synchronization configuration information, initializing the preset interface document generation program, and obtaining the initialized interface document generation program are executed; The preset business environment includes at least one of a business test environment and a business development environment.
5. An interface document synchronization device, characterized in that: include: A receiving unit configured to receive interface synchronization parameters passed in when an interface document synchronization interface is accessed, and determine an interface identifier in the interface synchronization parameters; A determination unit configured to determine a document scanning directory for an interface type corresponding to the interface identifier according to preloaded document synchronization configuration information; A reading unit, configured to read an interface document of an interface corresponding to the interface identifier in the document scanning directory; wherein the interface document is generated according to interface annotation information of the interface; and the interface annotation information is determined by reading an interface code of the interface; A synchronization unit, configured to execute synchronization of the interface document to an interface management platform; the interface management platform is used to present the interface document to a user account; The synchronization unit is specifically configured to execute acquisition of a target synchronization directory for the interface document; the target synchronization directory is a file directory in the interface management platform for storing the interface document; based on the target synchronization directory and the interface document, generate a document synchronization instruction; send the document synchronization instruction to the interface document import interface of the interface management platform, so as to import the interface document into the target synchronization directory in response to the document synchronization instruction; The synchronization unit is specifically configured to execute reading of the interface code of the interface to determine the synchronization directory annotation information of the interface; parsing the synchronization directory annotation information to determine the child synchronization directory for the interface document, and parsing the document synchronization configuration information to determine the parent synchronization directory for the interface document; and constructing the target synchronization directory based on the parent synchronization directory and the child synchronization directory.
6. The interface document synchronization device according to claim 5, characterized in that: The interface document synchronization device also includes: a parsing unit configured to execute and receive the document import result returned by the interface document import interface; parse the document import result to determine the quantity information of the interface documents that have been imported into the interface management platform.
7. The interface document synchronization device according to any one of claims 5 to 6, characterized in that: The interface document synchronization device also includes: an initialization unit, configured to execute loading of the document synchronization configuration information, initialize the preset interface document generation program, and obtain an initialized interface document generation program; wherein the initialized interface document generation program is used to read the interface code of the interface, determine the interface annotation information of the interface, and generate an interface description file with a preset format based on the interface annotation information; and is also used to save the interface description file as the interface document corresponding to the interface in the document scanning directory.
8. The interface document synchronization device according to claim 7, characterized in that: The initialization unit is specifically configured to execute the acquisition of the current business environment; if the current business environment meets the preset business environment, the step of loading the document synchronization configuration information, initializing the preset interface document generation program, and obtaining the initialized interface document generation program is executed; wherein the preset business environment includes at least one of a business test environment and a business development environment.
9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the interface document synchronization method as described in any one of claims 1 to 4.
10. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the interface document synchronization method as described in any one of claims 1 to 4.
11. A computer program product, comprising instructions, characterized in that: When the instruction is executed by a processor of an electronic device, the electronic device is enabled to execute the interface document synchronization method as described in any one of claims 1 to 4.
