data-api-builder icon indicating copy to clipboard operation
data-api-builder copied to clipboard

Add schema and serialization support for autoentities wildcard patterns

Open Copilot opened this issue 2 months ago • 0 comments

Why make this change?

Closes #[issue number not provided]

Enables configuration-driven automatic entity generation through wildcard pattern matching against database objects. The schema now supports defining entity templates with include/exclude patterns and default permissions.

What is this change?

Added autoentities section to the configuration schema and corresponding C# models for serialization/deserialization:

Schema Definition (schemas/dab.draft.schema.json):

  • Pattern matching: include, exclude (T-SQL LIKE syntax), name (interpolation: {schema}_{object})
  • Template configuration: mcp, rest, graphql, health, cache
  • Required permissions array with role-based actions

Object Models (src/Config/ObjectModel/):

  • AutoEntityPatterns - Pattern matching rules
  • AutoEntityTemplate - Template config with sub-records for each endpoint type
  • AutoEntity - Combines patterns, template, permissions
  • RuntimeAutoEntities - Collection class implementing IEnumerable<KeyValuePair<string, AutoEntity>>
  • RuntimeConfig.AutoEntities - Optional nullable property

Serialization (src/Config/Converters/):

  • RuntimeAutoEntitiesConverter - Custom JSON converter following RuntimeEntitiesConverter pattern

Example configuration:

{
  "autoentities": {
    "public-tables": {
      "patterns": {
        "include": "dbo.%",
        "exclude": "dbo.internal_%",
        "name": "{schema}_{object}"
      },
      "template": {
        "rest": { "enabled": true },
        "graphql": { "enabled": true }
      },
      "permissions": [
        { "role": "anonymous", "actions": ["read"] }
      ]
    }
  }
}

How was this tested?

  • [x] Unit Tests

New test CanLoadConfigWithAutoEntities validates:

  • Deserialization of multiple auto-entity definitions
  • Pattern properties (include/exclude/name)
  • Template settings across all endpoint types
  • Permissions array structure

Sample Request(s)

N/A - This change adds schema and serialization infrastructure. Actual pattern matching and entity generation logic is not included in this PR.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • azuread
    • Triggering command: /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/Cli.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/Cli.Tests.deps.json /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/testhost.dll --port 41689 --endpoint 127.0.0.1:041689 --role client --parentprocessid 4807 --telemetryoptedin false (dns block)
  • custom
    • Triggering command: /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/Cli.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/Cli.Tests.deps.json /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/testhost.dll --port 41689 --endpoint 127.0.0.1:041689 --role client --parentprocessid 4807 --telemetryoptedin false (dns block)
  • entraid
    • Triggering command: /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/Cli.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/Cli.Tests.deps.json /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/testhost.dll --port 41689 --endpoint 127.0.0.1:041689 --role client --parentprocessid 4807 --telemetryoptedin false (dns block)
  • xxxxx
    • Triggering command: /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/Cli.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/Cli.Tests.deps.json /home/REDACTED/work/data-api-builder/data-api-builder/src/out/tests/net8.0/testhost.dll --port 41689 --endpoint 127.0.0.1:041689 --role client --parentprocessid 4807 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Serialization/Deserialization of Wildcard properties</issue_title> <issue_description>Need to create the new properties from Wildcard inside of the schema. The format is as following:

{
  "autoentities": {
    "{definition-name}": {

      "patterns": {
        "include": "%.%", // default: null. mssql syntax (T-SQL LIKE)
        "exclude": "sales.%", // default: null. mssql syntax (T-SQL LIKE)
        "name": "{schema}{object}" // default: null. interpolation syntax (must be unique)
      },

      "template": {
        "mcp": { "dml-tool": "<boolean>" }, // default: true
        "rest": { "enabled": "<boolean>" }, // default: true
        "graphql": { "enabled": "<boolean>" }, // default: true
        "health": { "enabled": "<boolean>" }, // default: true
        "cache": {
          "enabled": "<boolean>", // default: false
          "ttl-seconds": "<integer>", // default: null
          "level": "<enum>" // default: null
        }
      },

      "permissions": [ // at least one is required
        {
          "role": "<string>",
          "actions": [
            "*",
            "create",
            "read",
            "update",
            "delete"
          ]
        }
      ]
    }
  }
}

</issue_description>

<agent_instructions>Create the properties mentioned in the task inside of the schema file.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

  • Fixes Azure/data-api-builder#2962

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Nov 13 '25 21:11 Copilot