> ## Documentation Index
> Fetch the complete documentation index at: https://omer-914cc1c6.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 添加 SDK 示例

> 在 API 端点旁展示特定语言的代码示例，向开发者说明如何使用你的 SDK

如果你的用户通过 SDK 而非直接发起网络请求来与 API 交互，你可以使用 `x-codeSamples` 扩展将代码示例添加到 OpenAPI 文档中，并在 OpenAPI 页面上展示。

此属性可添加到任意请求方法，并具有以下结构。

<ParamField body="lang" type="string" required>
  代码示例所用的语言。
</ParamField>

<ParamField body="label" type="string">
  示例的标签。在为同一端点提供多个示例时很有用。
</ParamField>

<ParamField body="source" type="string" required>
  示例的源代码。
</ParamField>

下面是一个植物追踪应用的代码示例，包含 Bash 命令行界面（CLI）工具和 JavaScript SDK。

```yaml theme={null}
paths:
  /plants:
    get:
      # ...
      x-codeSamples:
        - lang: bash
          label: 列出所有未浇水的植物
          source: |
            planter list -u
        - lang: javascript
          label: 列出所有未浇水的植物
          source: |
            const planter = require('planter');
            planter.list({ unwatered: true });
        - lang: bash
          label: 列出所有盆栽植物
          source: |
            planter list -p
        - lang: javascript
          label: 列出所有盆栽植物
          source: |
            const planter = require('planter');
            planter.list({ potted: true });
```
