Type definition file generation method and device, equipment, storage medium and product

By obtaining the type definition file configuration specifications and source files, generating custom configuration files and script files, and tuning the type definition source files, the problem of low accuracy and low efficiency in type definition file generation is solved, and a more accurate and efficient Type definition file generation, suitable for business scenarios.

CN118656079APending Publication Date: 2024-09-17CHINA MERCHANTS BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410801947.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-20
Publication Date
2024-09-17

AI Technical Summary

Technical Problem

The existing technology has low accuracy and low efficiency when generating type definition files. In particular, the parameter type identification in the get request is inaccurate, resulting in the generated type definition file not meeting business requirements and affecting development efficiency and accuracy.

Method used

By obtaining the type definition file configuration specifications and type definition source files, generate custom configuration files and tuning script files, tune the type definition source files based on these files, generate optimized type definition files, and ensure that the type definition files comply with the business scenario. Accuracy and maintainability.

Benefits of technology

It improves the accuracy and efficiency of type definition file generation, ensures that the generated type definition file conforms to the preset specifications, and improves the readability and maintainability of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118656079A
    Figure CN118656079A
Patent Text Reader

Abstract

The invention discloses a type definition file generation method and device, equipment, a storage medium and a product, and relates to the technical field of file generation. Generating a self-defined configuration file and a tuning script file according to the type definition file configuration specification; and performing file tuning on the type definition source file according to the self-defined configuration file and the tuning script file to generate an optimized type definition file, generating the self-defined configuration file and the script file according to a preset specification through the method, and then transmitting the generated type definition file into the script file to adjust the type definition accuracy. And the new type definition file is generated, so that the accuracy and the efficiency of generating the type definition file are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of file generation, and in particular to a type definition file generation method, apparatus, device, storage medium and product. Background Art

[0002] Currently, type definition files are manually written based on interface documents. This method has high accuracy, but has low efficiency and large workload due to repeated writing.

[0003] For example, according to the swagger document, the yapi-to-typescript library is used to automatically generate the interface type definition document. There are two problems, which lead to reduced accuracy. One is that the parameters in the get request cannot be generated as a number type, that is, if the input parameter is a number type parameter, it will be converted into a string type in the document generated by the original technology, resulting in reduced accuracy of the generated interface type definition. The other is that the type definition is inaccurate due to the inaccuracy of the swagger document, resulting in inaccuracy in the generated document. For example, the status field status can only have two values ​​​​"pass" or "nopass". Since the type is a string, the original technology automatically generates the type definition and recognizes the status field as a string. However, the type of string is relatively wide. In use, if status is written as "Y", the developer cannot be accurately reminded of the status type problem during the code writing process, resulting in development efficiency and accuracy.

