OpenAPI Specification v3 0.3 Introduction, Definitions, & More

Mapping keys MUST be string values, but tooling MAY convert response values to strings for comparison. Describes a single response from an API Operation, including design-time, static
links to operations based on the response. An encoding attribute is introduced to give you control over the serialization of parts of multipart request bodies. This attribute is only applicable to multipart and application/x–urlencoded request bodies. In order to support common ways of serializing simple parameters, a set of style values are defined. Unless specified otherwise, all properties that are URLs MAY be relative references as defined by RFC3986.

api specification

Examples are a crucial part of effective API documentation, as they help consumers understand endpoint behavior under a variety of conditions. Producers should include example requests in several client languages, as well as example responses, which enable consumers to troubleshoot issues they might encounter. Many developers want just the raw OpenAPI document to use in their own tooling.

Path Item Object

Patterned fields MUST have unique names within the containing object. Occasionally, non-backwards compatible changes may be made in minor versions of the OAS where impact is believed to be low relative to the benefit provided. The available status codes are defined by RFC7231 and registered status codes are listed in the IANA Status Code Registry. In addition to the examples we’ve shared throughout the article, here are some more for you to enjoy and take note of. All of them follow REST conventions, as this API architecture is currently the most popular for web-based APIs.

  • But even technical writers tend to leak a bit of jargon into the text.
  • It explains how the API functions and the results to expect when using the API.
  • It’s usually assumed that devs will know how to send HTTP requests in their language of choice, but sometimes, API creators include requests in various languages.
  • In 2019, SmartBear, the developer of tools for API designing and documenting Swagger, surveyed API developers and users.
  • Still, there’s a trend toward combining all specs under the hood of OpenAPI.

An API specification provides a broad understanding of how an API behaves and how the API links with other APIs. It explains how the API functions and the results to expect when using the API. A good example of an API specification is the OpenAPI Specification. You can view the latest version of this specification (3.0.1) on GitHub. As you can see, there are a lot of items to agree upon, and all of them must be properly documented. A mistake or misunderstanding in any of these items is undetectable while writing the code, and they lead to runtime issues ranging from program malfunction to system crashes.

Header Object

It is a specification language for HTTP APIs that defines structure and syntax in a way that is not wedded to the programming language the API is created in. API specifications are typically written in YAML or JSON, allowing for easy sharing and consumption of the specification. For more information about the properties, see JSON Schema Core and JSON Schema Validation. Unless stated otherwise, the property definitions follow the JSON Schema. A linked operation MUST be identified using either an operationRef or operationId.

The value of the chosen property has to be the friendly name given to the model under the definitions property. As such, inline schema definitions, which do not have a given id, cannot be used in polymorphism. Swagger allows combining and extending model definitions using the allOf property of JSON Schema, in effect offering model composition.

Version 3.0.3

The key that identifies the Path Item Object is a runtime expression that can be evaluated in the context of a runtime HTTP request/response to identify the URL to be used what is api in simple words for the callback request. However, using a runtime expression the complete HTTP message can be accessed. This includes accessing any part of a body that a JSON Pointer [[!

This is applicable for $ref fields in the specification as follows from the JSON Schema definitions. The Swagger specification defines a set of files required to describe such an API. These files can then be used by the Swagger-UI project to display the API and Swagger-Codegen to generate clients in various languages. Additional utilities can also take advantage of the resulting files, such as testing tools.


Fixed fields, which have a declared name, and Patterned fields, which declare a regex pattern for the field name. Patterned fields can have multiple occurrences as long as each has a unique name. The files describing the RESTful API in accordance with the Swagger specification are represented as JSON objects and conform to the JSON standards. YAML, being a superset of JSON, can be used as well to
represent a Swagger specification file. The last stage in our API cycle is about making the API available to API consumers.

AllOf takes an array of object definitions that are validated independently but together compose a single object. For computing links, and providing instructions to execute them, a runtime expression is used for accessing values in an operation and using them as parameters while invoking the linked operation. The following examples show how the various expressions evaluate, assuming the callback operation has a path parameter named eventType and a query parameter named queryUrl.

Table of Contents

An API definition is often used as a baseline for automated tools. API definitions can be used to generate API documentation, code samples, and SDKs automatically. A few examples of tools that generate API documentation (static and interactive) from an API definition file are SwaggerHub and Swagger Inspector. A few examples of tools that can automatically generate sample code and SDKs from API definitions include REST United and SwaggerHub. Allows the definition of a security scheme that can be used by the operations. Supported schemes are basic authentication, an API key (either as a header or as a query parameter) and OAuth2’s common flows (implicit, password, application and access code).

api specification

Holds the relative paths to the individual endpoints and their operations. The path is appended to the URL from the Server Object in order to construct the full URL. Each template expression in the path MUST correspond to a path parameter that is included in the Path Item itself and/or in each of the Path Item’s Operations. A document (or set of documents) that defines or describes an API. An OpenAPI definition uses and conforms to the OpenAPI Specification. Some objects in the OpenAPI Specification MAY be declared and remain empty, or be completely removed, even though they are inherently the core of the API documentation.

It should include code samples for commonly used languages such as Java, JavaScript, PHP, and Python. Documentation should provide an explanation for each API request and examples of error messages. It’s also important that API documentation is actively maintained and always up to date.

api specification