Automating the creation of APIs in Kong

Process automation is a constant exercise, we should be always aware of opportunities to automate tasks and optimize processes. And with this post, we want to share one of those occasions, which was the creation of a simple but effective tool to validate and import Open APIs (Swagger) into the Kong API Gateway, optimizing the deployment process of our customers.

At first glance, creating APIs seems an easy task to be performed by a member of the development team, however, with an increasing number of APIs, it can end up being a repetitive, costly and error prone proccess. In addition, developers already invest time to design great contracts with API First, why not automate their import as well?

With this need in mind, we created the Swagger to Kong.

The tool’s name is as simple as the its complexity, implemented in Python and making use of known libraries, has the main features:

Using the Tool

The tool can easily run with Docker, but for this you need the following requirements:

Validating the Open API / Swagger

The validation it is an important step to guarantee the compliance with the Open API specification, and can be performed as follows:

4. Checking the Result

ERROR in “/etc/openapi/spec.file” [ValidationError]: Could not determine specification schema version!

Importing Open API / Swagger into Kong

2. Checking APIs created through Konga UI

Services definitions
Routes definitions

Importing Open API / Swagger into Kong with Plugins

The Kong plugins can be defined via json, and the tool makes use of this functionality and combines the routes and plugins through regular expressions. This allows, for example, provisioning security in all APIs through the jwt-keycloak, or prometheus metrics, as follows:

2. Importing petstore-v3.0.yaml with the prometheus plugin definition

3. Checking APIs created through Konga UI

Route definition with plugin

Results

As a result of a simple automation, we had feedback that developers can now consume this time with other important business tasks, as well as using the tool for provisioning and local testing with the API First pattern. This also motivated other initiatives that generated more value for customers:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
3Bit Technologies

Cloud Specialists providing professional services with DevOps, BigData, Cloud Native Applications and Security. https://www.3bit.com.br/3bit