数据 API 生成器至少需要一个配置文件才能运行。 此基于 JSON 的文件定义 API 设置,从环境设置到实体定义。 它以属性 $schema 开头,该属性为文件的其余部分启用架构验证。
顶级属性
| Property | Description |
|---|---|
| $schema | 此配置的 JSON 架构的 URI。 |
| data-source | 包含数据库连接设置的对象。 |
| data-source-files | 其他配置文件路径的数组。 |
| runtime | 对象配置运行时行为。 |
| entities | 定义通过 REST 或 GraphQL 公开的所有实体的对象。 |
| autoentities | 定义基于模式的规则的对象,这些规则自动将匹配的数据库对象公开为实体(仅 MSSQL)。 |
| azure-key-vault | 用于机密管理的 Azure Key Vault 配置。 |
数据源属性
| Property | Description |
|---|---|
| data-source | 包含数据库连接设置的对象。 |
| data-source.database-type | 后端中使用的数据库类型(mssql、postgresql、mysql、cosmosdb_nosql、cosmosdb_postgresql)。 |
| data-source.connection-string | 所选数据库类型的连接字符串。 |
| data-source.options | 特定于数据库的选项和高级设置。 |
| data-source.health | 数据源的运行状况检查配置。 |
| data-source-files | 其他配置文件路径的数组。 |
运行时属性
| Property | Description |
|---|---|
| runtime | 对象配置运行时行为。 |
| runtime.pagination | API 响应的分页设置。 |
| runtime.rest | REST API 全局配置。 |
| runtime.graphql | GraphQL API 全局配置。 |
| runtime.cache | 全局响应缓存配置。 |
| runtime.compression | HTTP 响应压缩配置。 |
| runtime.mcp | 模型上下文协议 (MCP) 全局配置。 |
| runtime.telemetry | 遥测、日志记录和监视配置。 |
| runtime.health | 全局运行状况检查配置。 |
实体属性
| Property | Description |
|---|---|
| entities | 定义通过 REST 或 GraphQL 公开的所有实体的对象。 |
| entities.entity-name.source | 实体的数据库源详细信息。 |
| entities.entity-name.rest | 实体的 REST API 配置。 |
| entities.entity-name.graphql | 实体的 GraphQL API 配置。 |
| entities.entity-name.permissions | 实体的权限和访问控制。 |
| entities.entity-name.relationships | 与其他实体的关系。 |
| entities.entity-name.cache | 实体级缓存配置。 |
| entities.entity-name.health | 实体级运行状况检查配置。 |
| entities.entity-name.mcp | 实体级 MCP 配置。 |
| entities.entity-name.fields | 字段元数据、别名和主键指定。 |
| entities.entity-name.description | 人工可读实体说明。 |
Schema
| Parent | Property | 类型 | Required | Default |
|---|---|---|---|---|
$root |
$schema |
字符串 | ✔️ 是的 | None |
每个配置文件都以属性 $schema 开头,并指定用于验证的 JSON 架构 。
Format
{
"$schema": <string>
}
Example
{
"$schema": "https://github.com/Azure/data-api-builder/releases/latest/download/dab.draft.schema.json"
}
Tip
最新的架构始终在 https://github.com/Azure/data-api-builder/releases/latest/download/dab.draft.schema.json.
Versioning
架构文件在特定 URL 中可用,确保可以使用正确的版本或最新的可用架构。
https://github.com/Azure/data-api-builder/releases/download/<VERSION>-<suffix>/dab.draft.schema.json
将 VERSION-suffix 替换为所需的版本。
https://github.com/Azure/data-api-builder/releases/download/v0.3.7-alpha/dab.draft.schema.json
数据源文件
| Parent | Property | 类型 | Required | Default |
|---|---|---|---|---|
$root |
data-source-files |
字符串数组 | ❌ 否 | None |
数据 API 生成器支持多个配置文件,其中一个配置文件指定为顶级文件管理 runtime 设置。 所有配置共享相同的 JSON 架构,允许 runtime 任何文件或每个文件中的设置都不会出现错误。 拆分实体以更好地组织。
Format
{
"data-source-files": [ "<string>" ]
}
多个配置规则
- 每个配置文件都必须包括
data-source属性。 - 每个配置文件都必须包含
entities属性(或autoentities)。 - 顶级配置必须包括
runtime。 - 子配置可以包含
runtime,但数据 API 生成器会忽略它。 - 子配置文件可以包含其自己的子文件。
- 配置文件可以组织到子文件夹中。
- 实体名称在所有配置文件中必须是唯一的。
- 不支持不同配置文件中的实体之间的关系。
Examples
{
"data-source-files": [
"dab-config-2.json",
"my-folder/dab-config-3.json",
"my-folder/my-other-folder/dab-config-4.json"
]
}
自体
| Parent | Property | 类型 | Required | Default |
|---|---|---|---|---|
$root |
autoentities |
对象 | ❌ 否 | None |
本 autoentities 部分定义基于模式的规则,这些规则在启动时自动将匹配的数据库对象公开为 DAB 实体。 对象中的每个键都是包含模式、模板和权限的命名定义。
重要
Autoentities 目前仅支持 MSSQL 数据源。
如果 autoentities 存在,则不再需要该 entities 节。 配置架构允许或 autoentitiesentities (或两者)使用。 如果两者都存在,则显式定义的实体优先于具有相同名称的自动匹配项。
Format
{
"autoentities": {
"<definition-name>": {
"patterns": {
"include": [ "<string>" ],
"exclude": [ "<string>" ],
"name": "<string>"
},
"template": {
"mcp": { "dml-tools": <boolean> },
"rest": { "enabled": <boolean> },
"graphql": { "enabled": <boolean> },
"health": { "enabled": <boolean> },
"cache": {
"enabled": <boolean>,
"ttl-seconds": <integer>,
"level": "<string>"
}
},
"permissions": [
{
"role": "<string>",
"actions": [ { "action": "<string>" } ]
}
]
}
}
}
属性
| Property | 类型 | Required | Default | Description |
|---|---|---|---|---|
patterns |
对象 | ✔️ 是的 | None | 定义包括、排除和命名规则。 |
patterns.include |
字符串数组 | ❌ 否 | ["%.%"] |
要包含的对象的 MSSQL LIKE 模式。 |
patterns.exclude |
字符串数组 | ❌ 否 | null |
要排除的对象的 MSSQL LIKE 模式。 |
patterns.name |
字符串 | ❌ 否 | "{object}" |
使用 {schema} 和 {object}. |
template |
对象 | ❌ 否 | None | 应用于所有匹配实体的默认配置。 |
template.mcp |
对象 | ❌ 否 | None | 匹配实体的 MCP 设置。 |
template.mcp.dml-tools |
布尔 | ❌ 否 | true |
启用 MCP 数据操作语言 (DML) 工具。 |
template.rest |
对象 | ❌ 否 | None | 匹配实体的 REST 设置。 |
template.rest.enabled |
布尔 | ❌ 否 | true |
启用 REST 终结点。 |
template.graphql |
对象 | ❌ 否 | None | 匹配实体的 GraphQL 设置。 |
template.graphql.enabled |
布尔 | ❌ 否 | true |
启用 GraphQL。 |
template.health |
对象 | ❌ 否 | None | 匹配实体的运行状况检查设置。 |
template.health.enabled |
布尔 | ❌ 否 | false |
启用健康检查。 |
template.cache |
对象 | ❌ 否 | None | 匹配实体的缓存设置。 |
template.cache.enabled |
布尔 | ❌ 否 | false |
启用响应缓存。 |
template.cache.ttl-seconds |
整数 | ❌ 否 | null |
缓存生存时间(以秒为单位)。 |
template.cache.level |
字符串 | ❌ 否 | "L1L2" |
缓存级别。 |
permissions |
数组 | ❌ 否 | None | 应用于所有匹配实体的权限。 |
Example
{
"autoentities": {
"my-def": {
"patterns": {
"include": [ "dbo.%" ],
"exclude": [ "dbo.internal%" ],
"name": "{schema}_{object}"
},
"template": {
"rest": { "enabled": true },
"graphql": { "enabled": true },
"cache": { "enabled": true, "ttl-seconds": 30, "level": "l1l2" }
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
]
}
}
}
使用此配置,架构中的每个 dbo 表和视图(这些匹配 dbo.internal%除外)都将自动公开为 DAB 实体。 每个实体都使用 {schema}_{object} 模式(例如 dbo_Products),启用了 REST 和 GraphQL,使用具有 30 秒生存时间(TTL)的缓存,并授予 read 对角色的访问权限 anonymous 。
Tip
用于 dab auto-config 从 CLI 创建自动提交定义,并在 dab auto-config-simulate 提交更改之前预览哪些对象匹配。 有关详细信息,请参阅 版本 2.0 中的新增功能。
Azure Key Vault
| Parent | Property | 类型 | Required | Default |
|---|---|---|---|---|
$root |
azure-key-vault |
对象 | ❌ 否 | None |
配置 Azure Key Vault 集成以管理机密。 如果存在,则需要该 endpoint 属性。
嵌套属性
| Parent | Property | 类型 | Required | Default |
|---|---|---|---|---|
azure-key-vault |
endpoint |
字符串 | ✔️ 是的 | None |
azure-key-vault |
retry-policy |
对象 | ❌ 否 | None |
| Parent | Property | 类型 | Required | Default |
|---|---|---|---|---|
azure-key-vault.retry-policy |
mode |
枚举 (fixed | exponential) |
❌ 否 | "exponential" |
azure-key-vault.retry-policy |
max-count |
整数 | ❌ 否 | 3 |
azure-key-vault.retry-policy |
delay-seconds |
整数 | ❌ 否 | 1 |
azure-key-vault.retry-policy |
max-delay-seconds |
整数 | ❌ 否 | 60 |
azure-key-vault.retry-policy |
network-timeout-seconds |
整数 | ❌ 否 | 60 |
若要引用存储在 Azure Key Vault 中的机密,请使用 @akv() 配置值中的函数。 数据 API 生成器使用配置的终结点在启动时解析这些引用。
Format
{
"azure-key-vault": {
"endpoint": "<string>",
"retry-policy": {
"mode": <"exponential"> (default) | <"fixed">,
"max-count": <integer; default: 3>,
"delay-seconds": <integer; default: 1>,
"max-delay-seconds": <integer; default: 60>,
"network-timeout-seconds": <integer; default: 60>
}
}
}
Example
{
"azure-key-vault": {
"endpoint": "https://my-vault.vault.azure.net/",
"retry-policy": {
"mode": "exponential",
"max-count": 5,
"delay-seconds": 2,
"max-delay-seconds": 120,
"network-timeout-seconds": 90
}
},
"data-source": {
"database-type": "mssql",
"connection-string": "@akv('sql-connection-string')"
}
}