Skip to content
Open
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 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": true
},
"create-record": {
"type": "boolean",
"description": "Enable/disable the create-record tool.",
"default": true
},
"read-records": {
"type": "boolean",
"description": "Enable/disable the read-records tool.",
"default": true
},
"update-record": {
"type": "boolean",
"description": "Enable/disable the update-record tool.",
"default": true
},
"delete-record": {
"type": "boolean",
"description": "Enable/disable the delete-record tool.",
"default": true
},
"execute-entity": {
"type": "boolean",
"description": "Enable/disable the execute-entity tool.",
"default": true
}
}
}
]
}
}
},
"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" ],
"default": "L1"
}
}
}
}
},
"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
111 changes: 111 additions & 0 deletions src/Config/Converters/AutoentityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// 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;

internal class AutoentityConverter : JsonConverter<Autoentity>
{
// Settings for variable replacement during deserialization.
private readonly DeserializationVariableReplacementSettings? _replacementSettings;

/// <param name="replacementSettings">Settings for variable replacement during deserialization.
/// If null, no variable replacement will be performed.</param>
public AutoentityConverter(DeserializationVariableReplacementSettings? replacementSettings = null)
{
_replacementSettings = replacementSettings;
}

/// <inheritdoc/>
public override Autoentity? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType is JsonTokenType.StartObject)
{
// Initialize all sub-properties to null.
AutoentityPatterns? patterns = null;
AutoentityTemplate? template = null;
EntityPermission[]? permissions = null;

while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
{
return new Autoentity(patterns, template, permissions);
}

string? propertyName = reader.GetString();

reader.Read();
switch (propertyName)
{
case "patterns":
AutoentityPatternsConverter patternsConverter = new(_replacementSettings);
patterns = patternsConverter.Read(ref reader, typeof(AutoentityPatterns), options);
break;

case "template":
AutoentityTemplateConverter templateConverter = new(_replacementSettings);
template = templateConverter.Read(ref reader, typeof(AutoentityTemplate), options);
break;

Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AutoentityConverter Read method only handles "patterns" and "template" properties but doesn't handle the "permissions" property. The permissions are defined in the Autoentity class (line 19) and in the JSON schema, but they are never deserialized from JSON. Add a case to handle "permissions" property deserialization.

Suggested change
case "permissions":
permissions = JsonSerializer.Deserialize<EntityPermission[]>(ref reader, options);
break;

Copilot uses AI. Check for mistakes.
case "permissions":
permissions = JsonSerializer.Deserialize<EntityPermission[]>(ref reader, options);
break;

default:
throw new JsonException($"Unexpected property {propertyName}");
}
}
}

throw new JsonException("Unable to read the Autoentities");
}

/// <summary>
/// When writing the autoentities back to a JSON file, only write the properties
/// if they are user provided. This avoids polluting the written JSON file with properties
/// the user most likely omitted when writing the original DAB runtime config file.
/// This Write operation is only used when a RuntimeConfig object is serialized to JSON.
/// </summary>
/// <inheritdoc/>
public override void Write(Utf8JsonWriter writer, Autoentity value, JsonSerializerOptions options)
{
writer.WriteStartObject();

AutoentityPatterns? patterns = value?.Patterns;
if (patterns?.UserProvidedIncludeOptions is true
|| patterns?.UserProvidedExcludeOptions is true
|| patterns?.UserProvidedNameOptions is true)
{
AutoentityPatternsConverter autoentityPatternsConverter = options.GetConverter(typeof(AutoentityPatterns)) as AutoentityPatternsConverter ??
throw new JsonException("Failed to get autoentities.patterns options converter");
writer.WritePropertyName("patterns");
autoentityPatternsConverter.Write(writer, patterns, options);
}

AutoentityTemplate? template = value?.Template;
if (template?.UserProvidedMcpOptions is true
|| template?.UserProvidedRestOptions is true
|| template?.UserProvidedGraphQLOptions is true
|| template?.UserProvidedHealthOptions is true
|| template?.UserProvidedCacheOptions is true)
{
AutoentityTemplateConverter autoentityTemplateConverter = options.GetConverter(typeof(AutoentityTemplate)) as AutoentityTemplateConverter ??
throw new JsonException("Failed to get autoentities.template options converter");
writer.WritePropertyName("template");
autoentityTemplateConverter.Write(writer, template, options);
}

Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AutoentityConverter Write method doesn't serialize the permissions property. While patterns and template are conditionally written based on user-provided flags, permissions should also be serialized if provided. Add code to write the permissions array if value?.UserProvidedPermissionsOptions is true.

Suggested change
// Serialize permissions if user provided
if (value?.UserProvidedPermissionsOptions is true)
{
writer.WritePropertyName("permissions");
JsonSerializer.Serialize(writer, value.Permissions, options);
}

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, a valid suggestion

// Serialize permissions if user provided
if (value?.UserProvidedPermissionsOptions is true)
{
writer.WritePropertyName("permissions");
JsonSerializer.Serialize(writer, value.Permissions, options);
}

writer.WriteEndObject();
}
}
Loading
Loading