Skip to content

Sanitize autoentity-generated names to prevent invalid REST paths and GraphQL singular/plural tables for SQL objects with spaces#3609

Open
Copilot wants to merge 8 commits into
mainfrom
copilot/fix-invalid-rest-paths
Open

Sanitize autoentity-generated names to prevent invalid REST paths and GraphQL singular/plural tables for SQL objects with spaces#3609
Copilot wants to merge 8 commits into
mainfrom
copilot/fix-invalid-rest-paths

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

Why make this change?

Tables with whitespace in names (for example, Order Items) were being auto-generated into entity names like dbo_Order Items, which then produced invalid REST paths as well as invalid GraphQL names for singular/plural tables which failed config validation. This change ensures autoentity name generation does not pass whitespace through to REST path and GraphQL singular/plural tables defaults.

  • Autoentity naming currently interpolates {schema} / {object} verbatim; whitespace in object names breaks dab validate.

What is this change?

  • Autoentity name sanitization (MsSql metadata path)
    • Added a focused sanitizer in SqlMetadataProvider and applied it to generated entity_name before entity creation.
    • Sanitization removes whitespace and uppercases the next character (camel-join behavior), e.g. dbo_Order Itemsdbo_OrderItems.
  • Focused unit coverage
    • Added test that runs autoentities from start to finish with objects that have spaces in their name in TestAutoentitiesGeneratedWithUnusualElements on the ConfigurationTests file with cases for single/multiple spaces.
internal static string SanitizeGeneratedEntityName(string name)
{
    StringBuilder sanitizedName = new(name.Length);
    bool capitalizeNext = false;

    foreach (char character in name)
    {
        if (char.IsWhiteSpace(character))
        {
            capitalizeNext = true;
            continue;
        }

        sanitizedName.Append(capitalizeNext ? char.ToUpperInvariant(character) : character);
        capitalizeNext = false;
    }

    return sanitizedName.ToString();
}

How was this tested?

  • Integration Tests
  • Unit Tests

Sample Request(s)

  • Example CLI usage to reproduce/validate behavior:
    • dab auto-config add mydef --patterns.include "dbo.Order Items" --patterns.name "{schema}_{object}"
    • dab validate
  • Expected generated entity naming behavior:
    • SQL object: dbo.[Order Items]
    • Generated entity/REST path segment: dbo_OrderItems (no whitespace)

Copilot AI changed the title [WIP] Fix invalid REST paths generated for tables with spaces Sanitize autoentity-generated names to prevent invalid REST paths for SQL objects with spaces May 19, 2026
Copilot AI requested a review from RubenCerna2079 May 19, 2026 23:17
@RubenCerna2079 RubenCerna2079 marked this pull request as ready for review May 22, 2026 22:34
Copilot AI review requested due to automatic review settings May 22, 2026 22:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves MSSQL autoentity generation by sanitizing auto-generated entity names so SQL objects containing whitespace don’t produce invalid REST path segments or invalid GraphQL names during default singular/plural generation and config validation.

Changes:

  • Add a whitespace-removal (camel-join) sanitizer for generated entity names and apply it during MSSQL autoentity generation.
  • Extend MSSQL test schema with a table that contains spaces in its name and seed data for it.
  • Update configuration tests to validate REST + GraphQL access for an autoentity generated from an object with spaces.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/Service.Tests/DatabaseSchema-MsSql.sql Adds an MSSQL table with whitespace in its name to exercise autoentity naming.
src/Service.Tests/Configuration/ConfigurationTests.cs Extends autoentity end-to-end test to include an object with spaces and validates REST/GraphQL access.
src/Core/Services/MetadataProviders/SqlMetadataProvider.cs Introduces SanitizeGeneratedEntityName helper for generated entity names.
src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs Applies sanitization to autoentity-generated entityName before entity creation.

Comment thread src/Service.Tests/DatabaseSchema-MsSql.sql
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Comment thread src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs Outdated
@RubenCerna2079 RubenCerna2079 changed the title Sanitize autoentity-generated names to prevent invalid REST paths for SQL objects with spaces Sanitize autoentity-generated names to prevent invalid REST paths and GraphQL singular/plural tables for SQL objects with spaces May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Todo

6 participants