扩展参考
GitBook 支持的 OpenAPI 扩展完整参考
您可以使用扩展来增强您的 OpenAPI 规范 — 这些自定义字段以 x- 前缀开头。通过这些扩展,您可以添加额外信息并根据不同需求定制您的 API 文档。
GitBook 允许您通过向 OpenAPI 规范添加一系列不同的扩展来调整您已发布站点上 API 的外观和行为。
前往我们的 指南部分 了解更多关于使用 OpenAPI 扩展来配置文档的信息。
x-page-title | x-displayName
更改在导航和页面标题中使用的标签显示名称。
openapi: '3.0'
info: ...
tags:
- name: users
x-page-title: Usersx-page-description
为页面添加描述。
openapi: '3.0'
info: ...
tags:
- name: "users"
x-page-title: "Users"
x-page-description: "Manage user accounts and profiles."x-page-icon
为页面添加一个 Font Awesome 图标。查看可用图标 此处.
openapi: '3.0'
info: ...
tags:
- name: "users"
x-page-title: "Users"
x-page-description: "Manage user accounts and profiles."
x-page-icon: "user"parent | x-parent
为标签添加层级结构,以便在 GitBook 中组织页面。
parent 是在 OpenAPI 3.2+ 中的官方属性名称。如果使用早于 3.2 的 OpenAPI 版本(3.0.x、3.1.x),请使用 x-parent 替代。
openapi: '3.2'
info: ...
tags:
- name: organization
- name: admin
parent: organization
- name: user
parent: organization x-hideTryItPanel
显示或隐藏 OpenAPI 区块的“测试它”按钮。
openapi: '3.0'
info: ...
tags: [...]
paths:
/example:
get:
summary: Example summary
description: Example description
operationId: examplePath
responses: [...]
parameters: [...]
x-hideTryItPanel: truex-enable-proxy
通过 GitBook 的 OpenAPI 代理路由“测试它”请求。
将其添加到根级以应用于每个操作。将其添加到某个操作则仅应用于该端点。操作级设置会覆盖根级值。
openapi: '3.0.3'
info: ...
# Enable proxy for all operations
x-enable-proxy: true
paths:
/health:
get:
summary: Health check
# Opt out for a single operation
x-enable-proxy: false
responses:
'200':
description: OK阅读更多内容请见 使用 OpenAPI 代理.
x-codeSamples
显示、隐藏或为 OpenAPI 区块包含自定义代码示例。
字段
label
string
代码示例标签,例如 Node 或 Python2.7, 可选, lang 将被默认使用
source
string
代码示例源代码
openapi: '3.0'
info: ...
tags: [...]
paths:
/example:
get:
summary: Example summary
description: Example description
operationId: examplePath
responses: [...]
parameters: [...]
x-codeSamples:
- lang: 'cURL'
label: 'CLI'
source: |
curl -L \
-H 'Authorization: Bearer <token>' \
'https://api.gitbook.com/v1/user'x-enumDescriptions
为架构中的每个 enum 值添加单独的描述。
openapi: '3.0'
info: ...
components:
schemas:
project_status:
type: string
enum:
- LIVE
- PENDING
- REJECTED
x-enumDescriptions:
LIVE: 项目已上线。
PENDING: 项目正在等待审批。
REJECTED: 项目已被拒绝。x-internal | x-gitbook-ignore
在 API 参考中隐藏某个端点。
openapi: '3.0'
info: ...
tags: [...]
paths:
/example:
get:
summary: Example summary
description: Example description
operationId: examplePath
responses: [...]
parameters: [...]
x-internal: truex-stability
标记不稳定或正在进行中的端点。
支持的值: experimental, alpha, beta.
openapi: '3.0'
info: ...
tags: [...]
paths:
/example:
get:
summary: Example summary
description: Example description
operationId: examplePath
x-stability: experimentaldeprecated
标记端点是否已弃用。已弃用的端点将在您发布的站点中显示弃用警告。
openapi: '3.0'
info: ...
tags: [...]
paths:
/example:
get:
summary: Example summary
description: Example description
operationId: examplePath
responses: [...]
parameters: [...]
deprecated: truex-deprecated-sunset
为已弃用的操作添加终止日期(sunset date)。
支持的值: ISO 8601 格式(YYYY-MM-DD)
openapi: '3.0'
info: ...
tags: [...]
paths:
/example:
get:
summary: Example summary
description: Example description
operationId: examplePath
responses: [...]
parameters: [...]
deprecated: true
x-deprecated-sunset: 2030-12-05最后更新于
这有帮助吗?