Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 113 additions & 22 deletions schemas/dab.draft.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@
"properties": {
"type": {
"type": "string",
"enum": ["table", "view", "stored-procedure"],
"enum": [ "table", "view", "stored-procedure" ],
"description": "Database object type"
},
"object": {
Expand All @@ -774,12 +774,24 @@
"description": "Array of parameter objects with metadata",
"items": {
"type": "object",
"required": ["name"],
"required": [ "name" ],
"properties": {
"name": { "type": "string", "description": "Parameter name" },
"required": { "type": "boolean", "description": "Is parameter required" },
"default": { "type": ["string", "number", "boolean", "null"], "description": "Default value" },
"description": { "type": "string", "description": "Parameter description. Since descriptions for multiple parameters are provided as a comma-separated string, individual parameter descriptions must not contain a comma (',')." }
"name": {
"type": "string",
"description": "Parameter name"
},
"required": {
"type": "boolean",
"description": "Is parameter required"
},
"default": {
"type": [ "string", "number", "boolean", "null" ],
"description": "Default value"
},
"description": {
"type": "string",
"description": "Parameter description. Since descriptions for multiple parameters are provided as a comma-separated string, individual parameter descriptions must not contain a comma (',')."
}
}
}
}
Expand All @@ -793,7 +805,7 @@
"description": "List of fields to be used as primary keys. Mandatory field for views when generated through the CLI."
}
},
"required": ["type", "object"]
"required": [ "type", "object" ]
}
]
},
Expand All @@ -803,12 +815,24 @@
"items": {
"type": "object",
"properties": {
"name": { "type": "string", "description": "Database column name." },
"alias": { "type": "string", "description": "Exposed name for the field." },
"description": { "type": "string", "description": "Field description." },
"primary-key": { "type": "boolean", "description": "Indicates whether this field is a primary key." }
"name": {
"type": "string",
"description": "Database column name."
},
"alias": {
"type": "string",
"description": "Exposed name for the field."
},
"description": {
"type": "string",
"description": "Field description."
},
"primary-key": {
"type": "boolean",
"description": "Indicates whether this field is a primary key."
}
},
"required": ["name"]
"required": [ "name" ]
},
"uniqueItems": true
},
Expand All @@ -828,7 +852,7 @@
"type": "array",
"items": {
"type": "string",
"enum": ["get", "post", "put", "patch", "delete"]
"enum": [ "get", "post", "put", "patch", "delete" ]
}
},
"enabled": {
Expand All @@ -839,13 +863,13 @@
},
"anyOf": [
{
"required": ["path"]
"required": [ "path" ]
},
{
"required": ["methods"]
"required": [ "methods" ]
},
{
"required": ["enabled"]
"required": [ "enabled" ]
}
]
}
Expand All @@ -865,7 +889,7 @@
},
"operation": {
"type": "string",
"enum": ["mutation", "query"]
"enum": [ "mutation", "query" ]
},
"enabled": {
"type": "boolean",
Expand All @@ -875,18 +899,43 @@
},
"anyOf": [
{
"required": ["type"]
"required": [ "type" ]
},
{
"required": ["operation"]
"required": [ "operation" ]
},
{
"required": ["enabled"]
"required": [ "enabled" ]
}
]
}
]
},
"mcp": {
"oneOf": [
{
"type": "boolean",
"description": "Enable/disable DML tools. When true, all DML tools are enabled. When false, all DML tools are disabled. For stored procedures only: true also enables custom-tool as false by default."
},
{
"type": "object",
"description": "Granular MCP configuration. For stored procedures: can specify both custom-tool and dml-tools. For tables/views: only dml-tools is allowed.",
"additionalProperties": false,
"properties": {
"custom-tool": {
"type": "boolean",
"description": "Enable/disable the custom tool. Only applicable for stored-procedure entities.",
"default": false
},
"dml-tools": {
"type": "boolean",
"description": "Enable/disable the dml-tools.",
"default": true
}
}
}
]
},
"permissions": {
"type": "array",
"description": "Permissions assigned to this entity"
Expand All @@ -908,7 +957,7 @@
"properties": {
"cardinality": {
"type": "string",
"enum": ["one", "many"]
"enum": [ "one", "many" ]
},
"target.entity": {
"type": "string"
Expand Down Expand Up @@ -942,7 +991,7 @@
}
}
},
"required": ["cardinality", "target.entity"]
"required": [ "cardinality", "target.entity" ]
}
}
},
Expand Down Expand Up @@ -1145,6 +1194,48 @@
]
}
}
},
{
"if": {
"properties": {
"source": {
"type": "object",
"properties": {
"type": {
"const": "stored-procedure"
}
}
}
}
},
"then": {
"comment": "For stored procedures, both custom-tool and dml-tools are allowed in mcp"
},
"else": {
"comment": "For tables and views, only dml-tools is allowed in mcp",
"if": {
"properties": {
"mcp": {
"type": "object"
}
}
},
"then": {
"properties": {
"mcp": {
"type": "object",
"additionalProperties": false,
"properties": {
"dml-tools": {
"type": "boolean",
"description": "Enable/disable the dml-tools.",
"default": true
}
}
}
}
}
}
}
]
}
Expand Down
66 changes: 40 additions & 26 deletions src/Cli.Tests/AddEntityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ public Task AddNewEntityWhenEntitiesEmpty()
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);
return ExecuteVerifyTest(options);
}

