Basic Structure
You can write OpenAPI definitions in YAML or JSON. In this guide, we use only YAML examples but JSON works equally well. A sample OpenAPI 3.0 definition written in YAML looks like:
All keyword names are case-sensitive.
Metadata
Every API definition must include the version of the OpenAPI Specification that this definition is based on:
The OpenAPI version defines the overall structure of an API definition – what you can document and how you document it. OpenAPI 3.0 uses semantic versioning with a three-part version number. The available versions are 3.0.0
, 3.0.1
, 3.0.2
, and 3.0.3
; they are functionally the same.
The info
section contains API information: title
, description
(optional), version
:
title
is your API name. description
is extended information about your API. It can be multiline and supports the CommonMark dialect of Markdown for rich text representation. HTML is supported to the extent provided by CommonMark (see HTML Blocks in CommonMark 0.27 Specification). version
is an arbitrary string that specifies the version of your API (do not confuse it with file revision or the openapi
version). You can use semantic versioning like major.minor.patch, or an arbitrary string like 1.0-beta or 2017-07-25. info
also supports other keywords for contact information, license, terms of service, and other details.
Reference: Info Object.
Servers
The servers
section specifies the API server and base URL. You can define one or several servers, such as production and sandbox.
All API paths are relative to the server URL. In the example above, /users
means http://api.example.com/v1/users
or http://staging-api.example.com/users
, depending on the server used. For more information, see API Server and Base Path.
Paths
The paths
section defines individual endpoints (paths) in your API, and the HTTP methods (operations) supported by these endpoints. For example, GET /users
can be described as: