CN113157256A - Interface code generation method and device, electronic equipment, storage medium and product - Google Patents

Interface code generation method and device, electronic equipment, storage medium and product Download PDF

Info

Publication number
CN113157256A
CN113157256A CN202110321604.6A CN202110321604A CN113157256A CN 113157256 A CN113157256 A CN 113157256A CN 202110321604 A CN202110321604 A CN 202110321604A CN 113157256 A CN113157256 A CN 113157256A
Authority
CN
China
Prior art keywords
interface
code
data
type
variable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202110321604.6A
Other languages
Chinese (zh)
Other versions
CN113157256B (en
Inventor
张剑波
张新
张安迪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Dajia Internet Information Technology Co Ltd
Original Assignee
Beijing Dajia Internet Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Dajia Internet Information Technology Co Ltd filed Critical Beijing Dajia Internet Information Technology Co Ltd
Priority to CN202110321604.6A priority Critical patent/CN113157256B/en
Publication of CN113157256A publication Critical patent/CN113157256A/en
Application granted granted Critical
Publication of CN113157256B publication Critical patent/CN113157256B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Library & Information Science (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present disclosure relates to a method, an apparatus, an electronic device, a medium, and a product for generating an interface code, the method including: acquiring interface description data of each interface on an analog interface platform; determining the variable type and the comment of request and response data defined by each interface according to the interface description data; storing the variable type and the comment in the request and response data defined by each interface into a data structure object, and associating the variable type and the comment in the data structure object; and generating a type check code according to the variable type and the annotation in the data structure object, wherein the type check code is used for checking whether the variable in the code conforms to the checked type in the type check code. According to the method and the device, the type check code is utilized, the attribute of the variable type can be automatically prompted and checked according to the comment in the generated type check code when the code is developed, the error caused by the type code is effectively solved, the development efficiency of the code is improved, and the development cost is saved.

Description

Interface code generation method and device, electronic equipment, storage medium and product
Technical Field
The present disclosure relates to the field of internet technologies, and in particular, to a method and an apparatus for generating an interface code, an electronic device, a computer-readable storage medium, and a computer program product.
Background
In the field of internet technology, when a front-end interface code file is written, a JavaScript (js) programming language is typically statically checked by using a TypeScript (ts) programming language, where TypeScript is a language for application-level JavaScript and is a script programming language. In fact, TypeScript is a superset of JavaScript, namely, on the basis of the syntax of JavaScript, a function of static checking of variable types is added, and bug of a project code is effectively reduced through static checking of the variable types.
In the related technology, in the process of developing a front-end interface code, many codes need to be handwritten, for different code formats, many declarations of TypeScript types need to be defined, the formats of the different codes need to be converted (for example, a data structure in a json format is converted into a json abstract syntax tree and the like), traversal and the like are performed, and after repeated names are found out and deduplication processing is performed, an interface code file can be generated.
However, in the related art, in the conversion of formats of different codes, the conversion of the json string format is not supported, so that the annotation of the json string format is also limited, and the generated interface code (interface) file has no additional annotation, thereby reducing the efficiency of code development to a certain extent.
Disclosure of Invention
The present disclosure provides a method and an apparatus for generating an interface code, an electronic device, a computer-readable storage medium, and a computer program product, so as to at least solve the technical problem in the related art that in the process of developing a front-end interface code, no annotation is added to a generated interface code file because the conversion and annotation in the form of json character string are not supported, thereby reducing the code development efficiency. The technical scheme of the disclosure is as follows:
according to a first aspect of the embodiments of the present disclosure, there is provided a method for generating an interface code, including:
acquiring interface description data of each interface on an analog interface platform;
determining the variable type and the annotation of the request and response data defined by each interface according to the interface description data;
storing the variable types and the comments in the request and response data defined by each interface into corresponding data structure objects, and associating the variable types and the comments in the data structure objects;
and generating a corresponding type check code according to the variable type and the annotation in the data structure object, wherein the type check code is used for checking the variable type of the code.
Optionally, the method further includes:
judging whether the uniform resource identifiers of the requests for acquiring the interface description data are the same;
if the request uniform resource identifiers are the same, combining the interface description data of the same request uniform resource identifier;
storing the variable types and the comments in the same request data into the same data structure object, and associating the variable types and the comments in the data structure object;
and if not, executing the steps of storing the variable types and the comments in the request data and the response data defined by each interface into the corresponding data structure objects and associating the variable types and the comments in the data structure objects.
Optionally, the determining the variable type and the comment of the request and response data defined by each interface according to the interface description data includes:
and analyzing the request data and the response data defined by each interface according to the interface description data of each interface to obtain the variable type and the comment of each field in the request data and the variable type and the comment of each field in the response data.
Optionally, the generating a corresponding type check code according to the variable type and the annotation of the data structure object includes:
converting the variable type in each data structure object into a corresponding type check code through a type conversion tool;
and associating the annotations of the variable types in each data structure object to corresponding type check codes to generate annotated type check codes.
Optionally, after generating a corresponding type check code according to the variable type and the annotation in the data structure object, the method further includes:
and generating an interface code file by all the type check codes through the front-end code of the application program interface.
According to a second aspect of the embodiments of the present disclosure, there is provided an apparatus for generating an interface code, including:
the first acquisition module is configured to execute acquisition of interface description data of each interface on the simulation interface platform;
a determining module configured to perform determining variable types and annotations of request and response data defined by each interface according to the interface description data;
a first storage module configured to perform storing variable types and annotations in the request and response data defined by each interface into corresponding data structure objects, and associating the variable types and annotations in the data structure objects;
and the code generation module is configured to execute generation of a corresponding type check code according to the variable type and the annotation in the data structure object, wherein the type check code is used for checking whether the variable in the code conforms to the checked type in the type check code.
Optionally, the apparatus further comprises:
a judging module configured to perform judgment on whether the request uniform resource identifiers of the interface description data are the same;
a merging module configured to perform merging of the interface description data of the same request uniform resource identifier when the judging module judges that the request uniform resource identifiers of the interface description data are the same;
the second storage module is configured to store the variable types and the comments in the same request data into the same data structure object, and associate the variable types and the comments in the data structure object;
the first storage module is further configured to execute, when the judgment module judges that the request uniform resource identifiers of the interface description data are not the same, storing the variable types and the annotations in the request data and the response data defined by each interface into corresponding data structure objects, and associating the variable types and the annotations in the data structure objects.
Optionally, the determining module is specifically configured to execute interface description data according to each interface, analyze the request data and the response data defined by each interface, and obtain the variable type and the comment of each field in the request data and the variable type and the comment of each field in the response data.
Optionally, the code generation module includes:
the conversion module is configured to convert the variable type in each data structure object into a corresponding type check code through a type conversion tool;
and the association module is configured to perform association of the annotation of the variable type in the data structure object into a corresponding type check code, wherein the type check code is used for checking whether the variable in the encoding conforms to the checked type in the type check code.
Optionally, the apparatus further comprises:
and the file generation module is configured to execute that after the code generation module generates the corresponding type check codes, all the type check codes are generated into an interface code file through the front-end codes of the application program interface.
According to a third aspect of the embodiments of the present disclosure, there is provided an electronic apparatus including:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the interface code generation method as described above.
According to a fourth aspect of embodiments of the present disclosure, there is provided a computer-readable storage medium, in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform the method of generating interface code as described above.
According to a fifth aspect of embodiments of the present disclosure, there is provided a computer program product comprising a computer program or instructions which, when executed by a processor, implement the generation method of the interface code as described above.
The technical scheme provided by the embodiment of the disclosure at least has the following beneficial effects:
in the method, interface description data of each interface on a simulation interface platform is obtained, variable types and annotations of request and response data defined by each interface are determined according to the interface description data, the variable types and the annotations in the request and response data defined by each interface are stored in a corresponding data structure object, and the variable types and the annotations are associated in the data structure object; and generating a corresponding type check code according to the variable type and the annotation in the data structure object. That is to say, according to the interface description data of each interface on the obtained simulation platform, the variable type and the annotation of the request and response data defined by each interface are determined, the variable type and the annotation are stored in the corresponding data structure object, the variable type and the annotation are associated, the type check code including the annotation is automatically generated according to the variable type and the annotation, and by using the type check code, the annotation in the code can be checked according to the generated type during code development, the attribute of the variable type is automatically prompted, the error caused by the type code is effectively solved, the development efficiency of the code is improved, and the development cost is also saved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure and are not to be construed as limiting the disclosure.
Fig. 1 is a flowchart illustrating a method of generating interface code according to an example embodiment.
Fig. 2 is another flow chart illustrating a method of generating interface code in accordance with an exemplary embodiment.
Fig. 3 is a schematic diagram illustrating an application example of a generation method of an interface code according to an exemplary embodiment.
Fig. 4 is a block diagram illustrating an interface code generation apparatus according to an example embodiment.
Fig. 5 is another block diagram illustrating an apparatus for generating interface code in accordance with an example embodiment.
FIG. 6 is a block diagram illustrating a code generation module in accordance with an exemplary embodiment.
Fig. 7 is yet another block diagram illustrating an apparatus for generating an interface code in accordance with an example embodiment.
Fig. 8 is a block diagram illustrating a structure of an electronic device according to an example embodiment.
Fig. 9 is a block diagram illustrating an apparatus having generation of interface codes according to an example embodiment.
Detailed Description
In order to make the technical solutions of the present disclosure better understood by those of ordinary skill in the art, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the disclosure described herein are capable of operation in sequences other than those illustrated or otherwise described herein. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.
Fig. 1 is a flowchart illustrating a method for generating an interface code, which is used in a terminal as shown in fig. 1, according to an exemplary embodiment, and includes the following steps.
In step 101, interface description data of each interface on the analog interface platform is obtained.
In step 102, the variable type and annotation of the request and response data defined by each interface are determined according to the interface description data.
In step 103, the variable types and annotations in the request and response data defined by each interface are stored in the corresponding data structure object, and the variable types and annotations are associated in the data structure object.
In step 104, a corresponding type check code is generated according to the variable type and the annotation in the data structure object, and the type check code is used for checking whether the variable in the encoding conforms to the checked type in the type check code.
The interface code generation method disclosed by the present disclosure may be applied to a terminal, a server, and the like, and is not limited herein, and the terminal implementation device may be an electronic device such as a smart phone, a notebook computer, a tablet computer, and the like.
The following describes in detail specific implementation steps of a method for generating an interface code according to an embodiment of the present disclosure with reference to fig. 1.
First, step 101 is executed to obtain interface description data of each interface on the analog interface platform.
The simulation interface platform in this step is a self-defined interface platform, and is butted with the interface platforms at the front end and the rear end, and is used for simulating data transmission of an actual interface. Such as a mock platform, etc.
In this step, interface description data of each interface based on a HyperText Transfer Protocol (HTTP) may be obtained according to the configuration of each interface derived on the mock platform.
Next, step 102 is executed to determine the variable type and the annotation of the request and response data defined by each interface according to the interface description data.
In the step, according to the interface description data of each interface, the request data and the response data defined by each interface are analyzed to obtain the variable type and the comment of each field in the request data and the variable type and the comment of each field in the response data.
In the step, according to the interface description data of each interface, the configuration rule defined by each interface is analyzed to obtain the variable type and the comment of each field in the request data and the variable type and the comment of each field in the response data. Wherein, the configuration rule may include: the configuration interface requests the variable type and comment of each field in the data, and responds to the variable type and comment of each field in the data, and certainly, in practical application, the configuration interface is not limited to this, and may also include other configuration information, and this embodiment is not limited.
Step 103 is executed again, the variable type and the comment in the request and response data defined by each interface are stored in the corresponding data structure object, and the variable type and the comment are associated in the data structure object.
The data structure object in this step may be a json-schema, but is not limited to this, and the variable types and comments in the request and response data defined by each interface are stored in the corresponding data structure object. For example, the variable types and comments in the request and response data defined by the interface 1 are stored in the corresponding json-schema object 1, the variable types and comments in the request and response data defined by the interface 2 are stored in the corresponding data structure object 2, the variable types and comments in the request and response data defined by the interface 3 are stored in the corresponding data structure object 3, and the variable types and comments (usually referred to as code comments and the like) are associated in each data structure object;
the variable types and comments in the request and response data defined by each interface are stored in the corresponding data structure objects, and one storage mode is as follows: and storing the variable type and the comment in the request data defined by each interface into a corresponding data structure object in a Key-Value pair (Key, Value) manner, and storing the variable type and the comment in the response data defined by each interface into a corresponding other data structure object in a Key-Value pair (Key, Value) manner.
The Key-Value pair (Key-Value) is a Value obtained according to a keyword, the Key is the keyword, the identifier of the interface is represented in the text, the Value is a data Value of interface description data of the corresponding interface, and the variable type, the comment and the like are represented in the text.
It should be noted that the data structure itself is a JSON string, and can be identified in the form of key-value pairs (key-value). The data structure defines the types supported by json, and each type has 0-N constraint modes.
Finally, step 104 is executed to generate a corresponding type check code according to the variable type and the annotation in the data structure object, where the type check code is used to check whether the variable in the code (i.e. the code of the actual program written, the same applies below) conforms to the type checked in the type check code.
Specifically, in this step, the variable type in each data structure object may be converted into a corresponding type check code by a type conversion tool; the annotations for the variable type in each data structure object are then associated with a corresponding type check code (e.g., a TS type check code, etc.), which is used to check whether the variable in the encoding conforms to the type checked in the type check code. By using the type check code generated in the step, an editor and some check tools can be matched during front-end development, and whether the variable needing to be checked in the actual encoding process conforms to the type checked in the type declaration code or not can be detected.
It should be noted that the type check code in this embodiment may also be referred to as a type declaration code (i.e., a TS type declaration code), and by using the type declaration code generated in this step, an editor and some check tools may be used in front-end development to detect whether a variable declared in an actual encoding process conforms to a type declared in the type declaration code.
In this step, the variable type and the annotation in each data structure object can be converted into the corresponding type check code through a type conversion (such as quicktype) tool.
The quick type is an open-source data conversion tool, and can convert json, typescript class, postman, multiple json and json schema data into interface of typescript and struct format of golang, so that developers can generate type inspection codes quickly according to variable types and annotations.
In the method, interface description data of each interface on a simulation interface platform is obtained, variable types and annotations of request and response data defined by each interface are determined according to the interface description data, the variable types and the annotations in the request and response data defined by each interface are stored in a corresponding data structure object, and the variable types and the annotations are associated in the data structure object; and generating a corresponding type check code according to the variable type and the annotation in the data structure object. That is to say, according to the interface description data of each interface on the obtained simulation platform, the variable type and the annotation of the request and response data defined by each interface are determined, the variable type and the annotation are stored in the corresponding data structure object, the variable type and the annotation are associated, the type check code including the annotation is automatically generated according to the variable type and the annotation, and by using the type check code, the attribute of the variable type can be automatically prompted and checked according to the annotation in the generated type check code when the code is developed, so that the error caused by the type code is effectively solved, the development efficiency of the code is improved, and the development cost is also saved.
Referring to fig. 2, another schematic structural diagram of a method for generating an interface code according to an embodiment of the present disclosure is shown, where the method includes:
step 201: acquiring interface description data of each interface on an analog interface platform;
in the step, interface configuration of each interface on the analog platform is obtained, and then interface description data of a corresponding hypertext transfer protocol (HTTP) request interface is obtained according to the interface configuration. The simulation interface platform in the present disclosure is an interface platform connecting a front end and a rear end.
Step 202: determining the variable type and the annotation of the request and response data defined by each interface according to the interface description data;
step 201 and step 202 are the same as step 101 and step 102, and are specifically described above, and are not described herein again.
Step 203: judging whether the request Uniform Resource identifiers (URLs) of the interface description data are the same or not; if the two are the same, executing step 204 and step 205; otherwise, go to step 206;
in this step, after obtaining the interface description data of each interface, it is determined whether the uniform resource identifiers of the requests of the interface description data are the same, that is, whether the interface description data of the same request path (i.e., URL) exist, and if they are the same, it indicates that the requests are the interface description data of the same URL; otherwise, the interface description data of different URLs are requested.
Step 204: merging the interface description data of the same request uniform resource identifier;
in this step, if the URLs of the interface description data are judged to be the same, the interface description data are indicated to be the same request, and the request is the interface description data of the same URL, the interface description data are merged, that is, one interface description data is reserved.
Step 205: storing the variable types and the comments in the same request data into the same data structure object, and associating the variable types and the comments in the data structure object; thereafter, step 207 is performed;
in this step, the variable types and annotations in the same request data are stored in the same data structure object, and the variable types and annotations are associated in the data structure object. I.e. the identity of the interface and the type of variables and annotations in the interface description data of the interface are stored in the data structure object in the form of key-value pairs (K-V). Wherein K represents the identification of the interface, and V represents the variable type and the annotation in the interface description data of the interface.
Step 206: storing the variable types and the comments in the request data and the response data defined by each interface into corresponding data structure objects, and associating the variable types and the comments in the data structure objects;
step 207: and generating a corresponding type check code according to the variable type and the annotation in the data structure object, wherein the type check code is used for checking whether the variable in the code conforms to the checked type in the type check code.
Step 206 and step 207 in this embodiment are the same as step 103 and step 104, and are described in detail above, and are not described again here.
In the embodiment of the disclosure, whether the request uniform resource identifiers of the interface description data are the same is judged, if so, the interface description data of the same request uniform resource identifier are combined, so that different requests of the same URL are facilitated, the generated type check code is stored in the same type check code, the storage space is saved, the use is facilitated, namely, the URL is directly copied during the use, the corresponding type check code can be obtained, and the writing of the type check code of the reference path is completed.
Optionally, in another embodiment, on the basis of the foregoing embodiment, the method may further include:
step 208: and generating an interface code file by all the type checking codes through the front-end codes of the application program interface.
In this step, all annotated type checking codes can be generated into an interface code file through a front-end code (such as NodeJS) programming language of the application program interface.
Specifically, in one way, the interface code file may be generated from all types of check codes through a front-end code of the application program interface, and a specific implementation process thereof is well known to those skilled in the art and will not be described herein again.
In the embodiment of the disclosure, all the type check codes (such as TS type check codes (or TS type declaration codes) can also be generated into the interface code file through the NodeJS programming language, which effectively reduces the writing of template codes, improves the code development efficiency of front-end developers, and saves the development cost.
Referring to fig. 3, a schematic diagram of an application example of a method for generating an interface code according to an embodiment of the present disclosure is shown; in this embodiment, the mock interface platform takes a mock platform as an example, and takes project development as an example, the terminal tool automatically generates the type check code according to the interface configuration (including the definition of the interface and the configuration data of the interface) of the mock platform (i.e., HTTP request interface definition, docking platform), and this embodiment takes the generation of the annotated TS type check code as an example. In daily project development, errors caused by TS type errors can be effectively solved; and according to the generated TS type check code with the explanation, the attribute of the variable type is automatically prompted, so that the development efficiency is improved. The specific implementation process comprises the following steps:
1) and (3) deriving: and acquiring interface description data configured by each hypertext transfer protocol HTTP request interface according to the data export interface exposed by the mock platform. It should be noted that the mock platform is an analog interface platform, and is a platform for writing HTTP request interface configuration definition in advance according to rules.
2) And (3) analysis: and analyzing the configuration rule of each interface through the interface description data of each interface to obtain the variable type and the annotation of the request and response data defined by each interface.
3) Merging: merging (i.e. merging into one interface description data) the interface description data of the same request path (i.e. requesting the same URL); in this embodiment, the request data of the interface 1 and the interface 2 are taken as the same URL as an example. I.e. merging the interface description data requested by interface 1 and interface 2. I.e. merging variable types and annotations in the same request data.
4) Storing and marking: the variable type and the comment in the same request data are stored in the same data structure object (in the present embodiment, the variable type and the comment are stored in the data structure object 1 as an example), and the variable type and the comment of each interface are associated (or marked) in the data structure object.
5) Conversion: and converting each data structure object into annotated TS type check codes, such as TS type check code 1, TS type check code 2, TS type check code 3 and the like, through a type conversion tool. In this embodiment, the TS type check code is used to check whether a variable in the encoding conforms to a type checked in the type check code.
6) Generating: and generating interface code files from all TS type check codes through the front-end codes of the application program interface.
According to the interface code generation method shown in the exemplary embodiment, according to interface description data of each interface of a mock platform, variable types and annotations of request and response data defined by each interface are determined, the variable types and the annotations in the request and response data defined by each interface are stored in a data structure object, the variable types and the annotations are associated in the data structure object, TS type check codes with the annotations are automatically generated according to the variable types and the annotations, and an interface code file is generated by all the TS type check codes through front-end codes of an application program interface. That is to say, in this disclosure, the attribute meaning of the current variable type can be known according to the comment prompt in the TS type check code during development, and development efficiency is improved. In addition, the same type check code is generated according to the same request URL, the storage space is saved, the use is convenient, the URL can be directly copied to finish the operation, the writing of the type check code of the reference path is simplified, and the development efficiency is improved.
It is noted that, for simplicity of explanation, the method embodiments are described as a series of acts or combination of acts, but those skilled in the art will appreciate that the present disclosure is not limited by the order of acts described, as some steps may, in accordance with the present disclosure, occur in other orders and/or concurrently. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no particular act is required in order to implement the disclosure.
In the embodiment of the disclosure, a terminal tool is utilized to automatically generate TS type verification codes with annotations according to interface definition and interface description data of a mock platform (front-end and back-end interface definition platforms), so that writing of the interface codes is effectively reduced, and development efficiency of the codes is improved.
By adopting the technical scheme disclosed by the invention, the code writing efficiency is improved by at least more than 15% in the actual project development.
If: calculating the total line number of the automatically generated TS type check code and the total line number of the module code by taking the total line number of the code as a qualitative measurement standard; and the ratio of the two is used as the improvement efficiency of code writing. In order to reduce errors, the present disclosure takes two modules, namely, an analysis module task-management (task-management) module and a metric-acceleration (metric-acceleration) module as an example, and finally takes an average value of the two modules.
task-management module: the total number of code rows 992 and the total number of TS type check code rows 140 improve the efficiency of the handwritten code to (140/992) × 100% — 14.11%.
A metric-accelerate module: total number of code lines 2193, total number of TS type check code lines 566, and improves the efficiency of handwriting type check code to (566/2193) × 100% > -25.8%.
And taking the average value of the code writing efficiency and the code writing efficiency to finally obtain the code writing efficiency of 18.2%, and in conclusion, the type verification code writing efficiency is improved by at least 15%.
Fig. 4 is a block diagram illustrating an apparatus for generating interface code according to an example embodiment. Referring to fig. 4, the apparatus includes: a first obtaining module 401, a determining module 402, a first storing module 403 and a code generating module 404.
The first obtaining module 401 is configured to perform obtaining interface description data of each interface on the analog interface platform;
the determining module 402 is configured to execute determining the variable type and the annotation of the request and response data defined by each interface according to the interface description data;
the first storage module 403 is configured to perform storage of the variable type and the annotation in the request and response data defined by each interface into the corresponding data structure object, and associate the variable type and the annotation in the data structure object;
the code generating module 404 is configured to execute generating a corresponding type check code according to the variable type and the annotation in the data structure object, where the type check code is used to check whether the variable in the encoding conforms to the type checked in the type check code.
Optionally, in another embodiment, on the basis of the above embodiment, the apparatus may further include: a judging module 501, a combining module 502 and a second storing module 503, the schematic structural diagram of which is shown in fig. 5, wherein,
the determining module 501 is configured to perform a determination on whether the request uniform resource identifiers of the interface description data acquired by the first acquiring module 401 are the same;
the merging module 502 is configured to perform merging of the interface description data with the same request uniform resource identifier when the judging module 501 judges that the request uniform resource identifiers of the interface description data are the same;
the second storage module 503 is configured to perform storage of the variable type and the annotation in the same request data merged by the merging module 502 into the same data structure object, and associate the variable type and the annotation in the data structure object;
the first storing module 403 is further configured to execute, when the determining module 501 determines that the request uniform resource identifiers of the interface description data are not the same, storing the variable types and the annotations in the request data and the response data defined by each interface into corresponding data structure objects, and associating the variable types and the annotations in the data structure objects.
Optionally, in another embodiment, on the basis of the above embodiment, the determining module is specifically configured to execute interface description data according to each interface, analyze the request data and the response data defined by each interface, and obtain the variable type and the comment of each field in the request data and the variable type and the comment of each field in the response data.
Optionally, in another embodiment, on the basis of the foregoing embodiment, the code generation module 403 includes: the structure of the conversion module 601 and the association module 602 is schematically shown in fig. 6, wherein,
the conversion module 601 is configured to execute converting the variable type in each data structure object into a corresponding type check code through a type conversion tool;
the association module 602 is configured to perform an integration of the annotation of the variable type in each data structure object into a corresponding type check code, where the type check code is used to check whether the variable in the encoding conforms to the type checked in the type check code.
Optionally, in another embodiment, on the basis of the above embodiment, the apparatus may further include: the file generation module 701 is shown in fig. 7, wherein,
the file generating module 701 is configured to execute generating an interface code file from all the type check codes through a front end code of an application program interface after the code generating module generates the corresponding type check codes.
With regard to the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment related to the method, and reference may be made to part of the description of the embodiment of the method for the relevant points, and the detailed description will not be made here.
In an exemplary embodiment, the present disclosure also provides an electronic device including:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the interface code generation method as described above.
In an exemplary embodiment, the present disclosure also provides a computer-readable storage medium, in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform the interface code generation method as described above.
In an exemplary embodiment, the present disclosure also provides a storage medium comprising instructions, such as a memory comprising instructions, executable by a processor of an apparatus to perform the method described above. Alternatively, the storage medium may be a non-transitory computer readable storage medium, which may be, for example, a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
In an exemplary embodiment, the present disclosure also provides a computer program product comprising a computer program or instructions which, when executed by a processor, implement the generation method of the interface code as described above.
Fig. 8 is a block diagram illustrating an electronic device 800 in accordance with an example embodiment. For example, the electronic device 800 may be a mobile terminal or a server, and in the embodiment of the present disclosure, the electronic device is taken as a mobile terminal as an example for description. For example, the electronic device 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, an exercise device, a personal digital assistant, and the like.
Referring to fig. 8, electronic device 800 may include one or more of the following components: a processing component 802, a memory 804, a power component 806, a multimedia component 808, an audio component 810, an input/output (I/O) interface 812, a sensor component 814, and a communication component 816.
The processing component 802 generally controls overall operation of the electronic device 800, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing components 802 may include one or more processors 820 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 802 can include one or more modules that facilitate interaction between the processing component 802 and other components. For example, the processing component 802 can include a multimedia module to facilitate interaction between the multimedia component 808 and the processing component 802.
The memory 804 is configured to store various types of data to support operation at the device 800. Examples of such data include instructions for any application or method operating on the electronic device 800, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 804 may be implemented by any type or combination of volatile or non-volatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
The power supply component 806 provides power to the various components of the electronic device 800. The power components 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 800.
The multimedia component 808 includes a screen that provides an output interface between the electronic device 800 and a user. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front facing camera and/or a rear facing camera. The front-facing camera and/or the rear-facing camera may receive external multimedia data when the device 800 is in an operating mode, such as a shooting mode or a video mode. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
The audio component 810 is configured to output and/or input audio signals. For example, the audio component 810 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 800 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may further be stored in the memory 804 or transmitted via the communication component 816. In some embodiments, audio component 810 also includes a speaker for outputting audio signals.
The I/O interface 812 provides an interface between the processing component 802 and peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to: a home button, a volume button, a start button, and a lock button.
The sensor assembly 814 includes one or more sensors for providing various aspects of state assessment for the electronic device 800. For example, the sensor assembly 814 may detect an open/closed state of the device 800, the relative positioning of components, such as a display and keypad of the electronic device 800, the sensor assembly 814 may also detect a change in the position of the electronic device 800 or a component of the electronic device 800, the presence or absence of user contact with the electronic device 800, orientation or acceleration/deceleration of the electronic device 800, and a change in the temperature of the electronic device 800. Sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices. The electronic device 800 may access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G, or 5G), or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 further includes a Near Field Communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the electronic device 800 may be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic components for performing the above-described method of generating interface codes.
In an exemplary embodiment, a non-transitory computer-readable storage medium comprising instructions, such as the memory 804 comprising instructions, executable by the processor 820 of the electronic device 800 to perform the method of generating interface code illustrated above, is also provided. For example, the non-transitory computer readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
In an exemplary embodiment, there is also provided a computer program product, wherein the instructions of the computer program product, when executed by the processor 820 of the electronic device 800, cause the electronic device 800 to perform the above illustrated interface code generation method.
Fig. 9 is a block diagram illustrating an apparatus 900 for generation of interface code in accordance with an example embodiment. For example, the apparatus 900 may be provided as a server. Referring to fig. 9, the apparatus 900 includes a processing component 922, which further includes one or more processors, and memory resources, represented by memory 932, for storing instructions, such as applications, that are executable by the processing component 922. The application programs stored in memory 932 may include one or more modules that each correspond to a set of instructions. Further, the processing component 922 is configured to execute instructions to perform the method of generating the method interface code described above.
The device 900 may also include a power component 926 configured to perform power management of the device 900, a wired or wireless network interface 950 configured to connect the device 900 to a network, and an input output (I/O) interface 958. The apparatus 900 may operate based on an operating system stored in the memory 932, such as Windows Server, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, or the like.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It will be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (10)

