Interface information processing method and device, computer equipment and storage medium
By generating and synchronizing the base class file set of interface information, the problem of low efficiency in manual definition of interface declaration in front-end development is solved, and efficient front-end parameter consistency and simplified development process is achieved.
Patent Information
- Application Number
- CN202311837398.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-28
- Publication Date
- 2025-07-08
AI Technical Summary
In computer program development, front-end personnel need to manually read the back-end interface configuration and manually write out the interface declaration definition, resulting in low development efficiency and waste of human resources. Different developers may repeat the same work, making parameter consistency difficult to ensure.
Generate json data by obtaining interface information, parsing json objects and parameters to generate base class units, and converting them into code files of the target language to generate base class files, including annotation analysis and reference relationship processing, and finally synchronize the file set to the target warehouse and publishing platform.
It realizes that front-end development does not require manual declaration and definition, improves development efficiency, ensures the consistency of front-end parameters, reduces duplicate work, simplifies code maintenance and understanding, and improves code readability and transmission reliability.
Smart Images

Figure CN120276734A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular, to a method, apparatus, computer device, and storage medium for processing interface information. Background Art
[0002] During the process of computer program development, due to the characteristics of strongly typed development languages, front-end developers need to develop front-end interfaces based on the interface configurations of the back-end to meet the overall specifications and unified requirements of the program. Currently, during the development process, front-end developers need to manually read the parameters of the back-end interface configurations and then manually write the relevant interface declarations and definitions; alternatively, they need to use some code conversion script files to convert all the interface information of the interface configurations into a code file through the script file, and then manually modify the code file as needed to complete the relevant declarations and definitions. On the one hand, the method relying on manual operations by developers results in low development efficiency. On the other hand, different developers may repeat the same work, causing a waste of human resources.
[0003] In response to this, the inventor has found that if the configured interface information can be formed into a unified and referenceable file for other developers to reference as needed, thereby eliminating the need for manual declarations and definitions, and can also be separately referenced in different demand scenarios without repeated definitions, it helps to improve development efficiency on the premise of ensuring consistent definition of front-end and back-end parameters.
[0004] Therefore, how to form the configured interface information into a unified and referenceable file has become a technical problem urgently to be solved in this field. Summary of the Invention
[0005] The object of the present invention is to provide a method, apparatus, computer device, and storage medium for processing interface information to solve the above technical problems in the prior art.
[0006] On the one hand, to achieve the above object, the present invention provides a method for processing interface information.
[0007] The method for processing interface information includes: obtaining the interface information of a configured target interface; generating json data corresponding to the interface information, where the data type of the json data includes at least one of object or array; when it is parsed that the data type of the json object in the json data is object, generating a base class unit corresponding to the json object, and when it is parsed that the data type of the json object is array, further parsing the parameters under the json object, and when the data type of the parameter is object, generating a base class unit corresponding to the parameter; converting each of the base class units into a code file corresponding to the target language, and generating a set of base class files corresponding to the interface.
[0008] Further, after the step of generating the json data corresponding to the interface information, the method further includes: parsing the annotations in the json data to obtain multiple pieces of annotation information, where the annotation information includes global annotation information, local parameter annotation information, and input / output parameter annotation information; the base class unit includes an entry base class unit and a non-entry base class unit, and the step of generating the base class file set corresponding to the target interface includes: writing the input / output parameter annotation information into the entry base class unit, writing the global annotation information into each of the base class units, and writing the local parameter annotation information into the corresponding non-entry base class unit.
[0009] Further, the first base class unit is any one of the base class units. After the step of generating the json data corresponding to the target interface information, the method further includes: parsing the reference fields in the json data to determine the base class units referenced by the first base class unit; the step of generating the base class file set corresponding to the target interface includes: writing the base class units it references into the first base class unit.
[0010] Further, the step of writing the base class units it references into the first base class unit includes: the first base class unit references the second base class unit and the third base class unit. If the second base class unit is the same as the third base class unit, only write the second base class unit into the first base class unit; the first base class unit references the fourth base class unit. If the first base class unit and the fourth base class unit reference each other, copy the content of the fourth base class unit to the first base class unit. If the first base class unit unidirectionally references the fifth base class unit, declare the reference to the fifth base class unit in the first base class unit.
[0011] Further, after the step of generating the base class file set corresponding to the target interface, the method further includes: obtaining the information of the target download end; writing the base class file set into a temporary folder; creating a compression package object, reading each file in the temporary folder and adding it to the compression package; sending the compression package to the target download end.
[0012] Further, after the step of sending the compression package to the target download end, the method further includes: deleting the temporary folder and the content in the temporary folder.
[0013] Further, after the step of generating the base class file set corresponding to the target interface, the method further includes: reading a preset synchronization mapping table, where the synchronization mapping table includes a repository address and an information publishing address corresponding to the code language type; querying the repository address and the information publishing address corresponding to the target language in the synchronization mapping table to obtain a target repository address and a target information publishing address; synchronizing the base class file set to the base class repository indicated by the target repository address; and publishing the synchronization information of synchronizing the base class file set to the base class repository to the publishing platform indicated by the target information publishing address.
[0014] Further, the step of synchronizing the base class file set to the base class repository indicated by the target repository address includes: determining the base class repository indicated by the target repository address; cloning the base class repository to obtain a cloned repository; writing the base class file set into the cloned repository; and pushing the cloned repository to the repository address.
[0015] Further, the synchronization mapping table further includes tag information corresponding to the code language type. After the step of generating the base class file set corresponding to the target interface, the method further includes: querying the tag information corresponding to the target language in the synchronization mapping table; and before the step of cloning the base class repository to obtain a cloned repository after the step of determining the base class repository indicated by the target repository address, the step of synchronizing the base class file set to the base class repository indicated by the target repository address further includes: reading the tags of the base class repository; and updating the tags of the base class repository with the tag information corresponding to the target language.
[0016] Further, the step of publishing the information of synchronizing the base class file set to the information publishing platform according to the information update publishing address includes: capturing the logs of the base class repository; parsing the logs to obtain the dynamic information of the files in the base class repository; and publishing the dynamic information to the information publishing platform according to the information update publishing address.
[0017] On the other hand, to achieve the above object, the present invention provides a device for generating base class files.
[0018] The processing device for the interface information includes: an acquisition module, configured to acquire the interface information for configuring a target interface; a first processing module, configured to generate json data corresponding to the interface information, where the data type of the json data includes at least one of object or array; a parsing module, configured to generate a base class unit corresponding to the json object when parsing that the data type of the json object in the json data is object, and when parsing that the data type of the json object is array, further parse the parameters under the json object, and generate a base class unit corresponding to the parameter when the data type of the parameter is object; a second processing module, configured to convert each of the base class units into a code file corresponding to a target language, and generate a set of base class files corresponding to the interface.
[0019] On the other hand, to achieve the above object, the present invention further provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the steps of the above method are implemented.
[0020] On the other hand, to achieve the above object, the present invention further provides 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 above method are implemented.
[0021] The interface information processing method, device, computer device, and storage medium provided by the present invention acquire the interface information of the configured interface and then generate corresponding json data, and then parse the json data. After parsing, the base class units corresponding to each json object of the object type and each parameter of the object type in the json data are obtained. Finally, each base class unit is used to generate a set of base class files corresponding to the interface according to the requirements of the target language. Through the present invention, when the backend completes the interface configuration, a corresponding set of base class files is generated using the interface information. During the development process, front-end personnel no longer need to manually write or modify the declaration definitions of relevant interfaces, and only need to reference them as needed. Moreover, they can also be respectively referenced in different requirement scenarios without repeated definition. On the premise of ensuring the consistent definition of front-end and back-end parameters, the development efficiency is improved. Description of the Drawings
[0022] By reading the following detailed description of the preferred embodiments, various other advantages and benefits will become clear to those of ordinary skill in the art. The drawings are only for the purpose of showing the preferred embodiments and are not considered to be a limitation of the present invention. Moreover, throughout the drawings, the same reference numerals are used to represent the same components. In the drawings:
[0023] Figure 1 It is a flowchart of the interface information processing method provided in the first embodiment of the present invention;
[0024] Figure 2 It is a flowchart of another method for processing interface information provided in the first embodiment of the present invention;
[0025] Figure 3 It is a block diagram of a device for processing interface information provided in the second embodiment of the present invention;
[0026] Figure 4 It is a hardware structure diagram of a computer device provided in the third embodiment of the present invention. Detailed implementation manners
[0027] In order to make the objectives, technical solutions and advantages of the present invention clearer and more understandable, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0028] Embodiment 1
[0029] The embodiment of the present invention provides a method for processing interface information. Through this method, interface information of a configured interface can be generated into multiple base class files. Optionally, the execution entity of this method is the server running this processing method, and a front end interacting with the server is set to provide a human-computer interface so that the user can perform operations such as configuring an interface through the interface, selecting to process the interface information into a base class file set, selecting a target language, selecting to synchronize the base class file to a code repository, and selecting to download the base class file set. Through the interaction between the front end and the server, a complete processing flow of interface information is completed. Specifically, Figure 1 It is a flowchart of the method for processing interface information provided in the first embodiment of the present invention. As Figure 1 shown, the method for processing interface information provided in this embodiment includes the following steps S101 to S104.
[0030] Step S101: Obtain interface information of a configured target interface.
[0031] Optionally, after the interface definition personnel configure the interface information through the interface configuration interface, the interface information is written into the database. In this step, the above interface information can be read from the database according to identifiers such as the interface name; or, the interface information is written into an interface document or API specification. In this step, the above interface information can be obtained by reading the interface document or API specification. Or, it can also be obtained through other channels, and the present application does not display this.
[0032] Optionally, the interface information includes the data structure, field types, constraints, etc. of request parameters and response parameters. The constraints may specifically include data format constraints. For example, the interface may require the use of a specific data format in requests and responses, which helps ensure data consistency and readability. It also includes parameter constraints. For example, the interface may specify specific parameter requirements, including the type, range, and necessity of parameters, which helps prevent incorrect results caused by incorrect input data. It also includes return value constraints. For example, the interface may specify a specific return value format and data so that the calling party can correctly parse and process the response data. It also includes call order constraints. For example, in some cases, the interface may require calling different methods or services in a specific order to ensure the correct behavior of the system. It also includes security constraints. For example, the interface may have some security constraints, such as the need to use authentication tokens, encrypted communication, etc., to ensure the secure transmission and processing of data. It also includes concurrency constraints. For example, if the system needs to handle concurrent requests, the interface may specify limits on concurrent requests to avoid resource contention and performance issues. It also includes error handling constraints. For example, the interface should define possible error conditions and specify corresponding error codes, error messages, and error handling measures to be taken. It also includes version control constraints. For example, for long-existing interfaces, there may be version control constraints to ensure compatibility between different versions. These constraints help ensure the stability, maintainability, and scalability of the system. In actual software development, the constraints of the interface are often described in detail in the interface documentation or specification for developers to follow and understand.
[0033] Step S102: Generate json data corresponding to the interface information.
[0034] Among them, the data types of the json data include at least one of basic types, object, or array. The basic types include string, number, integer, and boolean, etc., that is, the data types of json objects or parameters in the json data.
[0035] Optionally, the generated json data is json-schema. When generating the json-schema corresponding to the interface information, the jsonschema library can be used to manually construct the json-schema object, or existing classes and methods can be used for automated generation. Or the ajv (Another JSON Schema Validator) library can also be used to implement the validation and generation of json-schema. Or automated scripts can be written to collect interface information and generate the corresponding json-schema. Or other methods can be adopted for generation. In short, the generated json-schema can accurately reflect the structure and constraints of the interface.
[0036] Step S103: Parse the json data to obtain the base class unit.
[0037] Among them, the json data is parsed, and when the data type of the json object in the json data is object, the base class unit corresponding to the json object is generated, and when the data type of the json object is array, the parameters under the json object are further parsed, and when the data type of the parameter is object, the base class unit corresponding to the parameter is generated.
[0038] Optionally, call a pre-written structure parser to extract the field name, type and other information of the basic structure of the json object from the json data for parsing. When the data type of the extracted json object is object, generate the base class unit corresponding to the json object, that is, generate a new base class unit; when the data type of the json object is the basic type, add the corresponding class attributes and constructor parameters to the base class unit to which it belongs according to the field name, type and other information of the json object, that is, directly display them in the current base class unit; when the data type of the json object is array, extract each parameter in the array, that is, further parse each parameter under the array, and when the data type of the extracted parameter is object, perform recursive traversal, and need to generate the base class unit corresponding to the parameter, that is, generate a new base class unit; when the data type of the extracted parameter is the basic type, display the parameter directly in the current base class unit of the array.
[0039] Step S104: converting each base class unit into a code file corresponding to the target language, and generating a base class file set corresponding to the interface.
[0040] Optionally, the target language to be generated for the base class file is pre-selected, such as OC, Java or TS code, and the language parser is called to generate base class files for each base class unit according to the requirements of the target language, and finally form a base class file set corresponding to the interface. Optionally, each base class unit is stored in the cache in the form of an array, and the array is translated into each code file of the target language by the language parser to obtain the base class file.
[0041] In the method for processing interface information provided in this embodiment, after obtaining the interface information of the configured interface, corresponding JSON data is generated, and then the JSON data is parsed. After parsing, each JSON object of the object type in the JSON data and the base class unit corresponding to the parameter of each object type are obtained. Finally, each base class unit is used to generate a set of base class files corresponding to the interface according to the requirements of the target language. By using the method for processing interface information provided in this embodiment, when the back-end completes the interface configuration, a corresponding set of base class files is generated using the interface information. During the development process, front-end personnel no longer need to manually write or modify the declaration definitions of relevant interfaces. They only need to reference them as needed, and can also reference them separately in different requirement scenarios without repeated definition. On the premise of ensuring the consistency definition of front-end and back-end parameters, the development efficiency is improved.
[0042] Optionally, in one embodiment, after the step of generating the JSON data corresponding to the interface information, the method for processing the interface information further includes: parsing the comments in the JSON data to obtain multiple comment messages, where the comment messages include global comment messages, local parameter comment messages, and input / output parameter comment messages; the base class unit includes an entry base class unit and a non-entry base class unit, and the step of generating a set of base class files corresponding to the target interface includes: writing the input / output parameter comment messages into the entry base class unit, writing the global comment messages into each base class unit, and writing the local parameter comment messages into the corresponding non-entry base class unit.
[0043] Specifically, a pre-written comment parser can be called to extract field comments from the JSON data for parsing to form the comments that need to be added to the subsequent base class files. For example, comments are extracted from JSON-schema for parsing. Comments can be used to provide code documentation, explain the purpose of fields, or provide relevant parameter information, etc. Among them, the parsed comment messages include global comment messages, local parameter comment messages, and input / output parameter comment messages.
[0044] Optionally, the multiple parsed annotation information is first written into a cache, and then written into the corresponding base class files from the cache when generating each base class file in the base class file set. Specifically, the main entry base class file (corresponding to the interface name) is defined as the entry base class unit, and the other base class units are defined as non-entry base class units. When writing the annotation information, the input and output parameter annotation information is written into the entry base class unit, and finally appears at the front end of the code of the main entry base class file; the global annotation information is written into each base class unit, and finally forms at the front end of the code of each base class file, including information such as the interface responsible person and the description of the interface; the local parameter annotation information is written into the non-entry base class unit including the corresponding parameters, that is, if a base class unit includes which local parameters, the annotation information of these local parameters is written into the base class unit, and finally forms at the front end of the code of each non-entry base class file, including information such as the parameter name and the parameter usage.
[0045] Using the interface information processing method provided by this embodiment, first parse the annotations in the json data to obtain multiple annotation information, and then classify and write them into the base class files respectively according to the global annotation information, local parameter annotation information, and input and output parameter annotation information, making the code of each base class file easier to understand, enhancing the readability of the code, and facilitating the maintenance and reference of the base class files.
[0046] Optionally, in one embodiment, the first base class unit is any base class unit. After the step of generating the json data corresponding to the target interface information, the interface information processing method further includes: parsing the reference fields in the json data to determine the base class units referenced by the first base class unit; the step of generating the base class file set corresponding to the target interface includes: writing the base class units it references into the first base class unit.
[0047] Specifically, a pre-written reference parser can be called to identify the reference fields in the json data. When a reference field is identified, parse the reference field to determine which base class units each base class unit references. In the present invention, for the convenience of description, the first base class unit is defined as any one base class unit. For this first base class unit, after determining the base class units it references, when generating the base class file set, write the base class units it references into the first base class unit, and then generate the base class file corresponding to the first base class unit according to the requirements of the target language. For example, if the first base class unit A references the base class unit B and the base class unit C, then write the base class unit B and the base class unit C into the first base class unit A. Specifically, it can be written in the form of a reference "#import the name of the base class file corresponding to the base class unit B", or directly copy the code corresponding to the base class unit B to the base class file corresponding to the first base class unit. No matter which way it is written, it is intended to ensure the correct handling of the reference relationship in the base class file.
[0048] Using the method for processing interface information provided by this embodiment, first parse the reference fields in the JSON data, and then reflect the reference relationship in the corresponding base class file, so as to simplify the code of each base class file, reduce duplicate identical structure definitions, and also help to track and understand the associations between data models when using the base class file, reducing the possibility of type errors.
[0049] Optionally, in one embodiment, the first base class unit references the second base class unit and the third base class unit. The steps of writing the base class units it references in the first base class unit include: when the first base class unit references the second base class unit and the third base class unit, if the second base class unit is the same as the third base class unit, only write the second base class unit in the first base class unit; when the first base class unit references the fourth base class unit, if the first base class unit and the fourth base class unit reference each other, copy the content of the fourth base class unit to the first base class unit, and if the first base class unit unidirectionally references the fifth base class unit, declare the reference to the fifth base class unit in the first base class unit.
[0050] Specifically, for the sake of convenience of description, the first to fifth base class units are defined in this embodiment. It should be noted that the "first" to "fifth" here are only used for distinguishing descriptions and do not limit the order. If two base class units referenced by a base class unit are the same, only one is written in this base class, that is, for the case of repeated references, duplicate removal processing is first performed, and then reference processing is performed. For example, if base class unit A references base class unit B and base class unit C, and base class unit C references base class unit B and base class unit D, then through recursive parsing, it is obtained that base class unit A references base class unit B, C, B, and D. Among them, B is repeatedly referenced, so the referenced base class units B, C, B, and D are de-duplicated, and it is obtained that the referenced base class units are B, C, and D.
[0051] Using the method for processing interface information provided by this embodiment, when writing other base class units it references in the base class unit, first perform duplicate removal and then write, which can reduce the repeated declaration of the same reference type in the base class file, reduce code redundancy, reduce the memory usage during compilation and operation, and reduce the repeated dependencies across different modules or components.
[0052] Optionally, in one embodiment, after the step of generating the set of base class files corresponding to the target interface, the method for processing interface information further includes: obtaining the information of the target download end; writing the set of base class files into a temporary folder; creating a compressed package object, reading each file in the temporary folder and adding it to the compressed package; sending the compressed package to the target download end.
[0053] Specifically, the user can write the information of the target download end through the front end. For example, if the target download end is a certain web end and the information of the target download end includes the address of the web end, after the server obtains the address of the web end, it first writes the base class file set into the temporary folder, then creates a zip file object, reads each file in the temporary folder and adds it to the zip file, and finally sends the zip file to the target download end to complete the download of the base class file set by the target download end. Among them, in the process of sending the zip file to the web end, set the Content-Type of the HTTP header to application / octet-stream, that is, binary stream, and use the HTTP protocol to send the generated zip file to the web end.
[0054] For example, after generating the base class file set corresponding to the interface in the Node environment, use the fs (File System) package to write the base class file set into the temporary folder. This temporary folder is used to store the generated base class files for subsequent packaging into a zip file. fs is a core module in Node.js for handling file system operations. This module provides a series of methods to interact with the computer's file system, including reading files, writing files, deleting files, renaming files, etc.
[0055] After writing the base class file set into the temporary folder, use the third-party library jszip to create a zip file object, read the buffer information in the temporary folder area, read each base class file in the temporary folder, add them to the zip file, and then set the Content-Type to application / octet-stream for subsequent sending of the zip file to the Web end. Optionally, the zip file can be synchronously sent to multiple target download ends.
[0056] Adopting the method for processing interface information provided by this embodiment, after generating the base class file set, it can be automatically downloaded and transmitted to the target download end, and the target download end can receive the base class file corresponding to the interface in a timely manner, facilitating information interaction among interface developers. In addition, by creating a zip file and packaging multiple base class files in the base class file set into a zip file for transmission, the size of the transmitted data is reduced, improving the reliability of the overall transmission and the integrity of the file content.
[0057] Optionally, in one embodiment, after the step of sending the zip file to the target download end, the method for processing interface information further includes: deleting the temporary folder and the content in the temporary folder.
[0058] Specifically, send the jszip compressed package to the web side, and at the same time delete the temporary folder area, deleting the previously created temporary folder and its contents. Optionally, use the fs.rmdirSync method and set the {recursive: true} option to ensure that the entire folder and its contents are deleted.
[0059] By adopting the method for processing interface information provided by this embodiment, after the transmission of the compressed package to the target download end is completed, the temporary folder created in the Node.js environment and its contents are deleted, which can avoid environmental pollution in the node area and at the same time reduce unnecessary resource occupation.
[0060] Optionally, in one embodiment, after the step of generating the base class file set corresponding to the target interface, the method for processing interface information further includes: reading a preset synchronization mapping table, where the synchronization mapping table includes a repository address and an information publishing address corresponding to the code language type; querying the repository address and the information publishing address corresponding to the target language in the synchronization mapping table to obtain the target repository address and the target information publishing address; synchronizing the base class file set to the base class repository indicated by the target repository address; and publishing the synchronization information of the synchronized base class file set to the base class repository to the publishing platform indicated by the target information publishing address. Optionally, the method provided by the above embodiment can be adopted to write the base class file set into the temporary folder, create a compressed package object, read each file in the temporary folder and add it to the compressed package, and synchronize the compressed package to the base class repository.
[0061] Specifically, based on the fact that different clients use different code language types. For example, there is a client using oc, a client using Java, and another client using Python. The base class unit is converted into a code file corresponding to the target language, and the base class file set includes code files in the target language. That is to say, for different target languages, the code language types of the code files are different. Under different language environment requirements, when the target languages are different, the code language types of the generated code files are different, and the base class file sets are stored in different base class repositories so that clients of each code language type can access the corresponding base class repositories.
[0062] According to different language type requirements, a map table, that is, a synchronization mapping table, is preset and maintained to store the information required to synchronize the base class file sets of different code language types to the base class repository. For example, the mapping table adopts a key-value pair data structure. Optionally, the synchronization mapping table includes the repository address and the information release address corresponding to the code language type. For example, when the code language type is oc, the corresponding repository address and information release address are aaoc and bboc respectively; when the code language type is Java, the corresponding repository address and information release address are aajava and bbjava respectively; when the code language type is Python, the corresponding repository address and information release address are aapython and bbpython respectively.
[0063] The user can input a synchronization command through the front end. Based on this synchronization command, the server reads the map table, queries the repository address and information release address corresponding to the target language in the map table, then synchronizes the base class file set to the base class repository indicated by the target repository address, and sends the synchronization information of synchronizing the base class file set to the base class repository to the release platform indicated by the target information release address. The release platform displays the synchronization information of the base class repository to the client, and the client can know in real time the changes of the base class files in the base class repository.
[0064] Optionally, when naming the base class files, the base class name can be used for naming. When synchronizing the base class file set to the base class repository, if the base class repository already includes base class files with the same name, in order to comply with the principle that the same field must maintain the unity of the field and type, the method of overwriting files is adopted for synchronization to ensure that there is only one and the latest base class file of the same base class in the base class repository.
[0065] By using the method for processing interface information provided in this embodiment, after generating the base class file set, the base class file set can be synchronized to the base class repository corresponding to the base class file code type, and at the same time, the synchronization information is displayed on the release platform corresponding to the code type, which is convenient for developers of the corresponding code type to timely learn about the synchronization changes of the base class file set in the base class repository through the release platform, and access the base class repository to obtain the base class file set as needed. Moreover, the storage locations and synchronization information release platforms of different code classes do not affect each other, which is convenient for development management. In addition, by using the mapping table to automatically determine the target repository and release address, the automation of the synchronization process is realized, the development efficiency is improved; the base class file set is synchronized to the repository and information release platform specified by the target language, and developers can easily find the required resources and relevant information, which improves the convenience of access and use, and supports the synchronization management of multiple languages and multiple platforms.
[0066] Optionally, in one embodiment, the step of synchronizing the base class file set to the base class repository indicated by the target repository address includes: determining the base class repository indicated by the target repository address; cloning the base class repository to obtain a cloned repository; writing the base class file set into the cloned repository; and pushing the cloned repository to the repository address.
[0067] Specifically, when synchronizing the base class file set to the base class repository, after determining the base class repository, clone it locally to form a cloned repository; then write the base class file set in the cloned repository, and finally push the cloned repository to the repository address. The cloned repository overwrites the original base class repository, completing the synchronization of the base class file set to the base class repository.
[0068] Optionally, the base class repository is a Git repository. Using a Git repository can track and manage different versions of the base class file set. According to the information in the map table, synchronize the base class file set to the corresponding Git repository. This step can specifically use Git command-line tools, Git APIs, or libraries for Git operations. Once the base class file set is synchronized to the corresponding Git repository, the business development team can obtain updates in a timely manner for development, testing, etc. Further optionally, child_process can be used to execute a script to download the code of the base class repository to a sibling directory. Among them, child_process is one of the core modules of Node.js. In this step, child_process creates a child process to execute the script for downloading the code of the base class repository, cloning the remote repository code to the specified execution path locally. The map table can contain the Git repository address (GitURL), branch, and path corresponding to the code language type. When downloading the code of the base class repository, it can be downloaded according to the Git repository address (Git URL), branch, and path. The sibling directory refers to a directory at the same level as the current working directory where the script is executed (i.e., the directory where the Node.js process runs).
[0069] Adopting the method for processing interface information provided in this embodiment, cloning the base class repository locally, uploading the base class file set and then returning to the original repository address. First, it ensures that the update is made on the basis of the latest version of the base class repository, which helps to maintain the version consistency of the code library. At the same time, data processing is carried out in the cloned repository, which can reduce the conflicts that may occur when operating on the base class repository at the original location, increasing the security of the operation. Moreover, the cloned repository provides a safe environment for testing and validating updates, ensuring that it can be pushed after confirmation, which can improve the reliability of code changes and provide a structured, safe, and efficient method to synchronize the base class file set to the code repository.
[0070] Optionally, in one embodiment, the synchronization mapping table further includes tag information corresponding to the code language type. After the step of generating the base class file set corresponding to the target interface, the method for processing interface information further includes: querying the tag information corresponding to the target language in the synchronization mapping table; after the step of determining the base class repository indicated by the target repository address, before the step of cloning the base class repository to obtain a cloned repository, the step of synchronizing the base class file set to the base class repository indicated by the target repository address further includes: reading the tag of the base class repository; updating the tag of the base class repository with the tag information corresponding to the target language.
[0071] Specifically, tag information is also set in the mapping table. The tag information may include information such as version number, build number, timestamp, and business keywords. By using the tag information, a tag is added to the base class repository to facilitate quickly locating or reverting to the code with this specific tag when needed. Before synchronizing the base class file set to the target repository, first read the tag information from the mapping table, then read the tag of the base class repository, and update the tag of the base class repository with the tag information read from the mapping table.
[0072] For example, assuming that Git tags are used to represent version information in a Git repository, the child_process module of Node.js can be used to execute Git commands to dynamically obtain version information, and use the version information read from the mapping table to update the Git tag to update the latest version in real time.
[0073] By using the method for processing interface information provided in this embodiment, maintaining and storing tag information in the mapping table, when uploading the base class file set to the base class repository, first update the tag of the base class repository with the tag information to ensure in real time that users can always obtain the latest version of the current code repository, which also helps to ensure the traceability of the code status in different environments and provides a convenient method to obtain and use the code with specific tag information.
[0074] Optionally, in one embodiment, the step of publishing the information of synchronizing the base class file set to the information publishing platform according to the information update publishing address includes: scraping the log of the base class repository; parsing the log to obtain the dynamic information of the files in the base class repository; publishing the dynamic information to the information publishing platform according to the information update publishing address.
[0075] Specifically, in order to publish the accurate synchronization information of the base class file set, when publishing the synchronization information, first scrape the log of the base class repository. For example, use the child_process module of Node.js to execute the Git log command to scrape the Git log and obtain the latest status of the files in the base class repository, including the addition, modification, and deletion of files, and then publish this latest information to the information publishing platform.
[0076] Optionally, when the base class file set is written to the base class repository and the files in the base class repository change, a Git log scraping operation is triggered to scrape the Git log. The dynamic information obtained is automatically synchronized to the specified communication group through the Hooks function of the Feishu robot, enabling team members to promptly understand the latest project dynamics. This approach can enhance the team's collaboration efficiency, especially in scenarios involving distributed teams or collaboration among multiple project members.
[0077] By using the method for processing interface information provided in this embodiment, the dynamic information of the base class repository is obtained through log scraping and published to the information publishing platform, ensuring the accuracy and real-time nature of the dynamic information.
[0078] Optionally, Figure 2 The following is a flowchart of another method for processing interface information provided in Embodiment 1 of the present invention. As Figure 2 shown, the method for processing interface information provided in this embodiment includes the following steps S201 to S205.
[0079] Step S201: Obtain json-schema
[0080] The front end provides an interface configuration interface. Users can configure the interface based on the interface configuration interface. After the interface configuration is completed, click the automatic conversion key on the interface configuration interface to input the automatic conversion command. The back end responds to this automatic conversion command, obtains the interface information, including request and response parameters and other basic parameters, etc., converts the interface information into the corresponding json-schema data, and displays the json-schema data on the operation interface through the display window.
[0081] Step S202: Generate the base class in the corresponding language
[0082] On the human-computer interaction interface of the front end, options for the code language types to be converted and generated are provided. For example, it is possible to select to generate oc, java, Python, etc. The user selects one of them as the target language, and the back end generates the base class file set in the corresponding language from the json-schema.
[0083] Specifically, the json-schema data can be used to generate the base class file set in the corresponding language by calling the preset annotation parser, structure parser, reference parser, and language parser.
[0084] Step S2021: Call the annotation parser
[0085] The annotation parser extracts relevant annotations from the interface information for including appropriate annotations in the generated base class files. Annotations are usually used to provide code documentation, explain the uses of fields, or provide other relevant information, including global annotations, local parameter annotations, and input / output parameter annotations. The annotation parser generates annotation information and stores it in memory for use when generating the base class files later.
[0086] Step S2022: Invoke the structure parser
[0087] In json-schema data, according to the schema type, json objects are divided into 'string', 'number', 'integer', 'boolean', 'array', and 'object'.
[0088] Among them, when the structure parser encounters an object, it is necessary to extract the base class, that is, generate a new base class, corresponding to generating a new base class file later, and at the same time initiate a new structure parser for parsing. That is to say, every time an object is encountered, a base class is generated, and at the same time a new structure parser is initiated to parse other objects.
[0089] After the structure parser encounters an array, it is necessary to further parse according to the parameter category under the array. If the parameter under the array is an object, recursive traversal is performed, and at the same time a new structure parser is initiated to parse each element parameter in the array to generate a new base class.
[0090] Step S2023: Invoke the reference parser
[0091] Invoke the reference parser to parse the base classes referenced in the current base class, determine which base classes are referenced in each base class, remove duplicates of the repeatedly referenced base classes, and use the method of directly copying the base class content to reference the mutually referenced base classes to avoid reference loops.
[0092] Step S2024: Invoke the language parser
[0093] Invoke the language parser. According to the target language selected by the user, based on the above annotation information, as well as the base class information and reference information parsed and generated, generate the base class file corresponding to each base class, and finally form a set of base class files corresponding to the interface.
[0094] The generated set of base class files can be displayed on the human-computer interaction interface. For example, display the file list on one side and the content of the base class file on the other side. When the user places the cursor on a certain file in the file list, the content display area on the right shows the content of that file.
[0095] Step S203: Provide a download package
[0096] After the base class file set is converted, a zip compression package is generated in the node environment for download. Specifically, after generating the corresponding base class file set in the Node environment, use the fs package to write it to the staging folder area. After reading the buffer information of the staging file area according to the jsZip compression package, set the Content-Type to application / octet-stream, then send the jszip compression package to the web side, and at the same time delete the staging folder area to avoid environmental pollution in the node area.
[0097] Step S204: Synchronize the base class file set to the base class repository
[0098] Maintain a map table according to different client language environments, that is, the code language type, to store information such as the git address, branch, path, tag version, etc. that need to be synchronized by the current client.
[0099] According to the target language, query the map table to obtain the git address, branch, and path that the client needs to synchronize. Use child_process to execute the script. According to the queried git address, branch, and path, clone the repository code to the same-level directory. According to the version in the local git repository after cloning, automatically fetch, and use the tag version obtained by querying the map table to update to the latest tag version in real time.
[0100] Write the base class file set to the git repository in the local same-level directory, and then push and update the repository with the written files.
[0101] Step S205: Display dynamic information
[0102] Select the git log log capture method to obtain the latest status of the currently updated files in the base class repository in real time. Use the Feishu robot hooks to automatically synchronize the latest updated information to the project communication group and display the latest dynamic information in real time in the web environment.
[0103] In the method for processing interface information provided in this embodiment, information is provided through jsonSchema, and an annotation parser, a structure parser, a reference parser, and a language parser are configured to generate a base class file set in languages such as oc / java / ts, etc. Then it is synchronized to the corresponding repository or directly downloaded as a compression package, and finally the updated platform information is automatically synchronized. Using the method for processing interface information provided in the embodiments of the present invention, after the interface configuration is completed, the interface information is converted into a base class file set, and the base class file set will be automatically synchronized to the corresponding base class repository, and the updated information will be published on the information release platform. After that, only rely on the corresponding tag information to use the corresponding base class file.
[0104] Embodiment 2
[0105] Corresponding to the above Embodiment 1, Embodiment 2 of the present invention provides a processing device for interface information. For the corresponding technical feature details and corresponding technical effects, reference can be made to the above Embodiment 1, and will not be elaborated herein. Figure 3 It is a block diagram of the processing device for interface information provided in Embodiment 2 of the present invention, as Figure 3 shown, the device includes: a first acquisition module 301, a first processing module 302, a first parsing module 303, and a second processing module 304.
[0106] Among them, the first acquisition module 301 is used to acquire the interface information of the configured target interface; the first processing module 302 is used to generate json data corresponding to the interface information, where the data type of the json data includes at least one of object or array; the first parsing module 303 is used to generate a base class unit corresponding to the json object when the data type of the json object in the pick-up and drop data is object, and when the data type of the json object is array, further parse the parameters under the json object, and when the data type of the parameter is object, generate a base class unit corresponding to the parameter; the second processing module 304 is used to convert each of the base class units into a code file corresponding to the target language, and generate a set of base class files corresponding to the interface.
[0107] Optionally, in one embodiment, the device further includes: a second parsing module, which is used to parse the comments in the json data after the first processing module generates the json data corresponding to the interface information, and obtain multiple comment information, where the comment information includes global comment information, local parameter comment information, and input / output parameter comment information; the base class unit includes an entry base class unit and a non-entry base class unit, and the second processing module includes: a first processing unit, which is used to write the input / output parameter comment information into the entry base class unit, write the global comment information into each of the base class units, and write the local parameter comment information into the corresponding non-entry base class unit.
[0108] Optionally, in one embodiment, the first base class unit is any one of the base class units, and the device further includes: a third parsing module, which is used to parse the reference fields in the json data after the step of the first processing module generating the json data corresponding to the target interface information, and determine the base class unit referred to by the first base class unit; the second processing module 204 includes: a second processing unit, which is used to write the referred base class unit into the first base class unit.
[0109] Optionally, in one embodiment, when the second processing unit executes the step of writing the base class unit that references it in the first base class unit, the specific steps executed include: the first base class unit references the second base class unit and the third base class unit. If the second base class unit is the same as the third base class unit, only write the second base class unit in the first base class unit; the first base class unit references the fourth base class unit. If the first base class unit and the fourth base class unit reference each other, copy the content of the fourth base class unit to the first base class unit. If the first base class unit unidirectionally references the fifth base class unit, declare in the first base class unit that it references the fifth base class unit.
[0110] Optionally, in one embodiment, the device further includes: a second acquisition module, configured to acquire information of a target download end after the second processing module generates a base class file set corresponding to the target interface; a writing module, configured to write the base class file set into a temporary folder; a creation module, configured to create a compressed package object, read each file in the temporary folder and add it to the compressed package; and a sending module, configured to send the compressed package to the target download end.
[0111] Optionally, in one embodiment, the device further includes: a deletion module, configured to delete the temporary folder and the content in the temporary folder after the sending module sends the compressed package to the target download end.
[0112] Optionally, in one embodiment, the device further includes: a reading module, configured to read a pre-set synchronization mapping table after the second processing module generates a base class file set corresponding to the target interface, where the synchronization mapping table includes a repository address and an information publishing address corresponding to a code language type; a query module, configured to query the repository address and the information publishing address corresponding to the target language in the synchronization mapping table to obtain a target repository address and a target information publishing address; a synchronization module, configured to synchronize the base class file set to the base class repository indicated by the target repository address; and a publishing module, configured to publish the synchronization information of synchronizing the base class file set to the base class repository to the publishing platform indicated by the target information publishing address.
[0113] Optionally, in one embodiment, the synchronization module includes: a determination unit, configured to determine the base class repository indicated by the target repository address; a cloning unit, configured to clone the base class repository to obtain a cloned repository; a writing unit, configured to write the base class file set into the cloned repository; and a pushing unit, configured to push the cloned repository to the repository address.
[0114] Optionally, in one embodiment, the synchronization mapping table further includes tag information corresponding to the code language type, and the query module is further configured to query the tag information corresponding to the target language in the synchronization mapping table; the synchronization module further includes: a reading unit, configured to read the tags of the base class repository; an updating unit, configured to update the tags of the base class repository by using the tag information corresponding to the target language.
[0115] Optionally, in one embodiment, the publishing module includes: a scraping unit, configured to scrape the logs of the base class repository; an analysis unit, configured to analyze the logs to obtain the dynamic information of the files in the base class repository; a publishing unit, configured to publish the dynamic information to the information publishing platform according to the information update publishing address.
[0116] Embodiment III
[0117] This embodiment further provides a computer device, such as a smart phone, a tablet computer, a notebook computer, a desktop computer, a rack server, a blade server, a tower server, or a cabinet server (including an independent server or a server cluster composed of multiple servers) that can execute programs. As Figure 4 shown, the computer device 01 of this embodiment at least includes, but is not limited to, a memory 012 and a processor 011 that can communicate with each other through a system bus, as Figure 4 shown. It should be noted that Figure 4 only the computer device 01 with components memory 012 and processor 011 is shown, but it should be understood that it is not required to implement all the shown components, and more or fewer components can be alternatively implemented.
[0118] In this embodiment, the memory 012 (i.e., the readable storage medium) includes flash memory, hard disks, multimedia cards, card-type memories (e.g., SD or DX memories, etc.), random access memories (RAM), static random access memories (SRAM), read-only memories (ROM), electrically erasable programmable read-only memories (EEPROM), programmable read-only memories (PROM), magnetic memories, magnetic disks, optical disks, etc. In some embodiments, the memory 012 may be an internal storage unit of the computer device 01, such as the hard disk or memory of the computer device 01. In other embodiments, the memory 012 may also be an external storage device of the computer device 01, such as a plug-in hard disk equipped on the computer device 01, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. Of course, the memory 012 may also include both the internal storage unit and the external storage device of the computer device 01. In this embodiment, the memory 012 is generally used to store the operating system installed on the computer device 01 and various reference software, such as the program code of the processing device for interface information in Embodiment 2. In addition, the memory 012 may also be used to temporarily store various types of data that have been output or will be output.
[0119] In some embodiments, the processor 011 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 011 is generally used to control the overall operation of the computer device 01. In this embodiment, the processor 011 is used to run the program code stored in the memory 012 or process data, such as the processing method of interface information, etc.
[0120] Embodiment 4
[0121] This embodiment also provides a computer-readable storage medium, such as flash memory, hard disks, multimedia cards, card-type memories (e.g., SD or DX memories, etc.), random access memories (RAM), static random access memories (SRAM), read-only memories (ROM), electrically erasable programmable read-only memories (EEPROM), programmable read-only memories (PROM), magnetic memories, magnetic disks, optical disks, servers, App reference marketplaces, etc., on which a computer program is stored. When the program is executed by a processor, corresponding functions are implemented. The computer-readable storage medium of this embodiment is used to store the processing device for interface information, and when executed by a processor, implements the processing method of interface information in Embodiment 1.
[0122] It should be noted that in this text, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements not only includes those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising one..." does not exclude the presence of additional identical elements in the process, method, article or device comprising such element.
[0123] The serial numbers of the above embodiments of the present invention are for description only and do not represent the superiority or inferiority of the embodiments.
[0124] From the description of the above embodiments, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.
[0125] The above are only the preferred embodiments of the present invention, and do not limit the patent scope of the present invention accordingly. Any equivalent structure or equivalent process transformation made by using the specification and drawings of the present invention, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present invention.
Claims
1. A method for processing interface information, characterized in that, Including: Obtain the interface information of the configured target interface; Generate json data corresponding to the interface information, wherein the data type of the json data includes at least one of object or array; When it is parsed that the data type of the json object in the json data is object, generate a base class unit corresponding to the json object. When it is parsed that the data type of the json object is array, further parse the parameters under the json object. When the data type of the parameter is object, generate a base class unit corresponding to the parameter; Convert each of the base class units into a code file corresponding to the target language, and generate a set of base class files corresponding to the target interface.
2. The method for processing interface information according to claim 1, wherein After the step of generating json data corresponding to the interface information, the method further includes: parsing the comments in the json data to obtain multiple comment information, wherein the comment information includes global comment information, local parameter comment information, and input / output parameter comment information; The base class unit includes an entry base class unit and a non-entry base class unit. The step of generating a set of base class files corresponding to the target interface includes: writing the input / output parameter comment information into the entry base class unit, writing the global comment information into each of the base class units, and writing the local parameter comment information into the corresponding non-entry base class unit.
3. The method for processing interface information according to claim 1, wherein The first base class unit is any one of the base class units. After the step of generating json data corresponding to the interface information, the method further includes: parsing the reference fields in the json data to determine the base class units referenced by the first base class unit; The step of generating a set of base class files corresponding to the target interface includes: writing the base class units it references into the first base class unit.
4. The method for processing interface information according to claim 3, wherein The step of writing the base class units it references into the first base class unit includes: The first base class unit references a second base class unit and a third base class unit. If the second base class unit is the same as the third base class unit, only write the second base class unit into the first base class unit; The first base class unit references a fourth base class unit. If the first base class unit and the fourth base class unit reference each other, copy the content of the fourth base class unit to the first base class unit. If the first base class unit unidirectionally references a fifth base class unit, declare in the first base class unit that it references the fifth base class unit.
5. The method for processing interface information according to claim 1, wherein After the step of generating a set of base class files corresponding to the target interface, the method further includes: Obtain the information of the target download end; Write the set of base class files into a temporary folder; Create a zip object, read each file in the temporary folder and add it to the zip; Send the zip to the target download end.
6. The method for processing interface information according to claim 5, wherein After the step of sending the zip to the target download end, the method further includes: deleting the temporary folder and the content in the temporary folder.
7. The method for processing interface information according to claim 1, wherein After the step of generating the base class file set corresponding to the target interface, the method further includes: Reading a preset synchronization mapping table, where the synchronization mapping table includes a repository address and an information publishing address corresponding to a code language type; Querying the repository address and the information publishing address corresponding to the target language in the synchronization mapping table to obtain a target repository address and a target information publishing address; Synchronizing the base class file set to the base class repository indicated by the target repository address; and Publishing the synchronization information of synchronizing the base class file set to the base class repository to the publishing platform indicated by the target information publishing address.
8. The method for processing interface information according to claim 7, wherein The step of synchronizing the base class file set to the base class repository indicated by the target repository address includes: Determining the base class repository indicated by the target repository address; Cloning the base class repository to obtain a cloned repository; Writing the base class file set into the cloned repository; Pushing the cloned repository to the repository address.
9. The method for processing interface information according to claim 8, wherein The synchronization mapping table further includes tag information corresponding to the code language type. After the step of generating the base class file set corresponding to the target interface, the method further includes: querying the tag information corresponding to the target language in the synchronization mapping table; After the step of determining the base class repository indicated by the target repository address and before the step of cloning the base class repository to obtain a cloned repository, the step of synchronizing the base class file set to the base class repository indicated by the target repository address further includes: reading the tag of the base class repository; updating the tag of the base class repository with the tag information corresponding to the target language.
10. The method for processing interface information according to claim 7, wherein The step of publishing the information of synchronizing the base class file set to the information publishing platform according to the information update publishing address includes: Fetching the log of the base class repository; Parsing the log to obtain the dynamic information of the files in the base class repository; Publishing the dynamic information to the information publishing platform according to the information update publishing address.
11. A processing device for interface information, characterized in that, Includes: An acquisition module for acquiring interface information for configuring a target interface; A first processing module for generating json data corresponding to the interface information, where the data type of the json data includes at least one of object or array; A parsing module for generating a base class unit corresponding to the json object when parsing that the data type of the json object in the json data is object, and further parsing the parameters under the json object when parsing that the data type of the json object is array, and generating a base class unit corresponding to the parameter when the data type of the parameter is object; A second processing module for converting each of the base class units into a code file corresponding to the target language and generating a base class file set corresponding to the interface.
12. A computer device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor implements the steps of the method according to any one of claims 1 to 10 when executing the computer program.
13. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program implements the steps of the method according to any one of claims 1 to 10 when executed by a processor.