[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention

[0005] The main purpose of this application is to provide a type definition file generation method, apparatus, device, storage medium and computer program product, aiming to improve the efficiency and accuracy of type file definition generation.

[0006] To achieve the above purpose, the present application proposes a method for generating a type definition file, the method comprising:

[0007] Get type definition file configuration specification and type definition source file;

[0008] Generate a custom configuration file and a tuning script file according to the type definition file configuration specification;

[0009] The type definition source file is optimized according to the custom configuration file and the tuning script file to generate an optimized type definition file.

[0010] In one embodiment, the process of obtaining the type definition source file includes:

[0011] Generate interface document annotations based on backend entity class information;

[0012] Obtain the interface document address corresponding to the interface document annotation;

[0013] Obtain the type definition source file corresponding to the interface document annotation according to the interface document address.

[0014] In one embodiment, the type definition source file corresponds to an interface class module, and the type definition file configuration specification includes a public type definition specification and a non-public type definition specification;

[0015] The interface class module corresponding to the public type definition specification includes several interface classes, and the interface properties of the several interface classes are consistent.

[0016] In one embodiment, the custom configuration file includes a public class configuration file and a non-public class configuration file, and the step of generating the custom configuration file and the tuning script file according to the type definition file configuration specification includes:

[0017] Parsing the public type definition specification and the non-public type definition specification in the type definition file configuration specification;

[0018] Generate a public class configuration file and a non-public class configuration file respectively according to the public type definition specification and the non-public type definition specification;

[0019] Determining the type definition to be adjusted in the type definition source file according to the type definition file configuration specification;

[0020] Generate a tuning script file according to the type definition to be adjusted.

[0021] In one embodiment, the step of performing file tuning on the pre-acquired type definition source file according to the custom configuration file and the tuning script file to generate an optimized type definition file comprises:

[0022] Determine, according to the custom configuration file, a type definition to be adjusted in a pre-acquired type definition source file;

[0023] Transferring the type definition source file into the tuning script file;

[0024] The tuning script file is run to adjust the type definition to be adjusted to obtain an optimized type definition file.

[0025] In one embodiment, the step of running the tuning script file, adjusting the type definition to be adjusted, and obtaining the optimized type definition file comprises:

[0026] Introduce additional dependency values ​​based on the pre-obtained external dependency file address;

[0027] Determining whether the type definition to be adjusted needs to be replaced according to the additional dependency value and the type definition file configuration specification;

[0028] If replacement is required, the adjustment content is generated according to the type definition file configuration specification to adjust the type definition to be adjusted, so as to obtain an optimized type definition file.

[0029] In addition, to achieve the above purpose, the present application also proposes a type definition file generation device, the type definition file generation device comprising:

[0030] An acquisition module, used to acquire type definition file configuration specifications and type definition source files;

[0031] A generation module, used to generate a custom configuration file and a tuning script file according to the type definition file configuration specification;

[0032] The tuning module is used to perform file tuning on the type definition source file according to the custom configuration file and the tuning script file to generate an optimized type definition file.

[0033] In addition, to achieve the above-mentioned purpose, the present application also proposes a type definition file generating device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the type definition file generating method as described above.

[0034] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the type definition file generation method described above are implemented.

[0035] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the type definition file generation method described above are implemented.

[0036] One or more technical solutions proposed in the present application obtain a type definition file configuration specification and a type definition source file; generate a custom configuration file and a tuning script file according to the type definition file configuration specification; perform file tuning on the type definition source file according to the custom configuration file and the tuning script file to generate an optimized type definition file. Through the above method, a custom configuration file and a script file are generated according to preset specifications, and then the generated type definition file is passed into the script file, the type definition accuracy is adjusted, and a new type definition file is generated, thereby improving the accuracy and efficiency of type definition file generation. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0038] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0039] Figure 1 A flowchart of the first embodiment of the method for generating a type definition file of the present application is provided;

[0040] Figure 2 A schematic diagram of a file optimization process for the first embodiment of the method for generating a file of the type definition of this application;

[0041] Figure 3 A flowchart diagram of the second embodiment of the method for generating a type definition file of the present application;

[0042] Figure 4 A schematic diagram of the file optimization process of Embodiment 2 of the method for generating a file of the type definition of this application;

[0043] Figure 5 A schematic diagram of the functional modules of the device for generating a type definition file for this application;

[0044] Figure 6 A schematic diagram of the device structure of the hardware operating environment involved in the type definition file generation method in the embodiment of the present application.

[0045] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0046] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0047] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0048] The main solution of the embodiment of the present application is to optimize the type definition file automatically generated by the ypi-to-TypeScript library by combining custom configuration files and script files to solve the problem of inaccurate type definition in the original technology. The solution pays special attention to public and non-public type definition rules to ensure that the generated type definition file meets the accuracy requirements of the business scenario and has good maintainability and scalability.

[0049] There are two main ways to generate TypeScript type definition files in the existing technology: one is to manually write them according to the interface document. This method has high accuracy but low efficiency and large workload; the other is to automatically generate type definition files based on the swagger document using the yapi-to-typescript library, but this method has two main problems: one is that the numeric type of the parameters in the get request cannot be correctly identified, and the other is that due to the inaccuracy of the swagger document, the generated type definition file may be inaccurate.

[0050] The present application provides a solution, which includes obtaining a type definition file configuration specification and a type definition source file; generating a custom configuration file and a tuning script file according to the type definition file configuration specification; performing file tuning on the type definition source file according to the custom configuration file and the tuning script file to generate an optimized type definition file. Through the above method, a custom configuration file and a script file are generated according to preset specifications, and then the generated type definition file is passed into the script file, the type definition accuracy is adjusted, and a new type definition file is generated, thereby improving the accuracy and efficiency of type definition file generation.

[0051] It should be noted that the execution subject of this embodiment may be a computing service device with type definition file generation, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a type definition file generation system, etc. The following takes the type definition file generation system as an example to illustrate this embodiment and the following embodiments.

[0052] Based on this, the embodiment of the present application provides a method for generating a type definition file, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the method for generating a type definition file of this application.