1. A method for generating an interface code, comprising:
acquiring interface description data of each interface on an analog interface platform;
determining the variable type and the annotation of the request and response data defined by each interface according to the interface description data;
storing the variable types and the comments in the request and response data defined by each interface into corresponding data structure objects, and associating the variable types and the comments in the data structure objects;
and generating a corresponding type check code according to the variable type and the annotation in the data structure object, wherein the type check code is used for checking whether the variable in the code conforms to the checked type in the type check code.
2. The method of generating an interface code according to claim 1, further comprising:
judging whether the uniform resource identifiers of the requests for acquiring the interface description data are the same;
if the request uniform resource identifiers are the same, combining the interface description data of the same request uniform resource identifier;
storing the variable types and the comments in the same request data into the same data structure object, and associating the variable types and the comments in the data structure object;
and if not, executing the steps of storing the variable types and the comments in the request data and the response data defined by each interface into the corresponding data structure objects and associating the variable types and the comments in the data structure objects.
3. The method for generating interface code according to claim 1 or 2, wherein the determining the variable type and the annotation of the request and response data defined by each interface according to the interface description data comprises:
and analyzing the request data and the response data defined by each interface according to the interface description data of each interface to obtain the variable type and the comment of each field in the request data and the variable type and the comment of each field in the response data.
4. The method for generating interface code according to claim 1 or 2, wherein the generating a corresponding type check code according to the variable type and the annotation of the data structure object comprises:
converting the variable type in each data structure object into a corresponding type check code through a type conversion tool;
and associating the annotations of the variable types in each data structure object to corresponding type check codes to generate annotated type check codes.
5. The method for generating interface code according to claim 1 or 2, wherein after generating corresponding type check code according to variable type and annotation in the data structure object, the method further comprises:
and generating an interface code file from all the type check codes through the front-end code of the application program interface.
6. An interface code generation apparatus, comprising:
the first acquisition module is configured to execute acquisition of interface description data of each interface on the simulation interface platform;
a determining module configured to perform determining variable types and annotations of request and response data defined by each interface according to the interface description data;
a first storage module configured to perform storing variable types and annotations in the request and response data defined by each interface into corresponding data structure objects, and associating the variable types and annotations in the data structure objects;
and the code generation module is configured to execute generation of a corresponding type check code according to the variable type and the annotation in the data structure object, wherein the type check code is used for checking whether the variable in the code conforms to the checked type in the type check code.
7. The apparatus for generating an interface code according to claim 6, said apparatus further comprising:
a judging module configured to perform judgment on whether the request uniform resource identifiers of the interface description data are the same;
a merging module configured to perform merging of the interface description data of the same request uniform resource identifier when the judging module judges that the request uniform resource identifiers of the interface description data are the same;
the second storage module is configured to store the variable types and the comments in the same request data into the same data structure object, and associate the variable types and the comments in the data structure object;
the first storage module is further configured to execute, when the judgment module judges that the request uniform resource identifiers of the interface description data are not the same, storing the variable types and the annotations in the request data and the response data defined by each interface into corresponding data structure objects, and associating the variable types and the annotations in the data structure objects.
8. An electronic device, comprising:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the method of generating interface code of any of claims 1 to 5.
9. A computer-readable storage medium, wherein instructions in the computer-readable storage medium, when executed by a processor of an electronic device, enable the electronic device to perform the method of generating interface code of any one of claims 1 to 5.
10. A computer program product comprising a computer program or instructions, characterized in that the computer program or instructions, when executed by a processor, implement the generation method of the interface code of any of claims 1 to 5.
CN202110321604.6A 2021-03-25 2021-03-25 Method and device for generating interface code, electronic equipment, storage medium and product Active CN113157256B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110321604.6A CN113157256B (en) 2021-03-25 2021-03-25 Method and device for generating interface code, electronic equipment, storage medium and product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110321604.6A CN113157256B (en) 2021-03-25 2021-03-25 Method and device for generating interface code, electronic equipment, storage medium and product

