Tech, ExplainedCloud platforms and developer tools
Concept

OpenAPI specification

Telling tools exactly what an API accepts.

HOW IT WORKSThe API's ownerwrites one file ina standard formatFor each endpoint,the file gives theinputs, the repliesand the errorsTools read the file tomake documentation,code and testsA caller, a person, aprogram or an AIagent, sends requeststhat match itWhen the API changes,the file changes, andevery tool is updatedOne exact description, readable by programs, keeps every caller and every tool in step with the API.HOW IT WORKSThe API'sowner writesone file in astandardformatFor eachendpoint,the filegives theinputs, thereplies andthe errorsTools readthe fileto makedocumentation,codeand testsA caller, aperson, aprogram or anAI agent,sendsrequests thatmatch itWhen theAPI changes,the filechanges, andevery toolis updatedOne exact description, readable by programs, keeps every caller and every tool in step with the API.HOW IT WORKSThe API's owner writes one file in astandard format↓For each endpoint, the file gives theinputs, the replies and the errors↓Tools read the file to makedocumentation, code and tests↓A caller, a person, a program or an AIagent, sends requests that match it↓When the API changes, the file changes,and every tool is updatedOne exact description, readable by programs, keeps everycaller and every tool in step with the API.
One OpenAPI file lists every endpoint of an API with its inputs, replies and errors, and documentation tools, code generators, test tools, gateways and AI agents all read the same file.
opens a page inside this one a page in the same scene a page in another scene a concept page a label only, with no page

The OpenAPI specification is a standard format for describing, in one file, everything an API accepts and returns. It was earlier called the Swagger specification, after the tools in which it began. An API, or application programming interface, is the agreed way in which one program asks another program to do something. The OpenAPI file is the exact written description of that agreement, so that both people and programs can read it.

Here is how it works in general. The team that owns an API writes one file, in a simple text format called YAML or JSON. For each endpoint, the address that a request is sent to, the file lists what the request must contain: which fields, of what type, which ones are required, and the allowed values. It lists every reply the API can send, with its status number, such as 200 for success or 404 for "not found", and the fields in each reply. It also says how a caller must prove who it is, for example with a key. Because the file follows one standard, tools can read it. An API development platform turns it into documentation pages and a screen for trying each request. Other tools generate client code, the code that a caller's program uses to send requests. API testing tools send many requests and check every reply against the file. An API gateway, the software in front of the API, can block requests that do not match it.

Many teams now write the file first, before any code, and agree it with the teams that will call the API. This is called design-first.

Take, for example, a courier company that lets online shops book pickups through its API. It publishes an OpenAPI file, and a shop's developer generates the booking code from it instead of copying every field by hand.

Consider a state transport department's ticketing app, built by two vendors. One vendor builds the API and the other builds the app. Both work from the same OpenAPI file, so the app can be built before the API is finished.

Say a travel company gives an AI agent access to a hotel-booking API. The agent reads the OpenAPI file to learn which requests exist and which fields each one needs, and then calls the API correctly.

How is an OpenAPI specification different from ordinary API documentation? Ordinary documentation is written for people, in sentences and examples, and it can fall out of date without anyone noticing. An OpenAPI file is written for programs as well as people. Tools can check it, generate code from it and test the API against it. Good documentation pages are now often produced from the file itself.

Appears in

Cloud platforms and developer tools
Tech, Explained is a part of ingrid.fyi. Every page explains one piece of technology in plain words.