Application Programming Interface Specification Generator
Disclosed herein are system, method, and computer program product embodiments for automatically generating an application programming language (API) specification for an API. An embodiment operates by receiving an identification an API and a specification format for the identified API. The embodiment receives, via an API gateway, an API request that includes a first set of attributes for the API. The embodiment then receives an API response that includes a second set of attributes in response to the API request. The embodiment further determines whether the API request is valid based on at least one of the API request and the API response. In response to the API request being valid, the embodiment generates an API specification for the API using the specification format. The API specification includes a third set of attributes generated based on the first and second sets of attributes.
1 . A method, comprising:
receiving an identification of an application programming interface (API) and a specification format for the API;
receiving, via an API gateway, an API request that includes a first set of attributes for the API;
receiving an API response that includes a second set of attributes in response to the API request;
determining, based on at least one of the API request and the API response, whether the API request is valid; and
generating, in response to the API request being valid, an API specification for the API using the specification format, wherein the API specification comprises a third set of attributes generated based on the first and second sets of attributes.
2 . The method of claim 1 , wherein the generating of the API specification comprises adding the first and second sets of attributes to the API specification.
3 . The method of claim 1 , wherein the generating of the API specification comprises identifying a predefined API specification from a set of predefined API specifications using a machine-learning model based on the first and second sets of attributes.
4 . The method of claim 3 , further comprising identifying endpoints of the API based on the predefined API specification.
5 . The method of claim 1 , further comprising:
identifying endpoints responding to the API request;
dividing the endpoints into a number of groups, wherein the endpoints in each group share at least one common attribute; and
splitting the API specification into a plurality of component API specifications, each of the plurality of component API specifications corresponding to one of the groups.
6 . The method of claim 1 , further comprising:
determining a number of API requests received for the API in a period time; and
removing the API in response to the number of API requests being below a threshold.
7 . The method of claim 1 , further comprising:
identifying, based on a predefined rule for the API response, additional attributes related to an attribute in the second set of attributes; and
adding the additional attributes to the API specification.
8 . The method of claim 1 , further comprising:
determining a category label for the API based on the first and second sets of attributes; and
adding the category label to the API specification, wherein the category label includes category information of the API.
9 . The method of claim 1 , further comprising updating the API specification based on additional API requests and additional API responses for the API.
10 . The method of claim 1 , wherein the first set of attributes comprise API request payloads, API request headers, resources, resource paths, and parameters of the resources for the API request, and wherein the second set of attributes comprise API response payloads, API response headers, and status codes for the API response.
11 . A system, comprising:
a memory; and
at least one processor coupled to the memory and configured to:
receive an identification of an application programming interface (API) and a specification format for the API;
receive, via an API gateway, an API request that includes a first set of attributes for the API;
receive an API response that includes a second set of attributes in response to the API request;
determine, based on at least one of the API request and the API response, whether the API request is valid; and
generate, in response to the API request being valid, an API specification for the API using the specification format, wherein the API specification comprises a third set of attributes generated based on the first and second sets of attributes.
12 . The system of claim 11 , wherein to generate the API specification the at least one processor is configured to add the first and second sets of attributes to the API specification.
13 . The system of claim 11 , wherein to generate the API specification the at least one processor is configured to identify a predefined API specification from a set of predefined API specifications using a machine-learning model based on the first and second sets of attributes.
14 . The system of claim 13 , wherein the at least one processor is further configured to identify endpoints of the API based on the predefined API specification.
15 . The system of claim 11 , wherein the at least one processor is further configured to:
identify endpoints responding to the API request;
divide the endpoints into a number of groups, wherein the endpoints in each group share at least one common attributes; and
split the API specification into a plurality of API component specifications, each of the plurality of component API specification corresponding to one of the groups.
16 . The system of claim 11 , wherein the at least one processor is further configured to:
determine a number of API requests received for the API in a period time; and
remove the API in response to the number of API requests being below a threshold.
17 . The system of claim 11 , wherein the at least one processor is further configured to:
identify, based on a predefined rule for the API response, additional attributes related to an attribute in the second set of attributes; and
add the additional attributes to the API specification.
18 . The system of claim 11 , wherein the at least one processor is further configured to:
determining a category label for the API based on the first and second sets of attributes; and
adding the category label to the API specification, wherein the category label includes category information of the API.
19 . A non-transitory computer-readable medium (CRM) having instructions stored thereon that, when executed by at least one computing device, causes the at least one computing device to perform operations comprising:
receiving an identification of an application programming interface (API) and a specification format for the API;
receiving, via an API gateway, an API request that includes a first set of attributes for the API;
receiving an API response that includes a second set of attributes in response to the API request;
determining, based on at least one of the API request and the API response, whether the API request is valid; and
generating, in response to the API request being valid, an API specification for the API using the specification format, wherein the API specification comprises a third set of attributes generated based on the first and second sets of attributes.
20 . The non-transitory CRM of claim 19 , further comprising:
identifying endpoints responding to the API request;
dividing the endpoints into a number of groups, wherein the endpoints in each group share at least one common attributes; and
splitting the API specification into a plurality of API specifications corresponding to the number of groups.