Expand Down Expand Up @@ -90,8 +91,9 @@ public Task AddNewEntityWhenEntitiesNotEmpty()
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

string initialConfiguration = AddPropertiesToJson(INITIAL_CONFIG, GetFirstEntityConfiguration());

Expand Down Expand Up @@ -130,8 +132,9 @@ public void AddDuplicateEntity()
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

string initialConfiguration = AddPropertiesToJson(INITIAL_CONFIG, GetFirstEntityConfiguration());
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(initialConfiguration, out RuntimeConfig? runtimeConfig), "Loaded config");
Expand Down Expand Up @@ -174,8 +177,9 @@ public Task AddEntityWithAnExistingNameButWithDifferentCase()
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

string initialConfiguration = AddPropertiesToJson(INITIAL_CONFIG, GetFirstEntityConfiguration());
return ExecuteVerifyTest(options, initialConfiguration);
Expand Down Expand Up @@ -213,8 +217,9 @@ public Task AddEntityWithCachingEnabled()
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

return ExecuteVerifyTest(options);
}
Expand Down Expand Up @@ -258,8 +263,9 @@ public Task AddEntityWithPolicyAndFieldProperties(
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

// Create VerifySettings and add all arguments to the method as parameters
VerifySettings verifySettings = new();
Expand Down Expand Up @@ -299,8 +305,9 @@ public Task AddNewEntityWhenEntitiesWithSourceAsStoredProcedure()
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

return ExecuteVerifyTest(options);
}
Expand Down Expand Up @@ -339,8 +346,9 @@ public Task TestAddStoredProcedureWithRestMethodsAndGraphQLOperations()
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

return ExecuteVerifyTest(options);
}
Expand Down Expand Up @@ -375,8 +383,9 @@ public void AddEntityWithDescriptionAndVerifyInConfig()
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

string config = INITIAL_CONFIG;
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(config, out RuntimeConfig? runtimeConfig), "Loaded base config.");
Expand Down Expand Up @@ -438,8 +447,9 @@ public void TestAddNewEntityWithSourceObjectHavingValidFields(
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

RuntimeConfigLoader.TryParseConfig(INITIAL_CONFIG, out RuntimeConfig? runtimeConfig);

Expand Down Expand Up @@ -506,8 +516,9 @@ public Task TestAddNewSpWithDifferentRestAndGraphQLOptions(
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

VerifySettings settings = new();
settings.UseHashedParameters(restMethods, graphQLOperation, restRoute, graphQLType);
Expand Down Expand Up @@ -550,8 +561,9 @@ public void TestAddStoredProcedureWithConflictingRestGraphQLOptions(
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

RuntimeConfigLoader.TryParseConfig(INITIAL_CONFIG, out RuntimeConfig? runtimeConfig);

Expand Down Expand Up @@ -597,8 +609,9 @@ public void TestAddEntityPermissionWithInvalidOperation(IEnumerable<string> perm
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);
fieldsPrimaryKeyCollection: [],
mcpCustomToolEnabled: null,
mcpDmlToolsEnabled: null);

RuntimeConfigLoader.TryParseConfig(INITIAL_CONFIG, out RuntimeConfig? runtimeConfig);

Expand Down Expand Up @@ -635,3 +648,4 @@ private Task ExecuteVerifyTest(AddOptions options, string config = INITIAL_CONFI
}
}
}

Loading
Loading