mirror of
https://github.com/mintlify/docs.git
synced 2026-09-14 13:35:46 +08:00
629f648c57
* docs: apply brand tone and writing style fixes * docs: split long sentences in self-host page --------- Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com>
51 lines
1.6 KiB
Plaintext
51 lines
1.6 KiB
Plaintext
---
|
|
title: "Add SDK examples"
|
|
description: "Add SDK code samples to your API documentation with autogenerated examples from Speakeasy and Stainless across multiple languages."
|
|
keywords: ["x-codeSamples", "SDK examples"]
|
|
---
|
|
|
|
If your users interact with your API through an SDK rather than direct network requests, add SDK code samples with the `x-codeSamples` extension. Mintlify displays these samples on your OpenAPI pages.
|
|
|
|
Add this property to any request method. It 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>
|
|
|
|
The following example shows code samples for a plant tracking app that 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 });
|
|
```
|
|
|