Skip to content

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

Merged
souvikghosh04 merged 19 commits into
mainfrom
copilot/fix-invalid-rest-paths
Jul 6, 2026
Merged

Remove whitespaces from autoentity-generated names to prevent invalid REST paths and GraphQL singular/plural tables for SQL objects with spaces#3609
souvikghosh04 merged 19 commits into
mainfrom
copilot/fix-invalid-rest-paths

Conversation

Copilot AI commented May 19, 2026

Copy link
Copy Markdown
Contributor

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 normalization (MsSql metadata path)
    • Added RemoveWhitespaceAddCamelCase in SqlMetadataProvider and applied it to generated entity_name before entity creation. The method name is intentionally specific to clarify it only removes whitespace (not other invalid characters).
    • Normalization removes whitespace and uppercases the character immediately following each removed whitespace (camelCase-join), e.g. dbo_Order Itemsdbo_OrderItems.
    • Added a guard after normalization: if the result is empty (e.g. the raw entity name was entirely whitespace), an error is logged with the original name and schema for context, and the entry is skipped.
    • Collision detection is improved: when TryAdd fails because two database objects normalize to the same entity name (e.g. "Order Item" and "OrderItem" both yield "OrderItem"), the exception message includes the pre-normalization name and schema to make the collision diagnosable.
protected static string RemoveWhitespaceAddCamelCase(string name)
{
    StringBuilder result = new(name.Length);
    bool capitalizeNext = false;

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

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

    return result.ToString();
}
  • Focused test coverage
    • Added a dedicated TestAutoentitiesGeneratedWithSpacesInObjectName test method that explicitly asserts the sanitized entity name dbo_OrderItems (via const string EXPECTED_ENTITY_NAME) and validates end-to-end REST and GraphQL access with that name.
    • Whitespace-handling validation is now separated from the non-default schema cases in TestAutoentitiesGeneratedWithUnusualElements for better readability and maintainability.

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
Comment thread src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs
Comment thread src/Core/Services/MetadataProviders/SqlMetadataProvider.cs
Comment thread src/Core/Services/MetadataProviders/SqlMetadataProvider.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
@github-project-automation github-project-automation Bot moved this from Todo to Review In Progress in Data API builder Jun 9, 2026
Copilot AI requested a review from anushakolan June 9, 2026 18:58
@anushakolan

Copy link
Copy Markdown
Contributor

LGTM!

@RubenCerna2079 RubenCerna2079 changed the title Sanitize autoentity-generated names to prevent invalid REST paths and GraphQL singular/plural tables for SQL objects with spaces Remove spaces from autoentity-generated names to prevent invalid REST paths and GraphQL singular/plural tables for SQL objects with spaces Jun 29, 2026
@RubenCerna2079 RubenCerna2079 changed the title Remove spaces from autoentity-generated names to prevent invalid REST paths and GraphQL singular/plural tables for SQL objects with spaces Remove whitespaces from autoentity-generated names to prevent invalid REST paths and GraphQL singular/plural tables for SQL objects with spaces Jun 29, 2026
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Core/Services/MetadataProviders/SqlMetadataProvider.cs

@souvikghosh04 souvikghosh04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing the comments. Approved.

@souvikghosh04
souvikghosh04 enabled auto-merge (squash) July 1, 2026 05:27
@RubenCerna2079

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 6 pipeline(s).

@souvikghosh04
souvikghosh04 merged commit a4505f8 into main Jul 6, 2026
12 checks passed
@souvikghosh04
souvikghosh04 deleted the copilot/fix-invalid-rest-paths branch July 6, 2026 17:59
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Data API builder Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

6 participants