CN113157256B - Method and device for generating interface code, electronic equipment, storage medium and product - Google Patents

Method and device for generating interface code, electronic equipment, storage medium and product Download PDF

Info

Publication number
CN113157256B
CN113157256B CN202110321604.6A CN202110321604A CN113157256B CN 113157256 B CN113157256 B CN 113157256B CN 202110321604 A CN202110321604 A CN 202110321604A CN 113157256 B CN113157256 B CN 113157256B
Authority
CN
China
Prior art keywords
interface
code
type
data
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.)
Active
Application number
CN202110321604.6A
Other languages
Chinese (zh)
Other versions
CN113157256A (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

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)
  • Software Systems (AREA)
  • General Engineering & Computer Science (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 disclosure relates to a method, a device, an electronic device, a medium and a product for generating an interface code, wherein the method comprises the following steps: acquiring interface description data of each interface on an analog interface platform; determining variable types and comments of request and response data defined by each interface according to the interface description data; storing variable types and comments in the request and response data defined by each interface into a data structure object, and associating the variable types and comments 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 accords with the type checked in the type check code. The method and the device can automatically prompt and check the attribute of the variable type according to the notes in the generated type check code when the code is developed by using the type check code, effectively solve the errors caused by the type code, not only improve the development efficiency of the code, but also save the development cost.

Description

Method and device for generating interface code, electronic equipment, storage medium and product
Technical Field
The present disclosure relates to the field of internet technologies, and in particular, to a method, an apparatus, an electronic device, a computer readable storage medium, and a computer program product for generating an interface code.
Background
In the internet technology field, when the front-end interface code file is written, a TypeScript (TS) programming language is generally used to perform static verification on the JavaScript (JS) programming language, where TypeScript is a language used for application-level JavaScript, and is a script programming language. In fact, typeScript is a superset of JavaScript, namely, based on JavaScript grammar, the function of variable type static verification is added, and the bug of the project code is effectively reduced through the variable type static verification.
In the related art, in the development process of the front-end interface code, many codes need to be written, a plurality of statement types of TypeScript need to be defined for different code formats, the formats of the different codes need to be converted (for example, a json abstract syntax tree is converted into a data structure in json format), traversal and the like are performed, and repeated names are found out to perform de-duplication processing, so that the interface code file can be generated.
However, in the related art, in the conversion of formats of different codes, the conversion of json character string formats is not supported, so that annotation of the json character string formats is limited, and the generated interface code (interface) file has no additional annotation, so that the efficiency of code development is reduced to a certain extent.
Disclosure of Invention
The disclosure provides a method, a device, an electronic device, a computer readable storage medium and a computer program product for generating an interface code, so as to at least solve the technical problem that in the development process of a front-end interface code in the related art, as the conversion and annotation in json character string form are not supported, the generated interface code file has no additional annotation, and the code development efficiency is reduced. The technical scheme of the present disclosure is as follows:
according to a first aspect of an embodiment 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 types and comments of the request and response data defined by each interface according to the interface description data;
storing variable types and comments in request and response data defined by each interface into corresponding data structure objects, and associating the variable types and 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 comprises:
Judging whether the request uniform resource identifiers for acquiring the interface description data are the same or not;
if the request is the same, merging the interface description data of the same request uniform resource identifier;
storing variable types and comments in the same request data into the same data structure object, and associating the variable types and comments in the data structure object;
and if the variable types and the comments in the request data and the response data defined by each interface are different, the steps of storing the variable types and the comments in the corresponding data structure objects and associating the variable types and the comments in the data structure objects are executed.
Optionally, the determining, according to the interface description data, the variable types and comments of the request and response data defined by each interface 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 annotation of each field in the request data and the variable type and the annotation of each field in the response data.
Optionally, the generating the corresponding type check code according to the variable type and the annotation of the data structure object includes:
Converting the variable types in each data structure object into corresponding type check codes through a type conversion tool;
the comments of the variable types in each data structure object are associated with the corresponding type check code, and the type check code with the comments is generated.
Optionally, after generating the corresponding type check code according to the variable type and the annotation in the data structure object, the method further comprises:
all the type check codes are generated into an interface code file 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 acquire interface description data of each interface on the analog interface platform;
a determining module configured to perform determining a variable type and annotation of the 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 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 the generation of corresponding type checking codes according to the variable types and the comments in the data structure object, wherein the type checking codes are used for checking whether the variable in the code accords with the types checked in the type checking codes.
Optionally, the apparatus further includes:
a judging module configured to perform a judgment as to whether the request uniform resource identifiers of the interface description data are the same;
a merging module configured to execute merging of the interface description data of the same request uniform resource identifier when the judgment module judges that the request uniform resource identifiers of the interface description data are the same;
a second storage module configured to perform storing of variable types and annotations in the same request data into the same data structure object, and associating the variable types and annotations in the data structure object;
the first storage module is further configured to perform storing the variable type and the annotation in the request data and the response data defined by each interface into a corresponding data structure object when the judging module judges that the request uniform resource identifiers of the interface description data are different, and associating the variable type and the annotation in the data structure object.
Optionally, the determining module is specifically configured to execute the 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 generating module includes:
a conversion module configured to execute a type verification code that converts the variable types in each data structure object to corresponding types by a type conversion tool;
and an association module configured to perform association of the annotation of the variable type in the data structure object into a corresponding type check code, the type check code being used to check whether the variable in the encoding conforms to the type checked in the type check code.
Optionally, the apparatus further includes:
and the file generation module is configured to execute the generation of the interface code file by the front-end code of the application program interface after the code generation module generates the corresponding type check codes.
According to a third aspect of embodiments of the present disclosure, there is provided 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 as described above.
According to a fourth aspect of embodiments of the present disclosure, there is provided a computer-readable storage medium, which when executed by a processor of an electronic device, causes the electronic device to perform the method of generating an 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 a method of generating an interface code as described above.
The technical scheme provided by the embodiment of the disclosure at least can comprise the following beneficial effects:
in the method, through acquiring interface description data of each interface on an analog interface platform, according to each interface description data, determining variable types and comments of request and response data defined by each interface, storing the variable types and comments in the request and response data defined by each interface into corresponding data structure objects, and associating the variable types and comments in the data structure objects; and generating corresponding type check codes according to the variable types and the notes in the data structure object. That is, the present disclosure determines, according to the obtained interface description data of each interface on the simulation platform, the variable types and comments of the request and response data defined by each interface, stores the variable types and comments in the corresponding data structure objects, associates the variable types and comments, automatically generates a type check code including comments according to the variable types and comments, and when the code is developed, can automatically prompt the attribute of the variable types according to the comments in the generated type check code, thereby effectively solving errors caused by the type code, improving the development efficiency of the code, and saving the development cost.
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 disclosure and together with the description, serve to explain the principles of the disclosure and do not constitute an undue limitation on the disclosure.
Fig. 1 is a flowchart illustrating a method of generating an interface code according to an exemplary embodiment.
Fig. 2 is another flowchart illustrating a method of generating an interface code according to an exemplary embodiment.
Fig. 3 is a schematic diagram showing an application example of a method of generating an interface code according to an exemplary embodiment.
Fig. 4 is a block diagram illustrating an interface code generating apparatus according to an exemplary embodiment.
Fig. 5 is another block diagram illustrating an interface code generating apparatus according to an exemplary embodiment.
FIG. 6 is a block diagram illustrating a code generation module according to an example embodiment.
Fig. 7 is a further block diagram illustrating an interface code generating apparatus according to an exemplary embodiment.
Fig. 8 is a block diagram illustrating a configuration of an electronic device according to an exemplary embodiment.
Fig. 9 is a block diagram illustrating a structure of an apparatus having generation of an interface code according to an exemplary embodiment.
Detailed Description
In order to enable those skilled in the art to better understand the technical solutions of the present disclosure, the technical solutions of 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 foregoing figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the disclosure described herein may be capable of operation in sequences other than those illustrated or described herein. The implementations described in the following exemplary examples are not representative of all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present disclosure as detailed in the accompanying claims.
Fig. 1 is a flowchart illustrating a method of generating an interface code, which is used in a terminal as shown in fig. 1, according to an exemplary embodiment, including the following steps.
In step 101, interface description data for each interface on the analog interface platform is obtained.
In step 102, variable types and comments 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, wherein the type check code is used for checking whether the variable in the code accords with the type checked in the type check code.
The method for generating the interface code according to the present disclosure may be applied to a terminal, a server, etc., and the terminal implementation device may be an electronic device such as a smart phone, a notebook computer, a tablet computer, etc., which is not limited herein.
Specific implementation steps of a method for generating an interface code according to an embodiment of the present disclosure are described in detail below with reference to fig. 1.
First, step 101 is performed to obtain interface description data of each interface on the analog interface platform.
The analog interface platform in the step is a self-defined interface platform, and is used for interfacing the interface platforms of the front end and the rear end and simulating the data transmission of an actual interface. Such as a mock platform, etc.
In this step, interface description data of each interface based on HyperText transfer protocol (HTTP, hyperText Transfer Protocol) can be acquired according to the configuration of each interface derived on the mock platform.
Next, step 102 is executed to determine, according to the interface description data, the variable types and comments of the request and response data defined by each interface.
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 annotation of each field in the request data and the variable type and the annotation 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 annotation of each field in the request data and the variable type and annotation 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 the variable type and comment of each field in the data, however, in practical application, the configuration interface is not limited to this, and other configuration information may be also included, and the embodiment is not limited.
Again, step 103 is performed to store the variable types and annotations in the request and response data defined by each interface into the corresponding data structure object, and associate the variable types and annotations in the data structure object.
The data structure object in this step may be, but is not limited to, json-schema, 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 (generally referred to as code comments, etc.) 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 object, and one storage mode is as follows: the variable types and comments in the request data defined by each interface are stored in the corresponding data structure object in a Key-Value pair (Key, value) mode, and the variable types and comments in the response data defined by each interface are stored in the corresponding other data structure object in a Key-Value pair (Key, value) mode.
Wherein, key-Value is the Value according to the Key, key is the Key, the mark of the interface is shown here, value is the data Value of the interface description data of the corresponding interface, the variable type and annotation are shown here.
It should be noted that the data structure itself is a JSON string, and may be identified by a key-value pair (key-value) format. The data structure defines the types supported by json, each with 0-N constraints.
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 actually writing the program, and the following description) accords with 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 comments for the variable type in each data structure object are then associated with a corresponding type verification code (e.g., TS type verification code, etc.) that is used to verify whether the variable in the code matches the type verified in the type verification code. By using the type verification code generated in the step, an editor and some verification tools can be matched during front-end development, and whether variables to be verified in the actual coding process accord with the type verified in the type declaration code or not can be detected.
It should be noted that, the type verification code in this embodiment may also be referred to as a type declaration code (i.e., a TS type declaration code), and with the type declaration code generated in this step, an editor and some verification tools may be cooperated during front-end development, so as to detect whether a variable declared in an actual encoding process accords with a type declared in the type declaration code.
In this step, the variable type and annotation in each data structure object may be converted into a corresponding type check code by a type conversion (e.g., quick type, etc.) tool.
The quick type is an open source data conversion tool, and can convert json, typescript class, postman, multiple json and json schame data into the interactive and golang struct formats of typescript, so that a developer can conveniently and quickly generate type check codes according to variable types and notes.
In the method, through acquiring interface description data of each interface on an analog interface platform, according to each interface description data, determining variable types and comments of request and response data defined by each interface, storing the variable types and comments in the request and response data defined by each interface into corresponding data structure objects, and associating the variable types and comments in the data structure objects; and generating corresponding type check codes according to the variable types and the notes in the data structure object. That is, the present disclosure determines, according to the obtained interface description data of each interface on the analog platform, the variable types and comments of the request and response data defined by each interface, stores the variable types and comments in the corresponding data structure objects, associates the variable types and comments, automatically generates a type check code including comments according to the variable types and comments, and when the code is developed, can automatically prompt and check the attribute of the variable types according to the comments in the generated type check code, thereby effectively solving errors caused by the type code, improving the development efficiency of the code, and saving the development cost.
Referring also to fig. 2, another schematic structural diagram of a method for generating an interface code according to an embodiment of the disclosure is provided, where the method includes:
step 201: acquiring interface description data of each interface on an analog interface platform;
in the step, firstly, the interface configuration of each interface on the simulation platform is obtained, and then, the interface description data of the corresponding HTTP request interface is obtained according to the interface configuration. The analog interface platform in the present disclosure is an interface platform connecting a front end and a back end.
Step 202: determining the variable types and comments 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 repeated here.
Step 203: judging whether the request uniform resource identifiers (URLs, uniform Resource Locator) of the interface description data are the same; if so, performing steps 204 and 205; otherwise, go to step 206;
in the step, after the interface description data of each interface is obtained, judging whether the request uniform resource identifiers of the interface description data are the same, namely, whether the interface description data of the same request path (namely, URL) exist or not, and if so, indicating that the request is the interface description data of the same URL; otherwise, interface description data of different URLs is requested.
Step 204: merging interface description data of the same request uniform resource identifier;
in this step, if it is determined that the URLs of the interface description data are the same, the description is the same request, the interface description data of the same URL are requested, and the interface description data are merged, that is, one interface description data is reserved.
Step 205: storing variable types and comments in the same request data into the same data structure object, and associating the variable types and comments in the data structure object; thereafter, step 207 is performed;
in this step, variable types and annotations in the same request data are stored in the same data structure object, and are associated in the data structure object. I.e. the identity of the interface and the type of variables and comments 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 identity of the interface and V represents the variable type and annotation in the interface description data of the interface.
Step 206: storing variable types and comments in request data and response data defined by each interface into corresponding data structure objects, and associating the variable types and 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 accords with the type checked in the type check code.
Step 206 and step 207 in this embodiment are the same as step 103 and step 104, and are specifically described above, and are not repeated here.
In the embodiment of the disclosure, by judging whether the request uniform resource identifiers of the interface description data are the same, if so, merging the interface description data of the same request uniform resource identifier so as to facilitate different requests of the same URL, and storing the generated type check codes in the same type check codes, the storage space is saved, and the use is convenient, namely, the URL is directly copied when in use, so that the corresponding type check codes can be obtained, thereby completing writing of the type check codes of the reference path.
Optionally, in another embodiment, based on the foregoing embodiment, the method may further include:
step 208: all the type check codes are generated into an interface code file through the front end code of the application program interface.
In this step, all annotated type check codes may be generated into an interface code file via the front end code (e.g., nodeJS) programming language of the application interface.
Specifically, a manner may generate the interface code file from all the type check codes through the front end code of the application program interface, and the specific implementation process thereof is a well-known technology for those skilled in the art, and will not be described herein.
In the embodiment of the disclosure, all types of check codes (such as TS type check codes (or TS type declaration codes)) can be generated into the interface code file through the NodeJS programming language, so that the writing of the template codes is effectively reduced, the code development efficiency of front-end developers is improved, and the development cost is saved.
Referring also to fig. 3, a schematic diagram of an application example of a method for generating an interface code according to an embodiment of the disclosure is provided; in this embodiment, the analog interface platform takes the mock platform as an example, and takes the project development as an example, and 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. the HTTP request interface definition and the docking platform), and the embodiment takes the generation of the TS type check code with comments as an example. In daily project development, errors caused by TS type errors can be effectively solved; and automatically prompting the attribute of the variable type according to the generated TS type test code with the annotation, thereby improving the development efficiency. The specific implementation process comprises the following steps:
1) And (3) export: and obtaining interface description data configured by each 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) Analysis: analyzing the configuration rule of each interface through the interface description data of each interface to obtain the variable types and comments of the request and response data defined by each interface.
3) Combining: merging (i.e., 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. I.e. the interface description data requested by interface 1 and interface 2 are combined. I.e. merging variable types and comments in the same request data.
4) Storing and marking: the variable types and annotations in the same request data are stored in the same data structure object (the data structure object 1 is taken as an example in this embodiment), and the variable types and annotations of each interface are associated (or marked) in the data structure object.
5) Conversion: each data structure object is converted into a annotated TS type check code, such as TS type check code 1, TS type check code 2, TS type check code 3, etc., by a type conversion tool. In this embodiment, the TS type check code is used to check whether the variable in the code conforms to the type checked in the type check code.
6) Generating: and generating interface code files by the front end codes of the application program interface and all TS type check codes.
According to the method for generating the interface codes, which is shown in the present exemplary embodiment, variable types and comments of request and response data defined by each interface are determined according to interface description data of each interface of a mock platform, the variable types and comments in the request and response data defined by each interface are stored in a data structure object, the variable types and comments are associated in the data structure object, TS type check codes with comments are automatically generated according to the variable types and comments, and all TS type check codes are generated into interface code files through front end codes of an application program interface. In other words, in the present 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, thereby improving the development efficiency. In addition, the same type check code is generated according to the same request URL, so that the storage space is saved, the use is convenient, the URL can be directly copied, the writing of the type check code of the reference path is simplified, and the development efficiency is improved.
It should be noted that, for the sake of simplicity of description, the method embodiments are all described as a series of combinations of actions, but it should be understood by those skilled in the art that the present disclosure is not limited by the order of actions described, as some steps may take place in other order or simultaneously in accordance with the present disclosure. Further, those skilled in the art will also appreciate that the embodiments described in the specification are all preferred embodiments and that the acts referred to are not necessarily required by the present disclosure.
In the embodiment of the disclosure, the terminal tool is utilized to automatically generate the TS type check code with the annotation according to the interface definition and the interface description data of the mock platform (front-back interface definition platform), so that the writing of the interface code is effectively reduced, and the development efficiency of the code is improved.
By adopting the technical scheme, in the practical project development, the code writing efficiency is improved by at least 15%.
If: calculating the total number of the code and the total number of the module code of the automatically generated TS type check code by taking the total number of the code as a qualitative measurement standard; and the ratio of the two is used as the improvement efficiency of code writing. To reduce errors, the present disclosure takes two modules, a task-management (task-management) module and a metric-acceleration (metric), as examples, and finally takes the average of the two.
task-message module: the total number of codes is 992 lines, the total number of TS type check codes is 140 lines, and the handwriting code efficiency is improved to (140/992) ×100% =14.11%.
The meta-acerate module: the total number of lines of codes 2193 and the total number of lines of TS type check codes 566, and improves the handwriting type check code efficiency by (566/2193) ×100% =25.8%.
And taking the average value of the code writing and the verification code writing, and finally obtaining that the code writing improves the efficiency by 18.2 percent, and in summary, the type verification code writing efficiency is improved by at least more than 15 percent.
Fig. 4 is a block diagram of an interface code generating apparatus according to an exemplary embodiment. Referring to fig. 4, the apparatus includes: a first acquisition module 401, a determination module 402, a first storage module 403, and a code generation 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 determine the variable types and comments of the request and response data defined by each interface according to the interface description data;
the first storage module 403 is configured to store variable types and comments in the request and response data defined by each interface into a corresponding data structure object, and associate the variable types and comments in the data structure object;
The code generation module 404 is configured to execute the 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 accords with the type checked in the type check code.
Optionally, in another embodiment, based on the foregoing embodiment, the apparatus may further include: the judging module 501, the combining module 502 and the second storing module 503 are shown in fig. 5, wherein,
the judging module 501 is configured to perform judging 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 of 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 storing the variable type and the annotation in the same request data by the merging module 502 into the same data structure object, and associating the variable type and the annotation in the data structure object;
The first storage module 403 is further configured to perform storing the variable type and the comment in the request data and the response data defined by each interface in a corresponding data structure object, and associating the variable type and the comment in the data structure object when the determination module 501 determines that the request uniform resource identifiers of the interface description data are different.
Optionally, in another embodiment, based on the foregoing embodiment, the determining module is specifically configured to execute the 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, based on the foregoing embodiment, the code generating module 403 includes: a schematic diagram of the conversion module 601 and the association module 602 is shown in fig. 6, in which,
the conversion module 601 is configured to execute a type verification code that converts the variable types in each data structure object to corresponding types by a type conversion tool;
The association module 602 is configured to perform integrating the annotation of the variable type in each data structure object into a corresponding type check code, the type check code being used to check whether the variable in the encoding complies with the type checked in the type check code.
Optionally, in another embodiment, based on the foregoing embodiment, the apparatus may further include: a file generation module 701 is schematically shown in fig. 7, in which,
the file generating module 701 is configured to execute generating, by the front end code of the application program interface, all the type check codes into the interface code file after the code generating module generates the corresponding type check codes.
The specific manner in which the operations of the respective modules are performed in the apparatus of the above embodiments has been described in detail in the embodiments related to the method, and the relevant points are only required to be referred to in the description of the embodiments related to the method, which will not be described in detail herein.
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 method of generating interface code as described above.
In an exemplary embodiment, the present disclosure also provides a computer-readable storage medium, which when executed by a processor of an electronic device, causes the electronic device to perform the method of generating an interface code as described above.
In an exemplary embodiment, the present disclosure also provides a storage medium including instructions, such as a memory including instructions, executable by a processor of an apparatus to perform the above-described method. Alternatively, the storage medium may be a non-transitory computer readable storage medium, which may be, for example, ROM, random Access Memory (RAM), CD-ROM, magnetic tape, floppy disk, 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 method of generating interface code as described above.
Fig. 8 is a block diagram of an electronic device 800, according to an example embodiment. For example, the electronic device 800 may be a mobile terminal or a server, and in the embodiment of the disclosure, the electronic device is taken as an example of the mobile terminal. For example, electronic device 800 may be a mobile phone, computer, digital broadcast terminal, messaging device, game console, tablet device, medical device, exercise device, personal digital assistant, or the like.
Referring to fig. 8, an 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 component 802 may include one or more processors 820 to execute instructions to perform all or part of the steps of the methods described above. Further, the processing component 802 can include one or more modules that facilitate interactions 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 operations 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 nonvolatile 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 disk.
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 sources, and other components associated with generating, managing, and distributing power for the electronic device 800.
The multimedia component 808 includes a screen between the electronic device 800 and the user that provides an output interface. 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 input signals from a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensor may sense not only the boundary of a touch or slide action, but also the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front camera and/or a rear camera. The front camera and/or the rear camera may receive external multimedia data when the device 800 is in an operational 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 focal length and optical zoom capabilities.
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 be further stored in the memory 804 or transmitted via the communication component 816. In some embodiments, audio component 810 further 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 a keyboard, click wheel, buttons, etc. These buttons may include, but are not limited to: homepage button, volume button, start button, and lock button.
The sensor assembly 814 includes one or more sensors for providing status assessment of various aspects of the electronic device 800. For example, the sensor assembly 814 may detect an on/off state of the device 800, a relative positioning of the components, such as a display and keypad of the electronic device 800, the sensor assembly 814 may also detect a change in position of the electronic device 800 or a component of the electronic device 800, the presence or absence of a user's contact with the electronic device 800, an orientation or acceleration/deceleration of the electronic device 800, and a change in temperature of the electronic device 800. The sensor assembly 814 may include a proximity sensor configured to detect the presence of nearby objects 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 gyroscopic sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 816 is configured to facilitate communication between the electronic device 800 and other devices, either wired or wireless. The electronic device 800 may access a wireless network based on a communication standard, such as WiFi, an operator network (e.g., 2G, 3G, 4G, or 5G), or a combination thereof. In one exemplary embodiment, the communication component 816 receives broadcast signals or broadcast related information from an external broadcast management system via a broadcast channel. In one 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, microcontrollers, microprocessors, or other electronic elements for performing the method of generating interface code as described above.
In an exemplary embodiment, a non-transitory computer readable storage medium is also provided, such as memory 804 including instructions executable by processor 820 of electronic device 800 to perform the method of generating interface code shown above. For example, the non-transitory computer readable storage medium may be ROM, random Access Memory (RAM), CD-ROM, magnetic tape, floppy disk, optical data storage device, etc.
In an exemplary embodiment, a computer program product is also provided, which when instructions in the computer program product are executed by the processor 820 of the electronic device 800, causes the electronic device 800 to perform the above-described method of generating interface code.
Fig. 9 is a block diagram illustrating an apparatus 900 for generation of interface code according to an example embodiment. For example, apparatus 900 may be provided as a server. Referring to FIG. 9, apparatus 900 includes a processing component 922 that further includes one or more processors, and memory resources represented by memory 932, for storing instructions, such as applications, executable by 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, processing component 922 is configured to execute instructions to perform the method of generating method interface code described above.
The apparatus 900 may also include a power component 926 configured to perform power management of the apparatus 900, a wired or wireless network interface 950 configured to connect the apparatus 900 to a network, and an input output (I/O) interface 958. The device 900 may operate based on an operating system stored in 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 adaptations, 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 is to be understood that the present disclosure is not limited to the precise arrangements and instrumentalities shown in the drawings, and that various modifications and changes may be effected without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (9)

