
OpenAPI Examples; A Practical Guide
May 5, 2026
OpenAPI Examples
Examples are a great way to show what data your API expects or responds with using real world examples. This can be especially useful when you want to highlight edge cases or show how data is serialized in locations such as a path's query. We're going to break down OpenAPI examples in parameters, schemas, and responses and requests based on the OpenAPI 3.2.X specification (which is backwards compatible with OpenAPI 3.1.X).
This article is a practical guide to using examples in OpenAPI 3.2.X (and 3.1.X). If you want a more comprehensive understanding, you can read the OpenAPI's working with examples section for more details .
Is it Example of Examples?
In OpenAPI, there is the example field and the examples field. For Schemas, examples should be used, with the singular example field deprecated as of OpenAPI 3.2.0. (You can find more information in the Fixed Fields section of the Schema Object section in the OpenAPI's 3.2.0 specification page here)
As for Parameters, Request Bodies, and Responses, example is the shorthand singular version of examples and only contains the value property.
In this article, I'll be focusing on the examples field since it is more versatile and comprehensive.
Examples in Schemas
Examples in schemas are very straightforward. Under examples, you can provide an array of examples that conform to the schema. That's it! Nice and simple. The example below contains 2 examples for a "Product" schema, one with a description, and one without one (since it isn't a required field).
Examples in Parameters
Examples for "Parameters" are more involved than Schema examples. For example, they:
- Are named
- Can have a summary and a description
- The example data is described via the
valueproperty - A
serializeValueexists to show howdataValueis encoded when special characters are used, or when special encoding is needed to renderdataValuein query parameters.
The last point is particularly helpful. It can be difficult to know how data should be encoded in requests. Providing a serializeValuecan resolve any ambiguity. For example, the sample below shows how the search query can be used to search for products ending with "juice" and how it would be encoded.
Examples in Requests and Responses
Examples in Requests and Responses are the same as examples in parameters. They are named and can can contain the dataValue andserializeValue properties. What is particularly useful about examples in responses is you can describe expected error flows with great fidelity without over-complicating your schema definitions.
For example, the below sample contains an endpoint for getting a product. In the 404 response, we can provide an example of what the response actually looks like, and include the appropriate status code for this response. Instead of embeding the error code in the Error schema, which can grow unwieldy, we can provide examples of what status codes the API client may bump into at the operation level.
Restly Now Supports Examples
Restly now supports all the above examples through the API designer interface. You can set schema examples, parameter examples, and request and response examples natively. In addition, these examples will be exported when you generate an OpenAPI 3.2.X schema file, and imported when you create an API from a spec file.
