> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/openapi/insert-api-reference-in-your-docs.md).

# 在你的文档中插入 API 参考

从你的 OpenAPI 规范中插入完整的 API 参考，或选择单个操作或架构

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

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

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

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

<figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2FYy8gCqxfaO4xjv2eqiL5%2Fcreate_api_pages%402x.png?alt=media&amp;token=62b8386b-9fea-4233-b961-b6a1e582411e" alt="A GitBook screenshot showing how to insert API references into the table of contents of a section"><figcaption><p>将 API 参考插入到某个部分的目录中。</p></figcaption></figure>

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

在你想要生成端点页面的部分中，点击 **添加新内容...** 按钮，位于该部分底部的 [目录](/docs/documentation/zh/can-kao/gitbook-ui.md#table-of-contents).

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

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

选择你之前上传的 OpenAPI 规范。然后选择一个 **页面结构**:

* **每个标签一个页面**
* **每个操作一个页面**

你也可以选择添加模型页面和下载链接。点击 **插入** 以生成参考文档。
{% endstep %}

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

GitBook 会根据你的 OpenAPI 规范以及其定义中设置的标签自动生成页面。如果你选择 **每个操作一个页面**，GitBook 会按标签对生成的操作页面分组。

前往 [OpenAPI 布局](/docs/documentation/zh/chuang-jian-nei-rong/openapi/guides/openapi-layouts.md) 来比较布局，或 [构建你的 API 参考](/docs/documentation/zh/chuang-jian-nei-rong/openapi/guides/structuring-your-api-reference.md) 用标签来组织页面。
{% endstep %}
{% endstepper %}

### 添加单个 OpenAPI 块

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

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

按下以下键打开块选择器 **/**，并搜索 OpenAPI。
{% endstep %}

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

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

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

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/openapi/insert-api-reference-in-your-docs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