1. A method for generating an interface code, comprising:
acquiring interface description data of each interface on an analog interface platform;
determining the variable types and comments of the request and response data defined by each interface according to the interface description data;
storing variable types and comments in request and response data defined by each interface into corresponding data structure objects, and associating the variable types and comments in the data structure objects;
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 of the actual written program accords with the type checked in the type check code;
generating interface code files by using the front end codes of the application program interface and all the type check codes;
the generating the corresponding type check code according to the variable type and the annotation of the data structure object comprises the following steps:
converting the variable types in each data structure object into corresponding type check codes through a type conversion tool; the type conversion tool is a quick type;
and associating the comments of the variable types in each data structure object with the corresponding type check codes to generate annotated type check codes.
2. The method of generating an interface code according to claim 1, characterized in that the method further comprises:
judging whether the request uniform resource identifiers for acquiring the interface description data are the same or not;
if the request is the same, merging the interface description data of the same request uniform resource identifier;
storing variable types and comments in the same request data into the same data structure object, and associating the variable types and comments in the data structure object;
And if the variable types and the comments in the request data and the response data defined by each interface are different, the steps of storing the variable types and the comments in the corresponding data structure objects and associating the variable types and the comments in the data structure objects are executed.
3. The method for generating an interface code according to claim 1 or 2, wherein said determining, from said interface description data, a variable type and an annotation of request and response data defined by said each interface 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 annotation of each field in the request data and the variable type and the annotation of each field in the response data.
4. An interface code generating apparatus, comprising:
the first acquisition module is configured to acquire interface description data of each interface on the analog interface platform;
a determining module configured to perform determining a variable type and annotation of the 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 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;
The code generation module is configured to execute the corresponding type check code generated according to the variable types and the comments in the data structure object, and the type check code is used for checking whether the variables in the code of the actual written program accord with the types checked in the type check code;
the file generation module is configured to execute the generation of the corresponding type check codes by the code generation module, and then generate interface code files by the front end codes of the application program interface;
the code generation module includes:
a conversion module configured to execute a type verification code that converts the variable types in each data structure object to corresponding types by a type conversion tool; the type conversion tool is a quick type;
an association module configured to perform integration of annotations of the variable type in the each data structure object into corresponding type check code.
5. The apparatus for generating an interface code according to claim 4, wherein the apparatus further comprises:
a judging module configured to perform a judgment as to whether the request uniform resource identifiers of the interface description data are the same;
A merging module configured to execute merging of the interface description data of the same request uniform resource identifier when the judgment module judges that the request uniform resource identifiers of the interface description data are the same;
a second storage module configured to perform storing of variable types and annotations in the same request data into the same data structure object, and associating the variable types and annotations in the data structure object;
the first storage module is further configured to perform storing the variable type and the annotation in the request data and the response data defined by each interface into a corresponding data structure object when the judging module judges that the request uniform resource identifiers of the interface description data are different, and associating the variable type and the annotation in the data structure object.
6. The device according to claim 4 or 5, wherein the determining module is configured to execute the 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.
7. 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 an interface code as claimed in any one of claims 1 to 3.
8. A computer readable storage medium, characterized in that 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 an interface code according to any one of claims 1 to 3.
9. A computer program product comprising a computer program or instructions which, when executed by a processor, carries out the method of generating an interface code as claimed in any one of claims 1 to 3.
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 CN113157256A (en) 2021-07-23
CN113157256B true 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)

