CN111488174B - Method and device for generating application program interface document, computer equipment and medium - Google Patents

Method and device for generating application program interface document, computer equipment and medium Download PDF

Info

Publication number
CN111488174B
CN111488174B CN202010290155.9A CN202010290155A CN111488174B CN 111488174 B CN111488174 B CN 111488174B CN 202010290155 A CN202010290155 A CN 202010290155A CN 111488174 B CN111488174 B CN 111488174B
Authority
CN
China
Prior art keywords
interface
target
array
attribute
interface 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.)
Active
Application number
CN202010290155.9A
Other languages
Chinese (zh)
Other versions
CN111488174A (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.)
Suzhou Dajiaying Information Technology Co Ltd
Original Assignee
Suzhou Dajiaying 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 Suzhou Dajiaying Information Technology Co Ltd filed Critical Suzhou Dajiaying Information Technology Co Ltd
Priority to CN202010290155.9A priority Critical patent/CN111488174B/en
Publication of CN111488174A publication Critical patent/CN111488174A/en
Application granted granted Critical
Publication of CN111488174B publication Critical patent/CN111488174B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/186Templates

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Artificial Intelligence (AREA)
  • Library & Information Science (AREA)
  • Stored Programmes (AREA)
  • Document Processing Apparatus (AREA)

Abstract

The invention discloses a method and a device for generating an application program interface document, computer equipment and a storage medium, wherein the method comprises the following steps: scanning the engineering file set of the microservice to obtain a structural body included in the engineering file set, and storing each attribute information included in the structural body in a corresponding structural body array; acquiring at least one interface definition file for storing interface definition functions in the project file set; analyzing each interface definition file, and storing key interface information corresponding to each interface definition function in a corresponding interface structure; and correspondingly analyzing each interface structure body and each structure body array to generate an interface document matched with the micro-service. The technical scheme of the embodiment of the invention provides a new way for automatically generating the interface document, improves the generation efficiency of the interface document, avoids various errors possibly caused by artificially generating the interface document and improves the accuracy of the interface document.

Description

