Skip to content

Warn when dab validate finds zero entities in the config#3306

Open
aaronburtle wants to merge 28 commits intomainfrom
dev/aaronburtle/warn-zero-entities-validate
Open

Warn when dab validate finds zero entities in the config#3306
aaronburtle wants to merge 28 commits intomainfrom
dev/aaronburtle/warn-zero-entities-validate

Conversation

@aaronburtle
Copy link
Copy Markdown
Contributor

@aaronburtle aaronburtle commented Mar 23, 2026

Why make this change?

Closes #3267

What is this change?

Alters the validation logic in the following way.

Is top-level config with data-source-files?
├── YES
│ ├── Has datasource? → ValidateEntityPresence (same rules as non-root)
│ ├── No datasource but has entities/autoentities? → ERROR
│ └── No datasource, no entities → VALID (children provide everything)
│ └── For each child → ValidateNonRootConfig(child, filename)

└── NO (standalone or child config)
├── No datasource? → ERROR: "data source is required"
└── Has datasource → ValidateEntityPresence

ValidateEntityPresence

Count resolved autoentities from AutoentityResolutionCounts
total = manual entities + resolved autoentities

total == 0? → ERROR: "No entities found"
total > 0 but autoentities discovered nothing? → WARN: "Autoentities configured but none discovered"

No double messaging. If total is 0, only the error is recorded, not the warning.

How was this tested?

New tests:

TestRootConfigWithNoDataSourceAndNoEntitiesParses Root config (has data-source-files) without datasource parses OK
TestNonRootConfigWithDataSourceAndNoEntitiesParses Non-root config with datasource + no entities parses OK (validation catches it later)
TestNonRootWithDataSourceAndNoEntitiesProducesError Calls ValidateDataSourceAndEntityPresence directly, error recorded
TestNonRootWithNoDataSourceProducesError No datasource, error with "data source is required"
TestNonRootWithDataSourceAndEntitiesIsValid Datasource + entities, no errors
TestRootWithNoDataSourceAndNoEntitiesIsValid Root with child, no own datasource, valid
TestRootWithNoDataSourceButEntitiesProducesError Root with entities but no datasource, error
TestRootWithDataSourceAndEntitiesIsValid Root with own datasource + entities, valid
TestChildWithDataSourceAndNoEntitiesProducesNamedError Child with no entities, error names the child file
TestChildWithNoDataSourceProducesNamedError Child with no datasource, error names the child file

Modified tests:

TestValidateConfigWithNoEntitiesProducesCleanError Replaced main's version (expected parse failure) with ours: parse succeeds, IsConfigValid returns false
ValidateAutoentitiesConfiguration Changed to isValidateOnly: true, asserts no crashes instead of zero errors

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

Adds a CLI validation-time warning to help users detect “valid” configs that define no entities (and have no autoentities / multi-config datasource files), aligning dab validate behavior with Issue #3267.

Changes:

  • Adds a WarnIfNoEntitiesDefined(RuntimeConfig) helper and invokes it during dab validate.
  • Refactors IsConfigValid to log the new structural warning regardless of overall validation outcome.
  • Adds a CLI unit test that verifies the warning is logged for a minimal config with zero entities.

Reviewed changes

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

File Description
src/Cli/ConfigGenerator.cs Introduces and invokes the new “zero entities” warning helper during dab validate.
src/Cli.Tests/ValidateConfigTests.cs Adds a unit test verifying the warning is emitted for an empty-entities config.

Comment thread src/Cli/ConfigGenerator.cs Outdated
Comment thread src/Cli/ConfigGenerator.cs Outdated
@aaronburtle aaronburtle self-assigned this Mar 23, 2026
@aaronburtle aaronburtle added 2.0 bug Something isn't working labels Mar 23, 2026
@aaronburtle aaronburtle moved this from Todo to Review In Progress in Data API builder Mar 23, 2026
@aaronburtle aaronburtle added this to the March 2026 milestone Mar 23, 2026
@anushakolan
Copy link
Copy Markdown
Contributor

/azp run

Copy link
Copy Markdown
Contributor

@anushakolan anushakolan left a comment

Choose a reason for hiding this comment

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

LGTM, Apart from the minor comment left.

Comment thread src/Cli.Tests/ValidateConfigTests.cs Outdated
Comment thread src/Cli/ConfigGenerator.cs Outdated
Comment thread src/Cli.Tests/ValidateConfigTests.cs Outdated
Copy link
Copy Markdown
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

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

Left few comments

Comment thread src/Cli/ConfigGenerator.cs
@JerryNixon
Copy link
Copy Markdown
Contributor

JerryNixon commented Apr 3, 2026

Config rules

Level 1. Root config (top level (has a child))

Root rules:

- if data-source-files is empty array, this is a non-Root.
- if data-source-files is NOT empty array, 
    data-source+entities is optional. 

Level 1.1. Non-Root A (including grandchildren)

Non-Root rules:

- must have data source and must have entities (or found entities if auto-entities is configured)
- if has children, same rules as above, must have ds and entities

When to warn

if (IsRoot) // at this point we know it has children
{
    if (has-data-source) // if you have a data source you must have entities
    {
        ValidateItHasEntities();
    }
    else if (!has-data-source && (has-any-entities || has-any-auto-entities-definitions))
    {
        Error("Entities found but no data source defined.");
    }
    else
    {
        Valid();
    }
}
else if (!IsRoot) // non-root/child
{
    ValidateItHasEntities();
}

ValidateItHasEntities()
{
    foreach (var definition in auto-entities-definitions)
    {
        if (definition has no entities)
        {
            Warning($"Auto-entities definition '{definition.Name}' but no entities found.");
        }
    }

    var entityCountFromAutoEntityDefinitions = 123; // count of all autoentities

    if (entityCountFromAutoEntityDefinitions == 0
        && entityCountFromEntities == 0)
    {
        Error("Data source defined but no entities found.");
    }

    Valid();
}

@Aniruddh25
Copy link
Copy Markdown
Collaborator

if (data-source-files not present)
{
   error if data-source missing
}

if (data-source not present)
{
    exit
}

if (entities and autoentities)
{
    error when none
}
else if (only entities)
{
    error when none
}
else if (only autoentities)
{
    error when none
}
else
{
    error unless data-source not present
    (already handled)
}

after offline discussion

@aaronburtle aaronburtle force-pushed the dev/aaronburtle/warn-zero-entities-validate branch from 4bb0609 to 5c93d5e Compare April 27, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.0 bug Something isn't working

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

[Bug]: dab validate should at least warn when zero entities are in the config.

5 participants