Method for realizing API (Application Program Interface) batch registration based on OpenAPI3.0 specification
Through the OpenAPI3.0 specification method, batch registration of APIs is realized, solving the problems of low API management efficiency and error-prone in large software systems, and improving work efficiency and management convenience.
Patent Information
- Application Number
- CN202510155552.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-12
- Publication Date
- 2025-05-09
AI Technical Summary
In large software systems, manual management and registration of large numbers of APIs is inefficient, error-prone, and difficult to maintain.
Using a method based on the OpenAPI3.0 specification, batch registration of API is realized by defining the necessary API information, verifying and parsing OpenAPI3.0 documents, setting API verification rules, batch processing API creation, online testing and publishing.
It realizes fast batch registration of API, reduces manual operations, improves work efficiency, reduces human errors, and centralized API management is easy to update and maintain.
Smart Images

Figure CN119966813A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software development technology, and in particular to a method for implementing batch registration of APIs based on the OpenAPI 3.0 specification. Background Art
[0002] In modern software development, API (application programming interface) is the key to communication between systems. With the popularity of microservice architecture, API management has become particularly important. In large systems, you may need to manage and register a large number of APIs, which will cause the following problems: 1. Difficult to maintain, and difficult to manage a large number of APIs.
[0003] 2. Low efficiency, unable to quickly complete the registration of a large number of APIs.
[0004] 3. The error rate is high. Manually registering each API is prone to errors.
[0005] Therefore, it is urgent to design a method to quickly realize the registration of a large number of APIs. Summary of the invention
[0006] In response to the above technical problems, the present invention provides a method for implementing API batch registration based on the OpenAPI 3.0 specification.
[0007] The present invention is implemented by adopting the following technical solution: a method for implementing batch registration of APIs based on the OpenAPI 3.0 specification, comprising the following steps: Step S1: define the necessary information of the system API; Step S2: Design and develop the microservice API based on the OpenAPI3.0 specification, and verify and parse the OpenAPI3.0 document in turn; Step S3: Setting API verification rules and processing APIs that do not meet the verification rules; Step S4: After the OpenAPI 3.0 document is parsed successfully according to the rules and meets all the API verification rules, batch processing is performed to complete the creation of the API on the API gateway; Step S5: Set up an API online testing mechanism, and the user completes the API debugging work online; Step S6: After the API online testing mechanism passes, the API is released online.
[0008] Specifically, the API necessary information includes: API name, API path, API request parameters, API response parameters, API request method, API description information, API publishing address, API authentication method and API plug-in chain information.
[0009] Specifically, the verification of the OpenAPI 3.0 document is specifically as follows: verifying whether the OpenAPI 3.0 document complies with the specification and determining whether it contains necessary parameters; and flexibly setting the OpenAPI 3.0 document size limit according to service performance.
[0010] Specifically, the necessary parameters include: openapi version number, components, paths and operations.
[0011] Specifically, parsing the OpenAPI 3.0 document includes: Step S21: Determine the OpenAPI specification version to be used according to the content of the openapi version number object; Step S22: parsing the metadata of the API according to the info information object, including the title, description and version; Step S23: Parse server information according to the servers service object, including URL and description; Step S24: Parse the reusable elements according to the schemas model in the components object, including parameters, responses and request bodies; Step S25: Parse the available paths and request methods of the API according to the paths object; Step S26: Generate an API set through the parsing results of the paths object and the components object.
[0012] Specifically, the step S25 specifically includes: using the summary parameter as the API name and API description, parsing the API header metadata, path resource path and query parameter from the parameters parameter object, using the requestBody annotation parsing result as the API body parameter, and using the responses object parsing result as the API response parameter.
[0013] Specifically, the API verification rules in step S3 are as follows: generate an API set that conforms to the API definition based on the results of the OpenAPI3.0 document parsing, and set corresponding rules for the API information, including: the API name and API publishing address cannot be repeated under the same microservice; perform special processing on APIs that do not conform to the verification rules, and rename the API name or API publishing address according to the specified method.
[0014] Specifically, the API online testing mechanism includes: according to the path of registering the API, actually accessing the API, checking whether the request link is normal, verifying whether the return result of the API meets the expected requirements, and generating a test log.
[0015] The beneficial effects of the present invention are: the present invention imports OpenAPI3.0 documents with one click to realize batch registration of APIs, reduce manual operations, and improve work efficiency; the API batch registration process does not require manual input of API information operations, reducing human errors; APIs are batch registered to the API gateway to centrally manage APIs, which is convenient for updating and maintenance; API information is defined strictly in accordance with the OpenAPI3.0 specification, which can further improve development specifications. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying creative work.
[0017] Figure 1 This is a schematic diagram of the API batch registration process in an embodiment of the present invention; Figure 2 This is a schematic diagram of OpenAPI 3.0 document parsing in one embodiment of the present invention. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0019] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0020] The following is combined with Figure 1-2 , some embodiments of the present invention are described in detail. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0021] The present invention proposes a method for implementing batch registration of APIs based on the OpenAPI 3.0 specification. The method aims to improve the problem that when there are many microservices in a large application system and a large number of APIs need to be registered, the manual registration of each API is inefficient and prone to errors. In addition, the manual registration of APIs has poor API standardization and is not conducive to API management. The method includes the following steps: Step S1: define the necessary information of the system API; Step S2: Design and develop the microservice API based on the OpenAPI3.0 specification, and verify and parse the OpenAPI3.0 document in turn; Step S3: Setting API verification rules and processing APIs that do not meet the verification rules; Step S4: After the OpenAPI 3.0 document is parsed successfully according to the rules and meets all the API verification rules, batch processing is performed to complete the creation of the API on the API gateway; Step S5: Set up an API online testing mechanism, and the user completes the API debugging work online; Step S6: After the API online testing mechanism passes, the API is released online.
[0022] In this embodiment, the necessary API information includes: API name, API path, API request parameters, API response parameters, API request method, API description information, API publishing address, API authentication method and API plug-in chain information.
[0023] In this embodiment, the verification of the OpenAPI3.0 document is specifically as follows: verifying whether the OpenAPI3.0 document complies with the specifications and determining whether it contains necessary parameters; and flexibly setting the OpenAPI3.0 document size limit according to service performance.
[0024] In this embodiment, the necessary parameters include: openapi version number, components, paths and operations.
[0025] In this embodiment, parsing the OpenAPI 3.0 document includes: Step S21: Determine the OpenAPI specification version to be used according to the content of the openapi version number object; Step S22: parsing the metadata of the API according to the info information object, including the title, description and version; Step S23: Parse server information according to the servers service object, including URL and description; Step S24: Parse the reusable elements according to the schemas model in the components object, including parameters, responses and request bodies; Step S25: Parse the available paths and request methods of the API according to the paths object; Step S26: Generate an API set through the parsing results of the paths object and the components object.
[0026] In this embodiment, step S25 specifically includes: using the summary parameter as the API name and API description, parsing the API header metadata, path resource path and query parameter from the parameters parameter object, using the requestBody annotation parsing result as the API body parameter, and using the responses object parsing result as the API response parameter.
[0027] In this embodiment, the API verification rules in step S3 are specifically as follows: an API set that conforms to the API definition is generated based on the results of the OpenAPI3.0 document parsing, and corresponding rules are set for the API information, including: the API name and API publishing address cannot be repeated under the same microservice; special processing is performed on APIs that do not conform to the verification rules, and the API name or API publishing address is renamed according to the specified method.
[0028] In this embodiment, the API online testing mechanism includes: according to the path of registering the API, actually accessing the API, checking whether the request link is normal, verifying whether the return result of the API meets the expected requirements, and generating a test log.
[0029] In one embodiment, the present invention parses the necessary API information according to the OpenApi3.0 specification and defines the API registration requirements; designs the API registration process according to the API registration requirements, including API definition, API creation, API testing and API publishing; the entire API registration process avoids manual modification of API information. Figure 1 As shown, the following steps are included: 1. API definition: define the necessary API information: API name, API path, API request parameters, API response parameters, API request method, API description information, API publishing address, API authentication method, API plug-in chain and other information.
[0030] 2.OpenAPI3.0 document analysis: Microservice APIs must be designed and developed strictly in accordance with the OpenAPI3.0 specification.
[0031] (1) OpenAPI 3.0 document verification: Verify that the OpenAPI 3.0 document complies with the specification and must include necessary parameters such as openapi, components, paths, etc.; flexibly set the OpenAPI 3.0 document size limit based on service performance.
[0032] (2) OpenAPI 3.0 document parsing rules, such as Figure 2 : Determine the OpenAPI specification version to use based on the content of the openapi object.
[0033] Parse the API metadata, such as title, description, version, etc., based on the info object.
[0034] Parse server information such as URL, description, etc. according to the servers object.
[0035] Parse reusable elements such as parameters, responses, request bodies, etc. according to the schemas in the components object.
[0036] The paths object is used to parse the available paths and request methods of the API. The summary parameter is used as the API name and description. The parameters object is used to parse the header, path, and query parameters of the API. The requestBody parsing result is used as the body parameter of the API. The responses object parsing result is used as the API response parameter.
[0037] Generate an API set by parsing the results of the paths object and components object 3.API verification rules: Generate an API set that conforms to the API definition based on the results of the OpenAPI3.0 document analysis, and set corresponding rules for API information, such as API names and API publishing addresses cannot be repeated under the same microservice. Perform special processing on APIs that do not conform to the verification rules, such as renaming the API name or API publishing address according to the specified method.
[0038] 4.API creation: After the OpenAPI3.0 document is parsed successfully according to the rules and meets all API verification rules, batch processing is performed to complete the creation of the API on the API gateway.
[0039] 5. API testing: It is necessary to design and implement a quick API online testing mechanism so that users can quickly complete the online debugging of the API.
[0040] According to the path of the registered API, actually access the API, check whether the request link is normal, verify whether the return result of the API meets the expected requirements, and generate a test log to facilitate error correction.
[0041] 6.API release: After the API test passes, the API can be released online.
[0042] For the aforementioned embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily required by the present application.
[0043] The above embodiments describe the basic principles and main features of the present invention and the advantages of the present invention. Those skilled in the art should understand that the present invention is not limited by the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the changes and modifications made by those skilled in the art shall be within the scope of protection of the appended claims of the present invention without departing from the spirit and scope of the present invention.
Claims
1. A method for implementing batch registration of APIs based on the OpenAPI 3.0 specification, characterized in that: The following steps are involved: Step S1: define the necessary information of the system API; Step S2: Design and develop the microservice API based on the OpenAPI3.0 specification, and verify and parse the OpenAPI3.0 document in turn; Step S3: Setting API verification rules and processing APIs that do not meet the verification rules; Step S4: After the OpenAPI 3.0 document is parsed successfully according to the rules and meets all the API verification rules, batch processing is performed to complete the creation of the API on the API gateway; Step S5: Set up an API online testing mechanism, and the user completes the API debugging work online; Step S6: After the API online testing mechanism passes, the API is released online.
2. A method for implementing batch registration of APIs based on the OpenAPI 3.0 specification as claimed in claim 1, characterized in that: The necessary API information includes: API name, API path, API request parameters, API response parameters, API request method, API description information, API publishing address, API authentication method and API plug-in chain information.
3. A method for implementing batch registration of APIs based on the OpenAPI 3.0 specification as claimed in claim 1, characterized in that: The verification of the OpenAPI3.0 document is specifically as follows: verifying whether the OpenAPI3.0 document complies with the specifications and determining whether it contains necessary parameters; and flexibly setting the OpenAPI3.0 document size limit based on service performance.
4. A method for implementing batch registration of APIs based on the OpenAPI 3.0 specification as claimed in claim 3, characterized in that: The necessary parameters include: openapi version number, components, paths and operations.
5. A method for implementing batch registration of APIs based on the OpenAPI 3.0 specification as claimed in claim 4, characterized in that: The parsing of the OpenAPI 3.0 document includes: Step S21: Determine the OpenAPI specification version to be used according to the content of the openapi version number object; Step S22: parsing the metadata of the API according to the info information object, including the title, description and version; Step S23: Parse server information according to the servers service object, including URL and description; Step S24: Parse the reusable elements according to the schemas model in the components object, including parameters, responses and request bodies; Step S25: Parse the available paths and request methods of the API according to the paths object; Step S26: Generate an API set through the parsing results of the paths object and the components object.
6. A method for implementing batch registration of APIs based on the OpenAPI 3.0 specification as claimed in claim 5, characterized in that: The step S25 specifically includes: using the summary parameter as the API name and API description, parsing the API header metadata, path resource path and query parameter from the parameters parameter object, using the requestBody annotation parsing result as the API body parameter, and using the responses object parsing result as the API response parameter.
7. A method for implementing batch registration of APIs based on the OpenAPI 3.0 specification as claimed in claim 1, characterized in that: The API verification rules in step S3 are specifically as follows: generating an API set that conforms to the API definition based on the results of the OpenAPI3.0 document parsing, and setting corresponding rules for the API information, including: the API name and API publishing address cannot be repeated under the same microservice; performing special processing on APIs that do not conform to the verification rules, and renaming the API name or API publishing address according to the specified method.
8. A method for implementing batch registration of APIs based on the OpenAPI 3.0 specification as claimed in claim 1, characterized in that: The API online testing mechanism includes: according to the path of registering the API, actually accessing the API, checking whether the request link is normal, verifying whether the return result of the API meets the expected requirements, and generating a test log.
Citation Information
Cited By
Application integration platform and interface rapid registration method
CN121283999A