[0053] In this embodiment, the type definition file generation method includes steps S1000 to S3000:

[0054] Step S1000: Obtain type definition file configuration specification and type definition source file;

[0055] It should be noted that the type definition configuration file is a set of rules or guidelines pre-written and defined by users or developers based on business requirements and technical specifications. This file is used to optimize and adjust the original type definition to ensure that the generated type definition file can meet specific project requirements. The type definition configuration file can contain public type definition specifications and non-public type definition specifications, which are respectively for the interface classes in the public interface module and the specific interface module.

[0056] Public type definition specifications refer to type definition rules shared by multiple interface class modules throughout the system. These rules usually define the common representation of certain attributes in all interfaces, such as field name, type, whether required, etc. For example, paging information (such as pageIndex and pageSize) may be a common public type definition that is required in multiple interfaces. Non-public type definition specifications target specific interface class modules and describe the type definition rules unique to the module. These rules are usually defined based on the specific business scenario of the interface module to ensure that the generated type definition can accurately reflect the business logic of the module.

[0057] In addition, it should be noted that the type definition source file is the original type definition file, which is usually automatically generated by the backend developer based on the interface document or swagger document. These files contain basic information about the interface, the structure of the request and response, and the type of each field. However, due to the technical limitations of automatic generation, these files may have some inaccuracies or not meet the project requirements, and need to be optimized and adjusted.

[0058] It should be noted that in this embodiment, reference Figure 2 , the system first needs to obtain these type definition configuration files and type definition source files. The type definition configuration files provide guidance rules for optimizing and adjusting type definitions, while the type definition source files are the original data that needs to be optimized. Through the combination of these two files, the system or developers can tune the source files according to the rules of the configuration files and generate optimized type definition files that better meet project requirements.

[0059] In addition, it should be noted that the type definition source file corresponds to the interface class module, and the type definition file configuration specification includes a public type definition specification and a non-public type definition specification;

[0060] The interface class module corresponding to the public type definition specification includes several interface classes, and the interface properties of the several interface classes are consistent.

[0061] In a feasible implementation manner, the process of obtaining the type definition source file in step S1000 may include steps S1100 to S1300:

[0062] Step S1100: Generate interface document annotations according to backend entity class information;

[0063] Step S1200: Obtain the interface document address corresponding to the interface document annotation;

