Skip to content

Commit 57ce9cf

Browse files
RubenCerna2079souvikghosh04Aniruddh25
authored
Fix autoentity validation & CLI/Schema mismatch bugs (#3416)
## Why make this change? - #3375 - The CLI and the schema have a mismatch in the `autoentities.<def-name>.template.mcp.dml-tools`, need to ensure that they are the same. - #3335 - Using `dab validate` produces the wrong output message. ## What is this change? For issue #3375: - We changed the `AutoConfigOption.cs` file so that it uses the proper name and changed the name of the variable to also match the schema in the `ConfigGenerator.cs`. For issue #3335: - We changed the log message in `MsSqlMetadataProvider.cs` so that it is easier for the user to understand the error. ## How was this tested? - [ ] Integration Tests - [ ] Unit Tests - [x] Local Testing The issues were related to mismatches or to the output of log messages that can only be tested locally. ## Sample Request(s) dab auto-config <def-name> --template.mcp.dml-tools true/false dab validate --config test.json --------- Co-authored-by: Souvik Ghosh <souvikofficial04@gmail.com> Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
1 parent 0cb58f0 commit 57ce9cf

5 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/Cli.Tests/AutoConfigTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void TestConfigureAutoentitiesDefinition_WithTemplateOptions()
8080
definitionName: "test-def",
8181
templateRestEnabled: true,
8282
templateGraphqlEnabled: false,
83-
templateMcpDmlTool: "true",
83+
templateMcpDmlTools: "true",
8484
templateCacheEnabled: true,
8585
templateCacheTtlSeconds: 30,
8686
templateCacheLevel: "L1",
@@ -196,7 +196,7 @@ public void TestConfigureAutoentitiesDefinition_InvalidMcpDmlTool()
196196

197197
AutoConfigOptions options = new(
198198
definitionName: "test-def",
199-
templateMcpDmlTool: "invalid-value",
199+
templateMcpDmlTools: "invalid-value",
200200
permissions: new[] { "anonymous", "read" },
201201
config: TEST_RUNTIME_CONFIG_FILE
202202
);

src/Cli/Commands/AutoConfigOptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public AutoConfigOptions(
2424
IEnumerable<string>? patternsInclude = null,
2525
IEnumerable<string>? patternsExclude = null,
2626
string? patternsName = null,
27-
string? templateMcpDmlTool = null,
27+
string? templateMcpDmlTools = null,
2828
bool? templateRestEnabled = null,
2929
bool? templateGraphqlEnabled = null,
3030
bool? templateCacheEnabled = null,
@@ -39,7 +39,7 @@ public AutoConfigOptions(
3939
PatternsInclude = patternsInclude;
4040
PatternsExclude = patternsExclude;
4141
PatternsName = patternsName;
42-
TemplateMcpDmlTool = templateMcpDmlTool;
42+
TemplateMcpDmlTools = templateMcpDmlTools;
4343
TemplateRestEnabled = templateRestEnabled;
4444
TemplateGraphqlEnabled = templateGraphqlEnabled;
4545
TemplateCacheEnabled = templateCacheEnabled;
@@ -61,8 +61,8 @@ public AutoConfigOptions(
6161
[Option("patterns.name", Required = false, HelpText = "Interpolation syntax for entity naming (must be unique for each generated entity). Default: '{object}'")]
6262
public string? PatternsName { get; }
6363

64-
[Option("template.mcp.dml-tool", Required = false, HelpText = "Enable/disable DML tools for generated entities. Allowed values: true, false. Default: true")]
65-
public string? TemplateMcpDmlTool { get; }
64+
[Option("template.mcp.dml-tools", Required = false, HelpText = "Enable/disable DML tools for generated entities. Allowed values: true, false. Default: true")]
65+
public string? TemplateMcpDmlTools { get; }
6666

6767
[Option("template.rest.enabled", Required = false, HelpText = "Enable/disable REST endpoint for generated entities. Allowed values: true, false. Default: true")]
6868
public bool? TemplateRestEnabled { get; }

src/Cli/ConfigGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,11 +3109,11 @@ private static AutoentityPatterns BuildAutoentityPatterns(AutoConfigOptions opti
31093109
bool userProvidedCache = existingAutoentity?.Template.UserProvidedCacheOptions ?? false;
31103110

31113111
// Update MCP options
3112-
if (!string.IsNullOrWhiteSpace(options.TemplateMcpDmlTool))
3112+
if (!string.IsNullOrWhiteSpace(options.TemplateMcpDmlTools))
31133113
{
3114-
if (!bool.TryParse(options.TemplateMcpDmlTool, out bool mcpDmlToolValue))
3114+
if (!bool.TryParse(options.TemplateMcpDmlTools, out bool mcpDmlToolValue))
31153115
{
3116-
_logger.LogError("Invalid value for template.mcp.dml-tool: {value}. Valid values are: true, false", options.TemplateMcpDmlTool);
3116+
_logger.LogError("Invalid value for template.mcp.dml-tools: {value}. Valid values are: true, false", options.TemplateMcpDmlTools);
31173117
return null;
31183118
}
31193119

@@ -3122,7 +3122,7 @@ private static AutoentityPatterns BuildAutoentityPatterns(AutoConfigOptions opti
31223122
bool? dmlToolValue = mcpDmlToolValue;
31233123
mcp = new EntityMcpOptions(customToolEnabled: customToolEnabled, dmlToolsEnabled: dmlToolValue);
31243124
userProvidedMcp = true;
3125-
_logger.LogInformation("Updated template.mcp.dml-tool for definition '{DefinitionName}'", options.DefinitionName);
3125+
_logger.LogInformation("Updated template.mcp.dml-tools for definition '{DefinitionName}'", options.DefinitionName);
31263126
}
31273127

31283128
// Update REST options

src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
357357
if (!entities.TryAdd(entityName, generatedEntity) || !runtimeConfig.TryAddGeneratedAutoentityNameToDataSourceName(entityName, autoentityName))
358358
{
359359
throw new DataApiBuilderException(
360-
message: $"Entity with name '{entityName}' already exists. Cannot create new entity from autoentities definition '{autoentityName}'.",
360+
message: $"Entity '{entityName}' conflicts with autoentity pattern '{autoentityName}'. Use --patterns.exclude to skip it.",
361361
statusCode: HttpStatusCode.BadRequest,
362362
subStatusCode: DataApiBuilderException.SubStatusCodes.ErrorInInitialization);
363363
}

src/Service.Tests/Configuration/ConfigurationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5611,7 +5611,7 @@ public async Task TestAutoentitiesAreGeneratedIntoEntities(bool useEntities, int
56115611
/// <returns></returns>
56125612
[TestCategory(TestCategory.MSSQL)]
56135613
[DataTestMethod]
5614-
[DataRow("publishers", "uniqueSingularPublisher", "uniquePluralPublishers", "/unique/publisher", "Entity with name 'publishers' already exists. Cannot create new entity from autoentities definition 'PublisherAutoEntity'.", DisplayName = "Autoentities fail due to entity name")]
5614+
[DataRow("publishers", "uniqueSingularPublisher", "uniquePluralPublishers", "/unique/publisher", "Entity 'publishers' conflicts with autoentity pattern 'PublisherAutoEntity'. Use --patterns.exclude to skip it.", DisplayName = "Autoentities fail due to entity name")]
56155615
[DataRow("UniquePublisher", "publishers", "uniquePluralPublishers", "/unique/publisher", "Entity publishers generates queries/mutation that already exist", DisplayName = "Autoentities fail due to graphql singular type")]
56165616
[DataRow("UniquePublisher", "uniqueSingularPublisher", "publishers", "/unique/publisher", "Entity publishers generates queries/mutation that already exist", DisplayName = "Autoentities fail due to graphql plural type")]
56175617
[DataRow("UniquePublisher", "uniqueSingularPublisher", "uniquePluralPublishers", "/publishers", "The rest path: publishers specified for entity: publishers is already used by another entity.", DisplayName = "Autoentities fail due to rest path")]

0 commit comments

Comments
 (0)