CN117908952A - Method, system and device for generating interface function definition - Google Patents

Method, system and device for generating interface function definition Download PDF

Info

Publication number
CN117908952A
CN117908952A CN202410066843.5A CN202410066843A CN117908952A CN 117908952 A CN117908952 A CN 117908952A CN 202410066843 A CN202410066843 A CN 202410066843A CN 117908952 A CN117908952 A CN 117908952A
Authority
CN
China
Prior art keywords
api
interface
service
request
definition
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.)
Pending
Application number
CN202410066843.5A
Other languages
Chinese (zh)
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.)
Hangzhou Shuzhi Zhengtong Technology Co ltd
Original Assignee
Hangzhou Shuzhi Zhengtong 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 Hangzhou Shuzhi Zhengtong Technology Co ltd filed Critical Hangzhou Shuzhi Zhengtong Technology Co ltd
Priority to CN202410066843.5A priority Critical patent/CN117908952A/en
Publication of CN117908952A publication Critical patent/CN117908952A/en
Pending legal-status Critical Current

Links

Abstract

The invention discloses a method, a system and a device for generating interface function definition, wherein the related method for generating interface function definition comprises the following steps: s1, inputting a document IP and an address corresponding to a document tool interface, and obtaining a document resource list of Swagger specifications based on the document IP and the address resolution; s2, analyzing the document resource list to obtain data related to the API; wherein the API-related data includes an API request path, a definition of the API, a tag of the API; s3, analyzing the API request path and the definition of the API to obtain an array set of the API object; the array set comprises definition of an API service module name, an API request mode, an API request parameter and an API return result; s4, analyzing the array set of the API object to obtain a service interface and a service function corresponding to the API; s5, analyzing the service interfaces and service functions corresponding to the APIs to obtain interface definition files of the storage interface request functions, the request types and the return types corresponding to the storage interface request functions.

Description