Publications (2)

Publication Number Publication Date
CN113157256A true CN113157256A (en) 2021-07-23
CN113157256B CN113157256B (en) 2024-03-19

Family

ID=76884767

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110321604.6A Active CN113157256B (en) 2021-03-25 2021-03-25 Method and device for generating interface code, electronic equipment, storage medium and product

Country Status (1)

Country Link
CN (1) CN113157256B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023098043A1 (en) * 2021-12-03 2023-06-08 深圳前海微众银行股份有限公司 Interface parameter checking method and apparatus
CN116501303A (en) * 2023-06-25 2023-07-28 北京长亭科技有限公司 Automatic API code generation method and device

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150058830A1 (en) * 2013-08-26 2015-02-26 Facebook, Inc. Systems and methods for converting typed code
CN107341014A (en) * 2017-06-27 2017-11-10 乐视致新电子科技(天津)有限公司 Electronic equipment, the generation method of technical documentation and device
US9823913B2 (en) * 2015-12-03 2017-11-21 International Business Machines Corporation Method of adding local variables in place of global in JavaScript
CN107515739A (en) * 2016-06-16 2017-12-26 阿里巴巴集团控股有限公司 Improve the method and device of code execution performance
CN109614329A (en) * 2018-12-06 2019-04-12 中国航空工业集团公司洛阳电光设备研究所 A kind of software test case auxiliary design method based on Interface Control File
CN110825431A (en) * 2019-11-14 2020-02-21 京东数字科技控股有限公司 Interface document processing method, device, system, storage medium and electronic equipment
CN111737040A (en) * 2020-06-22 2020-10-02 北京字节跳动网络技术有限公司 Program code repairing method and device

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150058830A1 (en) * 2013-08-26 2015-02-26 Facebook, Inc. Systems and methods for converting typed code
US9823913B2 (en) * 2015-12-03 2017-11-21 International Business Machines Corporation Method of adding local variables in place of global in JavaScript
CN107515739A (en) * 2016-06-16 2017-12-26 阿里巴巴集团控股有限公司 Improve the method and device of code execution performance
CN107341014A (en) * 2017-06-27 2017-11-10 乐视致新电子科技(天津)有限公司 Electronic equipment, the generation method of technical documentation and device
CN109614329A (en) * 2018-12-06 2019-04-12 中国航空工业集团公司洛阳电光设备研究所 A kind of software test case auxiliary design method based on Interface Control File
CN110825431A (en) * 2019-11-14 2020-02-21 京东数字科技控股有限公司 Interface document processing method, device, system, storage medium and electronic equipment
CN111737040A (en) * 2020-06-22 2020-10-02 北京字节跳动网络技术有限公司 Program code repairing method and device

