Files
mintlify__docs/api-playground/adding-sdk-examples.mdx
Ethan Palm 30d7e22acf Flatten "Document APIs" group (#1752)
* consolidate MDX group into single page

* update nav and redirects

* match filename to title

* revise intro and setup

* update auth section

* remove outdated intro

* copyedit overview

* add link to example endpoint page

* remove asyncapi subdirectory

* 💅

* move MDX content out of OpenAPI setup

* copyedit openapi-setup

* Revert "move MDX content out of OpenAPI setup"

This reverts commit 3baed8e572.

* copyedit mdx-setup

* clean up openapi-setup

* task-based title

* fix title

* copyedit manage page visibility

* 💅

* update descriptions

* fix title

* add missing keywords

* fix YAML
2025-11-17 15:51:49 -08:00

51 lines
1.5 KiB
Plaintext

---
title: "Add SDK examples"
description: "Display SDK code samples in your API documentation."
keywords: ["x-codeSamples", "SDK examples"]
---
If your users interact with your API using an SDK rather than directly through a network request, you can use the `x-codeSamples` extension to add code samples to your OpenAPI document and display them in your OpenAPI pages.
This property can be added to any request method and has the following schema.
<ParamField body="lang" type="string" required>
The language of the code sample.
</ParamField>
<ParamField body="label" type="string">
The label for the sample. This is useful when providing multiple examples for a single endpoint.
</ParamField>
<ParamField body="source" type="string" required>
The source code of the sample.
</ParamField>
Here is an example of code samples for a plant tracking app, which has both a Bash CLI tool and a JavaScript SDK.
```yaml
paths:
/plants:
get:
# ...
x-codeSamples:
- lang: bash
label: List all unwatered plants
source: |
planter list -u
- lang: javascript
label: List all unwatered plants
source: |
const planter = require('planter');
planter.list({ unwatered: true });
- lang: bash
label: List all potted plants
source: |
planter list -p
- lang: javascript
label: List all potted plants
source: |
const planter = require('planter');
planter.list({ potted: true });
```