> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify-mintlify-add-hello-world-quickstart-48843.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
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 });
```
