Method and apparatus for generating information
By receiving API information input from users, using language recognition tools to parse the request body and combining it with basic API description information to generate API documentation, the problem of time-consuming, labor-intensive, and complex API documentation generation in existing technologies is solved, achieving efficient and automatic generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-10-15
- Publication Date
- 2026-04-07
AI Technical Summary
In existing technologies, the API documentation generation process is time-consuming, labor-intensive, and of inconsistent quality. Manual writing is complex, while automatic API documentation generation requires predefined specifications, making the process quite complicated.
By receiving API information input from users, the system uses language recognition tools to parse the request body, combines basic API description information and request parameter information to generate API documentation, and uses a template engine to populate the document content template for automatic generation.
It enables automatic generation of API documentation, improving generation efficiency and documentation quality, and simplifying the generation process.
Smart Images

Figure CN110738036B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present disclosure relate to the technical field of computer, and particularly, to a method and apparatus for generating information. BACKGROUND
[0002] The gateway provides various function supports for API (Application Programming Interface). Generally, an application encapsulates its service capability into API, and exposes it to users through the gateway. When exposing the API through the gateway, API document needs to be used. At present, the API document can be generated in a manual writing manner, or can be automatically generated in a manner of predefining API document specification. The manual writing of API document is time-consuming and laborious, and the quality is uneven. The API document generated in the manner of predefining API document specification can guarantee the standard and specification of the generated API document, but the standard API document specification needs to be predefined, and the user also needs to write specific API request information according to the API document specification, so the whole generation process is relatively complex. SUMMARY
[0003] Embodiments of the present disclosure provide a method and apparatus for generating information.
[0004] In a first aspect, the embodiments of the present disclosure provide a method for generating information, the method comprising: receiving API information input by a user, wherein the API information comprises API basic description information and API request information, and the API request information comprises a request body; analyzing the request body based on a language recognition tool to obtain request parameter information, wherein the language recognition tool is used to analyze the request body according to a preset analysis rule; determining analysis data for the API information based on the API basic description information, the API request information and the request parameter information; and generating an API document according to the analysis data and a pre-established document content template.
[0005] In some embodiments, the request body comprises JSON structure data and an annotation; and the analyzing the request body based on the language recognition tool to obtain the request parameter information comprises: analyzing the JSON structure data and the annotation based on the language recognition tool to obtain parameter features and parameter description information; and taking the parameter features and the parameter description information as the analysis-obtained request parameter information.
[0006] In some embodiments, the API request information further includes a request address, a request method, and a request header; and determining the parsing data for the API information based on the API basic description information, the API request information, and the request parameter information includes: verifying the API basic description information, the request address, the request method, and the request header; and in response to determining that the API basic description information, the request address, the request method, and the request header have passed the verification, determining the API basic description information, the request address, the request method, the request header, and the request parameter information as the parsing data for the API information.
[0007] In some embodiments, determining the parsed data for the API information based on the API basic description information, the API request information, and the request parameter information further includes: in response to determining that at least one of the API basic description information, the request address, the request method, and the request header has failed verification, sending a prompt message to the user based on the verification result.
[0008] In some embodiments, generating API documentation based on the parsed data and a pre-established document content template includes: using a template engine to populate the parsed data into the document content template to generate API documentation.
[0009] Secondly, embodiments of this disclosure provide an apparatus for generating information, the apparatus comprising: a receiving unit configured to receive API information input by a user, wherein the API information includes API basic description information and API request information, wherein the API request information includes a request body; a parsing unit configured to parse the request body based on a language recognition tool to obtain request parameter information, wherein the language recognition tool is used to parse the request body according to preset parsing rules; a determining unit configured to determine parsing data for the API information based on the API basic description information, the API request information, and the request parameter information; and a generating unit configured to generate an API document based on the parsing data and a pre-established document content template.
[0010] In some embodiments, the request body includes JSON structure data and comments; and the parsing unit is further configured to: use the language recognition tool to parse the JSON structure data and the comments to obtain parameter features and parameter description information; and use the parameter features and parameter description information as the parsed request parameter information.
[0011] In some embodiments, the API request information further includes a request address, a request method, and a request header; and the determining unit is further configured to: verify the API basic description information, the request address, the request method, and the request header; and in response to determining that the API basic description information, the request address, the request method, and the request header have passed the verification, determine the API basic description information, the request address, the request method, the request header, and the request parameter information as parsed data for the API information.
[0012] In some embodiments, the determining unit is further configured to: in response to determining that at least one of the API basic description information, the request address, the request method, and the request header has failed verification, send a prompt message to the user based on the verification result.
[0013] In some embodiments, the above-mentioned generation unit is further configured to: use a template engine to populate the above-mentioned parsed data into the above-mentioned document content template to generate API documents.
[0014] Thirdly, embodiments of this disclosure provide an apparatus comprising: one or more processors; and a storage device having stored one or more programs thereon, which, when executed by the one or more processors, cause the one or more processors to implement the method described in any implementation of the first aspect.
[0015] Fourthly, embodiments of this disclosure provide a computer-readable medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method as described in any implementation of the first aspect.
[0016] The method and apparatus for generating information provided in this disclosure first receive API information input by a user, then parse the request body using a language recognition tool to obtain request parameter information, then determine parsing data for the API information based on the API basic description information, API request information, and request parameter information, and finally generate API documents based on the parsed data and a pre-established document content template, thereby realizing the automatic generation of API documents and improving the generation efficiency of API documents. Attached Figure Description
[0017] Other features, objects, and advantages of this disclosure will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0018] Figure 1 This is an exemplary system architecture diagram to which one embodiment of this disclosure can be applied;
[0019] Figure 2 This is a flowchart of one embodiment of a method for generating information according to the present disclosure;
[0020] Figure 3 This is a schematic diagram of an application scenario of the method for generating information according to this disclosure;
[0021] Figure 4 This is a flowchart of yet another embodiment of the method for generating information according to the present disclosure;
[0022] Figure 5 This is a schematic diagram of a structure of an embodiment of an apparatus for generating information according to the present disclosure;
[0023] Figure 6 This is a schematic diagram of the structure of a computer system suitable for implementing the electronic device of the present disclosure. Detailed Implementation
[0024] The present disclosure will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings.
[0025] It should be noted that, unless otherwise specified, the embodiments and features described in this disclosure can be combined with each other. This disclosure will now be described in detail with reference to the accompanying drawings and embodiments.
[0026] Figure 1 An exemplary system architecture 100 for generating information, or for generating information, which can be applied to embodiments of this disclosure, is shown.
[0027] like Figure 1 As shown, system architecture 100 may include terminal devices 101, 102, and 103, a network 104, and a server 105. Network 104 serves as the medium for providing communication links between terminal devices 101, 102, and 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0028] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social media platform software, API documentation auto-generation software, etc.
[0029] Terminal devices 101, 102, and 103 can be either hardware or software. When terminal devices 101, 102, and 103 are hardware, they can be various electronic devices with a display screen and supporting information input, including but not limited to smartphones, tablets, laptops, and desktop computers. When terminal devices 101, 102, and 103 are software, they can be installed in the electronic devices listed above. They can be implemented as multiple software programs or software modules (e.g., to provide distributed services) or as a single software program or software module. No specific limitations are made here.
[0030] Server 105 can be a server that provides various services, such as a backend server that supports the information displayed on terminal devices 101, 102, and 103. The backend server can analyze and process the received API information and other data, and feed back the processing results (such as API documentation) to terminal devices 101, 102, and 103.
[0031] It should be noted that server 105 can be either hardware or software. When server 105 is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When server 105 is software, it can be implemented as multiple software programs or software modules (e.g., used to provide distributed services), or as a single software program or software module. No specific limitations are made here.
[0032] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0033] It should be noted that the method for generating information provided in this embodiment can be executed by terminal devices 101, 102, and 103, or by server 105. Correspondingly, the device for generating information can be located in terminal devices 101, 102, and 103, or in server 105.
[0034] Continue to refer to Figure 2 The diagram illustrates a flow 200 of an embodiment of a method for generating information according to the present disclosure. The method for generating information includes the following steps:
[0035] Step 201: Receive API information input by the user.
[0036] In this embodiment, the execution entity of the method for generating information (e.g.) Figure 1The terminal devices 101, 102, 103, or server 105 shown can receive API information input by the user. This API information may include basic API description information and API request information. Here, the basic API description information can describe the basic information of the API, including a brief overview of the API's functions, version, responsible person, geographical information, etc. The geographical information can describe the deployment location of the server supporting the service corresponding to the API. The API request information may include the request address, request method, request headers, request body, etc. The request body may include an example of how the request parameters are invoked.
[0037] Typically, users who want to generate API documentation can input API information into the execution entity by filling out a form on the page.
[0038] Step 202: Parse the request body using a language recognition tool to obtain request parameter information.
[0039] In this embodiment, the executing entity can parse the request body using a language recognition tool to obtain request parameter information. The language recognition tool can be used to parse the request body according to preset parsing rules. As an example, the language recognition tool can be based on Antlr (Another Tool for Language Recognition). Specifically, parsing rules for parsing the request body can be defined according to the Antlr specification, i.e., a syntax description file corresponding to the parsing rules can be written. Then, Antlr can automatically generate a corresponding parser based on the syntax description file; this parser is the language recognition tool. This language recognition tool can parse the request body according to the aforementioned parsing rules to obtain request parameter information.
[0040] Step 203: Based on the API basic description information, API request information, and request parameter information, determine the parsing data for the API information.
[0041] In this embodiment, the executing entity can determine the parsing data for the API information based on the API basic description information, API request information, and request parameter information. As an example, the executing entity can use the various information included in the API basic description information, the other information in the API request information excluding the request body, and the request parameter information parsed in step 202 as the parsing data for the API information.
[0042] In some optional implementations of this embodiment, the API request information may further include a request address, a request method, and request headers. Furthermore, step 203 may specifically include the following:
[0043] First, verify the basic API description information, request address, request method, and request headers.
[0044] In this implementation, the execution entity can validate the API's basic description information, request address, request method, and request headers. As an example, the execution entity can pre-store validation rules for each of these elements. The execution entity can then validate these elements according to these rules. In practice, the validation rules can be set according to actual needs. For example, for the API's basic description information, validation rules can be set to validate the data format and content. For the request address, request method, and request headers, validation rules can be set to verify whether they conform to a preset format. Typically, the request address, request method, and request headers need to conform to a predetermined format; for example, the request address needs to conform to the HTTP (Hypertext Transfer Protocol) address format.
[0045] Then, in response to the confirmation that the API basic description information, request address, request method, and request headers have passed the verification, the API basic description information, request address, request method, request headers, and request parameter information are determined as the parsed data for the API information.
[0046] In this implementation, the executing entity can determine whether the API basic description information, request address, request method, and request header have passed the verification. If the verification passes, the API basic description information, request address, request method, request header, and request parameter information can be determined as the parsed data for the API information.
[0047] In some alternative implementations, step 203 above may also include the following:
[0048] In response to the determination that at least one of the API basic description information, request address, request method and request headers fails the validation, a prompt message is sent to the user based on the validation result.
[0049] In this implementation, if one or more of the API basic description information, request address, request method, and request headers fail validation, the executing entity can send a prompt message to the user based on the validation result. Specifically, the executing entity can send a prompt message based on the validation result of the failed information item. For example, assuming the request address validation result is that it contains illegal characters, the executing entity can send a prompt message to the user indicating that the entered request address contains illegal characters. In this way, the user can modify the failed information item based on the prompt message. Afterwards, the executing entity can determine the parsed data for the API information based on the user's modified information item.
[0050] Step 204: Generate API documentation based on the parsed data and the pre-established document content template.
[0051] In this embodiment, the executing entity can generate API documentation based on the parsed data obtained in step 203 and a pre-established document content template. As an example, the generated API documentation may include, but is not limited to, an API introduction, service information, general instructions (e.g., API version number), parameter descriptions, etc. Here, the aforementioned document content template can be established according to actual needs.
[0052] In some optional implementations of this embodiment, step 204 can be specifically performed as follows: using a template engine, the parsed data is filled into the document content template to generate the API document.
[0053] In this implementation, the executing entity can use a template engine to populate the parsed data obtained in step 203 into the document content template, thereby generating API documentation. As an example, the document content template can be a YAML (YAML Ain't Markup Language) template, supporting Markdown tag formatting. YAML is a highly readable format used to express data serialization. Markdown is a markup language that can be written using a plain text editor; through simple markup syntax, it can format plain text content. The template engine can be Velocity, a Java-based template engine.
[0054] See also Figure 3 , Figure 3 This is a schematic diagram illustrating an application scenario of the method for generating information according to this embodiment. Figure 3In this application scenario, terminal device 301 first receives API information input by the user. This API information includes basic API description information and API request information, where the API request information includes a request body. Next, terminal device 301 parses the request body using a language recognition tool to obtain request parameter information. Then, based on the basic API description information, API request information, and request parameter information, terminal device 301 determines the parsing data for the API information. Finally, terminal device 301 generates API documentation based on the parsed data and a pre-established document content template. It should be noted that... Figure 3 The content included in the API information and API documentation is merely illustrative and not a limitation on the content included in the API information and API documentation.
[0055] The method provided by the above embodiments of this disclosure can automatically generate API documentation based on user-input API information, thereby realizing automatic generation of API documentation and improving the generation efficiency of API documentation.
[0056] Further reference Figure 4 This illustrates a flow 400 of yet another embodiment of a method for generating information. The flow 400 of the method for generating information includes the following steps:
[0057] Step 401: Receive API information input by the user.
[0058] In this embodiment, the execution entity of the method for generating information (e.g.) Figure 1 The terminal devices 101, 102, 103, or server 105 shown can receive API information input by the user. This API information may include basic API description information and API request information. The API request information may include a request body, which may include a call example of the request parameters. The call example may include JSON structured data and comments. The comments can be used to describe the parameters.
[0059] Step 402: Use a language recognition tool to parse the JSON structure data and comments to obtain parameter features and parameter description information.
[0060] In this embodiment, the executing entity can use a speech recognition tool to parse the JSON structure data and annotations to obtain parameter features and parameter description information.
[0061] As an example, the request parameters in the request body of an API request entered by the user may fall into one of the following categories:
[0062] Category 1 consists only of JSON structured data, with no comments.
[0063] Category Two: JSON structured data + Category One comments. Here, Category One comments can refer to simple, direct comments.
[0064] Category 3 consists of JSON-structured data plus comments from Category 2. Category 2 comments can refer to complex comments.
[0065] For example, the following request body includes a call example with three request parameters, which respectively conform to the three categories mentioned above. The first line belongs to category one, the second line to category two, and the third line to category three.
[0066]
[0067] The executing entity can use a language recognition tool to parse the request body, thereby obtaining parameter characteristics and parameter description information. Specifically, the language recognition tool can parse parameter names, types, whether they are required, parameter positions, example values, etc., as parameter characteristics, and can use the category of comments as parameter description information. For example, the above request body can be parsed to obtain the parameter characteristics and parameter description information shown in Table 1 below.
[0068] Table 1:
[0069]
[0070] It is understood that the request body and parameter information in Table 1 are merely illustrative and not limiting. In practice, the parameter information of the request body can be set according to actual needs.
[0071] Step 403: Use the parameter features and parameter description information as the parsed request parameter information.
[0072] In this embodiment, the executing entity can use the parameter features and parameter description information obtained in step 402 as the parsed request parameter information.
[0073] Step 404: Based on the API basic description information, API request information, and request parameter information, determine the parsing data for the API information.
[0074] In this embodiment, step 404 and Figure 2 Step 203 in the illustrated embodiment is similar and will not be repeated here.
[0075] Step 405: Generate API documentation based on the parsed data and the pre-established document content template.
[0076] In this embodiment, step 405 and Figure 2 Step 204 in the illustrated embodiment is similar and will not be repeated here.
[0077] from Figure 4 It can be seen from this that, with Figure 2 Compared to the corresponding embodiments, the process 400 of the method for generating information in this embodiment emphasizes the parsing of the request body, which includes JSON structured data and comments. Therefore, the method described in this embodiment can support more types of request bodies, and the generated API documentation can contain richer information.
[0078] Further reference Figure 5 As an implementation of the methods shown in the above figures, this disclosure provides an embodiment of an apparatus for generating information, which is similar to... Figure 2 Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.
[0079] like Figure 5 As shown, the apparatus 500 for generating information in this embodiment includes: a receiving unit 501, a parsing unit 502, a determining unit 503, and a generating unit 504. The receiving unit 501 is configured to receive API information input by a user, wherein the API information includes basic API description information and API request information, wherein the API request information includes a request body. The parsing unit 502 is configured to parse the request body using a language recognition tool to obtain request parameter information, wherein the language recognition tool is used to parse the request body according to preset parsing rules. The determining unit 503 is configured to determine parsed data for the API information based on the basic API description information, the API request information, and the request parameter information. The generating unit 504 is configured to generate an API document based on the parsed data and a pre-established document content template.
[0080] In this embodiment, the specific processing of the receiving unit 501, parsing unit 502, determining unit 503, and generating unit 504 of the information generation device 500, and the resulting technical effects, can be referred to respectively. Figure 2 The relevant descriptions of steps 201, 202, 203 and 204 in the corresponding embodiments will not be repeated here.
[0081] In some optional implementations of this embodiment, the request body includes JSON structure data and comments; and the parsing unit 502 is further configured to: use the language recognition tool to parse the JSON structure data and the comments to obtain parameter features and parameter description information; and use the parameter features and parameter description information as the parsed request parameter information.
[0082] In some optional implementations of this embodiment, the API request information further includes a request address, a request method, and a request header; and the determining unit 503 is further configured to: verify the API basic description information, the request address, the request method, and the request header; and in response to determining that the API basic description information, the request address, the request method, and the request header have passed the verification, determine the API basic description information, the request address, the request method, the request header, and the request parameter information as parsing data for the API information.
[0083] In some optional implementations of this embodiment, the determining unit 503 is further configured to: in response to determining that at least one of the API basic description information, the request address, the request method, and the request header has failed verification, send a prompt message to the user based on the verification result.
[0084] In some optional implementations of this embodiment, the generation unit 504 is further configured to: use a template engine to fill the parsed data into the document content template to generate an API document.
[0085] The following is for reference. Figure 6 It illustrates an electronic device suitable for implementing embodiments of the present disclosure (e.g., Figure 1 A structural diagram of the server or terminal device (600) in the system. Figure 6 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments of this disclosure.
[0086] like Figure 6 As shown, electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 601, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 602 or a program loaded from storage device 608 into random access memory (RAM) 603. RAM 603 also stores various programs and data required for the operation of electronic device 600. Processing device 601, ROM 602, and RAM 603 are interconnected via bus 604. Input / output (I / O) interface 605 is also connected to bus 604.
[0087] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 608 including, for example, magnetic tapes, hard disks, etc.; and communication devices 609. Communication device 609 allows electronic device 600 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 An electronic device 600 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively. Figure 6 Each box shown can represent a device or multiple devices as needed.
[0088] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by a processing device 601, it performs the functions defined in the methods of embodiments of this disclosure.
[0089] It should be noted that the computer-readable medium described in the embodiments of this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the embodiments of this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the embodiments of this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0090] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device. The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to: receive API information input by a user, wherein the API information includes basic API description information and API request information, wherein the API request information includes a request body; parse the request body using a language recognition tool to obtain request parameter information, wherein the language recognition tool is used to parse the request body according to preset parsing rules; determine parsing data for the aforementioned API information based on the aforementioned basic API description information, the aforementioned API request information, and the aforementioned request parameter information; and generate an API document based on the parsed data and a pre-established document content template.
[0091] Computer program code for performing the operations of embodiments of this disclosure can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0092] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0093] The units described in the embodiments of this disclosure can be implemented in software or hardware. The described units can also be housed in a processor; for example, a processor may be described as including a receiving unit, a parsing unit, a determining unit, and a generating unit. The names of these units do not necessarily limit the specific unit; for example, a receiving unit may also be described as "a unit that receives API information input by the user."
[0094] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in the embodiments of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described inventive concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features with similar functions disclosed in the embodiments of this disclosure.
Claims
1. A method for generating information, comprising: Receive API information input by the user, wherein the API information includes basic API description information and API request information, wherein the API request information includes request body, request address, request method and request header; The request body is parsed using a language recognition tool to obtain request parameter information, wherein the language recognition tool is used to parse the request body according to preset parsing rules; The API basic description information, the request address, the request method, and the request header are each validated using corresponding validation rules. The validation rules corresponding to the API basic description information are used to validate the data format and data content of the API basic description information. The validation rules corresponding to the request address, the request method, and the request header are used to validate whether the request address, the request method, and the request header conform to a preset format. In response to the determination that the API basic description information, the request address, the request method, and the request header have passed the verification, the API basic description information, the request address, the request method, the request header, and the request parameter information are determined as parsed data for the API information; API documentation is generated based on the parsed data and the pre-established document content template.
2. The method according to claim 1, wherein, The request body includes JSON structured data and comments; as well as The request body is parsed using a language recognition tool to obtain request parameter information, including: The language recognition tool is used to parse the JSON structure data and the comments to obtain parameter features and parameter description information; The parameter features and parameter description information are used as the parsed request parameter information.
3. The method according to claim 2, wherein, The step of determining the parsed data for the API information based on the API basic description information, the API request information, and the request parameter information further includes: In response to the determination that at least one of the API basic description information, the request address, the request method, and the request header has failed the verification, a prompt message is sent to the user based on the verification result.
4. The method according to claim 1, wherein, The step of generating API documentation based on the parsed data and a pre-established document content template includes: Using a template engine, the parsed data is populated into the document content template to generate API documentation.
5. An apparatus for generating information, comprising: The receiving unit is configured to receive API information input by the user, wherein the API information includes basic API description information and API request information, wherein the API request information includes a request body, a request address, a request method, and a request header; The parsing unit is configured to parse the request body based on a language recognition tool to obtain request parameter information, wherein the language recognition tool is used to parse the request body according to a preset parsing rule; The determining unit is configured to: validate the API basic description information, the request address, the request method, and the request header using validation rules corresponding to each of the API basic description information, the request address, the request method, and the request header respectively; the validation rules corresponding to the API basic description information are used to validate the data format and data content of the API basic description information; the validation rules corresponding to the request address, the request method, and the request header are used to validate whether the request address, the request method, and the request header conform to a preset format; in response to determining that the API basic description information, the request address, the request method, and the request header have passed validation, the API basic description information, the request address, the request method, the request header, and the request parameter information are determined as parsed data for the API information; The generation unit is configured to generate API documentation based on the parsed data and a pre-established document content template.
6. The apparatus according to claim 5, wherein, The request body includes JSON structured data and comments; and The parsing unit is further configured to: The language recognition tool is used to parse the JSON structure data and the comments to obtain parameter features and parameter description information; The parameter features and parameter description information are used as the parsed request parameter information.
7. The apparatus according to claim 6, wherein, The determining unit is further configured to: In response to the determination that at least one of the API basic description information, the request address, the request method, and the request header has failed the verification, a prompt message is sent to the user based on the verification result.
8. The apparatus according to claim 5, wherein, The generation unit is further configured to: Using a template engine, the parsed data is populated into the document content template to generate API documentation.
9. An electronic device, comprising: One or more processors; Storage device, on which one or more programs are stored, When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-4.
10. A computer-readable medium having a computer program stored thereon, wherein, When the program is executed by the processor, it implements the method as described in any one of claims 1-4.
Citation Information
Patent Citations
Interface document generation method and device and computer readable storage medium
CN107766040A
Application programming interface document generation method and device and terminal equipment
CN110162296A