> 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/guides/managing-api-operations.md).

# 管理 API 操作

了解如何将 OpenAPI API 操作标记为实验性、已弃用，或将其从文档中隐藏

出现尚未完全稳定或需要逐步淘汰的操作很常见。GitBook 支持若干 OpenAPI 扩展，帮助你管理这些场景。

### 将操作标记为实验版、Alpha 版或 Beta 版

使用 `x-stability` 来说明某个端点不稳定或仍在开发中。这有助于用户避开尚未达到生产就绪状态的端点。支持的值： `experimental`, `alpha`, `beta`.

<pre class="language-yaml" data-title="openapi.yaml"><code class="lang-yaml">paths:
  /pet:
    put:
      operationId: updatePet
<strong>      x-stability: experimental
</strong></code></pre>

### 弃用操作

若要将操作标记为已弃用，请添加 `deprecated: true` 属性。

<pre class="language-yaml" data-title="openapi.yaml"><code class="lang-yaml">paths:
  /pet:
    put:
      operationId: updatePet
<strong>      deprecated: true
</strong></code></pre>

如需指定支持何时结束，请添加 `x-deprecated-sunset`:

<pre class="language-yaml" data-title="openapi.yaml"><code class="lang-yaml">paths:
  /pet:
    put:
      operationId: updatePet
<strong>      deprecated: true
</strong><strong>      x-deprecated-sunset: 2030-12-05
</strong></code></pre>

### 从 API 参考中隐藏操作

若要在 API 参考文档中隐藏某个操作，请添加 `x-internal: true` 或 `x-gitbook-ignore: true` 属性。

<pre class="language-yaml" data-title="openapi.yaml"><code class="lang-yaml">paths:
  /pet:
    put:
      operationId: updatePet
<strong>      x-internal: true
</strong></code></pre>

### 隐藏一个标签的所有操作

若要隐藏某个标签下的所有操作，请为该标签声明 `x-internal: true` 或 `x-gitbook-ignore: true`:

<pre class="language-yaml" data-title="openapi.yaml"><code class="lang-yaml">tags:
  - name: admin
<strong>    x-internal: true
</strong></code></pre>

将标签从 `tags` 数组中省略，并不会隐藏其操作。

### 隐藏响应示例

将 `x-hideSample: true` 属性添加到响应对象，以便在响应示例部分中排除该响应。

<pre class="language-yaml" data-title="openapi.yaml"><code class="lang-yaml">paths:
  /pet:
    put:
      operationId: updatePet
<strong>      responses:
</strong><strong>        200:
</strong><strong>          x-hideSample: true
</strong></code></pre>

### 自定义授权前缀和令牌占位符

你可以自定义授权前缀（例如 `Bearer`, `Token`或自定义字符串），以及在 GitBook 中使用安全方案时显示的令牌占位符。

在 OpenAPI 规范的 `components.securitySchemes`下，按如下方式定义你的方案：

<pre class="language-yaml" data-title="openapi.yaml"><code class="lang-yaml">components:
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: Authorization
<strong>      x-gitbook-prefix: Token
</strong><strong>      x-gitbook-token-placeholder: YOUR_CUSTOM_TOKEN
</strong></code></pre>

这些扩展：

* `x-gitbook-prefix` 用于定义添加在令牌前面的前缀。
  * 示例： `Authorization: <x-gitbook-prefix> YOUR_API_TOKEN`
* `x-gitbook-token-placeholder` 用于设置默认令牌值。
  * 示例： `Authorization: Bearer <x-gitbook-token-placeholder>`

{% hint style="warning" %}
`x-gitbook-prefix` 不支持用于 `http` 安全方案，因为这些方案必须遵循 IANA 标准身份验证定义。 [了解更多](https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml)
{% endhint %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/openapi/guides/managing-api-operations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