[0064] It should be noted that, in this embodiment, the back-end entity class (such as the class in Java and C#) usually contains key information of business logic and data structure. In order to expose this information to the front-end or other systems, an interface document needs to be generated. The interface document annotation refers to the additional information added in the code or configuration file, which is used to automatically generate the interface document. The back-end developer first writes the entity class and adds appropriate annotations to the class, method or attribute according to business requirements. These annotations contain key information such as the name, parameters, return type, etc. of the interface. Then, use special tools (such as Swagger, Javadoc, etc.) to scan these annotations and generate the corresponding interface document.

[0065] For example, a Java entity class named User contains attributes such as id, name, and email. To generate an interface document, add Swagger annotations to these attributes, such as @ApiModelProperty(value = "user ID", required = true). Then, by running the Swagger tool, an interface document containing all the attributes and methods of the User class can be automatically generated.

[0066] After the interface document is generated, it is usually deployed to a server and accessed through a specific URL. This URL is the address of the interface document. Once the interface document is generated and deployed to the server, the URL of this document can be obtained in some way (such as configuration files, environment variables, etc.). This URL is usually fixed, or can be dynamically generated according to certain rules.

[0067] Assume that the interface document is deployed in a web application named api-docs and can be accessed through the URL http: / / example.com / api-docs. Then, to obtain the address of the interface document, you only need to simply read this URL.

[0068] Step S1300: Obtain the type definition source file corresponding to the interface document annotation according to the interface document address.

[0069] Step S1100: Generate interface document annotations based on backend entity class information

[0070] Step S1300: Obtain the type definition source file corresponding to the interface document annotation according to the interface document address

[0071] It should be noted that in front-end development, it is often necessary to use static type languages ​​such as TypeScript to write code. In order to obtain the type definition information of the back-end interface, it is necessary to extract this information from the interface document and generate the corresponding TypeScript type definition file (such as a .ts file). According to the obtained interface document address, you can use specific tools or scripts to extract type definition information from the interface document. This information includes the name of the interface, parameter types, return type, etc. Then, use this information to generate a TypeScript type definition file.

[0072] For example, there is a tool that can parse the interface document in Swagger format and generate the corresponding TypeScript type definition file. You can first obtain the interface document content corresponding to the URL http: / / example.com / api-docs through HTTP request. Then, use the tool to parse the document content and generate a TypeScript file containing all interface type definitions. Finally, save this file to the project for front-end developers to use.

[0073] Step S2000: Generate a custom configuration file and a tuning script file according to the type definition file configuration specification;

[0074] It should be noted that after obtaining the type definition file configuration specifications and type definition source files, we need to generate custom configuration files and tuning script files according to these specifications so as to subsequently tune the source files.

[0075] Specifically, the execution process of this step may include: first, the system will parse the type definition file configuration specification, which specifies in detail the requirements for public type definitions and non-public type definitions, including data types, naming rules, comment formats, etc. By parsing this specification, the system can clearly know how to generate a configuration file that meets the requirements based on the actual situation of the source file.

[0076] Next, the system will generate public class configuration files and non-public class configuration files based on the parsed public type definition specifications and non-public type definition specifications. These configuration files will serve as the basis for subsequent tuning work. They contain specific tuning rules and parameter settings for specific type definitions.

[0077] At the same time, the system will also determine the type definitions to be adjusted in the type definition source file according to the type definition file configuration specification. These type definitions to be adjusted may not meet the specification requirements, or need further optimization to improve code quality and maintainability.

[0078] Finally, the system will generate tuning script files based on these type definitions to be adjusted. These script files contain specific tuning logic and code, which will be used to automatically perform tuning operations in subsequent steps to generate optimized type definition files.

[0079] For example, to generate a TypeScript type definition file for a platform's backend service, first obtain the backend entity class information and generate the corresponding interface document annotations and interface document addresses. Then, obtain the type definition source file based on the interface document address and parse the type definition file configuration specification, which clearly specifies the naming rules and data types for public type definitions such as product information, user information, and order information. At the same time, the specification also specifies the naming prefixes and annotation requirements for non-public type definitions (such as auxiliary types used internally).

[0080] Based on these specifications, public and non-public configuration files are generated. The public configuration files contain the tuning rules and parameter settings for type definitions such as product information, user information, and order information, such as marking certain attributes as optional and adding comments to specific attributes. The non-public configuration files contain the tuning rules for auxiliary types used internally.

[0081] At the same time, the type definitions to be adjusted in the type definition source file can also be determined according to the specification, such as the data types of some attributes do not conform to the specification, and the naming of some types does not conform to the naming rules. For these type definitions to be adjusted, tuning script files are generated. These script files contain specific tuning logic and code, such as modifying data types, renaming attributes, etc. In the subsequent steps, these custom configuration files and tuning script files are used to tune the type definition source files to generate optimized type definition files.

[0082] Step S3000: performing file tuning on the type definition source file according to the custom configuration file and the tuning script file to generate an optimized type definition file.

[0083] It should be noted that after generating custom configuration files and tuning script files according to the type definition file configuration specification, you can load the custom configuration files and tuning script files previously generated according to the type definition file configuration specification. These files contain specific tuning strategies and rules for the type definition source files.

[0084] A custom configuration file usually contains specific configuration information of the public type definition specifications and non-public type definition specifications in the type definition source file. For example, it may define which interface properties in the interface class modules need to remain consistent, which property names or types need to be modified or unified, etc.

[0085] The tuning script file is an automated script generated based on these configuration information and the type definition to be adjusted. It is responsible for reading the type definition source file and adjusting the type definition in the file according to the rules in the custom configuration file. Specifically, the tuning script will first determine the type definition to be adjusted in the type definition source file based on the custom configuration file, which usually includes identifying interface classes or properties that do not comply with public type definition specifications or non-public type definition specifications.

[0086] The tuning script then passes the type definition source file in and runs it. During the run, it adjusts the identified type definitions to be adjusted according to the rules in the custom configuration file. This can include modifying attribute names, adjusting attribute types, deleting redundant attributes, or adding necessary attribute comments.

[0087] After being processed by the tuning script, the original type definition source file will be converted into an optimized type definition file. This file not only meets the requirements of the type definition file configuration specification, but also optimizes for specific business scenarios or development requirements, improving the readability and maintainability of the code.

[0088] For example, the backend system of a platform includes multiple interface modules such as products, orders, and users. In the product interface module, there is a product details interface and a product list interface, both of which need to return a product object type definition. However, due to version or system reasons, there are some differences in the product object type definitions returned by these two interfaces, such as inconsistent attribute names and mismatched attribute types.

[0089] To solve this problem, you can use the above type definition file generation method. First, generate the interface document annotation based on the backend entity class information, and obtain the corresponding interface document address and type definition source file. Then, generate the custom configuration file and tuning script file according to the type definition file configuration specification. In the custom configuration file, define the product object as part of the public type definition specification, requiring that all interfaces involving the product object must maintain consistent attribute names and types.

[0090] Next, run the tuning script file to tune the type definition source file. The script first identifies the type definition of the product object returned in the product details interface and the product list interface, and adjusts it according to the rules in the custom configuration file. For example, it may change the "price" attribute name in the product details interface to "productPrice" that is consistent with the product list interface, and change the attribute type from a string to a number, etc.

[0091] After the tuning script is processed, an optimized type definition file is obtained. In this file, the type definition of the product objects returned by the product details interface and the product list interface are consistent and comply with the public type definition specification. In this way, these type definition files can be used more efficiently in the subsequent development and maintenance process.

[0092] The present embodiment provides a method for generating a type definition file, which includes obtaining a type definition file configuration specification and a type definition source file; generating a custom configuration file and a tuning script file according to the type definition file configuration specification; performing file tuning on the type definition source file according to the custom configuration file and the tuning script file to generate an optimized type definition file. Through the above method, a custom configuration file and a script file are generated according to preset specifications, and then the generated type definition file is passed into the script file, the type definition accuracy is adjusted, and a new type definition file is generated, thereby improving the accuracy and efficiency of type definition file generation.

[0093] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 3 The custom configuration file includes a public class configuration file and a non-public class configuration file. Step S2000 of the type definition file generation method may include steps S2100 to S2400:

[0094] Step S2100: parsing the public type definition specification and the non-public type definition specification in the type definition file configuration specification;

[0095] Step S2200: Generate a public class configuration file and a non-public class configuration file respectively according to the public type definition specification and the non-public type definition specification;

[0096] Step S2300: determining the type definition to be adjusted in the type definition source file according to the type definition file configuration specification;

[0097] Step S2400: Generate a tuning script file according to the type definition to be adjusted.

[0098] It should be noted that in the process of generating type definition files, the given type definition file configuration specifications need to be deeply analyzed first. The core of this step is to clearly distinguish and interpret in detail the public type definition specifications and non-public type definition specifications in the configuration specifications. Public type definition specifications usually involve type definitions that need to be shared among multiple modules or projects, such as common data structures and interfaces; while non-public type definition specifications focus more on type definitions that are unique to a specific module or project and do not need to be exposed to the outside world.

[0099] First, backend personnel need to add swagger annotations when writing entity classes and generate swagger document addresses. The content structure obtained by accessing the swagger address is a JSON file with the following structure:

[0100] Fields illustrate OpenAPI Unique Values info Contains basic information of structural parameters servers Contains the address url and description description paths Specific request body / response header fields and type definitions

[0101] Secondly, prepare custom configuration files, agree on configuration rules with back-end personnel, and write configuration files according to the corresponding rules. Regarding public type definition rules (all interfaces under an interface module that involve the same attributes must ensure that the field names and types are consistent, and the relevant field descriptions in the swagger file are set to empty).

[0102] Add a new public attribute type definition file common.d.ts, and add the public attribute type definition that needs to be adjusted (adjust according to the specific business scenario).

[0103] For example, in Table 1 below, in a get request, the input parameter has paging scenarios, and the paging input parameter type is a number type. You can add a paging interface definition IPageInfoProps in the common.d.ts file.

[0104] Table 1

[0105] Fields type Required pageIndex Number no pageSize Number no

[0106] Regarding the non-public type definition rules, add a non-public type definition file xxx.d.ts according to the specific situation of the interface module (if there is a type definition field that needs to be processed, add a docking file, if not, no need to add it), and write the type definition that needs to be replaced in this file.

[0107] For example, the input parameter field of the process query list, status, can only be TOCLAIM, CLAIIMED, CANCEL, and FINISH. However, the status type generated by the original solution is string. To ensure accuracy, the status field needs to be processed and replaced with an accurate type.

[0108] The interface definition of the original file is as follows in Table 2:

[0109] Table 2

[0110]

[0111] Add the interface type definition file xxx.d.ts that needs to be adjusted, and the corresponding interface definition is shown in Table 3 below.

[0112] Table 3

[0113]

[0114] Next, prepare the script file and use TypeScript's ability to inherit (extends) and omit (Omit: certain properties can be ignored from an object type) to complete the tuning of type definition accuracy.

[0115] During the parsing process, the system will scan and analyze the configuration specifications line by line according to the preset grammatical rules and logical structure, extract key information of public type definition specifications and non-public type definition specifications, such as type name, attribute list, inheritance relationship, etc., to provide basic data for subsequent configuration file generation and tuning script writing.

[0116] After parsing the type definition file configuration specification, the system will generate corresponding public and non-public class configuration files based on the key information of the public and non-public type definition specifications. These two configuration files are important bases for subsequent type definition source file tuning. They describe in detail the properties, structure, and possible adjustment plans of various type definitions.

[0117] Public class configuration files focus on type definitions that need to be shared among multiple modules or projects, ensuring the consistency and maintainability of these type definitions; while non-public class configuration files focus more on unique type definitions in specific modules or projects, ensuring that these type definitions can meet the specific needs of the project.

[0118] After the custom configuration file is generated, the system will scan and analyze the pre-acquired type definition source file according to the type definition file configuration specification to determine the type definitions that need to be adjusted. The key to this step is to accurately identify those type definitions that do not meet the configuration specifications or need to be optimized and improved, providing target objects for subsequent tuning script writing.

[0119] After determining the type definition to be adjusted, the system will automatically generate a tuning script file based on this information and the adjustment schemes in the public and non-public class configuration files. This script file describes in detail how to modify and optimize the type definition source file, including which properties to modify, which new type definitions to add, and which type definitions are no longer needed to delete.

[0120] In a feasible implementation manner, step S3000 may include steps S3100 to S3300:

[0121] Step S3100: determining the type definition to be adjusted in the pre-acquired type definition source file according to the custom configuration file;

[0122] Step S3200: transferring the type definition source file into the tuning script file;

[0123] Step S3300: Run the tuning script file to adjust the type definition to be adjusted to obtain an optimized type definition file.

[0124] It should be noted that, in this embodiment, the primary goal of tuning the type definition source file is to clarify which type definitions need to be adjusted. First, the system will read the custom configuration file previously generated according to the type definition file configuration specification. This file contains the specific rules and conditions that need to be adjusted in the type definition source file. Then, the system will traverse the type definition source file, and compare and identify those type definitions that need to be adjusted one by one according to the rules in the custom configuration file. These type definitions to be adjusted may be due to non-compliance with public type definition specifications, non-public type definition specifications, or adjustments required due to changes in business logic.

[0125] Once the type definitions to be adjusted are determined, the next step is to pass the type definition source files containing these definitions to the tuning script file. The tuning script file is generated according to the type definition file configuration specification, and it contains the specific logic and algorithm for tuning the type definition. In this step, the system will pass the type definition source file as an input parameter to the tuning script file according to the preset interface or protocol, preparing for subsequent adjustment work.

[0126] The last step is to run the tuning script file to actually adjust the identified type definitions to be adjusted. The tuning script file will modify, supplement, or delete the relevant parts of the type definition source file according to the rules and conditions in the custom configuration file. This adjustment process can be automatic or require human participation, depending on the implementation method and adjustment rules of the tuning script file. The adjusted type definition file is called an optimized type definition file, which will better meet business requirements and technical specifications, and improve the readability and maintainability of the code.

[0127] Following the above example, there is a platform backend system that contains multiple entity classes such as goods, orders, and users. These entity classes generate interface documents through swagger annotations, and corresponding type definition source files are generated. However, due to changes in business logic, the "price" field in the product class needs to be changed from the original floating point type to an integer type to adapt to the new price calculation rules.

[0128] In this scenario, you can follow the steps below to tune the type definition:

[0129] Generate a custom configuration file: Generate a custom configuration file based on the public type definition specifications and non-public type definition specifications, which specifies that the "price" field in the product class needs to be adjusted in type.

[0130] Generate a tuning script file: Based on the custom configuration file and type definition file configuration specifications, we generate a tuning script file that contains the specific logic for changing the "price" field from a floating-point type to an integer type.

[0131] Determine the type definition to be adjusted: The system reads the custom configuration file and identifies that the "Price" field in the commodity class is the type definition that needs to be adjusted.

[0132] Pass in type definition source file: The system passes the type definition source file containing the Price field definition to the tuning script file.

[0133] Run the tuning script file: The tuning script file runs, changes the type of the Price field from floating point to integer, and generates an optimized type definition file.

[0134] After such a tuning process, a type definition file that better meets business requirements and technical specifications is obtained, which facilitates subsequent development and maintenance work.

[0135] In a feasible implementation manner, step S3300 may include steps S3310 to S3330:

[0136] Step S3310: introducing additional dependency values ​​according to the pre-acquired external dependency file address;

[0137] Step S3320: judging whether the type definition to be adjusted needs to be replaced according to the additional dependency value and the type definition file configuration specification;

[0138] Step S3330: If replacement is required, the type definition to be adjusted is adjusted by generating adjustment content according to the type definition file configuration specification to obtain an optimized type definition file.

[0139] It should be noted that, refer to Figure 4 In the process of optimizing type definition files, external dependency files often play an important role. These external dependencies may include type definitions, tool functions, or specific configuration data of third-party libraries. First, the system reads a predefined list of external dependency file addresses. These addresses may exist in the form of URLs, file paths, or other forms, depending on the design and implementation of the system. Then, the system will obtain the corresponding external dependency files based on these addresses. The acquisition methods may include network requests, file reading, etc.

[0140] Once the external dependency files are successfully obtained, the system will parse these files and extract the required additional dependency values. These dependency values ​​may be type definitions, constants, functions, etc., which will be used in the subsequent type definition optimization process.

[0141] After obtaining the additional dependency values, the system needs to determine whether the type definition to be adjusted needs type replacement based on these dependency values ​​and a predefined type definition file configuration specification.

[0142] The core of this step is to compare whether the type definition to be adjusted is consistent with the definition in the configuration specification, and whether the additional dependency value can provide a better type definition. For example, if the type definition to be adjusted uses an outdated type or does not make full use of the more precise type provided by the additional dependency, then type replacement is required.

[0143] If it is determined that type replacement is required, the system will generate corresponding adjustment content according to the type definition file configuration specification and replace the type definition to be adjusted.

[0144] The specific adjustment process may include modifying the type name, adding or deleting type attributes, changing type references, etc. These adjustments need to strictly follow the type definition file configuration specification to ensure that the generated optimized type definition file not only complies with the specification but also can fully utilize the advantages provided by the additional dependency values.

[0145] For example, we optimize the type definition file for a TypeScript-based web application. In this application, a third-party library called axios is used to send HTTP requests. In order to make full use of the type definitions provided by the axios library, it is necessary to replace the relevant type definitions in the application. First, based on the URL address of the axios library type definition file obtained in advance, the type definition of the axios library is introduced as an additional dependency value. Then, the type definition to be adjusted in the application is compared with the definition in the type definition file configuration specification. It is found that a custom HttpResponse type is used in the application to represent the HTTP response, but this type does not make full use of the more precise type definition provided by the axios library. Therefore, we decided to replace the type.

[0146] Finally, in step S3330, we generate corresponding adjustments based on the type definition file configuration specification, replacing the HttpResponse type in the application with the AxiosResponse type provided by the axios library. In this way, we get a more accurate and optimized type definition file.

[0147] In this embodiment, the public type definition specifications and non-public type definition specifications in the type definition file configuration specification are parsed; public class configuration files and non-public class configuration files are generated respectively according to the public type definition specifications and non-public type definition specifications; the type definition to be adjusted in the type definition source file is determined according to the type definition file configuration specification; a tuning script file is generated according to the type definition to be adjusted. Through the above method, a custom configuration file and a script file are generated according to preset specifications, and then the generated type definition file is passed into the script file, the type definition accuracy is adjusted, and a new type definition file is generated, thereby improving the accuracy and efficiency of type definition file generation.

[0148] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the method for generating the type definition file of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0149] The present application also provides a type definition file generation device 50, please refer to Figure 4 , the type definition file generating device comprises:

