Software toolkit development method and device, computer equipment and storage medium
By automatically parsing interface documents and generating request messages using annotation and reflection techniques, the problems of low development efficiency and high error rate in traditional SDK development methods are solved, and seamless conversion from interface declaration to development toolkit code is achieved, ensuring that Standardization and maintainability of code.
Patent Information
- Application Number
- CN202411209536.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2024-12-13
AI Technical Summary
Traditional SDK development methods require developers to manually assemble request messages, resulting in low development efficiency and easy to miss fields when there are many API fields, resulting in API calls failure or data errors.
By reading interface declarations in interface documents, identifying and defining data transmission object classes, generating request messages using annotation and reflection techniques, and integrating interface declarations and request messages through a preset code template engine to generate development toolkit code.
Implement automated analysis of interface documents, quickly generate accurate data transmission objects and request messages, reduce manual coding workload and error rate, ensure code standardization and maintainability, improve development efficiency and reduce manual coding work quantity and error rate.
Smart Images

Figure CN119127285A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of software development technology, and specifically relates to a software toolkit development method, device, computer equipment and storage medium. Background Art
[0002] SDK (Software Development Kit) is a set of development tools for software developers to build application software, including specific software packages, software frameworks, hardware platforms, operating systems, etc. These development tools usually include APIs (application programming interfaces), library files, documents, sample codes, compilers, debuggers, etc., and are designed to help developers create, test, deploy, and manage applications more easily and efficiently.
[0003] Traditional SDKs only provide encryption, decryption, signature, and signature verification functions, but do not provide specific call examples for each API, including how to construct request parameters, process response data, etc. Therefore, developers need to read the API documentation to understand the purpose, parameters, request format, and response format of each API, and manually assemble request messages based on this information. This not only reduces development efficiency, but also makes it easy to miss some fields during document reading when there are many API fields, resulting in API call failure or data errors. Summary of the invention
[0004] The purpose of the embodiments of the present application is to propose a software toolkit development method, apparatus, computer equipment and storage medium to solve the technical problem that the existing SDK adopts the method of manually assembling request messages, which not only has low development efficiency, but also easily misses certain fields during the document reading process when there are many API fields, resulting in the final API call failure or data errors.
[0005] In order to solve the above technical problems, the present application embodiment provides a software toolkit development method, which adopts the following technical solution:
[0006] A software toolkit development method, comprising:
[0007] Read the interface declaration in the interface document, where the interface declaration includes interface function, request method, request path, request parameters, and return type;
[0008] Identify the data transfer object corresponding to the interface according to the interface declaration, define the data transfer object class, and generate the fields of the data transfer object class;
[0009] Use annotation and reflection technology to generate request messages based on the fields of the data transfer object class;
[0010] Use the preset code template engine to generate development kit code from interface declarations and request messages.
[0011] Further, the steps of identifying the data transfer object corresponding to the interface according to the interface declaration, defining the data transfer object class, and generating fields of the data transfer object class specifically include:
[0012] Parse the interface declaration and obtain the interface's incoming and outgoing parameters;
[0013] Identify the data transmission object of the input and output parameters of the interface based on the input parameters and the output parameters, and obtain the data transmission object corresponding to the interface;
[0014] Create a corresponding class object for the data transfer object corresponding to the interface to obtain the data transfer object class;
[0015] A data item associated with the data transmission object class is acquired, and a field corresponding to the data item is generated in the data transmission object class to obtain the field of the data transmission object class.
[0016] Further, the step of identifying the data transmission object of the input and output parameters of the interface based on the input parameters and the output parameters, and obtaining the data transmission object corresponding to the interface specifically includes:
[0017] Determine the request body structure of the interface based on the incoming parameters;
[0018] Determine the response body structure of the interface based on the outgoing parameters;
[0019] Identify the interface's input parameter data transfer object from the request body structure, and identify the interface's output parameter data transfer object from the response body structure.
[0020] Furthermore, the steps of using annotation and reflection technology to generate a request message based on the fields of the data transmission object class specifically include:
[0021] Get the mapping relationship and validation rules between the fields of the data transfer object class;
[0022] Annotate the mapping relationship and validation rules to obtain field annotation information;
[0023] When processing data transfer object classes, use the reflection API to query field annotation information;
[0024] Generate a request message based on the queried field annotation information.
[0025] Furthermore, the step of generating a request message according to the queried field annotation information specifically includes:
[0026] Create a JSON object corresponding to the request message, where the JSON object consists of key-value pairs;
[0027] Identify the annotation name in the field annotation information;
[0028] Generate a request message by using the annotation name as the key of the JSON object and the fields of the data transfer object class as the value of the JSON object.
[0029] Furthermore, before the step of reading the interface declaration in the interface document, the method further includes:
[0030] Traverse each data interface in the preset interface database, read the interface declaration of each data interface, and identify the interface type of each data interface;
[0031] Define a corresponding code template for the data interface of each interface type to obtain several interface code templates;
[0032] Build a code template engine based on several interface code templates.
[0033] Furthermore, the interface code template includes a static code structure and a placeholder, the placeholder includes an interface declaration placeholder and a request message placeholder, and the steps of generating a development toolkit code from the interface declaration and the request message using a preset code template engine specifically include:
[0034] Determine a matching interface code template based on the interface declaration of each interface;
[0035] Fill the interface declaration of each interface into the interface declaration placeholder matching the interface code template;
[0036] Fill the request message of each interface into the request message placeholder matching the interface code template to obtain the development toolkit code.
[0037] In order to solve the above technical problems, the embodiment of the present application also provides a software toolkit development device, which adopts the following technical solution:
[0038] A software toolkit development device, comprising:
[0039] An interface declaration reading module is used to read the interface declaration in the interface document, wherein the interface declaration includes the interface function, request method, request path, request parameters and return type;
[0040] A class field generation module is used to identify the data transfer object corresponding to the interface according to the interface declaration, define the data transfer object class, and generate fields of the data transfer object class;
[0041] The request message generation module is used to generate request messages based on the fields of the data transfer object class using annotations and reflection technology;
[0042] The toolkit code generation module is used to generate development toolkit code from interface declarations and request messages using a preset code template engine.
[0043] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0044] A computer device comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the software toolkit development method as described in any one of the above when executing the computer-readable instructions.
[0045] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0046] A computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the software toolkit development method as described in any one of the above.
[0047] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0048] The present application discloses a software toolkit development method, device, computer equipment and storage medium, belonging to the field of software development technology. First, the information in the interface document is parsed, including function description, request method, path, parameters and return type. Subsequently, the data transmission object class matching the interface is identified and defined, and the field of the object class is generated according to the interface declaration. Then, the field of the data transmission object class is constructed as a request message by using annotation and reflection technology. Finally, by integrating a preset code template engine, the interface declaration and the request message are integrated to generate a standardized development toolkit code. The present application automates the parsing of interface documents to quickly generate accurate data transmission objects and request messages, thereby reducing the workload and error rate of manual coding. By combining annotation, reflection technology and code template engine, a seamless conversion from interface declaration to development toolkit code is realized, ensuring the standardization and maintainability of the code, thereby achieving the consistency and standardization of software toolkit development, improving development efficiency, and reducing the workload and error rate of manual coding. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0050] Figure 1An exemplary system architecture diagram is shown in which the present application can be applied;
[0051] Figure 2 A flowchart of an embodiment of a software toolkit development method according to the present application is shown;
[0052] Figure 3 A schematic structural diagram of an embodiment of a software toolkit development device according to the present application is shown;
[0053] Figure 4 A schematic structural diagram of an embodiment of a computer device according to the present application is shown. DETAILED DESCRIPTION
[0054] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0055] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0056] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0057] like Figure 1 As shown, the system architecture 100 may include a terminal device 101, a network 102 and a server 103. The terminal device 101 may be a laptop 1011, a tablet computer 1012 or a mobile phone 1013. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired, wireless communication links or optical fiber cables.
[0058] The user can use the terminal device 101 to interact with the server 103 through the network 102 to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0059] The terminal device 101 can be any electronic device with a display screen and supporting web browsing. In addition to a laptop computer 1011, a tablet computer 1012 or a mobile phone 1013, the terminal device 101 can also be an e-book reader, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV), a laptop computer, a desktop computer, etc.
[0060] The server 103 may be a server that provides various services, such as a background server that provides support for a web page displayed on the terminal device 101 .
[0061] It should be noted that the software toolkit development method provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the software toolkit development device is generally set in the server / terminal device.
[0062] It should be understood that Figure 1 The numbers of terminal devices, networks and servers in the embodiment are merely illustrative. The above system may have any number of terminal devices, networks and servers according to implementation requirements.
[0063] Traditional SDKs only provide encryption, decryption, signature, and signature verification functions, but do not provide specific call examples for each API, including how to construct request parameters, process response data, etc. Therefore, developers need to read the API documentation to understand the purpose, parameters, request format, and response format of each API, and manually assemble request messages based on this information. This not only reduces development efficiency, but also makes it easy to miss some fields during document reading when there are many API fields, resulting in API call failure or data errors.
[0064] In order to solve the above technical problems, this application simplifies and accelerates the process of developers integrating the APIs of specific products or services into their own applications by building an efficient and easy-to-use product-level SDK development system, while reducing the manual coding work they need to do in this process. The SDK development system automatically parses interface documents and quickly generates accurate data transmission objects and request messages, reducing the workload and error rate of manual coding. It combines annotations, reflection technology and code template engines to achieve seamless conversion from interface declarations to development toolkit code, ensuring the standardization and maintainability of the code, thereby achieving consistency and standardization of software toolkit development, improving development efficiency, and reducing the workload and error rate of manual coding.
[0065] Continue to refer Figure 2 , shows a flow chart of an embodiment of a method for developing a software toolkit according to the present application. The software toolkit development method comprises the following steps:
[0066] S201, reading an interface declaration in an interface document, wherein the interface declaration includes an interface function, a request method, a request path, request parameters, and a return type.
[0067] Specifically, the system reads the interface declaration from the interface document. The interface declaration is a key part of the API (application programming interface) document, which defines how to interact with the backend service. The interface declaration includes the interface function, request method, request path, request parameters, and return type, among which:
[0068] Interface function: briefly describe the function or purpose of the interface.
[0069] Request method: HTTP request method, such as GET, POST, PUT, DELETE, etc. Each method corresponds to different operations.
[0070] Request path: Also known as URL path or endpoint, it is the access address of the API.
[0071] Request parameters: data that needs to be passed when calling an interface, which may include path parameters, query parameters, request body parameters, etc.
[0072] Return type: The data type or structure of the interface response, usually including status code and response body parameters.
[0073] S202, identifying the data transmission object corresponding to the interface according to the interface declaration, defining the data transmission object class, and generating fields of the data transmission object class.
[0074] Data Transfer Objects (DTOs) are objects used to encapsulate and transfer data, usually used to transfer data between different layers (such as the service layer and the presentation layer) or different systems. In the SDK, Data Transfer Objects DTOs are usually defined as a set of simple Java classes used to encapsulate API request and response data. Each interface has corresponding input and output Data Transfer Objects DTOs.
[0075] Specifically, first, the system needs to traverse the interface declaration and obtain the interface declaration information, which usually includes information such as the interface's functional description, request method, request path, request parameters, and return type. From this information, you can identify which data is input (data in the request body) and which is output (data in the response body), and these data need to be encapsulated into DTOs classes. For each set of interface declaration information identified, one or more DTOs classes need to be defined to encapsulate these data. The naming of the DTOs class reflects the purpose or content of the data it encapsulates. After defining the DTOs class, you need to generate fields for the class based on the actual data structure. The naming and type of the fields should match the data described in the interface declaration to ensure the accuracy and consistency of the data.
[0076] S203, using annotation and reflection technology, generating a request message based on the fields of the data transmission object class.
[0077] In this technical solution, reflection and annotation are two key programming technologies. Reflection and annotation are used closely together, enabling the SDK to automatically convert data transfer objects DTOs into request messages (such as JSON strings), thereby simplifying the API call process and improving the maintainability and scalability of the code.
[0078] Annotations are a way for programming languages such as Java to add metadata to code. Metadata is data about data. Metadata provides additional information for the code. This information is not directly executed by the program, but can be used by the compiler, runtime environment, or other tools to generate code, perform checks, or perform other processing. Using annotations on DTOs, you can mark the mapping relationship of fields (such as JSON field names), validation rules, etc.
[0079] Reflection is a mechanism provided by programming languages such as Java that allows programs to query and manipulate the properties and behaviors of classes and objects at runtime. Through reflection, programs can dynamically create objects, call methods, access and modify fields, etc.
[0080] Specifically, annotations are used on data transfer objects DTOs to mark field mapping relationships (such as JSON field names), validation rules, etc. Inside the SDK, the reflection mechanism is used to read these annotations and automatically convert DTO objects into request messages (such as JSON strings).
[0081] S204, using a preset code template engine to generate a development toolkit code from the interface declaration and the request message.
[0082] The code template engine is composed of code templates pre-set according to the interface type. These code templates can automatically generate SDK code according to the interface information and request messages. The code templates include static code structures and placeholders. The placeholders are used to receive interface information and request messages.
[0083] Specifically, during the software development process, the preset code template engine is used to automatically generate SDK code based on the interface declaration and request message of the interface. The code template engine is a key component that contains a series of predefined code templates, which are usually designed based on common programming patterns and best practices to generate specific types of code snippets, such as API client code, service layer code, etc. The template engine supports filling dynamic data (such as interface declarations and request messages) into placeholder positions in the template at runtime to generate a complete code file. The system uses the preset code template engine to automatically generate the corresponding SDK code using the interface declaration and request message as input. These codes usually include the calling method of the API client, the encapsulation of request parameters, the parsing of response results, and other logic. The generated SDK code can be directly referenced and used by developers to simplify the interaction process with the backend API.
[0084] In the above embodiment, the present application automatically parses the interface document to quickly generate accurate data transmission objects and request messages, thereby reducing the workload and error rate of manual coding. By combining annotations, reflection technology and code template engines, it achieves a seamless conversion from interface declarations to development toolkit codes, ensuring the standardization and maintainability of the code, thereby achieving consistency and standardization of software toolkit development, improving development efficiency, and reducing the workload and error rate of manual coding.
[0085] Further, the steps of identifying the data transfer object corresponding to the interface according to the interface declaration, defining the data transfer object class, and generating fields of the data transfer object class specifically include:
[0086] Parse the interface declaration and obtain the interface's incoming and outgoing parameters;
[0087] Identify the data transmission object of the input and output parameters of the interface based on the input parameters and the output parameters, and obtain the data transmission object corresponding to the interface;
[0088] Create a corresponding class object for the data transfer object corresponding to the interface to obtain the data transfer object class;
[0089] A data item associated with the data transmission object class is acquired, and a field corresponding to the data item is generated in the data transmission object class to obtain the field of the data transmission object class.
[0090] In this embodiment, first, a parsing mechanism is required to read the interface declaration, which is usually done by parsing the interface document (such as JSON, YAML or Swagger file). The parser can extract all relevant information in the interface declaration, including incoming parameters and outgoing parameters. Then, identify which parts correspond to the data transfer objects DTOs from the interface declaration, which usually involves analyzing the data structure of the request and response. Then, for each identified DTOs, create a corresponding class object. The name of the class object should be named according to the purpose or content of the DTO for easy understanding and maintenance. The definition of the class object should include necessary package declarations, class declarations, and any possible import statements. Finally, according to the structure of the DTOs, a corresponding field is generated for each data item in the class object. The type of the field is determined according to the type of the data item, such as String, int, Date, etc.
[0091] In software programming, DTOs are usually implemented by defining a class that will contain fields corresponding to the DTOs structure. Each data item will be mapped to a field in the class. In this way, when data is passed through DTOs, the data can be stored in an instance of the class and accessed or manipulated when needed.
[0092] For example, if there is a DTOs representing user information, including data items such as the user's ID, name, email, and age, then when defining the DTOs class for user information, the system will generate corresponding fields for these data items, such as userId, name, email, and age.
[0093] In the SDK, when the client library is generated according to the API definition, the API definition (such as the Swagger / OpenAPI document) is read through the automated code generation tool (such as SwaggerCodegen, OpenAPI Generator, etc.), the DTOs structure is identified, and the class code containing the corresponding fields is automatically generated.
[0094] Through the above steps, the interface document is automatically parsed, DTOs are extracted and identified, and then the corresponding class objects and field definitions are generated, which not only improves the accuracy and efficiency of code generation, but also ensures the consistency of DTOs and interface documents, reducing manual coding errors. At the same time, standardized naming and type definitions enhance the readability and maintainability of the code.
[0095] Further, the step of identifying the data transmission object of the input and output parameters of the interface based on the input parameters and the output parameters, and obtaining the data transmission object corresponding to the interface specifically includes:
[0096] Determine the request body structure of the interface based on the incoming parameters;
[0097] Determine the response body structure of the interface based on the outgoing parameters;
[0098] Identify the interface's input parameter data transfer object from the request body structure, and identify the interface's output parameter data transfer object from the response body structure.
[0099] In this embodiment, first, the system reads the interface declaration and extracts all relevant information in the interface declaration, including input parameters and output parameters, etc., wherein the input parameters define the request body structure of the data transfer objects DTOs, and the output parameters define the response body structure of the data transfer objects DTOs.
[0100] Suppose there is an API for an online shopping platform, one of which is used to create a new order. The user (or client application) submits the order information through this interface, the server receives and processes the information, and finally returns a response containing the order creation result.
[0101] In this scenario, the incoming parameters define the structure of the request body, which contains one or more Data Transfer Objects (DTOs). For example, the main structure of the request body is OrderCreationDTO, which contains all the information required to create an order, such as the customer ID, the list of purchased items, and the shipping address. Once the server processes the request and creates the order, it will return a response, which is also defined by one or more DTOs. For example, the main structure of the response body is OrderCreationResponseDTO, which contains the result of the order creation operation, such as the order ID, order status (created), and order total. This DTO clearly defines the structure of the response body, making it easy for the client to parse and display this information to the user.
[0102] The system then determines the request body structure of the interface based on the incoming parameters, and determines the response body structure of the interface based on the outgoing parameters; then identifies the input parameter data transmission object of the interface from the request body structure, and identifies the output parameter data transmission object of the interface in the response body structure.
[0103] Through the above steps, the interface parameters can be accurately parsed, and the data transmission objects of the input and output parameters can be automatically identified and extracted, which significantly simplifies the interface design and development process, ensures the clear definition of interface request and response data, and improves the readability and maintainability of the code.
[0104] Furthermore, the steps of using annotation and reflection technology to generate a request message based on the fields of the data transmission object class specifically include:
[0105] Get the mapping relationship and validation rules between the fields of the data transfer object class;
[0106] Annotate the mapping relationship and validation rules to obtain field annotation information;
[0107] When processing data transfer object classes, use the reflection API to query field annotation information;
[0108] Generate a request message based on the queried field annotation information.
[0109] In this embodiment, in the SDK, DTOs are usually defined as a set of simple Java classes that encapsulate API request and response data. By using annotations on the fields of DTOs, the mapping relationship between these fields and formats such as JSON and the validation rules that need to be met can be clearly specified. The SDK will read these annotations at runtime or compile time, and generate request messages or perform other processing based on the information in the annotations. In this way, developers do not need to manually write a lot of conversion and validation code, which improves development efficiency.
[0110] Inside the SDK, the reflection mechanism is used to read the annotations on DTOs and dynamically convert the DTOs objects into request messages (such as JSON strings) based on these annotations. This conversion process is automated and developers do not need to manually write conversion code. The reflection mechanism makes the SDK more flexible. Since the reflection mechanism dynamically processes objects at runtime, it can easily adapt to different data structures and request formats. In addition, when the API interface changes, developers only need to update the annotations on the DTOs and the corresponding processing logic without modifying a large amount of conversion code.
[0111] Through the above steps, this application uses annotation and reflection technology to generate request messages based on the fields of the data transfer object class. After that, developers can call the API interface like calling local methods without having to worry about the underlying details such as the assembly of request messages and the parsing of response messages. This not only improves development efficiency, but also reduces the risk of errors.
[0112] Furthermore, the step of generating a request message according to the queried field annotation information specifically includes:
[0113] Create a JSON object corresponding to the request message, where the JSON object consists of key-value pairs;
[0114] Identify the annotation name in the field annotation information;
[0115] Generate a request message by using the annotation name as the key of the JSON object and the fields of the data transfer object class as the value of the JSON object.
[0116] JSON objects consist of key-value pairs, where the key is a string and the value can be a string, a number, a Boolean, an array, an object (that is, a nested object), or null.
[0117] In this embodiment, first, the system defines annotations for the fields in the DTOs class. These annotations are used to describe additional information about the fields, such as the field name in JSON, whether validation is required, etc. When declaring the fields of the DTOs class, use the annotations defined previously to mark these fields. For example, use the @JsonProperty annotation to specify the field name in JSON. Inside the SDK, write logic to process these DTOs. This part of the logic usually includes reading the annotations of the DTOs and performing corresponding operations based on the information in the annotations. When processing DTOs, the SDK uses the Java reflection API to dynamically query the annotations on the DTOs class and its fields. Through reflection, the SDK can obtain information in the annotations, such as field name mapping, validation rules, etc.
[0118] Then, the SDK builds the request message based on the information read from the annotation. For example, if a field in the DTOs class uses the @JsonProperty annotation, the SDK will use the name specified in the annotation as the key of the JSON object. The field value of the DTOs class is converted to an appropriate format (such as a string, number, etc.) and embedded in the request message as the value of the JSON object.
[0119] In programming languages such as Java, when the @JsonProperty annotation is used on a field of DTOs and a name is explicitly specified in this annotation, the SDK will not use the name of the field in the Java class as the key of the JSON object when serializing the DTO object into a JSON string. Instead, it will use the name specified in the @JsonProperty annotation as the key.
[0120] The above steps allow developers to customize the key names of JSON objects without affecting the Java class structure, which is very useful for scenarios that need to meet specific API requirements or maintain consistency with front-end code. The field names in the Java class are not intuitive or easy to understand. The @JsonProperty annotation can provide a clearer and more descriptive key name, thereby improving the readability of JSON data.
[0121] In addition, when the API is upgraded or changed, if the field name of the DTOs class changes, but the front-end code still relies on the old JSON key name, the @JsonProperty annotation can maintain the stability of the JSON key name, thereby reducing the impact on the front-end code.
[0122] Furthermore, before the step of reading the interface declaration in the interface document, the method further includes:
[0123] Traverse each data interface in the preset interface database, read the interface declaration of each data interface, and identify the interface type of each data interface;
[0124] Define a corresponding code template for the data interface of each interface type to obtain several interface code templates;
[0125] Build a code template engine based on several interface code templates.
[0126] In this embodiment, first, the system needs to define code templates for different types of data interfaces. These templates usually exist in the form of text files, containing static code structures and some placeholders, which will be replaced by actual data (such as interface declarations, request messages, etc.) during the code generation process. The template engine supports multiple template syntaxes, such as FreeMarker, Velocity, Handlebars, etc. The code template allows developers to define template files and use these data to fill in the templates at runtime. After the system defines the corresponding code templates for the data interface of each interface type and obtains several interface code templates, it configures the template engine and builds the code template engine based on several interface code templates.
[0127] Through the above steps, code templates for multiple types of data interfaces are predefined, and combined with a flexible template engine, the automatic generation of development toolkit code is realized, the interface code writing process is simplified, and the rapid iteration and deployment of the system is promoted.
[0128] Furthermore, the interface code template includes a static code structure and a placeholder, the placeholder includes an interface declaration placeholder and a request message placeholder, and the steps of generating a development toolkit code from the interface declaration and the request message using a preset code template engine specifically include:
[0129] Determine a matching interface code template based on the interface declaration of each interface;
[0130] Fill the interface declaration of each interface into the interface declaration placeholder matching the interface code template;
[0131] Fill the request message of each interface into the request message placeholder matching the interface code template to obtain the development toolkit code.
[0132] Static code structure refers to those parts of the code template that do not change with the interface, such as the basic framework of the function, error handling logic, necessary comments, etc.
[0133] Placeholders are used as markers that are replaced by actual interface information during code generation, including interface declaration placeholders and request message placeholders. Interface declaration placeholders are used to replace specific interface names, parameter lists, return types, and other information, while request message placeholders are used to replace the request body structure of a specific interface, usually including the name and type of request parameters, and other information.
[0134] In this embodiment, the system selects a suitable code template in the code template engine according to the characteristics of the interface (such as HTTP method, request type, etc.), fills the specific information of the interface (such as interface name, parameter list, etc.) into the interface declaration placeholder in the code template, and then converts the request message structure of the interface (such as JSON or XML format) into the data structure or parameter list in the code, and fills it into the request message placeholder in the code template to realize automatic writing of development toolkit code.
[0135] Through the above steps, the code template is accurately matched according to the interface characteristics, and the specific interface information and request message structure are directly converted into the development toolkit code, which significantly improves the development efficiency, reduces the tediousness and errors of manual coding, and ensures the consistency and standardization of the code.
[0136] In the above embodiment, the present application discloses a software toolkit development method, which belongs to the field of software development technology. First, the information in the interface document is parsed, including function description, request method, path, parameters and return type. Subsequently, the data transmission object class matching the interface is identified and defined, and the fields of the object class are generated according to the interface declaration. Next, the fields of the data transmission object class are constructed as request messages using annotation and reflection technology. Finally, by integrating a preset code template engine, the interface declaration and the request message are integrated to generate a standardized development toolkit code. The present application automates the parsing of interface documents to quickly generate accurate data transmission objects and request messages, thereby reducing the workload and error rate of manual coding, and combines annotation, reflection technology and code template engines to achieve seamless conversion from interface declaration to development toolkit code, ensuring the standardization and maintainability of the code, thereby achieving consistency and standardization of software toolkit development, improving development efficiency, and reducing the workload and error rate of manual coding.
[0137] In this embodiment, the software toolkit development method is executed on the electronic device (eg Figure 1 The server shown in the figure) can receive instructions or obtain data through a wired connection or a wireless connection. It should be noted that the above wireless connection method may include but is not limited to 3G / 4G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.
[0138] It should be emphasized that in order to further ensure the privacy and security of the above-mentioned interface document information, the above-mentioned interface document information can also be stored in a node of a blockchain.
[0139] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0140] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0141] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0142] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0143] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0144] Further references Figure 3 , as a response to the above Figure 2 The present application provides an embodiment of a software toolkit development device, and the device embodiment is Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0145] like Figure 3 As shown, the software toolkit development device 300 described in this embodiment includes:
[0146] The interface declaration reading module 301 is used to read the interface declaration in the interface document, wherein the interface declaration includes the interface function, request method, request path, request parameters and return type;
[0147] A class field generation module 302, used to identify the data transmission object corresponding to the interface according to the interface declaration, define the data transmission object class, and generate fields of the data transmission object class;
[0148] A request message generation module 303, used to generate a request message based on the fields of the data transmission object class using annotation and reflection technology;
[0149] The toolkit code generation module 304 is used to generate development toolkit code from the interface declaration and request message using a preset code template engine.
[0150] Furthermore, the class field generation module 302 is specifically used for:
[0151] Parse the interface declaration to obtain the input parameters and outgoing parameters of the interface; identify the data transfer objects of the input and outgoing parameters of the interface based on the input parameters and outgoing parameters, and obtain the data transfer object corresponding to the interface; create a corresponding class object for the data transfer object corresponding to the interface, and obtain the data transfer object class; obtain the data items associated with the data transfer object class, and generate fields corresponding to the data items in the data transfer object class, and obtain the fields of the data transfer object class.
[0152] Furthermore, the class field generation module 302 is further used for:
[0153] Determine the request body structure of the interface based on the incoming parameters; determine the response body structure of the interface based on the outgoing parameters; identify the input parameter data transmission object of the interface from the request body structure, and identify the output parameter data transmission object of the interface in the response body structure.
[0154] Furthermore, the request message generation module 303 is specifically used for:
[0155] Get the mapping relationship and validation rules between the fields of the data transfer object class;
[0156] Annotate the mapping relationship and validation rules to obtain field annotation information;
[0157] When processing data transfer object classes, use the reflection API to query field annotation information;
[0158] Generate a request message based on the queried field annotation information.
[0159] Furthermore, the request message generation module 303 is further used to:
[0160] Create a JSON object corresponding to the request message, where the JSON object consists of key-value pairs;
[0161] Identify the annotation name in the field annotation information;
[0162] Generate a request message by using the annotation name as the key of the JSON object and the fields of the data transfer object class as the value of the JSON object.
[0163] Furthermore, the software toolkit development device 300 also includes a template engine construction module, and the code template engine construction module is specifically used for:
[0164] Traverse each data interface in the preset interface database, read the interface declaration of each data interface, and identify the interface type of each data interface; define a corresponding code template for each data interface type to obtain several interface code templates; and build a code template engine based on several interface code templates.
[0165] Furthermore, the interface code template includes a static code structure and placeholders, the placeholders include an interface declaration placeholder and a request message placeholder, and the toolkit code generation module 304 is specifically used for:
[0166] Determine a matching interface code template based on the interface declaration of each interface;
[0167] Fill the interface declaration of each interface into the interface declaration placeholder matching the interface code template;
[0168] Fill the request message of each interface into the request message placeholder matching the interface code template to obtain the development toolkit code.
[0169] In the above embodiment, the present application discloses a software toolkit development device, which belongs to the field of software development technology. First, the information in the interface document is parsed, including function description, request method, path, parameters and return type. Subsequently, the data transmission object class matching the interface is identified and defined, and the fields of the object class are generated according to the interface declaration. Next, the fields of the data transmission object class are constructed as request messages using annotation and reflection technology. Finally, by integrating a preset code template engine, the interface declaration and the request message are integrated to generate standardized development toolkit code. The present application automatically parses the interface document to quickly generate accurate data transmission objects and request messages, thereby reducing the workload and error rate of manual coding, and combines annotation, reflection technology and code template engine to achieve seamless conversion from interface declaration to development toolkit code, ensuring the standardization and maintainability of the code, thereby achieving consistency and standardization of software toolkit development, improving development efficiency, and reducing the workload and error rate of manual coding.
[0170] To solve the above technical problems, the present application also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0171] The computer device 4 includes a memory 41, a processor 42, and a network interface 43 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 4 with a memory 41, a processor 42, and a network interface 43, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0172] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0173] The memory 41 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 41 can be an internal storage unit of the computer device 4, such as a hard disk or memory of the computer device 4. In other embodiments, the memory 41 can also be an external storage device of the computer device 4, such as a plug-in hard disk equipped on the computer device 4, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 41 can also include both the internal storage unit of the computer device 4 and its external storage device. In this embodiment, the memory 41 is generally used to store the operating system and various application software installed on the computer device 4, such as computer-readable instructions of the software toolkit development method, etc. In addition, the memory 41 can also be used to temporarily store various types of data that have been output or are to be output.
[0174] The processor 42 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip in some embodiments. The processor 42 is generally used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is used to run the computer-readable instructions stored in the memory 41 or process data, such as running the computer-readable instructions of the software toolkit development method.
[0175] The network interface 43 may include a wireless network interface or a wired network interface. The network interface 43 is generally used to establish a communication connection between the computer device 4 and other electronic devices.
[0176] In the above embodiment, the present application discloses a computer device, which belongs to the field of software development technology. First, the information in the interface document is parsed, including function description, request method, path, parameters and return type. Subsequently, the data transmission object class matching the interface is identified and defined, and the fields of the object class are generated according to the interface declaration. Next, the fields of the data transmission object class are constructed as request messages using annotation and reflection technology. Finally, by integrating a preset code template engine, the interface declaration and the request message are integrated to generate a standardized development toolkit code. The present application automates the parsing of interface documents to quickly generate accurate data transmission objects and request messages, thereby reducing the workload and error rate of manual coding, and combines annotation, reflection technology and code template engines to achieve seamless conversion from interface declaration to development toolkit code, ensuring the standardization and maintainability of the code, thereby achieving consistency and standardization of software toolkit development, improving development efficiency, and reducing the workload and error rate of manual coding.
[0177] The present application also provides another embodiment, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the software toolkit development method as described above.
[0178] In the above embodiment, the present application discloses a computer-readable storage medium, which belongs to the field of software development technology. First, the information in the interface document is parsed, including function description, request method, path, parameters and return type. Subsequently, the data transmission object class matching the interface is identified and defined, and the fields of the object class are generated according to the interface declaration. Next, the fields of the data transmission object class are constructed as request messages using annotation and reflection technology. Finally, by integrating a preset code template engine, the interface declaration and the request message are integrated to generate a standardized development toolkit code. The present application automates the parsing of interface documents to quickly generate accurate data transmission objects and request messages, thereby reducing the workload and error rate of manual coding, and combines annotation, reflection technology and code template engines to achieve seamless conversion from interface declaration to development toolkit code, ensuring the standardization and maintainability of the code, thereby achieving consistency and standardization of software toolkit development, improving development efficiency, and reducing the workload and error rate of manual coding.
[0179] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0180] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0181] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A software toolkit development method, characterized in that: include: Reading an interface declaration in an interface document, wherein the interface declaration includes an interface function, a request method, a request path, request parameters, and a return type; Identify the data transmission object corresponding to the interface according to the interface declaration, define the data transmission object class, and generate fields of the data transmission object class; Generate a request message based on the fields of the data transfer object class using annotation and reflection technology; The interface declaration and the request message are used to generate a development kit code using a preset code template engine.
2. The software toolkit development method according to claim 1, characterized in that: The step of identifying the data transmission object corresponding to the interface according to the interface declaration, defining the data transmission object class, and generating the fields of the data transmission object class specifically includes: Parse the interface declaration to obtain the input parameters and output parameters of the interface; Identify the data transmission object of the input and output parameters of the interface based on the input parameters and the output parameters, and obtain the data transmission object corresponding to the interface; Creating a corresponding class object for the data transmission object corresponding to the interface to obtain the data transmission object class; A data item associated with the data transmission object class is acquired, and a field corresponding to the data item is generated in the data transmission object class to obtain the field of the data transmission object class.
3. The software toolkit development method according to claim 2, characterized in that: The step of identifying the data transmission object of the input and output parameters of the interface based on the input parameters and the output parameters, and obtaining the data transmission object corresponding to the interface specifically includes: Determine the request body structure of the interface based on the input parameters; Determining a response body structure of the interface based on the outgoing parameters; Identify the input parameter data transmission object of the interface from the request body structure, and identify the output parameter data transmission object of the interface in the response body structure.
4. The software toolkit development method according to claim 1, characterized in that: The step of using annotation and reflection technology to generate a request message based on the fields of the data transmission object class specifically includes: Obtaining the mapping relationship and validation rules between the fields of the data transfer object class; Annotating the mapping relationship and the validation rule to obtain field annotation information; When processing the data transfer object class, querying the field annotation information using the reflection API; A request message is generated according to the queried field annotation information.
5. The software toolkit development method according to claim 4, characterized in that: The step of generating a request message according to the queried field annotation information specifically includes: Create a JSON object corresponding to the request message, wherein the JSON object consists of key-value pairs; Identifying an annotation name in the field annotation information; The request message is generated by using the annotation name as the key of the JSON object and the field of the data transmission object class as the value of the JSON object.
6. The software toolkit development method according to claim 1, wherein: Before the step of reading the interface declaration in the interface document, the method further includes: Traversing each data interface in the preset interface database, reading the interface declaration of each data interface, and identifying the interface type of each data interface; Define a corresponding code template for the data interface of each interface type to obtain several interface code templates; The code template engine is constructed based on a plurality of the interface code templates.
7. The software toolkit development method according to claim 6, characterized in that: The interface code template includes a static code structure and a placeholder, wherein the placeholder includes an interface declaration placeholder and a request message placeholder. The step of using a preset code template engine to generate a development toolkit code from the interface declaration and the request message of each interface specifically includes: Determine a matching interface code template based on an interface declaration of each of the interfaces; Filling the interface declaration of each interface into the interface declaration placeholder of the matching interface code template; Fill the request message of each interface into the request message placeholder of the matching interface code template to obtain the development toolkit code.
8. A software toolkit development device, characterized in that: include: An interface declaration reading module, used to read the interface declaration in the interface document, wherein the interface declaration includes the interface function, request method, request path, request parameters and return type; A class field generation module, used to identify the data transmission object corresponding to the interface according to the interface declaration, define the data transmission object class, and generate fields of the data transmission object class; A request message generation module, used to generate a request message based on the fields of the data transmission object class using annotation and reflection technology; The toolkit code generation module is used to generate development toolkit code from the interface declaration and the request message using a preset code template engine.
9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the software toolkit development method according to any one of claims 1 to 7 when executing the computer-readable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the software toolkit development method according to any one of claims 1 to 7.
Citation Information
Cited By
Reverse architecture method and device based on javaparser and storage medium
CN119847487A