Method and device for generating application program interface document, computer equipment and medium
Technical Field
The embodiment of the invention relates to a data processing technology, in particular to a method and a device for generating an application program interface document, a computer device and a medium.
Background
In the development process of a software project, the requirement of docking a front-end client and a back-end server is avoided, the front-end client and the back-end server are generally developed by different developers, so that the server needs to provide services to the outside through an Application Programming Interface (API) defined by the developers, and the client needs to dock and develop according to the functions provided by the API, so that an API document (also referred to as an Interface document) for describing the API functions of the server is indispensable.
In the process of implementing the invention, the inventor finds that: the current API document needs to be manually written by a developer according to the structure of the API, so that a great deal of time is spent by the developer, and errors are easily defined; meanwhile, when interface definition modification occurs, interface description in the API document is not consistent with actual conditions easily, and cooperation of the front end and the back end is affected.
Disclosure of Invention
The embodiment of the invention provides a method and a device for generating an application program interface document, computer equipment and a storage medium, which realize a new mode of automatically generating an API document and improve the generation efficiency and accuracy of the API document.
In a first aspect, an embodiment of the present invention provides a method for generating an application program interface document, where the method includes:
scanning a project file set of micro-services, acquiring each structural body included in the project file set, and storing each attribute information included in each structural body in a corresponding structural body array;
acquiring at least one interface definition file for storing interface definition functions in the project file set;
analyzing each interface definition file, and storing key interface information corresponding to each interface definition function in a corresponding interface structure;
and correspondingly analyzing each interface structure body and each structure body array to generate an interface document matched with the micro-service.
In a second aspect, an embodiment of the present invention further provides an apparatus for generating an application program interface document, where the apparatus includes:
the system comprises a structure array generation module, a data processing module and a data processing module, wherein the structure array generation module is used for scanning a project file set of the micro service, acquiring each structure body included in the project file set and storing each attribute information included in each structure body in a corresponding structure array;
an interface definition file acquisition module, configured to acquire at least one interface definition file for storing an interface definition function from the project file set;
the interface structure body generation module is used for analyzing each interface definition file and storing key interface information corresponding to each interface definition function in a corresponding interface structure body;
and the interface document generation module is used for correspondingly analyzing each interface structure body and each structure body array and generating an interface document matched with the micro service.
In a third aspect, an embodiment of the present invention further provides a computer device, where the computer device includes:
one or more processors;
storage means for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a method of generating an application programming interface document according to any embodiment of the invention.
In a fourth aspect, the embodiment of the present invention further provides a computer storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for generating an application program interface document according to any embodiment of the present invention.
The technical scheme of the embodiment of the invention provides a new mode for automatically generating the API document, improves the generation efficiency of the API document, avoids various errors possibly caused by artificial generation of the API document and improves the accuracy of the API document by storing the attribute information in each structural body included in the engineering file set in the corresponding structural body array, storing the key interface information corresponding to each interface definition function in at least one interface definition file for storing the interface definition functions in the corresponding interface structural body, and correspondingly analyzing each interface structural body and each structural body array to generate the API document matched with the micro service.
Drawings
FIG. 1 is a flowchart of a method for generating an API document according to a first embodiment of the present invention;
FIG. 2 is a flowchart of a method for generating an API document according to a second embodiment of the present invention;
FIG. 3 is a flowchart of a method for generating an API document according to a third embodiment of the present invention;
FIG. 4a is a flowchart of a method for generating an API document according to a fourth embodiment of the present invention;
FIG. 4b is a diagram of a result interface of an API document in accordance with a fourth embodiment of the present invention;
FIG. 5 is a block diagram of an API document generating apparatus according to a fifth embodiment of the present invention;
fig. 6 is a schematic structural diagram of a computer device in the sixth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
It should be further noted that, for the convenience of description, only some but not all of the relevant elements of the present invention are shown in the drawings. Before discussing exemplary embodiments in more detail, it should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although a flowchart may describe the operations (or steps) as a sequential process, many of the operations can be performed in parallel, concurrently or simultaneously. In addition, the order of the operations may be re-arranged. The process may be terminated when its operations are completed, but could have additional steps not included in the figure. The processes may correspond to methods, functions, procedures, subroutines, and the like.
Example one
Fig. 1 is a flowchart of a method for generating an API document according to an embodiment of the present invention, where the embodiment is applicable to a situation that an API document corresponding to a micro service is automatically generated according to a structure and an interface definition file in a project file set of the micro service, and the method may be executed by an API document generation apparatus, which may be implemented by software and/or hardware and may be generally integrated in a terminal or a server having data identification and processing functions, and the method of the embodiment specifically includes the following steps:
s110, scanning the engineering file set of the micro service, acquiring the structural bodies included in the engineering file set, and storing the attribute information included in each structural body in the corresponding structural body array.
The micro-service is a small service formed by a single application program, and has an independent process and a light weight process. For example, a microservice for implementing cinema ticketing or a microservice for implementing order inquiry, etc. Generally, in order to implement a micro service, a project is first created, various project files for implementing the micro service function are compiled in the project, and the micro service is finally obtained by compiling the project files.
Correspondingly, all the project files included in the project directory corresponding to one micro service are the project file set.
Generally, in an API document, it is necessary to record interface entry parameters (input parameters) and interface exit parameters (output parameters) of each interface in a project, and to record various attribute information of the interface entry parameters and the interface exit parameters at the same time. The interface input parameter and the interface output parameter are defined in an interface definition function in an interface definition file, and the attribute information of the interface input parameter and the interface output parameter is defined in a structural body of the engineering file.
Therefore, in order to automatically generate an API document, it is necessary to analyze each structure and interface definition file included in the engineering file set to obtain all contents necessary for generating the API document.
Specifically, the method for generating the API document according to the embodiments of the present invention may be implemented by using an interface function, where a name of the micro service and a physical storage directory of the micro service, that is, a physical storage directory of the engineering file set corresponding to the micro service, may be specified in the interface function.
Further, it may also be specified in the interface function, specifically, whether an API document needs to be generated for all the interfaces included in the engineering document set, or an API document needs to be generated for one or several specified interfaces included in the engineering document set.
The engineering file set of the microservice can be scanned recursively, and all struct structural body definitions are obtained through ast (abstract syntax tree) analysis in go languages. Generally, a struct structure includes a plurality of data lines, each data line defines attribute information of an attribute (parameter), and accordingly, after all information in each data line of the structure is stored in a new structure, the attribute information of each line of each structure is correspondingly stored in a structure array corresponding to each structure.
S120, acquiring at least one interface definition file for storing interface definition functions in the project file set.
In this embodiment, it may be predefined that a developer needs to write an interface definition function into a go file including a file name and including a keyword interface or a keyword pblmpl, and then the at least one interface definition file may be obtained in the project file set in a manner of keyword matching.
S130, analyzing each interface definition file, and storing the key interface information corresponding to each interface definition function in the corresponding interface structure.
Specifically, the interface structure corresponds to the interface definition function one to one. The key interface information corresponding to the interface definition function may include: interface name, interface out-parameter (interface output parameter), interface in-parameter (interface input parameter), and interface description information.
In this embodiment, it may be predetermined that the developer writes a reference to a Req or Request structure in the interface definition function, writes a reference to a Resp or Rsp structure in the interface definition function, defines description information of the interface above each interface definition function, and starts with a set keyword, for example, "// ApiDoc".
Accordingly, in this embodiment, first, each interface definition function (a complete structure with func as a beginning) may be located in the interface definition file, and then, according to each interface definition function obtained by the location, the interface name, the interface out-reference, the interface in-reference, and the description information of the interface may be obtained.
Specifically, the interface definition functions can be located by counting "{ }" included in each interface definition function.
And S140, correspondingly analyzing each interface structure body and each structure body array, and generating an interface document matched with the micro-service.
In this embodiment, through the interface parameter input and output defined in the interface structure, the structure array corresponding to each interface parameter input or output respectively can be obtained from the structure array, and then the attribute information corresponding to each interface parameter input and output respectively is obtained recursively, so as to finally generate the API document matching the micro service, that is, the interface document.
Specifically, the API document may be an API document corresponding to all interfaces included in the micro service, or an API document corresponding to one or more interfaces specified in the micro service.
The technical scheme of the embodiment of the invention provides a new mode for automatically generating the API document, improves the generation efficiency of the API document, avoids various errors possibly caused by artificial generation of the API document and improves the accuracy of the API document by storing the attribute information in each structural body included in the engineering file set in the corresponding structural body array, storing the key interface information corresponding to each interface definition function in at least one interface definition file for storing the interface definition functions in the corresponding interface structural body, and correspondingly analyzing each interface structural body and each structural body array to generate the API document matched with the micro service.
Example two
Fig. 2 is a flowchart of a method for generating an API document according to a second embodiment of the present invention, which is further embodied based on the above embodiments, in this embodiment, an operation of scanning a project file set of a microservice, acquiring a structure body included in the project file set, and storing each attribute information included in the structure body in a corresponding structure body array is embodied as: extracting a target structure body from a target project file currently processed by the project file set, and establishing an initialized target structure body array matched with the target structure body; generating a first standard structural body corresponding to each line according to each item of attribute information included in each line of the target structural body; and taking the first standard structure bodies respectively corresponding to the rows as array objects and storing the array objects in the target structure body array.
Correspondingly, as shown in fig. 2, the scheme of the embodiment of the present invention specifically includes the following steps:
s210, in the project file set of the micro service, one project file is sequentially obtained to serve as a target project file of current processing.
S220, extracting a target structure body from the currently processed target project file, and establishing an initialized target structure body array matched with the target structure body.
In general, a structure can be identified by identification information specific to the structure. For example, in each project document, the structure starts with struct. Therefore, one or more target structures can be extracted from the currently processed project file (i.e., the target project file) by recognizing the struct keyword.
Furthermore, each row of data in the structure corresponds to each data parameter of a certain item of data, so that each row of data of the target structure can be extracted to generate and obtain one structure, and one structure corresponds to one structure array formed by a plurality of structures.
Correspondingly, after a target structure is extracted, an initialized structure array can be established for the target structure, and a one-to-one correspondence relationship between the target structure and the initialized structure array can be specified.
And S230, generating first standard structural bodies corresponding to the rows respectively according to the attribute information included in the rows of the target structural body.
Specifically, S230 may further include the following operations: acquiring a currently processed target line in the target structure data; identifying each target attribute information included in the target row, and performing filling processing on a first structure body template according to each target attribute information to obtain a first standard structure body corresponding to the target row; wherein the first structure body template comprises: at least one field name, and blank items to be filled which are matched with the field names respectively.
Wherein the field names in the first structure template include at least one of: attribute name, attribute type name, attribute comment, whether the attribute is must be filled, whether the attribute needs serialization, and the serialized name of the attribute.
In a specific example, the data format of a certain target structure is as follows:
typeAddNameForOpenAPIReqstruct{
SpEntID int 64' apidoc: "test attribute:
from SpID int64 ' json, ' from _ sp _ ID '/origin service ID
ToSpID int64// to facilitator ID labor SpId
}
The data format of a predetermined first structure template is as follows:
typeFieldItemstruct{
VarName string// attribute name
VarTypeVarTypeEnum//0str 1int 2bool 3arr 4obj
structName string// attribute type name
VarTag string// Note
Whether Must int// Must fill
Whether or not ISVobool// requires serialization
VoName string// serialized name
}
Wherein the first structure body template comprises: at least one field name (i.e., fields of VarName, varType, and StructName), and blank entries to be filled that match each of the field names, respectively.
Accordingly, the attribute information included in each line of the target structure may be mapped to one first structure template, so as to obtain a first standard structure corresponding to each line.
Specifically, the field VarName included in the first structure is the name of the attribute itself, and the blank item to be filled corresponding to the field is used to fill a specific attribute name, for example, for a data line "SpEntID int 64' apidococ:" test attribute × "", spetid may be filled in the blank item to be filled corresponding to the VarName, that is: "VarName SpEntID";
the field VarTypeVarTypeEnum included in the first structure template is an attribute type, and a blank item to be filled corresponding to the field is used for filling a specific attribute type. The blank entry to be filled is used to fill different numbers for different attribute types.
For example, if one attribute type is str (character) type, it corresponds to numeral 0, and if one attribute type is int (integer) type, it corresponds to numeral 1, and if one attribute type is bool (boolean) type, it corresponds to numeral 2, and if one attribute type is arr (array) type, it corresponds to numeral 3, and if one attribute type is obj (object) type, it corresponds to numeral 4. In the previous example, for the data line "SpEntID int 64' apidoco:" test attribute × "", 1 may be filled in the blank entry to be filled corresponding to the VarTypeVarTypeEnum, that is: "VarTypeVarTypeEnum 1";
the field StructName included in the first structure template is a property type name, and the blank item to be filled corresponding to the field is used for filling a specific property type name. For example, for the data line "SpEntID int 64' apidoco:" test attribute × "", int64 may be filled in the blank entry to be filled corresponding to the StructName, that is: "StructName int64";
the field VarTag included in the first structure template is an attribute comment, and the field best included in the first structure template is whether an attribute Must be filled. The attribute explanation and whether the attribute information needs to be filled in or not can obtain tag labels and comments of the attributes in a format matching mode when performing ast analysis. If the tag of the attribute contains the tag of "apidoc" (as an example only), or contains the annotation identifier of "//", the corresponding annotation content is obtained and filled in the blank item to be filled corresponding to the VarTag, and then, whether the annotation content has a setting character string therein is determined again, for example, ": if Yes, the attribute is determined to be filled, and then "Yes" may be filled in the blank item to be filled corresponding to the best.
Correspondingly, in an optional implementation manner of this embodiment, identifying each piece of target attribute information included in the target row, and performing filling processing on the first structure template according to each piece of target attribute information to obtain a first standard structure corresponding to the target row may specifically include:
if the preset attribute label (for example, the setting attribute label apidoc:) or the comment symbol (for example, "///") is identified in the target line, extracting the content behind the attribute label or the comment symbol in the target line as the alternative attribute information;
judging whether a preset key character string (e.g., ") is included in the candidate attribute information;
if Yes, acquiring the content except the key character string in the alternative attribute information, filling the content in the first structure template into a blank item to be filled corresponding to the attribute annotation field name, and filling a logic (for example, "Yes") into the blank item to be filled corresponding to whether the attribute is the required field name in the first structure template;
if not, filling the candidate attribute information into the blank item to be filled corresponding to the attribute annotation field name in the first structure template, and filling a No logic (for example, "No") into the blank item to be filled corresponding to whether the attribute is the mandatory field name in the first structure template.
For example, also for the data line "spintid int 64' apidoco:" test attribute × "", because the attribute tag "apidoco:" is recognized, the "test attribute" following the attribute tag can be filled in the blank entry to be filled corresponding to the field VarTag, that is: "VarTag test attribute"; it is to be logically filled in the blank entry to be filled corresponding to the field Must, i.e., "Must Yes".
The field IsVobol included in the first structure template is whether the attribute needs to be serialized, and the field VoName included in the first structure template is the serialization name of the attribute. Because json in go has two serialization modes, one is that the initial character of the attribute name uses the capital form, and the other is written in Tag label of json, whether the attribute needs to be serialized to the front end is judged through the two modes.
Specifically, if the tag of the attribute includes a json tag, a matched json serialized name can be read back and used as a filling result corresponding to the VoName; alternatively, if the first character of the attribute name is capitalized, the attribute name may be acquired as a fill result corresponding to the von ame.
Correspondingly, identifying each target attribute information included in the target row, and performing filling processing on the first structure template according to each target attribute information to obtain a first standard structure corresponding to the target row, and may further include:
if the first separator is identified in the target line, acquiring the content before the first separator as alternative serialization name information;
if the initial letter of the alternative serialization name information is determined to be a capital letter, filling logic (Yes) in a blank item to be filled corresponding to the attribute field name needing serialization in the first structure template;
and filling the alternative serialization name information into blank items to be filled corresponding to the serialization name field names of the attributes in the first structure template.
In this embodiment, if it is determined that the first letter in the attribute name of the currently processed data line is a capital letter, it may be stated that serialization is required, and the attribute name may be taken as a serialization name.
Further, identifying each target attribute information included in the target row, and performing filling processing on the first structure template according to each target attribute information to obtain a first standard structure corresponding to the target row, may further include:
if the preset serialization keyword (for example, 'json:') is determined to be identified in the target row, extracting the content positioned behind the serialization keyword in the target row as serialization name information;
filling the blank items to be filled corresponding to the attribute field names which need to be serialized in the first structure template in a logic mode, and filling the serialization name information in the blank items to be filled corresponding to the attribute field names in the first structure template in a serialization mode.
For example, for the data line from SpID int 64' json: "from _ sp _ ID"// origin service ID ″, since the tag of "json:" is recognized, the "from _ sp _ ID" following the attribute tag can be filled in the blank entry to be filled corresponding to the field VoName, that is: "VoName from _ sp _ id"; it will be logical fill in the blank entry to be filled corresponding to this field isvobol, i.e. "isvobol Yes".
In another specific example, for ToSpID int64// to service ID labor SpId, since the first character of "ToSpID" is identified as capital, toSpID can be filled in the blank to be filled corresponding to this field VoName, that is: "VoName ToSpID"; it will be logical fill in the blank entry to be filled corresponding to this field isvobol, i.e. "isvobol Yes".
And S240, taking the first standard structure bodies corresponding to the rows respectively as array objects and storing the array objects in the target structure body array.
S250, judging whether the processing of all the project files in the project file set is finished: if yes, go to S260; otherwise, return to execute S210.
Through the above operations, each item of attribute information of each line in one structure can be filled into the matched first structure template, so as to obtain a structure array corresponding to the structure, for example, [ ] > FieldItem. Accordingly, one [ f ] FieldItem stores information of each attribute inside one structure.
Accordingly, by performing the above operations in a loop, after all the files and structures are scanned, all the structures corresponding to all the project files in the project file set are stored in a large map. Key is the name of a structure, and value is the specific information of each structure.
S260, acquiring at least one interface definition file for storing interface definition functions in the project file set.
S270, analyzing each interface definition file, and storing the key interface information corresponding to each interface definition function in the corresponding interface structure.
S280, correspondingly analyzing each interface structure body and each structure body array, and generating an interface document matched with the micro-service.
According to the technical scheme of the embodiment of the invention, each item of attribute information in each structural body in the engineering file set is stored in the corresponding structural body array according to the preset data extraction rule, so that various attribute information of each attribute can be accurately and efficiently obtained in a recursive analysis mode in the subsequent process of generating the API document, a new mode of automatically generating the API document is realized, and the generation efficiency and accuracy of the API document are improved.
EXAMPLE III
Fig. 3 is a flowchart of a method for generating an API document according to a third embodiment of the present invention, where the third embodiment of the present invention is further embodied based on the foregoing embodiments, and in this embodiment, the operation of parsing the interface definition file and storing the key interface information corresponding to each interface definition function in the corresponding interface structure is embodied as: acquiring a currently processed target interface definition file, and identifying at least one interface definition function in the target interface definition file; and generating a second standard structure body corresponding to each interface definition function according to each item of key interface information included in each interface definition function.
Correspondingly, as shown in fig. 3, the scheme of the embodiment of the present invention specifically includes the following steps:
s310, scanning the engineering file set of the microservice, acquiring each structural body included in the engineering file set, and storing each attribute information included in each structural body in a corresponding structural body array.
S320, acquiring at least one interface definition file for storing interface definition functions in the project file set.
S330, sequentially acquiring an interface definition file as a currently processed target interface definition file.
S340, identifying at least one interface definition function in the target interface definition file.
In this embodiment, at least one interface definition function can be identified by scanning the code in the target interface definition file line by line and finding each corresponding func function closure in the code. Each func function is composed of a plurality of closed ' { } ', and a closed func function can be finally identified and obtained by traversing paired ' { }. That is, the count may be incremented by 1 each time the "is traversed to a" { "and decremented by 1 each time the" is traversed to a "}", and the count is cleared to 0, which indicates that the current traversal is to the end of a complete func function.
Correspondingly, identifying at least one interface definition function in the target interface definition file may specifically include:
traversing identification parenthesis identifiers in the target interface definition file, the parenthesis identifiers including a start parenthesis identifier and a stop parenthesis identifier;
when the starting bracket identifier is identified and the current count of the closed state counter is 0, updating the position of a starting function according to the file position of the starting bracket identifier, and adding one to the closed state counter;
when the starting bracket identifier is identified and the current count of the closed state counter is not 0, directly adding one to the closed state counter;
upon identifying a termination bracket identifier, decrementing the closed state counter by one;
and when the zero clearing state of the closed state counter is determined, determining an interface definition function in the target interface definition file according to the file position of the currently identified termination bracket identifier and the position of the starting function.
Wherein the start bracket identifier may be "{" and the stop bracket identifier may be "}".
And S350, generating second standard structures respectively corresponding to the interface definition functions according to the key interface information included in the interface definition functions.
In this embodiment, it may be predefined that when a developer generates an interface definition file, an interface entry needs to be defined in a structure including a Req or a Request, an interface exit needs to be defined in a structure including a Resp or an Rsp, and further, description information of an interface needs to be defined above each interface definition function.
Correspondingly, after each interface definition function is accurately identified, each item of key interface information included in the interface definition function can be accurately identified based on the predefined rule, and is stored in the corresponding second standard structure.
Correspondingly, according to each item of key interface information included in the interface definition function, generating second standard structures corresponding to the interface definition functions respectively, which may specifically include:
identifying at least one item of key interface information in a currently processed target interface definition function; filling a preset second structural body template according to the information of each key interface to obtain a second standard structural body corresponding to the target interface definition function; wherein the second structural body formwork includes: at least one field name, and blank items to be filled which are respectively matched with the field names.
Wherein: the field names in the second structure template include at least one of: interface name, interface out-reference, interface in-reference and interface description information.
In one specific example, an interface definition function is as follows:
// ApiDoc derived Excel documents
func(s*server)ExportNameList(ctx context.Context,in*pbaas.InvokeserviceRequest)(*pbaas.InvokeserviceResponse,error)
{log.Debug(msg:”Expo rtNameLlst”,CtX…:"AppData",In.AppData)
//req:=new(AddNameFo ropenAPIReq)
var req AddNameFo ropenAPIReq
err:=json.Unmarshal([]byte(in.GetAppData()),&req)
if err!=nil{…}
uid:=in.GetUid()
if uid<=0{…}
var rsp*FileUploadResponse
isWoda,userRole,errcode:=checkUserRight(ctx,uid)
if errCode==OK{…}
return&pbaas.InvokeserviceResponse{ServiceResponseData:generateJSON(errCode,rsp)},nil}
Wherein, the interface definition function includes: interface name, interface out-reference, interface in-reference, and interface description information.
A standard form of a second structure form is as follows:
type CallInfo struct{
name string// interface Name
Req string// reference structure name
Rsp string// reference structure name
Description of Comment string// interface
}
The interface definition function is scanned line by line, and the finally filled second standard structure is as follows:
{
Name:ExportNameList
Req:AddNameForOpenAPIReq
Rsp:FileUploadResponse
commment exporting Excel document
}
S360, judging whether the processing of all the interface definition files is finished: if yes, go to S370; otherwise, return to execute S330.
After the progressive scanning of all the interface definition functions in all the interface definition files is completed, the second standard structural bodies corresponding to the interface definition functions can be obtained.
And S370, correspondingly analyzing each interface structure body and each structure body array, and generating an interface document matched with the micro service.
According to the technical scheme of the embodiment of the invention, each item of key interface information in each interface definition function in the engineering file set is stored in the corresponding structural body according to the preset data extraction rule, so that various attribute information of each attribute can be accurately and efficiently obtained in a recursive analysis mode in the subsequent process of generating the API document, a new mode of automatically generating the API document is realized, and the generation efficiency and accuracy of the API document are improved.
Example four
Fig. 4a is a flowchart of a method for generating an API document according to a fourth embodiment of the present invention, where the embodiment of the present invention is further embodied based on the foregoing embodiments, and in this embodiment, an operation of performing correspondence analysis on each interface structure and each structure array to generate an interface document matching the micro service is embodied as: acquiring a currently processed target interface structure; recursively analyzing array objects in the array of the structure according to field values corresponding to the interface input parameter field names and the interface output parameter field names in the target interface structure to obtain complete input parameters and complete output parameters; and generating an interface document of an interface definition function associated with the target interface structure body in the micro service according to the complete parameter input value and the complete parameter output value.
Correspondingly, as shown in fig. 4a, the scheme of the embodiment of the present invention specifically includes the following steps:
s410, scanning the engineering file set of the microservice, acquiring each structural body included in the engineering file set, and storing each attribute information included in each structural body in a corresponding structural body array.
S420, acquiring at least one interface definition file for storing interface definition functions from the project file set.
S430, analyzing each interface definition file, and storing the key interface information corresponding to each interface definition function in the corresponding interface structure.
And S440, sequentially acquiring an interface structure as a target interface structure of the current processing.
S450, recursively analyzing array objects in the array of the structure according to field values corresponding to the interface parameter field names and the interface parameter field names in the target interface structure, and obtaining complete input parameters and complete output parameters.
Continuing the previous example, interface to export Excel documents
Figure BDA0002450090910000151
The matched complete parameter input value is required to be obtained for AddNameForOpenAPIReq, the matched complete parameter output value is obtained for FileUpLoadResponse, and the contents can be obtained by recursively analyzing array objects in the array of the structure body.
Assume that for addmaefopenapireq, the predefined structure is as follows:
Figure BDA0002450090910000152
Figure BDA0002450090910000161
it can be seen that the structure includes an array, a pointer, and other structures, so that the array of the structure corresponding to the AddNameForOpenAPIReq needs to be subjected to recursion and multilayer analysis, and all attribute information corresponding to the AddNameForOpenAPIReq is acquired.
Correspondingly, recursively parsing the array object in the array of the structure according to the field value corresponding to the name of the field of the interface output parameter in the target interface structure to obtain a complete input parameter, which may include:
searching a target structure array matched with the target field value in each structure array according to the target field value corresponding to the interface output field name in the target interface structure;
sequentially acquiring a data object included in the target structure array as a current processing object;
if the attribute type of the current processing object does not belong to the recursive structure type, generating an entry parameter value matched with the interface entry parameter according to the current processing object;
if the attribute type of the current processing object belongs to a recursion type, carrying out recursion analysis on other associated structure array by taking the current processing object as a starting point to obtain all input parameter values matched with the current processing object;
and returning to execute the operation of sequentially acquiring one data object included in the target structure array as the current processing object until the operation of all the data objects included in the target structure array is completed so as to obtain a complete parameter value corresponding to the interface parameter.
Wherein the recursion type comprises at least one of: array, pointer, and structure type.
And S460, generating an interface document of an interface definition function associated with the target interface structure body in the micro service according to the complete input parameter value and the complete output parameter value.
Fig. 4b is a schematic diagram of a result interface of an API document in the fourth embodiment of the present invention.
S470, judging whether the processing of all the interface structural bodies is finished: if so, determining to obtain an interface document corresponding to the micro service, and ending the process; otherwise, return to execute S440.
The technical scheme of the embodiment of the invention provides a new mode for automatically generating the API document, improves the generation efficiency of the API document, avoids various errors possibly caused by artificial generation of the API document and improves the accuracy of the API document by storing the attribute information in each structural body included in the engineering file set in the corresponding structural body array, storing the key interface information corresponding to each interface definition function in at least one interface definition file for storing the interface definition functions in the corresponding interface structural body, and correspondingly analyzing each interface structural body and each structural body array to generate the API document matched with the micro service.
On the basis of the above embodiments, scanning a project file set of a microservice to obtain each structural body included in the project file set, and storing each attribute information included in each structural body in a corresponding structural body array, which is realized by using a plurality of Go coroutines; and/or
And analyzing each interface definition file, and storing the key interface information corresponding to each interface definition function in a corresponding interface structure body by using a plurality of Go coroutines.
The advantages of such an arrangement are: the multi-coroutine technology of go is used for concurrent scanning, so that the tool execution time can be improved, and the API document generation efficiency and the data processing efficiency are further improved.
EXAMPLE five
Fig. 5 is a structural diagram of an API document generating apparatus according to a fifth embodiment of the present invention, where the apparatus includes: a structure array generating module 510, an interface definition file acquiring module 520, an interface structure generating module 530 and an interface document generating module 540. Wherein:
the structure array generating module 510 is configured to scan a project file set of the microservice, acquire each structure included in the project file set, and store each attribute information included in each structure in a corresponding structure array.
An interface definition file obtaining module 520, configured to obtain at least one interface definition file used for storing an interface definition function in the project file set.
The interface structure generating module 530 is configured to parse each interface definition file, and store the key interface information corresponding to each interface definition function in the corresponding interface structure.
And an interface document generating module 540, configured to perform corresponding parsing on each interface structure and each structure array, and generate an interface document matched with the micro service.
The technical scheme of the embodiment of the invention provides a new mode for automatically generating the API document, improves the generation efficiency of the API document, avoids various errors possibly caused by artificial generation of the API document and improves the accuracy of the API document by storing the attribute information in each structural body included in the engineering file set in the corresponding structural body array, storing the key interface information corresponding to each interface definition function in at least one interface definition file for storing the interface definition functions in the corresponding interface structural body, and correspondingly analyzing each interface structural body and each structural body array to generate the API document matched with the micro service.
On the basis of the foregoing embodiments, the structure array generating module 510 may specifically include:
the target structure array initialization unit is used for extracting a target structure from a target project file currently processed by the project file set and establishing an initialized target structure array matched with the target structure;
a first standard structural body generating unit, configured to generate, according to each item of attribute information included in each line of the target structural body, first standard structural bodies corresponding to the respective lines;
and the target structure array generating unit is used for storing the first standard structures respectively corresponding to the rows as array objects in the target structure array.
On the basis of the foregoing embodiments, the first standard structure body generating unit may specifically include:
a target row acquiring subunit, configured to acquire a currently processed target row in the target structure data;
a filling processing subunit, configured to identify each piece of target attribute information included in the target row, and perform filling processing on the first structure template according to each piece of target attribute information to obtain a first standard structure corresponding to the target row;
wherein the first structure body template comprises: at least one field name, and blank items to be filled which are matched with the field names respectively.
On the basis of the foregoing embodiments, the field names in the first structure template include at least one of the following:
attribute name, attribute type name, attribute annotation, whether an attribute is must-fill, whether an attribute requires serialization, and the serialized name of an attribute.
On the basis of the foregoing embodiments, the filling processing subunit may specifically be configured to:
if the preset attribute tag or the comment symbol is identified in the target line, extracting the content behind the attribute tag or the comment symbol in the target line as alternative attribute information;
judging whether the candidate attribute information comprises a preset key character string or not;
if yes, acquiring the content except the key character string in the alternative attribute information, filling the content in the first structure template into a blank item to be filled corresponding to the attribute annotation field name, and logically filling the content in the first structure template into the blank item to be filled corresponding to whether the attribute is the required field name;
if not, filling the candidate attribute information into the blank item to be filled corresponding to the attribute annotation field name in the first structure template, and logically filling the candidate attribute information into the blank item to be filled corresponding to whether the attribute is the required field name or not in the first structure template.
On the basis of the foregoing embodiments, the filling processing subunit may specifically be configured to:
if the first separator is identified in the target line, acquiring the content before the first separator as alternative serialization name information;
if the first letter of the alternative serialization name information is determined to be a capital letter, the alternative serialization name information is logically filled in a blank item to be filled corresponding to the field name of whether the attribute needs to be serialized or not in the first structure template;
and filling the alternative serialization name information into blank items to be filled corresponding to the serialization name field names of the attributes in the first structure template.
On the basis of the foregoing embodiments, the filling processing subunit may specifically be configured to:
if the preset serialization keywords are identified in the target row, extracting the contents behind the serialization keywords in the target row as serialization name information;
filling the blank items to be filled corresponding to the attribute field names which need to be serialized in the first structure template in a logic mode, and filling the serialization name information in the blank items to be filled corresponding to the attribute field names in the first structure template in a serialization mode.
On the basis of the foregoing embodiments, the interface structure generating module 530 may specifically include:
the interface definition function identification unit is used for acquiring a currently processed target interface definition file and identifying at least one interface definition function in the target interface definition file;
and the second standard structure generating unit is used for generating second standard structures corresponding to the interface definition functions respectively according to the key interface information included in the interface definition functions.
On the basis of the foregoing embodiments, the interface definition function identifying unit may be specifically configured to:
traversing identification parenthesis identifiers including a start parenthesis identifier and an end parenthesis identifier in the target interface definition file;
when the starting bracket identifier is identified and the current count of the closed state counter is 0, updating the starting function position according to the file position of the starting bracket identifier, and adding one to the closed state counter;
when the starting bracket identifier is identified and the current count of the closed state counter is not 0, directly increasing one by the closed state counter;
upon identifying a termination bracket identifier, decrementing the closed state counter by one;
and when the zero clearing state of the closed state counter is determined, determining an interface definition function in the target interface definition file according to the file position of the currently identified termination bracket identifier and the position of the starting function.
On the basis of the foregoing embodiments, the second standard structure body generating unit may be specifically configured to:
identifying at least one item of key interface information in a currently processed target interface definition function;
filling a preset second structural body template according to the information of each key interface to obtain a second standard structural body corresponding to the target interface definition function;
wherein the second structure form comprises: at least one field name, and blank items to be filled which are respectively matched with the field names.
On the basis of the foregoing embodiments, the field names in the second structural body template include at least one of the following:
interface name, interface out-reference, interface in-reference and interface description information.
On the basis of the foregoing embodiments, the interface document generating module 540 may specifically include:
a target interface structure acquisition unit for acquiring a currently processed target interface structure;
the complete parameter value acquisition unit is used for recursively analyzing array objects in the array of the structure body according to field values corresponding to the interface output parameter field names and the interface input parameter field names in the target interface structure body to obtain complete input parameter values and complete output parameter values;
and the document generating unit is used for generating an interface document of an interface definition function related to the target interface structure body in the micro service according to the complete input parameter value and the complete output parameter value.
On the basis of the foregoing embodiments, the complete parameter value obtaining unit may be specifically configured to:
searching a target structure array matched with the target field value in each structure array according to the target field value corresponding to the interface output field name in the target interface structure;
sequentially acquiring a data object included in the target structure array as a current processing object;
if the attribute type of the current processing object does not belong to the recursive structure type, generating an entry parameter value matched with the interface entry parameter according to the current processing object;
if the attribute type of the current processing object belongs to a recursion type, carrying out recursion analysis on other associated structure array by taking the current processing object as a starting point to obtain all input parameter values matched with the current processing object;
and returning to execute the operation of sequentially acquiring one data object in the target structure array as the current processing object until the operation on all the data objects in the target structure array is completed so as to obtain a complete parameter value corresponding to the interface parameter.
On the basis of the above embodiments, the recursion type may include at least one of the following: array, pointer, and structure type.
On the basis of the foregoing embodiments, the structure array generating module 510 may be implemented by using a plurality of Go coroutines; and/or
The interface structure generation module 530 may be implemented using a plurality of Go protocols.
The device for generating the API document, provided by the embodiment of the invention, can execute the method for generating the API document, provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
EXAMPLE six
Fig. 6 is a schematic structural diagram of a computer device according to a sixth embodiment of the present invention. FIG. 6 illustrates a block diagram of an exemplary computer device 12 suitable for use in implementing embodiments of the present invention. The computer device 12 shown in FIG. 6 is only an example and should not impose any limitations on the functionality or scope of use of embodiments of the present invention.
As shown in FIG. 6, computer device 12 is in the form of a general purpose computing device. The components of computer device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that couples various system components including the system memory 28 and the processing unit 16.
Bus 18 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, industry Standard Architecture (ISA) bus, micro channel architecture (MA 6) bus, enhanced ISA bus, video Electronics Standards Association (VESA) local bus, and peripheral component interconnect (P6I) bus.
Computer device 12 typically includes a variety of computer system readable media. Such media can be any available media that is accessible by computer device 12 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 30 and/or cache memory 32. Computer device 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 6, and commonly referred to as a "hard drive"). Although not shown in FIG. 6, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a 6D-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28, such program modules 42 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination of which may comprise an implementation of a network environment. Program modules 42 generally carry out the functions and/or methodologies of embodiments of the invention as described.
The computer device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), with one or more devices that enable a user to interact with the device/terminal/server 12, and/or with any device (e.g., network card, modem, etc.) that enables the device/terminal/server 12 to communicate with one or more other computing devices. Such communication may be through an input/output (I/O) interface 22. Also, computer device 12 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network such as the Internet) via network adapter 20. As shown, network adapter 20 communicates with the other modules of computer device 12 via bus 18. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with computer device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, for example, implementing the method for generating the API document provided by the embodiment of the present invention.
Namely: when executed by the one or more processors, cause the one or more processors to perform: scanning a project file set of micro-services, acquiring each structural body included in the project file set, and storing each attribute information included in each structural body in a corresponding structural body array; acquiring at least one interface definition file for storing an interface definition function from the project file set; analyzing each interface definition file, and storing key interface information corresponding to each interface definition function in a corresponding interface structure; and correspondingly analyzing each interface structure body and each structure body array to generate an interface document matched with the micro-service.
EXAMPLE seven
The seventh embodiment of the invention further provides a computer readable storage medium. Having stored thereon a computer program which, when executed by a processor, implements: scanning a project file set of micro-services, acquiring each structural body included in the project file set, and storing each attribute information included in each structural body in a corresponding structural body array; acquiring at least one interface definition file for storing an interface definition function from the project file set; analyzing each interface definition file, and storing key interface information corresponding to each interface definition function in a corresponding interface structure body; and correspondingly analyzing each interface structure body and each structure body array to generate an interface document matched with the micro-service.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. 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, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (17)