[0150] An acquisition module 51 is used to acquire a type definition file configuration specification and a type definition source file;

[0151] A generating module 52, used to generate a custom configuration file and a tuning script file according to the type definition file configuration specification;

[0152] The tuning module 53 is used to perform file tuning on the type definition source file according to the custom configuration file and the tuning script file to generate an optimized type definition file.

[0153] The type definition file generation device provided by the present application adopts the type definition file generation method in the above embodiment, which can solve the technical problem of type definition file generation. Compared with the prior art, the beneficial effects of the type definition file generation device provided by the present application are the same as the beneficial effects of the type definition file generation method provided by the above embodiment, and other technical features in the type definition file generation device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0154] The present application provides a type definition file generating device, the type definition file generating device comprising: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the type definition file generating method in the above-mentioned embodiment 1.

[0155] Reference below Figure 6 , which shows a schematic diagram of the structure of a type definition file generation device suitable for implementing the embodiment of the present application. The type definition file generation device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The type definition file generating device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0156] like Figure 6As shown, the type definition file generating device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the type definition file generating device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the type definition file generation device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a type definition file generation device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.

[0157] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0158] The type definition file generation device provided by the present application adopts the type definition file generation method in the above embodiment, which can solve the technical problem of type definition file generation. Compared with the prior art, the beneficial effects of the type definition file generation device provided by the present application are the same as the beneficial effects of the type definition file generation method provided by the above embodiment, and other technical features in the type definition file generation device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0159] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0160] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0161] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the type definition file generation method in the above-mentioned embodiment.