Non-Patent Citations (6)

* Cited by examiner, † Cited by third party
Title
TAL ORON-GILAD 等: ""Use of Graphic Imagery as a Mean of Communication Between Operators and Unmanned Systems in C3Fire Tasks"", 《 ENGINEERING PSYCHOLOGY AND COGNITIVE ERGONOMICS: PERFORMANCE, EMOTION AND SITUATION AWARENESS 》, pages 362 - 381 *
呼延十: ""使用自定义注解实现接口参数校验"", pages 1 - 6, Retrieved from the Internet <URL:https://blog.csdn.net/qq_24629159/article/details/86568104> *
李文健: ""基于SolidWorks的产品发布物数字化研究与应用"", 《中国优秀硕士学位论文全文数据库 (工程科技Ⅱ辑)》, pages 029 - 123 *
王明 等: ""OMS平台模型的服务化封装方法研究"", 《地理信息世界》, vol. 25, no. 03, pages 11 - 16 *
王明军: ""西门子S7-200 PLC与智能仪表串行轮询通信"", 《设备管理与维修》, no. 01, pages 37 - 41 *
胡荣贵, 陈意云, 郭帆, 张昱: "基于类型注解的认证编译器设计与实现", 计算机研究与发展, no. 01 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023098043A1 (en) * 2021-12-03 2023-06-08 深圳前海微众银行股份有限公司 Interface parameter checking method and apparatus
CN116501303A (en) * 2023-06-25 2023-07-28 北京长亭科技有限公司 Automatic API code generation method and device
CN116501303B (en) * 2023-06-25 2023-11-14 北京长亭科技有限公司 Automatic API code generation method and device

Also Published As

Publication number Publication date
CN113157256B (en) 2024-03-19

Similar Documents

Publication Publication Date Title
CN106569800B (en) Front-end interface generation method and device
CN111274131A (en) Interface testing method and device, electronic equipment and storage medium
CN113157256B (en) Method and device for generating interface code, electronic equipment, storage medium and product
CN111554382B (en) Medical image processing method and device, electronic equipment and storage medium
CN113434134B (en) Component processing method and device, electronic equipment and storage medium
CN113568621A (en) Data processing method and device for page embedded point
CN111209195B (en) Method and device for generating test case
CN112559309A (en) Method and device for adjusting page performance acquisition algorithm
CN115408277B (en) Interface testing method and device
CN111079040B (en) Resource sniffing method, device, terminal, server and storage medium
CN112416751A (en) Processing method and device for interface automation test and storage medium
CN113626321B (en) Bridging test method, device, system and storage medium
CN112486617B (en) Ciphertext data processing architecture, method, apparatus and machine readable medium
CN112631695B (en) Data verification method and device, electronic equipment and storage medium
CN111061633B (en) Webpage first screen time detection method, device, terminal and medium
CN114691104A (en) Language conversion method and device, electronic equipment and storage medium
CN114218235A (en) Page text updating method and device, electronic equipment and storage medium
CN112507261A (en) First screen time calculation method and device
CN112214698A (en) Information processing method and device
CN111131000A (en) Information transmission method, device, server and terminal
CN111427566B (en) Data processing method and device suitable for analog interface platform and server
CN113420531B (en) Code text conversion method, device and storage medium
CN112346968B (en) Automatic detection method and device for definition of multimedia file
CN111538486B (en) Layout file nesting layer number screening method and device and electronic equipment
CN114896165A (en) Testing method and device of conversation robot system, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant