CN114489590A - Automatic document generation method and system based on swagger interface - Google Patents

Automatic document generation method and system based on swagger interface Download PDF

Info

Publication number
CN114489590A
CN114489590A CN202111529248.3A CN202111529248A CN114489590A CN 114489590 A CN114489590 A CN 114489590A CN 202111529248 A CN202111529248 A CN 202111529248A CN 114489590 A CN114489590 A CN 114489590A
Authority
CN
China
Prior art keywords
interface
swagger
document
interface document
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111529248.3A
Other languages
Chinese (zh)
Inventor
王沛林
夏慧强
李孟元
谢宇
魏贺生
单国军
赵哿滢
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Aisino Corp
Original Assignee
Aisino Corp
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 Aisino Corp filed Critical Aisino Corp
Priority to CN202111529248.3A priority Critical patent/CN114489590A/en
Publication of CN114489590A publication Critical patent/CN114489590A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code

Abstract

The invention discloses a swagger interface based automatic document generation method and system. The method comprises the following steps: writing an http interface through a receiver; performing swagger configuration on the http interface to generate a swagger interface document; pushing the swagger interface document according to the swagger interface document and the related information of the swagger interface document; and viewing the swagger interface document through a calling party. Therefore, a set of more automatic interface document automatic generation mechanism is provided, the advantages of automation, standardization, real-time synchronization and the like brought by using swagger are integrated, a set of mechanism for automatically notifying interface change can be automatically maintained, and various problems brought by unsmooth communication among different departments and project groups in a company are greatly reduced.

Description

Automatic document generation method and system based on swagger interface
Technical Field
The invention relates to the field of documents, in particular to a method and a system for automatically generating a document based on a swagger interface.
Background
In the software industry, an http interface is the most basic request mode of various network services at present. However, an interface can work normally only by having a fixed request message and a fixed return message, so that an interface document is an important standard in software development.
However, the maintenance of the interface document consumes a lot of time and cost of research personnel, the software research and development requirements change greatly, and if the update is not timely, the document and the actual code are inconsistent, and the possibility of human errors exists during the writing of the document.
In this case, the way of automatically generating the interface document is a very important ring for improving the development efficiency. At present, a relatively mature solution-swagger exists in the development process of a server. Interface documents can be dynamically generated by using swagger, and are automatically generated according to codes, and the documents can be changed along with the change of the codes. However, under the conditions of complex company business and numerous structures, one interface may have numerous invokers, and even if the document is updated in time, the invokers are not aware of the situations frequently, and the existence of the poor information may cause serious production environment accidents.
Disclosure of Invention
According to the invention, the method and the system for automatically generating the document based on the swagger interface are provided, so that the technical problems that in the prior art, under the conditions of complex company service and numerous structures, one interface can be frequently called, the document is updated in time, the situation that the calling party is unknown is frequent, and serious production environment accidents can be caused due to the poor information are solved.
According to a first aspect of the invention, a method for automatically generating a document based on a swagger interface is provided, which comprises the following steps:
writing an http interface through a receiver;
performing swagger configuration on the http interface to generate a swagger interface document;
pushing the swagger interface document according to the swagger interface document and the related information of the swagger interface document;
and viewing the swagger interface document through a calling party.
Optionally, swagger configuring the http interface, including:
and adding swagger notes to the classes of the request message and the return message of the http interface, setting a request field and setting a return field.
Optionally, pushing the swagger interface document according to the swagger interface document and the relevant information of the swagger interface document includes:
according to the swagger interface document and the relevant information of the swagger interface document,
determining new interface information or modifying interface information.
Optionally, determining new interface information or modifying interface information according to the swagger interface document and the relevant information of the swagger interface document includes:
judging whether interface information of the swagger interface document exists in a database;
if the interface information of the swagger interface document does not exist in the database, inserting the MD5 abstract of the swagger interface request and the returned message into the database, and sending the push and the mail of the newly added interface according to the configured calling party personnel and the mail address;
and if the interface information of the swagger interface document does not exist in the database, judging whether the MD5 digest value changes, if so, updating the MD5 digest value, and pushing and sending the mail to the message with the modified interface through a rabbitMQ pushing mechanism according to the configured calling party personnel and mail addresses.
Optionally, viewing the swagger interface document through a calling party, including:
and after receiving the swagger interface document through the calling party, logging in and checking the swagger interface document.
According to another aspect of the present invention, there is also provided a swagger interface-based document automatic generation system, including:
the http interface module is used for compiling an http interface through a receiving party;
an interface document generation module, configured to perform swagger configuration on the http interface, and generate a swagger interface document;
the interface document pushing module is used for pushing the swagger interface document according to the swagger interface document and the related information of the swagger interface document;
and the interface document viewing module is used for viewing the swagger interface document through a calling party.
Optionally, the interface document generation module includes:
and the swagger annotation adding submodule is used for adding swagger annotation to the classes of the request message and the return message of the http interface, setting a request field and setting a return field.
Optionally, the push interface document module includes:
and the interface information determining submodule is used for determining newly-added interface information or modifying interface information according to the swagger interface document and the related information of the swagger interface document.
Optionally, the determining interface information sub-module includes:
the interface information judging unit is used for judging whether the interface information of the swagger interface document exists in a database or not;
the newly added pushing interface unit is used for inserting the swagger interface request and the MD5 abstract of the returned message into the database if the interface information of the swagger interface document does not exist in the database, and sending pushing and mail of the newly added interface according to configured calling party personnel and mail addresses;
and the pushing and modifying interface unit is used for judging whether the MD5 digest value changes or not if the interface information of the swagger interface document does not exist in the database, updating the MD5 digest value if the MD5 digest value changes, and pushing and sending the mail to the message of the modified interface through a rabbitMQ pushing mechanism according to the configured calling party personnel and mail addresses.
Optionally, the viewing interface document module includes:
and the view interface document sub-module is used for logging in and viewing the swagger interface document after the calling party receives the swagger interface document.
Therefore, a set of more automatic interface document automatic generation mechanism is provided, the advantages of automation, standardization, real-time synchronization and the like brought by using swagger are integrated, a set of mechanism for automatically notifying interface change can be automatically maintained, and various problems brought by unsmooth communication among different departments and project groups in a company are greatly reduced.
Drawings
A more complete understanding of exemplary embodiments of the present invention may be had by reference to the following drawings in which:
fig. 1 is a schematic diagram of an automatic document generation method based on a swagger interface according to this embodiment;
FIG. 2 is a schematic diagram of an interface document auto-generation mechanism;
fig. 3 is a schematic diagram of an automatic document generation system based on a swagger interface according to this embodiment.
Detailed Description
The exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, however, the present invention may be embodied in many different forms and is not limited to the embodiments described herein, which are provided for complete and complete disclosure of the present invention and to fully convey the scope of the present invention to those skilled in the art. The terminology used in the exemplary embodiments illustrated in the accompanying drawings is not intended to be limiting of the invention. In the drawings, the same units/elements are denoted by the same reference numerals.
Unless otherwise defined, terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. Further, it will be understood that terms, such as those defined in commonly used dictionaries, should be interpreted as having a meaning that is consistent with their meaning in the context of the relevant art and will not be interpreted in an idealized or overly formal sense.
According to a first aspect of the present invention, there is provided a method 100, as illustrated with reference to fig. 1, the method 100 comprising:
s101, writing an http interface through a receiving party;
s102, performing swagger configuration on the http interface to generate a swagger interface document;
s103, pushing the swagger interface document according to the swagger interface document and the related information of the swagger interface document;
and S104, checking the swagger interface document through a calling party.
Specifically, the interface caller develops the interface, configures the swagger attribute after the development is completed, and then the interface document can be automatically generated, and the url address of the interface document can be accessed online or downloaded to the local document after the access. And meanwhile, when the service is started each time, whether the interface is modified or not needs to be checked through the request of the interface document and the abstract value of the returned message, and if the interface is modified, an interface calling party needs to be informed.
Referring to fig. 2, the detailed implementation steps are as follows:
the method comprises the following steps: and the interface receiver writes the code of the http interface, and the interface adds swagger annotation, requests the message and returns the class of the message to add swagger annotation to enable swagger to take effect.
Step two: after configuration is completed, the interface document is automatically generated, and a requester can check the interface document after logging in by using the allocated account password.
Step three: the background checks the information of the interface document, judges whether the interface related information exists in the database, if not, inserts the interface request and returns the MD5 abstract of the message, and sends the push and mail of the newly added interface according to the configured caller personnel and mail address; and if the interface change information exists, judging whether the MD5 digest value is changed, if so, updating the MD5 digest value, and pushing and sending the mail to the message with the changed interface through a pushing mechanism of a rabbitMQ according to the configured caller personnel and mail address.
Step four: the caller receives the message of adding new interface or modifying interface.
Step five: the caller can log in the interface document and research and develop the function after checking.
Through the steps, the automatic generation of the interface document and the automatic message pushing mechanism are executed.
The invention uses swagger to generate the interface document, thereby ensuring the automatic real-time update of the interface document. Maintaining a set of information of each interface caller and abstract values of request and return messages, if the abstract values are changed, indicating that the interface is changed, sending an interface document change notice through a mail in the information of the interface caller, and pushing communication software according to the information of the caller to ensure that a receiver can receive the notice of the interface document change.
Therefore, a set of more automatic interface document automatic generation mechanism is provided, the advantages of automation, standardization, real-time synchronization and the like brought by using swagger are integrated, a set of mechanism for automatically notifying interface change can be automatically maintained, and various problems brought by unsmooth communication among different departments and project groups in a company are greatly reduced.
Optionally, swagger configuring the http interface includes:
and adding swagger notes to the classes of the request message and the return message of the http interface, setting a request field and setting a return field.
Optionally, pushing the swagger interface document according to the swagger interface document and the relevant information of the swagger interface document includes:
according to the swagger interface document and the relevant information of the swagger interface document,
determining new interface information or modifying interface information.
Optionally, determining newly-added interface information or modifying interface information according to the swagger interface document and the related information of the swagger interface document, including:
judging whether interface information of the swagger interface document exists in a database or not;
if the interface information of the swagger interface document does not exist in the database, inserting the MD5 abstract of the swagger interface request and the returned message into the database, and sending the push and the mail of the newly added interface according to the configured calling party personnel and the mail address;
and if the interface information of the swagger interface document does not exist in the database, judging whether the MD5 digest value changes, if so, updating the MD5 digest value, and pushing and sending the mail to the message with the modified interface through a rabbitMQ pushing mechanism according to the configured calling party personnel and mail addresses.
Optionally, viewing the swagger interface document through a calling party, including:
and after receiving the swagger interface document through the calling party, logging in and checking the swagger interface document.
According to another aspect of the present invention, there is also provided a swagger interface based document automatic generation system 300, and referring to fig. 3, the system 300 includes:
the http interface writing module 310 is configured to write an http interface through a receiving party;
the interface document generation module 320 is used for performing swagger configuration on the http interface to generate swagger interface documents;
the interface document pushing module 330 is configured to push the swagger interface document according to the swagger interface document and the relevant information of the swagger interface document;
and the viewing interface document module 340 is used for viewing the swagger interface document through a calling party.
Optionally, the generate interface document module 320 includes:
and the swagger annotation adding submodule is used for adding swagger annotation to the classes of the request message and the return message of the http interface, setting a request field and setting a return field.
Optionally, the push interface document module 330 includes:
and the interface information determining submodule is used for determining newly-added interface information or modifying interface information according to the swagger interface document and the related information of the swagger interface document.
Optionally, the determining interface information sub-module includes:
the interface information judging unit is used for judging whether the interface information of the swagger interface document exists in a database or not;
the newly added pushing interface unit is used for inserting the swagger interface request and the MD5 abstract of the returned message into the database if the interface information of the swagger interface document does not exist in the database, and sending pushing and mail of the newly added interface according to configured calling party personnel and mail addresses;
and the pushing and modifying interface unit is used for judging whether the MD5 digest value changes or not if the interface information of the swagger interface document does not exist in the database, updating the MD5 digest value if the MD5 digest value changes, and pushing and sending the mail to the message of the modified interface through a rabbitMQ pushing mechanism according to the configured calling party personnel and mail addresses.
Optionally, the viewing interface documents module 340 includes:
and the interface document viewing submodule is used for logging in and viewing the swagger interface document after the calling party receives the swagger interface document.
The swagger interface-based automatic document generation system 300 according to the embodiment of the present invention corresponds to the swagger interface-based automatic document generation method 100 according to another embodiment of the present invention, and details thereof are not repeated herein.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein. The scheme in the embodiment of the application can be implemented by adopting various computer languages, such as object-oriented programming language Java and transliterated scripting language JavaScript.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While the preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A method for automatically generating a document based on a swagger interface is characterized by comprising the following steps:
writing an http interface through a receiver;
performing swagger configuration on the http interface to generate a swagger interface document;
pushing the swagger interface document according to the swagger interface document and the related information of the swagger interface document;
and checking the swagger interface document through a calling party.
2. The method of claim 1, wherein swagger configuring the http interface comprises:
and adding swagger notes to the classes of the request message and the return message of the http interface, setting a request field and setting a return field.
3. The method according to claim 1, wherein pushing the swagger interface document according to the swagger interface document and the relevant information of the swagger interface document comprises:
and determining newly-added interface information or modifying interface information according to the swagger interface document and the related information of the swagger interface document.
4. The method according to claim 3, wherein determining new interface information or modified interface information according to the swagger interface document and the relevant information of the swagger interface document includes:
judging whether interface information of the swagger interface document exists in a database;
if the interface information of the swagger interface document does not exist in the database, inserting the MD5 abstract of the swagger interface request and the returned message into the database, and sending the push and the mail of the newly added interface according to the configured calling party personnel and the mail address;
and if the interface information of the swagger interface document does not exist in the database, judging whether the MD5 digest value changes, if so, updating the MD5 digest value, and pushing and sending the mail to the message with the modified interface through a rabbitMQ pushing mechanism according to the configured calling party personnel and mail addresses.
5. The method of claim 1, wherein viewing the swagger interface document by a caller comprises:
and after receiving the swagger interface document through the calling party, logging in and checking the swagger interface document.
6. A document automatic generation system based on swagger interface is characterized by comprising:
the http interface module is used for compiling an http interface through a receiving party;
an interface document generation module, configured to perform swagger configuration on the http interface, and generate a swagger interface document;
the interface document pushing module is used for pushing the swagger interface document according to the swagger interface document and the related information of the swagger interface document;
and the interface document viewing module is used for viewing the swagger interface document through a calling party.
7. The system of claim 6, wherein the generate interface documents module comprises:
and the swagger annotation adding submodule is used for adding swagger annotation to the classes of the request message and the return message of the http interface, setting a request field and setting a return field.
8. The system of claim 7, wherein the push interface documents module comprises:
and the interface information determining submodule is used for determining newly-added interface information or modifying interface information according to the swagger interface document and the related information of the swagger interface document.
9. The system of claim 8, wherein the determine interface information submodule comprises:
the interface information judging unit is used for judging whether the interface information of the swagger interface document exists in a database or not;
the newly-added pushing interface unit is used for inserting the swagger interface request and the MD5 abstract of the returned message into the database if the interface information of the swagger interface document does not exist in the database, and sending pushing and mail of the newly-added interface according to configured caller personnel and mail addresses;
and the pushing and modifying interface unit is used for judging whether the MD5 digest value changes or not if the interface information of the swagger interface document does not exist in the database, updating the MD5 digest value if the MD5 digest value changes, and pushing and sending the mail to the message of the modified interface through a rabbitMQ pushing mechanism according to the configured calling party personnel and mail addresses.
10. The system of claim 6, wherein the view interface documents module comprises:
and the interface document viewing submodule is used for logging in and viewing the swagger interface document after the calling party receives the swagger interface document.
CN202111529248.3A 2021-12-14 2021-12-14 Automatic document generation method and system based on swagger interface Pending CN114489590A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111529248.3A CN114489590A (en) 2021-12-14 2021-12-14 Automatic document generation method and system based on swagger interface

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111529248.3A CN114489590A (en) 2021-12-14 2021-12-14 Automatic document generation method and system based on swagger interface