[0162] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0163] The computer-readable storage medium may be included in the type definition file generating device; or may exist independently without being assembled into the type definition file generating device.

[0164] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the type definition file generating device, the type definition file generating device generates a type definition file.

[0165] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0166] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0167] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0168] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned type definition file generation method, and can solve the technical problem of type definition file generation. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the type definition file generation method provided by the above-mentioned embodiment, and will not be repeated here.

[0169] The present application also provides a computer program product, including a computer program, which implements the steps of the type definition file generation method as described above when executed by a processor.

[0170] The computer program product provided by this application can solve the technical problem of type definition file generation. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as the beneficial effects of the type definition file generation method provided by the above embodiment, which will not be repeated here.

[0171] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A method for generating a type definition file, characterized in that: The method comprises: Get type definition file configuration specification and type definition source file; Generate a custom configuration file and a tuning script file according to the type definition file configuration specification; The type definition source file is optimized according to the custom configuration file and the tuning script file to generate an optimized type definition file.

2. The method according to claim 1, characterized in that The process of obtaining the type definition source file includes: Generate interface document annotations based on backend entity class information; Obtain the interface document address corresponding to the interface document annotation; Obtain the type definition source file corresponding to the interface document annotation according to the interface document address.

3. The method according to claim 2, characterized in that The type definition source file corresponds to an interface class module, and the type definition file configuration specification includes a public type definition specification and a non-public type definition specification; The interface class module corresponding to the public type definition specification includes several interface classes, and the interface properties of the several interface classes are consistent.

