# 在文档中插入 API 参考

GitBook 可让你根据 OpenAPI 规范中的端点自动生成相关页面。这些页面将包含 OpenAPI 操作块，使你和访问者能够测试你的端点，并根据规范中找到的信息进一步探索它们。

{% hint style="success" %}
从你的规范中添加的端点将会在你的规范更新时持续更新。请参见 [更新你的规范](/docs/documentation/zh/api-references/openapi/add-an-openapi-specification.md#update-your-specification) 部分以了解更多信息。
{% endhint %}

### 根据你的规范自动创建 OpenAPI 页面

在你已经 [添加了你的 OpenAPI 规范](/docs/documentation/zh/api-references/openapi/add-an-openapi-specification.md)之后，你可以通过插入一个 **OpenAPI 参考** 到 Space 的目录中来生成端点页面。

<figure><img src="/files/22304f3aaa594a5a51ce2043d5bd82f98be6f4d5" alt="A GitBook screenshot showing how to insert API references into the table of contents of a space"><figcaption><p>在 Space 的目录中插入 API 参考。</p></figcaption></figure>

{% stepper %}
{% step %}
**从 OpenAPI 生成页面**

在你想生成端点页面的空间中，点击 **添加新的...** 按钮，位于你的空间的底部 [目录](/docs/documentation/zh/zi-yuan/gitbook-ui.md#table-of-contents).

在这里，点击 **OpenAPI 参考**.
{% endstep %}

{% step %}
**选择你的 OpenAPI 规范**

选择你之前上传的 OpenAPI 规范，然后点击 **插入** 即可自动将你的端点添加到你的空间中。你也可以选择添加一个模型页面，用于引用你所有的 OpenAPI schema。
{% endstep %}

{% step %}
**管理你的 API 操作**

GitBook 将根据你的 OpenAPI 规范以及其中定义的标签自动生成页面。

进入 [组织你的 API 参考结构](/docs/documentation/zh/api-references/guides/structuring-your-api-reference.md) 以了解更多关于如何通过你的 OpenAPI 规范组织你的操作。
{% endstep %}
{% endstepper %}

### 添加一个单独的 OpenAPI 块

或者，你也可以将规范中的 OpenAPI 操作或 schema 单独添加到文档中的各个页面。

{% stepper %}
{% step %}
**添加一个新的 OpenAPI 块**

按下 **/**&#x4EE5;打开块选择器，并搜索 OpenAPI。
{% endstep %}

{% step %}
**选择你的 OpenAPI 规范**

选择你之前上传的 OpenAPI 规范，然后点击 **继续** 来选择你想使用的端点。
{% endstep %}

{% step %}
**选择你想插入的操作或 schema**

选择你想插入文档中的操作和 schema，然后点击 **插入**.
{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/api-references/openapi/insert-api-reference-in-your-docs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