Publications (1)

Publication Number Publication Date
CN114489590A true CN114489590A (en) 2022-05-13

Family

ID=81494458

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111529248.3A Pending CN114489590A (en) 2021-12-14 2021-12-14 Automatic document generation method and system based on swagger interface

Country Status (1)

Country Link
CN (1) CN114489590A (en)

Similar Documents

Publication Publication Date Title
CN109840429B (en) Intelligent contract deployment and calling method and device
US9176730B2 (en) On-demand database service system, method, and computer program product for validating a developed application
US8196100B2 (en) Content management system for computer software with dynamic traceability between code and design documents
CN106874247B (en) Report generation method and device
CN107092491B (en) Configuration loading method and system
US10216508B1 (en) System and method for configurable services platform
CN110795485A (en) Database access method, device and equipment
JP2014519102A (en) Auto-suggested content item request
US8103701B2 (en) Metadata to technical design review document process
WO2023179749A1 (en) Configuration data processing system and method, and electronic device
CN103593406A (en) Static resource identifier processing method and device
CN106708897B (en) Data warehouse quality guarantee method, device and system
WO2023151397A1 (en) Application program deployment method and apparatus, device, and medium
CN110599112B (en) Network page development and maintenance method and device
CN111522881A (en) Service data processing method, device, server and storage medium
CN114489590A (en) Automatic document generation method and system based on swagger interface
CN114153461A (en) Script processing method and device, electronic equipment and storage medium
EP4154129A1 (en) Database management methods and associated apparatus
CN115794827B (en) Data table structure management system and method
CN116661758B (en) Method, device, electronic equipment and medium for optimizing log framework configuration
CN112051999B (en) Configurable download file generation method and device
CN115080194A (en) Business method transaction detection method and system
CN115543969A (en) Data migration method, device, equipment and medium
CN110728584A (en) Information processing method and device, readable storage medium and electronic equipment
CN115438632A (en) Text data processing method and device, electronic equipment and readable 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