4. The method according to any one of claims 3, characterized in that The custom configuration file includes a public class configuration file and a non-public class configuration file. The step of generating the custom configuration file and the tuning script file according to the type definition file configuration specification includes: Parsing the public type definition specification and the non-public type definition specification in the type definition file configuration specification; Generate a public class configuration file and a non-public class configuration file respectively according to the public type definition specification and the non-public type definition specification; Determining the type definition to be adjusted in the type definition source file according to the type definition file configuration specification; Generate a tuning script file according to the type definition to be adjusted.

5. The method according to claim 4, characterized in that The step of performing file tuning on the pre-acquired type definition source file according to the custom configuration file and the tuning script file to generate an optimized type definition file comprises: Determine, according to the custom configuration file, a type definition to be adjusted in a pre-acquired type definition source file; Transferring the type definition source file into the tuning script file; The tuning script file is run to adjust the type definition to be adjusted to obtain an optimized type definition file.

6. The method according to claim 5, characterized in that The step of running the tuning script file, adjusting the type definition to be adjusted, and obtaining the optimized type definition file comprises: Introduce additional dependency values ​​based on the pre-obtained external dependency file address; Determining whether the type definition to be adjusted needs to be replaced according to the additional dependency value and the type definition file configuration specification; If replacement is required, the adjustment content is generated according to the type definition file configuration specification to adjust the type definition to be adjusted, so as to obtain an optimized type definition file.

7. A type definition file generating device, characterized in that: The device comprises: An acquisition module, used to acquire type definition file configuration specifications and type definition source files; A generation module, used to generate a custom configuration file and a tuning script file according to the type definition file configuration specification; The tuning module is used to perform file tuning on the type definition source file according to the custom configuration file and the tuning script file to generate an optimized type definition file.

8. A type definition file generating device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the type definition file generation method according to any one of claims 1 to 6.

9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the type definition file generation method according to any one of claims 1 to 6 are implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the method for generating a type definition file according to any one of claims 1 to 6 are implemented.