Method, system and device for generating interface function definition
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, a system, and an apparatus for generating an interface function definition.
Background
In the traditional Web software development format, one of the ways is for the front-end engineer to rely on the interface document address provided by the back-end engineer. After the document is referred to, the encoding work for interface function definition is performed in the front-end program. In the conventional Web development technical background, the conventional method has the following technical problems: 1. the traditional method relies on the front end to repeatedly consult interface documents provided by the back end to carry out programming work; 2. the traditional method needs to define a declaration function for each interface, which is time-consuming and easy to cause omission or errors, especially when facing a large number of interfaces or interface changes; 3. the developer needs to repeatedly consult the document to know the field information contained in the interface; 4. when a plurality of persons cooperatively develop the same project, a plurality of interface functions with different coding styles can be written because of different development habits of each developer.
Aiming at the technical problems, the invention provides a method, a system and a device for generating interface function definitions.
Disclosure of Invention
The invention aims at overcoming the defects of the prior art, and provides a method, a system and a device for generating interface function definition, which can automatically complete the definition of the interface function under the whole interface document and also comprise request parameter definition (interface) and return result definition (interface) corresponding to the interface function.
In order to achieve the above purpose, the present invention adopts the following technical scheme:
a method of generating an interface function definition, comprising:
s1, inputting a document IP and an address corresponding to a document tool interface, and obtaining a document resource list of Swagger specifications based on the document IP and the address resolution;
S2, analyzing the document resource list to obtain data related to the API; wherein the API-related data includes an API request path, a definition of the API, a tag of the API;
s3, analyzing the API request path and the definition of the API to obtain an array set of the API object; the array set comprises definition of an API service module name, an API request mode, an API request parameter and an API return result;
S4, analyzing the array set of the API object to obtain a service interface and a service function corresponding to the API;
s5, analyzing the service interfaces and service functions corresponding to the APIs to obtain interface definition files of the storage interface request functions, the request types and the return types corresponding to the storage interface request functions.
Further, the step S4 further includes traversing the array set of API objects.
Further, in the step S4, the parsing of the array set of the API object specifically includes: and constructing an abstract syntax tree according to the name of the API service module, and creating nodes of the abstract syntax tree to obtain service interfaces and service functions corresponding to the API.
Further, the service interface corresponding to the API obtained in step S4 specifically includes: and creating a first node of the abstract syntax tree according to the definition of the API request parameters and the API return results, and collecting the first node according to the name of the API service module to obtain a service interface taking the name of the API service module as a key value.
Further, the service function corresponding to the API obtained in step S4 is specifically: and creating a second node of the abstract syntax tree corresponding to the storage interface request function according to the API request path, and defining the request type and the return type of the storage interface request function to obtain the service function taking the name of the API service module as a key value.
Further, the step S5 specifically includes: traversing the service interfaces and service functions, creating interface definition files of a storage interface request function, a request type and a return type of the storage interface request function according to the name of the API service module, and writing the name of the API service module into the interface definition files corresponding to the first node and the second node of the abstract syntax tree.
Correspondingly, a system for generating interface function definition is also provided, which comprises:
The first analysis module is used for inputting a document IP and an address corresponding to the document tool interface and obtaining a document resource list of Swagger specifications based on the document IP and the address analysis;
The second analysis module is used for analyzing the document resource list to obtain data related to the API; wherein the API-related data includes an API request path, a definition of the API, a tag of the API;
the third analysis module is used for analyzing the API request path and the definition of the API to obtain an array set of the API object; the array set comprises definition of an API service module name, an API request mode, an API request parameter and an API return result;
The fourth analysis module is used for analyzing the array set of the API object to obtain a service interface and a service function corresponding to the API;
And the fifth analysis module is used for analyzing the service interface and the service function corresponding to the API to obtain a storage interface request function, a request type corresponding to the storage interface request function and an interface definition file of a return type.
Further, the parsing of the array set of the API object in the fourth parsing module specifically includes: constructing an abstract syntax tree according to the name of an API service module, and creating nodes of the abstract syntax tree to obtain service interfaces and service functions corresponding to the API;
The service interface corresponding to the obtained API specifically comprises the following steps: creating a first node of an abstract syntax tree according to the definition of the API request parameters and the API return results, and collecting the first node according to the name of the API service module to obtain a service interface taking the name of the API service module as a key value;
the service functions corresponding to the obtained API are specifically as follows: and creating a second node of the abstract syntax tree corresponding to the storage interface request function according to the API request path, and defining the request type and the return type of the storage interface request function to obtain the service function taking the name of the API service module as a key value.
Further, the fifth parsing module specifically includes: traversing the service interfaces and service functions, creating interface definition files of a storage interface request function, a request type and a return type of the storage interface request function according to the name of the API service module, and writing the name of the API service module into the interface definition files corresponding to the first node and the second node of the abstract syntax tree.
Correspondingly, there is also provided an apparatus for generating an interface function definition, including:
one or more processors;
And a storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the one method of generating an interface function definition.
Compared with the prior art, the invention has the following beneficial effects:
1. the definition of the interface function is automatically completed under the whole interface document, and the interface function also comprises a request parameter definition (interface) and a return result definition (interface) corresponding to the interface function, so that the work of repeated coding is solved.
2. When the interface is changed, the latest interface function definition can be regenerated only by re-inputting the instruction. To reduce manual work and potential errors.
3. According to the target format, the interface function definition is output in a modularized mode, and the readability and maintainability of codes are improved.
Drawings
Fig. 1 is a flowchart of a method for generating an interface function definition according to an embodiment.
Detailed Description
Other advantages and effects of the present invention will become apparent to those skilled in the art from the following disclosure, which describes the embodiments of the present invention with reference to specific examples. The invention may be practiced or carried out in other embodiments that depart from the specific details, and the details of the present description may be modified or varied from the spirit and scope of the present invention. It should be noted that the following embodiments and features in the embodiments may be combined with each other without conflict.
The invention aims at overcoming the defects of the prior art and provides a method, a system and a device for generating interface function definitions.
Example 1
The present embodiment provides a method for generating an interface function definition, as shown in fig. 1, including:
s1, inputting a document IP and an address corresponding to a document tool interface, and obtaining a document resource list of Swagger specifications based on the document IP and the address resolution;
S2, analyzing the document resource list to obtain data related to the API; wherein the API-related data includes an API request path, a definition of the API, a tag of the API;
s3, analyzing the API request path and the definition of the API to obtain an array set of the API object; the array set comprises definition of an API service module name, an API request mode, an API request parameter and an API return result;
S4, analyzing the array set of the API object to obtain a service interface and a service function corresponding to the API;
s5, analyzing the service interfaces and service functions corresponding to the APIs to obtain interface definition files of the storage interface request functions, the request types and the return types corresponding to the storage interface request functions.
In step S1, a document IP and an address corresponding to the document tool interface are input, and a document resource list of Swagger specification is obtained based on the document IP and the address resolution.
Through terminal command line interaction, the terminal operation interface can directly input the address of an interface document by using a keyboard, then obtain the input ShowDoc interface document IP and address, obtain the configuration data of Swagger documents by network request after obtaining the interface document address, then find out Swagger-resources corresponding information, process, further analyze a Swagger-canonical document resource list (Swagger-resources), and the user can select Swagger-resources to be analyzed. Wherein the condition of selection is that after parsing to swagger-resources set, keyboard for supporting terminal command line the "+. ∈" key is selected back and forth.
According to the embodiment, through inputting the interface document address provided by the back end, swagger-resources contained in the ShowDoc interface document are resolved, after the selection of a developer, definition of an interface function is automatically generated, and the problem that programming work is performed by repeatedly consulting the interface document provided by the back end depending on the front end is solved
In step S2, analyzing the document resource list to obtain API related data; wherein the API-related data includes API request paths, definitions of APIs, tags of APIs.
Terminal command line passing "+++++.3) one of swagger-resources is selected, the data that is needed to obtain swagger-resources can be selected, API-related data is obtained, which includes paths (request path), tags, definitions.
In step S3, analyzing the API request path and the definition of the API to obtain an array set of API objects; the array set comprises the definitions of an API service module name, an API request mode, an API request parameter and an API return result.
And (3) resolving to obtain an array set (interfaceResultArr) of the API object by combining paths and definition data in the step S2, wherein the array set of the API object comprises an API service module name, an API request mode, an API request parameter, definition (definition) of an API return result and the like.
The parsing method in this embodiment is to traverse the object paths, and each path corresponds to one interface, so as to obtain information related to the interface (requestWay, response, parameters, summary, etc.). The result definition is obtained by judging requestWay two cases (POST/GET) and combining the fields originalRef inside response as index to query in definitions. definitionParam was obtained in parameters. definition and definitionParam are field definitions for interface return results and request parameters, and according to the type of each field, the data is processed into a structure { field name: field data type } as a result interfaceResult and interfaceParamResult. And combining the obtained path interface information to obtain interfaceResultArr. Contains field information (interfaceResult, interfaceParamResult, path interface information).
In the front-end coding TYPESCRIPT environment, the embodiment automatically generates request parameter definition (interface) and return result definition (interface) related to the interface declaration function. The Interface information includes the type of the field, the field remark description, the field request example, and the like. The developer can directly locate the interface in the code editor, and related information is not required to be searched when the interface document is opened, so that the technical problem that the existing developer needs to repeatedly consult the document and know field information contained in the interface is solved.
In step S4, the array set of the API object is parsed to obtain the service interface and service function corresponding to the API.
And traversing interfaceResultArr data in the step S3, wherein the data at the traversal comprises field information interfaceResult, interfaceParamResult, path interface information.
An Abstract Syntax Tree (AST) identified by the API service module name is created depending on the external plug-in 'gogocode', and AST objects (as containers for AST nodes) are created depending on the external plug-in 'gogocode' and the parsed data interfaceResult and interfaceParamResult. And creates a first Node (AST Node) of the AST of the field according to the field information contained therein, and inserts the first Node into the first Node. Node aggregation is carried out on the first Node according to the name of the API service module, so that a service interface object (businessInterfaceModel) taking the name of the API service module as a Key value (Key value) is obtained; wherein the key value of the service interface object is the name of the API service module, and the value is the AST object (container) of the interface under the API service module.
The node collection is specifically as follows: one API service module name may correspond to multiple interfaces. Each interface retains this identification in the data parsing operation described above. When traversing the interface, the interface can be collected under the corresponding API service module according to the identification.
And traversing interfaceResultArr data in the step S3, and constructing an Abstract Syntax Tree (AST) according to the name of the service module of the API, wherein the traversing and the creating are the same as the previous mode.
According to the request Path (Path) of the API in step S2, and depending on the external plugin 'gogocode', creating an AST object identified by the request Path of the API to obtain a second Node (Node) of the AST of the storage interface request function, and after the AST object of the storage interface request function is created, modifying the attribute in the AST, and further modifying the request type (INTERFACEPARAMNAME) and the return type (interfaceRoName) of the storage interface request function. Obtaining a service function object (businessFunctionModel) taking the name of the API service module as a Key value, wherein businessFunctionModel contains an AST set of a declaration function and an entity type required to be introduced under the name of the API service module; wherein the entity types include INTERFACEPARAMNAME and interfaceRoName.
The embodiment realizes the modularization generation of interface function definition; when the interface is changed, the latest interface function definition can be regenerated only by re-inputting the instruction, so that manual work and potential errors are reduced, and the technical problem of repeated code writing work in the prior art is solved.
In step S5, the service interface and the service function corresponding to the API are parsed to obtain the storage interface request function, the request type corresponding to the storage interface request function, and the interface definition file of the return type.
Traversing businessInterfaceModel, businessFunctionModel in step S4, creating a file of a request type (INTERFACEPARAMNAME) and a return type (interfaceRoName) corresponding to a storage interface request function (Java service module name ts ') according to the API service module name, and writing an AST node corresponding to the API service module name into the file according to a method of writing the file provided by an external plug-in ' gogocode ', wherein the AST node comprises a first node of AST and a second node of AST.
According to the embodiment, according to the target format, the interface function definition is outputted in a modularized mode, the readability and maintainability of codes are improved, and the technical problem that the naming of the existing interface function is not standard is solved.
Example two
The present embodiment provides a system for generating an interface function definition, including:
the first analysis module is used for acquiring a document IP and an address corresponding to the input document tool interface and analyzing a document resource list of Swagger specifications based on the document IP and the address;
The second analysis module is used for analyzing the document resource list to obtain data related to the API; wherein the API-related data includes an API request path, a definition of the API;
The third analysis module is used for analyzing the API request path and the definition of the API to obtain an array set of the API object; the array set comprises an API service module name, an API request parameter and an API return result;
The construction module is used for constructing an abstract syntax tree according to the name of the API service module;
The first creating module is used for creating a first node of the abstract syntax tree according to the API request parameters and the API return result, and collecting the first node of the abstract syntax tree according to the name of the API service module to obtain a first object taking the name of the API service module as a key value;
The second creating module is used for creating a second node of the abstract syntax tree corresponding to the storage interface request function according to the API request path, defining the request type and the return type of the storage interface request function, and obtaining a second object taking the name of the API service module as a key value;
The third creating module is used for traversing the first object and the second object, creating an interface definition file of a storage interface request function, a request type and a return type of the storage interface request function according to the name of the API service module, and writing the name of the API service module into the interface definition file corresponding to the first node and the second node of the abstract syntax tree.
Further, the data related to the API in the second parsing module further includes a tag of the API.
Further, the method also comprises a traversing module for traversing the array set of the API object.
Further, the second object in the second creation module includes an array set of ASTI objects storing the interface request function and an entity type to be introduced under the name of the API service module.
It should be noted that, the system for generating the interface function definition provided in this embodiment is similar to the embodiment, and will not be described herein.
The embodiment has the following beneficial effects:
1. the definition of the interface function is automatically completed under the whole interface document, and the interface function also comprises a request parameter definition (interface) and a return result definition (interface) corresponding to the interface function, so that the work of repeated coding is solved.
2. When the interface is changed, the latest interface function definition can be regenerated only by re-inputting the instruction. To reduce manual work and potential errors.
3. According to the target format, the interface function definition is output in a modularized mode, and the readability and maintainability of codes are improved.
Example III
The embodiment provides an apparatus for generating an interface function definition, including:
one or more processors; processors such as central processing units, graphics processors, and the like.
And a storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement a method of generating an interface function definition in accordance with the first embodiment. Such as a memory RAM.
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.

Claims (10)

1. A method of generating an interface function definition, comprising:
s1, inputting a document IP and an address corresponding to a document tool interface, and obtaining a document resource list of Swagger specifications based on the document IP and the address resolution;
S2, analyzing the document resource list to obtain data related to the API; wherein the API-related data includes an API request path, a definition of the API, a tag of the API;
s3, analyzing the API request path and the definition of the API to obtain an array set of the API object; the array set comprises definition of an API service module name, an API request mode, an API request parameter and an API return result;
S4, analyzing the array set of the API object to obtain a service interface and a service function corresponding to the API;
s5, analyzing the service interfaces and service functions corresponding to the APIs to obtain interface definition files of the storage interface request functions, the request types and the return types corresponding to the storage interface request functions.
2. The method of claim 1, wherein the step S4 is preceded by traversing an array set of API objects.
3. The method for generating interface function definitions according to claim 1, wherein the parsing of the array set of API objects in step S4 is specifically: and constructing an abstract syntax tree according to the name of the API service module, and creating nodes of the abstract syntax tree to obtain service interfaces and service functions corresponding to the API.
4. A method for generating an interface function definition according to claim 3, wherein the service interface corresponding to the API obtained in step S4 is specifically: and creating a first node of the abstract syntax tree according to the definition of the API request parameters and the API return results, and collecting the first node according to the name of the API service module to obtain a service interface taking the name of the API service module as a key value.
5. A method for generating interface function definitions according to claim 3, wherein the service functions corresponding to the APIs obtained in step S4 are specifically: and creating a second node of the abstract syntax tree corresponding to the storage interface request function according to the API request path, and defining the request type and the return type of the storage interface request function to obtain the service function taking the name of the API service module as a key value.
6. The method of generating interface function definitions according to claim 1, wherein the step S5 is specifically: traversing the service interfaces and service functions, creating interface definition files of a storage interface request function, a request type and a return type of the storage interface request function according to the name of the API service module, and writing the name of the API service module into the interface definition files corresponding to the first node and the second node of the abstract syntax tree.
7. A system for generating an interface function definition, comprising:
The first analysis module is used for inputting a document IP and an address corresponding to the document tool interface and obtaining a document resource list of Swagger specifications based on the document IP and the address analysis;
The second analysis module is used for analyzing the document resource list to obtain data related to the API; wherein the API-related data includes an API request path, a definition of the API, a tag of the API;
the third analysis module is used for analyzing the API request path and the definition of the API to obtain an array set of the API object; the array set comprises definition of an API service module name, an API request mode, an API request parameter and an API return result;
The fourth analysis module is used for analyzing the array set of the API object to obtain a service interface and a service function corresponding to the API;
And the fifth analysis module is used for analyzing the service interface and the service function corresponding to the API to obtain a storage interface request function, a request type corresponding to the storage interface request function and an interface definition file of a return type.
8. The method for generating interface function definitions according to claim 7, wherein the parsing of the array set of API objects in the fourth parsing module is specifically: constructing an abstract syntax tree according to the name of an API service module, and creating nodes of the abstract syntax tree to obtain service interfaces and service functions corresponding to the API;
The service interface corresponding to the obtained API specifically comprises the following steps: creating a first node of an abstract syntax tree according to the definition of the API request parameters and the API return results, and collecting the first node according to the name of the API service module to obtain a service interface taking the name of the API service module as a key value;
the service functions corresponding to the obtained API are specifically as follows: and creating a second node of the abstract syntax tree corresponding to the storage interface request function according to the API request path, and defining the request type and the return type of the storage interface request function to obtain the service function taking the name of the API service module as a key value.
9. The method of generating an interface function definition according to claim 7, wherein the fifth parsing module is specifically: traversing the service interfaces and service functions, creating interface definition files of a storage interface request function, a request type and a return type of the storage interface request function according to the name of the API service module, and writing the name of the API service module into the interface definition files corresponding to the first node and the second node of the abstract syntax tree.
10. An apparatus for generating an interface function definition, comprising:
one or more processors;
Storage means for storing one or more programs which when executed by one or more processors cause the one or more processors to implement a method of generating an interface function definition as claimed in any one of claims 1 to 6.
CN202410066843.5A 2024-01-17 2024-01-17 Method, system and device for generating interface function definition Pending CN117908952A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410066843.5A CN117908952A (en) 2024-01-17 2024-01-17 Method, system and device for generating interface function definition

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410066843.5A CN117908952A (en) 2024-01-17 2024-01-17 Method, system and device for generating interface function definition

Publications (1)

Publication Number Publication Date
CN117908952A true CN117908952A (en) 2024-04-19

Family

ID=90695768

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410066843.5A Pending CN117908952A (en) 2024-01-17 2024-01-17 Method, system and device for generating interface function definition

Country Status (1)

Country Link
CN (1) CN117908952A (en)

Similar Documents

Publication Publication Date Title
US7069501B2 (en) Structured document processing system and structured document processing method
CN111488174B (en) Method and device for generating application program interface document, computer equipment and medium
US8352913B2 (en) Generating and resolving component names in an integrated development environment
CN112000398B (en) Method and device for determining bottom layer interface call link, computer equipment and medium
CN110502227B (en) Code complement method and device, storage medium and electronic equipment
CN103412853A (en) Method for automatically generating test cases aiming at document converters
CN111736840A (en) Compiling method and running method of applet, storage medium and electronic equipment
CN112882974A (en) JSON data conversion method and device, computer equipment and storage medium
CN112540862A (en) Interface document data generation method, device, equipment and storage medium
CN114594927A (en) Low code development method, device, system, server and storage medium
CN115599386A (en) Code generation method, device, equipment and storage medium
CN113901083A (en) Heterogeneous data source operation resource analysis positioning method and equipment based on multiple analyzers
CN112148343A (en) Rule issuing method and device and terminal equipment
CN109325217B (en) File conversion method, system, device and computer readable storage medium
CN114253995A (en) Data tracing method, device, equipment and computer readable storage medium
CN114168149A (en) Data conversion method and device
CN113760891A (en) Data table generation method, device, equipment and storage medium
CN111126008A (en) XSD-based code generation method and device, computer equipment and storage medium
CN117908952A (en) Method, system and device for generating interface function definition
CN115640279A (en) Method and device for constructing data blood relationship
CN115599388A (en) API (application programming interface) document generation method, storage medium and electronic equipment
CN111277650B (en) Automatic micro-service identification method combining functional indexes and non-functional indexes
CN113050987A (en) Interface document generation method and device, storage medium and electronic equipment
CN111125483A (en) Method and device for generating webpage data extraction template, computer device and computer readable storage medium
CN111221610A (en) Page element acquisition method and device

Legal Events

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