Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 201 additions & 0 deletions schemas/dab.draft.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,207 @@
}
}
},
"autoentities": {
"type": "object",
"description": "Auto-entity definitions for wildcard pattern matching",
"patternProperties": {
"^.*$": {
"type": "object",
"additionalProperties": false,
"properties": {
"patterns": {
"type": "object",
"description": "Pattern matching rules for including/excluding database objects",
"additionalProperties": false,
"properties": {
"include": {
"type": "array",
"description": "T-SQL LIKE pattern to include database objects (e.g., '%.%')",
"items": {
"type": "string"
},
"default": null
},
"exclude": {
"type": "array",
"description": "T-SQL LIKE pattern to exclude database objects (e.g., 'sales.%')",
"items": {
"type": "string"
},
"default": null
},
"name": {
"type": "string",
"description": "Interpolation syntax for entity naming, must be unique for every entity inside the pattern",
"default": "{schema}{object}"
}
}
},
"template": {
"type": "object",
"description": "Template configuration for generated entities",
"additionalProperties": false,
"properties": {
"mcp": {
"type": "object",
"description": "MCP endpoint configuration",
"additionalProperties": false,
"properties": {
"dml-tools": {
"oneOf": [
{
"type": "boolean",
"description": "Enable/disable all DML tools with default settings."
},
{
"type": "object",
"description": "Individual DML tools configuration",
"additionalProperties": false,
"properties": {
"describe-entities": {
"type": "boolean",
"description": "Enable/disable the describe-entities tool.",
"default": false
},
"create-record": {
"type": "boolean",
"description": "Enable/disable the create-record tool.",
"default": false
},
"read-records": {
"type": "boolean",
"description": "Enable/disable the read-records tool.",
"default": false
},
"update-record": {
"type": "boolean",
"description": "Enable/disable the update-record tool.",
"default": false
},
"delete-record": {
"type": "boolean",
"description": "Enable/disable the delete-record tool.",
"default": false
},
"execute-entity": {
"type": "boolean",
"description": "Enable/disable the execute-entity tool.",
"default": false
}
}
}
]
}
}
},
"rest": {
"type": "object",
"description": "REST endpoint configuration",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"description": "Enable/disable REST endpoint",
"default": true
}
}
},
"graphql": {
"type": "object",
"description": "GraphQL endpoint configuration",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"description": "Enable/disable GraphQL endpoint",
"default": true
}
}
},
"health": {
"type": "object",
"description": "Health check configuration",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"description": "Enable/disable health check endpoint",
"default": true
}
}
},
"cache": {
"type": "object",
"description": "Cache configuration",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"description": "Enable/disable caching",
"default": false
},
"ttl-seconds": {
"type": [ "integer", "null" ],
"description": "Time-to-live for cached responses in seconds",
"default": null,
"minimum": 1
},
"level": {
"type": "string",
"description": "Cache level (L1 or L1L2)",
"enum": [ "L1", "L1L2", null ],
"default": null
}
}
}
}
},
"permissions": {
"type": "array",
"description": "Permissions assigned to this object",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"role": {
"type": "string"
},
"actions": {
"oneOf": [
{
"type": "string",
"pattern": "[*]"
},
{
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/$defs/action"
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"action": {
"$ref": "#/$defs/action"
}
}
}
]
},
"uniqueItems": true
}
]
}
}
},
"required": [ "role", "actions" ]
}
}
}
}
},
"entities": {
"type": "object",
"description": "Entities that will be exposed via REST and/or GraphQL",
Expand Down
36 changes: 36 additions & 0 deletions src/Config/Converters/RuntimeAutoEntitiesConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json;
using System.Text.Json.Serialization;
using Azure.DataApiBuilder.Config.ObjectModel;

namespace Azure.DataApiBuilder.Config.Converters;

/// <summary>
/// Custom JSON converter for RuntimeAutoEntities.
/// </summary>
class RuntimeAutoEntitiesConverter : JsonConverter<RuntimeAutoEntities>
{
/// <inheritdoc/>
public override RuntimeAutoEntities? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Dictionary<string, AutoEntity>? autoEntities =
JsonSerializer.Deserialize<Dictionary<string, AutoEntity>>(ref reader, options);

return new RuntimeAutoEntities(autoEntities);
}

/// <inheritdoc/>
public override void Write(Utf8JsonWriter writer, RuntimeAutoEntities value, JsonSerializerOptions options)
{
writer.WriteStartObject();
foreach ((string key, AutoEntity autoEntity) in value)
{
writer.WritePropertyName(key);
JsonSerializer.Serialize(writer, autoEntity, options);
}

writer.WriteEndObject();
}
}
18 changes: 18 additions & 0 deletions src/Config/ObjectModel/AutoEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json.Serialization;

