What is the OpenAPI Specification?
The OpenAPI Specification (OAS) specifies a standard, language-agnostic and machine-readable format to describe a web API in one or more files. Nowadays, it acts as a vendor-neutral standard for describing the structure and behaviour of HTTP-based APIs, and exists as part of the OpenAPI Initiative (OAI). Following the OAS brings the following advantages:- A description of the API that is readable from both humans and machines.
- The possibility of automatically generating documentation, implementation logic and even mock servers for testing.
- Early validation of the data flows happening within the API.
Swagger vs OpenAPI
The OpenAPI Specification is the newer, fully open source-driven incarnation of the Swagger Specification maintained by SmartBear Software. The spec describes, produces, consumes, and visualizes RESTful application and web services. The name Swagger today indicates a set of tools, both free and paid, that support users of the OpenAPI ecosystem.Exploring the specification
The core of our API specification will happen in the OpenAPI root document, normally namedopenapi.json
or openapi.yml
. We can choose between JSON and YAML formats as we like.
The bare minimum we need to declare is the OpenAPI version, the basic information about our API, and finally the available endpoints.
OpenAPI.yml
GET
operation:
OpenAPI.yml
id
parameter, as well as the response.
OpenAPI.yml
OpenAPI.yml
Generating documentation from OpenAPI
Let’s now take a look at a more complex, finished example: the Swagger PetStore demo. Even if we had written it ourselves, this description of a complete API could be overwhelming if we just tried to parse the file line by line. To first-time users, that could feel even more daunting. A better option would be to use the open-source toolset Swagger offers to generate human-readable, interactive API documentation from the file we already have. Pasting the content of the spec file to Swagger Editor will produce a preview of our Swagger UI documentation. This is helpful for consumers of the API, who will be presented with an orderly documentation page breaking down each endpoint while also allowing users to test out different operations.Generating boilerplate code from OpenAPI
When writing a new API, we will oftentimes need to produce a certain amount of boilerplate code for both our provider (e.g. a server exposing our API for consumption) and consumer (e.g. an SDK for our API) applications. Once we have our OpenAPI file in place, we can use Swagger Codegen (also available within Swagger Editor) to automatically generate that code for us, saving us precious time and reducing the avenues for human error. The following snippet is an example of the code Swagger Codegen can generate starting from an OAS file.OpenAPI.js
Generated monitoring checks with Checkly
API monitoring is key to ensure that our endpoints are returning the correct results in an acceptable timeframe. If we can generate APIs from a OAS description file, we can also generate monitoring checks for them. Checkly is a member of the OpenAPI initiative, and allows us to import an OpenAPI spec file and automatically creates one or more checks depending on the amount of information available. All it takes is a couple of clicks. When creating an API check, select theimport from Swagger / OpenAPI
button.






- Save us a large amount of time otherwise spent in manual check setup.
- Reduce the chance for human error in check configuration.
- Help us ensure the right checks are set up according to our single source of truth.
Building on our generated monitors
As we look to increase our endpoint coverage across our APIs, we might want to explore the following resources:- Learning more about API monitoring basics and best practices.
- Defining our API checks as code to scale our setup.
- Integrating our API monitoring with E2E monitoring for our websites.