Using examples in OpenAPI shows API consumers what requests and responses look like. They can be provided for request bodies, response bodies, and individual parameters.
Inline examples
Examples can be placed directly within the operation definition under paths
. Here’s an example:
Reusable examples
For more general examples that apply to multiple parts of the API, you can define them under the components/examples
section. These can be referenced elsewhere in the documentation.
How Examples are used in Fern SDKs
Fern SDKs use examples from your OpenAPI document to generate comments that show up in your IDE. For example, in a Node.js SDK:
Here’s an example in GitHub from Flatfile’s Node.js SDK.
How Examples are used in Fern Docs
In the request and response code snippets, you’ll see the example values used.
If you generate SDKs with Fern, the code examples for each language will also be populated with the example values. Check out Flatfile’s Docs to see this in action. Change the language toggle to see the examples in different languages.