namespace Azure.DataApiBuilder.Config.ObjectModel;

/// <summary>
/// Defines an individual auto-entity definition with patterns, template, and permissions.
/// </summary>
/// <param name="Patterns">Pattern matching rules for including/excluding database objects</param>
/// <param name="Template">Template configuration for generated entities</param>
/// <param name="Permissions">Permissions configuration for generated entities (at least one required)</param>
public record AutoEntity(
[property: JsonPropertyName("patterns")] AutoEntityPatterns Patterns,
[property: JsonPropertyName("template")] AutoEntityTemplate Template,
[property: JsonPropertyName("permissions")] EntityPermission[] Permissions
);
18 changes: 18 additions & 0 deletions src/Config/ObjectModel/AutoEntityPatterns.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json.Serialization;

namespace Azure.DataApiBuilder.Config.ObjectModel;

/// <summary>
/// Defines the pattern matching rules for auto-entities.
/// </summary>
/// <param name="Include">T-SQL LIKE pattern to include database objects (default: null)</param>
/// <param name="Exclude">T-SQL LIKE pattern to exclude database objects (default: null)</param>
/// <param name="Name">Interpolation syntax for entity naming (must be unique, default: null)</param>
public record AutoEntityPatterns(
[property: JsonPropertyName("include")] string? Include = null,
[property: JsonPropertyName("exclude")] string? Exclude = null,
[property: JsonPropertyName("name")] string? Name = null
);
54 changes: 54 additions & 0 deletions src/Config/ObjectModel/AutoEntityTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json.Serialization;

namespace Azure.DataApiBuilder.Config.ObjectModel;

/// <summary>
/// Defines the template configuration for auto-entities.
/// </summary>
/// <param name="Mcp">MCP endpoint configuration</param>
/// <param name="Rest">REST endpoint configuration</param>
/// <param name="GraphQL">GraphQL endpoint configuration</param>
/// <param name="Health">Health check configuration</param>
/// <param name="Cache">Cache configuration</param>
public record AutoEntityTemplate(
[property: JsonPropertyName("mcp")] AutoEntityMcpTemplate? Mcp = null,
[property: JsonPropertyName("rest")] AutoEntityRestTemplate? Rest = null,
[property: JsonPropertyName("graphql")] AutoEntityGraphQLTemplate? GraphQL = null,
[property: JsonPropertyName("health")] AutoEntityHealthTemplate? Health = null,
[property: JsonPropertyName("cache")] EntityCacheOptions? Cache = null
);

/// <summary>
/// MCP template configuration for auto-entities.
/// </summary>
/// <param name="DmlTool">Enable/disable DML tool (default: true)</param>
public record AutoEntityMcpTemplate(
[property: JsonPropertyName("dml-tool")] bool DmlTool = true
);

/// <summary>
/// REST template configuration for auto-entities.
/// </summary>
/// <param name="Enabled">Enable/disable REST endpoint (default: true)</param>
public record AutoEntityRestTemplate(
[property: JsonPropertyName("enabled")] bool Enabled = true
);

/// <summary>
/// GraphQL template configuration for auto-entities.
/// </summary>
/// <param name="Enabled">Enable/disable GraphQL endpoint (default: true)</param>
public record AutoEntityGraphQLTemplate(
[property: JsonPropertyName("enabled")] bool Enabled = true
);

/// <summary>
/// Health check template configuration for auto-entities.
/// </summary>
/// <param name="Enabled">Enable/disable health check endpoint (default: true)</param>
public record AutoEntityHealthTemplate(
[property: JsonPropertyName("enabled")] bool Enabled = true
);
Loading
Loading