Families Citing this family (2)

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

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9329849B2 (en) * 2013-08-26 2016-05-03 Facebook, Inc. Systems and methods for converting typed code

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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 (5)

* Cited by examiner, † Cited by third party
Title
"OMS平台模型的服务化封装方法研究";王明 等;《地理信息世界》;第25卷(第03期);第11-16页 *
"Use of Graphic Imagery as a Mean of Communication Between Operators and Unmanned Systems in C3Fire Tasks";Tal Oron-Gilad 等;《 Engineering Psychology and Cognitive Ergonomics: Performance, Emotion and Situation Awareness 》;第362-381页 *
"基于SolidWorks的产品发布物数字化研究与应用";李文健;《中国优秀硕士学位论文全文数据库 (工程科技Ⅱ辑)》;第C029-123页 *
"西门子S7-200 PLC与智能仪表串行轮询通信";王明军;《设备管理与维修》(第01期);第37-41页 *
基于类型注解的认证编译器设计与实现;胡荣贵, 陈意云, 郭帆, 张昱;计算机研究与发展(01);全文 *

Also Published As

Publication number Publication date
CN113157256A (en) 2021-07-23

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
CN113434134B (en) Component processing method and device, electronic equipment and storage medium
CN111061452A (en) Voice control method and device of user interface
CN104991857B (en) Trace debug method and device
CN113568621A (en) Data processing method and device for page embedded point
CN111813932B (en) Text data processing method, text data classifying device and readable storage medium
CN111079040B (en) Resource sniffing method, device, terminal, server and storage medium
CN112416751A (en) Processing method and device for interface automation test and storage medium
CN112559309A (en) Method and device for adjusting page performance acquisition algorithm
CN111209195A (en) Method and device for generating test case
CN113626321B (en) Bridging test method, device, system and storage medium
CN106790683B (en) Network data display method and device based on mobile terminal
CN112486617B (en) Ciphertext data processing architecture, method, apparatus and machine readable medium
CN111338961B (en) Application debugging method and device, electronic equipment and storage medium
CN111061633B (en) Webpage first screen time detection method, device, terminal and medium
CN111131000B (en) Information transmission method, device, server and terminal
CN114428737A (en) Communication method, device, equipment and storage medium based on micro service system
CN114489603A (en) Code generation method, apparatus, electronic device, medium, and product
CN113761588A (en) Data verification method and device, terminal equipment and storage medium
CN107526683B (en) Method and device for detecting functional redundancy of application program and storage medium
CN115408277B (en) Interface testing method and device
CN112711420B (en) Code conversion method and device
CN111427566B (en) Data processing method and device suitable for analog interface platform and server

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