1. A method for generating an application program interface document, comprising:
scanning a project file set of micro-services, acquiring each structural body included in the project file set, and storing each attribute information included in each structural body in a corresponding structural body array;
acquiring at least one interface definition file for storing interface definition functions in the project file set;
analyzing each interface definition file, and storing key interface information corresponding to each interface definition function in an interface structure corresponding to the interface definition function; the key interface information includes: interface name, interface out-reference, interface in-reference and interface description information;
correspondingly analyzing each interface structure body and each structure body array, acquiring structure body arrays respectively corresponding to each interface input parameter and each interface output parameter through interface output parameters and interface input parameters defined in the interface structure bodies, further recursively obtaining each item of attribute information respectively corresponding to each interface input parameter and each interface output parameter, and finally generating an interface document matched with the micro service;
the scanning of the engineering file set of the microservice to obtain the structural bodies included in the engineering file set and storing the attribute information included in each structural body in the corresponding structural body array comprises the following steps:
extracting a target structure body from a target project file currently processed by the project file set, and establishing an initialized target structure body array matched with the target structure body;
generating a first standard structural body corresponding to each line according to each item of attribute information included in each line of the target structural body;
and taking the first standard structure bodies respectively corresponding to the rows as array objects and storing the array objects in the target structure body array.
2. The method according to claim 1, wherein generating a first standard structure body corresponding to each row according to each item of attribute information included in each row of the target structure body comprises:
acquiring a currently processed target line in the target structure data;
identifying each target attribute information included in the target row, and performing filling processing on a first structure body template according to each target attribute information to obtain a first standard structure body corresponding to the target row;
wherein the first structure body template comprises: at least one field name, and blank items to be filled which are respectively matched with the field names.
3. The method of claim 2, wherein the field names in the first structure template comprise at least one of:
attribute name, attribute type name, attribute comment, whether the attribute is must be filled, whether the attribute needs serialization, and the serialized name of the attribute.
4. The method according to claim 3, wherein identifying each target attribute information included in the target row, and performing filling processing on the first structure template according to each target attribute information to obtain a first standard structure corresponding to the target row comprises:
if the preset attribute tag or the comment symbol is identified in the target line, extracting the content behind the attribute tag or the comment symbol in the target line as alternative attribute information;
judging whether the candidate attribute information comprises a preset key character string or not;
if yes, acquiring the content except the key character string in the alternative attribute information, filling the content in the first structure template into a blank item to be filled corresponding to the attribute annotation field name, and logically filling the content in the first structure template into the blank item to be filled corresponding to whether the attribute is the required field name;
if not, filling the candidate attribute information into the blank item to be filled corresponding to the attribute annotation field name in the first structure template, and logically filling the candidate attribute information into the blank item to be filled corresponding to whether the attribute is the required field name or not in the first structure template.
5. The method according to claim 3, wherein identifying each target attribute information included in the target row, and performing filling processing on the first structure template according to each target attribute information to obtain a first standard structure corresponding to the target row, comprises:
if the first separator is identified in the target line, acquiring the content before the first separator as alternative serialization name information;
if the first letter of the alternative serialization name information is determined to be a capital letter, logically filling the capital letter into a blank item to be filled corresponding to whether the attribute needs to serialize the field name or not in the first structure template;
and filling the alternative serialization name information into blank items to be filled corresponding to the serialization name field names of the attributes in the first structure template.
6. The method according to claim 3, wherein identifying each target attribute information included in the target row, and performing filling processing on the first structure template according to each target attribute information to obtain a first standard structure corresponding to the target row, comprises:
if the preset serialization keywords are identified in the target row, extracting the contents behind the serialization keywords in the target row as serialization name information;
filling the blank items to be filled corresponding to the attribute field names which need to be serialized in the first structure template in a logic mode, and filling the serialization name information in the blank items to be filled corresponding to the attribute field names in the first structure template in a serialization mode.
7. The method of claim 1, wherein parsing the interface definition file and storing key interface information corresponding to each of the interface definition functions in a corresponding interface structure comprises:
acquiring a currently processed target interface definition file, and identifying at least one interface definition function in the target interface definition file;
and generating a second standard structure body corresponding to each interface definition function according to each item of key interface information included in each interface definition function.
8. The method of claim 7, wherein identifying at least one interface definition function in the target interface definition file comprises:
traversing identification parenthesis identifiers in the target interface definition file, the parenthesis identifiers including a start parenthesis identifier and a stop parenthesis identifier;
when the starting bracket identifier is identified and the current count of the closed state counter is 0, updating the position of a starting function according to the file position of the starting bracket identifier, and adding one to the closed state counter;
when the starting bracket identifier is identified and the current count of the closed state counter is not 0, directly adding one to the closed state counter;
upon identifying a termination bracket identifier, decrementing the closed state counter by one;
and when the zero clearing state of the closed state counter is determined, determining an interface definition function in the target interface definition file according to the file position of the currently identified termination bracket identifier and the position of the starting function.
9. The method according to claim 7, wherein generating a second standard structure body corresponding to each of the interface definition functions according to each item of key interface information included in each of the interface definition functions includes:
identifying at least one item of key interface information in a currently processed target interface definition function;
filling a preset second structural body template according to the information of each key interface to obtain a second standard structural body corresponding to the target interface definition function;
wherein the second structure form comprises: at least one field name, and blank items to be filled which are matched with the field names respectively.
10. The method of claim 9, wherein the field names in the second structure template comprise at least one of:
interface name, interface out-reference, interface in-reference and interface description information.
11. The method of claim 1, wherein performing corresponding parsing on each interface structure and each structure array to generate an interface document matching the micro service comprises:
acquiring a currently processed target interface structure;
recursively analyzing array objects in the array of the structure according to field values corresponding to the interface output parameter field names and the interface input parameter field names in the target interface structure to obtain complete input parameters and complete output parameters;
and generating an interface document of an interface definition function associated with the target interface structure body in the micro service according to the complete parameter input value and the complete parameter output value.
12. The method of claim 11, wherein recursively parsing array objects in an array of structures according to field values in a target interface structure corresponding to names of interface out-parameter fields to obtain complete in-parameter values, comprises:
searching a target structure array matched with the target field value in each structure array according to the target field value corresponding to the interface output field name in the target interface structure;
sequentially acquiring a data object included in the target structure array as a current processing object;
if the attribute type of the current processing object does not belong to the recursive structure type, generating an entry parameter value matched with the interface entry parameter according to the current processing object;
if the attribute type of the current processing object belongs to a recursion type, carrying out recursion analysis on other associated structure array by taking the current processing object as a starting point to obtain all input parameter values matched with the current processing object;
and returning to execute the operation of sequentially acquiring one data object in the target structure array as the current processing object until the operation on all the data objects in the target structure array is completed so as to obtain a complete parameter value corresponding to the interface parameter.
13. The method of claim 12, wherein the recursion type comprises at least one of: array, pointer, and structure type.
14. The method of claim 1, wherein:
scanning a project file set of micro-services, acquiring each structural body included in the project file set, storing each attribute information included in each structural body in a corresponding structural body array, and realizing the operation by using a plurality of Go protocols; and/or
And analyzing each interface definition file, and storing the key interface information corresponding to each interface definition function in a corresponding interface structure body by using a plurality of Go coroutines.
15. An apparatus for generating an application program interface document, comprising:
the system comprises a structure array generation module, a data processing module and a data processing module, wherein the structure array generation module is used for scanning a project file set of the micro service, acquiring each structure body included in the project file set and storing each attribute information included in each structure body in a corresponding structure array;
an interface definition file acquisition module, configured to acquire at least one interface definition file for storing an interface definition function from the project file set;
the interface structure body generation module is used for analyzing each interface definition file and storing key interface information corresponding to each interface definition function in the interface structure body corresponding to the interface definition function; the key interface information includes: interface name, interface out-reference, interface in-reference and interface description information;
the interface document generation module is used for correspondingly analyzing each interface structure body and each structure body array, acquiring the structure body arrays respectively corresponding to each interface input parameter and each interface output parameter through the interface output parameters and the interface input parameters defined in the interface structure bodies, further recursively obtaining each item of attribute information respectively corresponding to each interface input parameter and each interface output parameter, and finally generating an interface document matched with the micro service;
the structure array generating module specifically includes:
the target structure array initialization unit is used for extracting a target structure from a target project file currently processed by the project file set and establishing an initialized target structure array matched with the target structure;
a first standard structure body generation unit configured to generate first standard structure bodies corresponding to respective lines of the target structure body according to the attribute information included in the respective lines;
and the target structure array generating unit is used for storing the first standard structures respectively corresponding to the rows as array objects in the target structure array.
16. A computer device, characterized in that the computer device comprises:
one or more processors;
storage means for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a method of generating an application programming interface document according to any of claims 1-14.
17. A computer storage medium having stored thereon a computer program, characterized in that the program, when being executed by a processor, carries out the method of generating an application program interface document according to any one of claims 1-14.
CN202010290155.9A 2020-04-14 2020-04-14 Method and device for generating application program interface document, computer equipment and medium Active CN111488174B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010290155.9A CN111488174B (en) 2020-04-14 2020-04-14 Method and device for generating application program interface document, computer equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010290155.9A CN111488174B (en) 2020-04-14 2020-04-14 Method and device for generating application program interface document, computer equipment and medium

Publications (2)

Publication Number Publication Date
CN111488174A CN111488174A (en) 2020-08-04
CN111488174B true CN111488174B (en) 2022-10-11

Family

ID=71812762

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010290155.9A Active CN111488174B (en) 2020-04-14 2020-04-14 Method and device for generating application program interface document, computer equipment and medium

Country Status (1)

Country Link
CN (1) CN111488174B (en)

Families Citing this family (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111949253B (en) * 2020-08-07 2023-12-01 抖音视界有限公司 Method, apparatus, computer device and storage medium for combining IDL files
CN112162751A (en) * 2020-09-09 2021-01-01 杭州涂鸦信息技术有限公司 Automatic generation method and system of interface document
CN112148302A (en) * 2020-09-23 2020-12-29 北京自如信息科技有限公司 Interface document generation method, device, equipment and readable storage medium
CN112130837B (en) * 2020-09-25 2022-03-08 腾讯科技(深圳)有限公司 Code processing method and device and storage medium
CN112506769B (en) * 2020-12-04 2024-06-14 数字广东网络建设有限公司 Request body generation method and device based on interface document and computer equipment
CN113392623A (en) * 2021-06-17 2021-09-14 中国工商银行股份有限公司 Service data object generation method, generation device, electronic device and storage medium
CN113392112A (en) * 2021-06-17 2021-09-14 中国工商银行股份有限公司 Data analysis method, data analysis device, electronic device, and storage medium
CN113485746B (en) * 2021-07-28 2024-02-06 山石网科通信技术股份有限公司 Method and device for generating application program interface document
CN113590095A (en) * 2021-07-30 2021-11-02 上海哔哩哔哩科技有限公司 Swagger document-based type declaration file generation method and device
CN114461193B (en) * 2022-04-11 2022-07-12 北京远特科技股份有限公司 Method, device, equipment and storage medium for generating communication protocol code
CN115630593B (en) * 2022-11-11 2023-03-14 摩尔线程智能科技(北京)有限责任公司 Method and device for generating verification information data
CN117195863B (en) * 2023-09-12 2024-08-13 蔷薇聚信(北京)科技有限公司 Dictionary/field analysis method and device, micro-service system and storage medium
CN117435177B (en) * 2023-12-20 2024-03-26 浙江寰福科技有限公司 Application program interface construction method, system, equipment and storage medium
CN117573140B (en) * 2024-01-16 2024-04-02 成都安世赛斯特软件技术有限公司 Method, system and device for generating document by scanning codes

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20120100094A (en) * 2011-03-03 2012-09-12 (주)네오위즈게임즈 Packet dumping system, management device and method
CN110377336A (en) * 2019-06-17 2019-10-25 平安普惠企业管理有限公司 Interface document generation method, device, computer equipment and storage medium
CN110806863A (en) * 2019-11-05 2020-02-18 泰康保险集团股份有限公司 Interface document generation method and device, electronic equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20120100094A (en) * 2011-03-03 2012-09-12 (주)네오위즈게임즈 Packet dumping system, management device and method
CN110377336A (en) * 2019-06-17 2019-10-25 平安普惠企业管理有限公司 Interface document generation method, device, computer equipment and storage medium
CN110806863A (en) * 2019-11-05 2020-02-18 泰康保险集团股份有限公司 Interface document generation method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN111488174A (en) 2020-08-04

Similar Documents

Publication Publication Date Title
CN111488174B (en) Method and device for generating application program interface document, computer equipment and medium
CN111428462B (en) Communication protocol template construction method and terminal equipment
CN110347598B (en) Test script generation method and device, server and storage medium
CN112000398B (en) Method and device for determining bottom layer interface call link, computer equipment and medium
US8589888B2 (en) Demand-driven analysis of pointers for software program analysis and debugging
CN113900958A (en) Test case script generation method, system, medium and electronic device
CN109165209B (en) Data verification method, device, equipment and medium for object types in database
US11853196B1 (en) Artificial intelligence driven testing
CN111753140A (en) XML file parsing method and related equipment
CN115952758A (en) Chip verification method and device, electronic equipment and storage medium
CN112035443A (en) Big data execution method, system, equipment and storage medium based on Linux platform
CN113094625A (en) Page element positioning method and device, electronic equipment and storage medium
CN117632710A (en) Method, device, equipment and storage medium for generating test code
CN111475150A (en) Cross-language binding method, device, equipment and storage medium
CN110737431A (en) Software development method, development platform, terminal device and storage medium
CN112965838B (en) Concurrent program data competition checking method and device
Cristiá et al. A language for test case refinement in the Test Template Framework
CN117435189A (en) Test case analysis method, device, equipment and medium of financial system interface
US20140137083A1 (en) Instrumenting computer program code by merging template and target code methods
CN116431481A (en) Code parameter verification method and device based on multi-code condition
CN113050987B (en) Method and device for generating interface document, storage medium and electronic equipment
CN115640279A (en) Method and device for constructing data blood relationship
CN112445468A (en) Typescript type file generation method, device, equipment and computer readable storage medium
CN113238940A (en) Interface test result comparison method, device, equipment and storage medium
CN111447268A (en) File structure conversion method, device, equipment and storage medium

Legal Events

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