Skip to content
Closed
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
32 changes: 31 additions & 1 deletion schemas/dab.draft.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,21 @@
}
]
},
"fields": {
"type": "array",
"description": "Defines the fields (columns) exposed for this entity, with metadata.",
"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": "Is this field a primary key?" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a question for someone? I think we should change this description

},
"required": ["name"]
},
"uniqueItems": true
},
"rest": {
"oneOf": [
{
Expand Down Expand Up @@ -1104,7 +1119,22 @@
}
}
},
"required": ["source", "permissions"]
"required": ["source", "permissions"],
"allOf": [
{
"if": {
"required": ["fields"]
},
"then": {
"not": {
"anyOf": [
{ "required": ["mappings"] },
{ "properties": { "source": { "properties": { "key-fields": { } }, "required": ["key-fields"] } } }
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

The JSON schema constraint to prevent fields and key-fields coexistence is incorrect. The nested structure doesn't properly check for the presence of key-fields in the source object. It should be: { \"properties\": { \"source\": { \"required\": [\"key-fields\"] } } }.

Suggested change
{ "properties": { "source": { "properties": { "key-fields": { } }, "required": ["key-fields"] } } }
{ "properties": { "source": { "required": ["key-fields"] } } }

Copilot uses AI. Check for mistakes.
]
}
}
}
]
}
}
}
Expand Down
78 changes: 65 additions & 13 deletions src/Cli.Tests/AddEntityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public Task AddNewEntityWhenEntitiesEmpty()
cacheTtl: null,
config: TEST_RUNTIME_CONFIG_FILE,
restMethodsForStoredProcedure: null,
graphQLOperationForStoredProcedure: null
graphQLOperationForStoredProcedure: null,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
Comment on lines +49 to +52
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to make these parameters empty and not null?

Copy link
Contributor

Choose a reason for hiding this comment

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

The same question applies to the other instances where this change was made.

);

return ExecuteVerifyTest(options);
Expand Down Expand Up @@ -75,7 +79,11 @@ public Task AddNewEntityWhenEntitiesNotEmpty()
cacheTtl: null,
config: TEST_RUNTIME_CONFIG_FILE,
restMethodsForStoredProcedure: null,
graphQLOperationForStoredProcedure: null
graphQLOperationForStoredProcedure: null,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

string initialConfiguration = AddPropertiesToJson(INITIAL_CONFIG, GetFirstEntityConfiguration());
Expand Down Expand Up @@ -107,7 +115,11 @@ public void AddDuplicateEntity()
cacheTtl: null,
config: TEST_RUNTIME_CONFIG_FILE,
restMethodsForStoredProcedure: null,
graphQLOperationForStoredProcedure: null
graphQLOperationForStoredProcedure: null,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

string initialConfiguration = AddPropertiesToJson(INITIAL_CONFIG, GetFirstEntityConfiguration());
Expand Down Expand Up @@ -143,7 +155,11 @@ public Task AddEntityWithAnExistingNameButWithDifferentCase()
cacheTtl: null,
config: TEST_RUNTIME_CONFIG_FILE,
restMethodsForStoredProcedure: null,
graphQLOperationForStoredProcedure: null
graphQLOperationForStoredProcedure: null,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

string initialConfiguration = AddPropertiesToJson(INITIAL_CONFIG, GetFirstEntityConfiguration());
Expand Down Expand Up @@ -174,7 +190,11 @@ public Task AddEntityWithCachingEnabled()
cacheTtl: "1",
config: TEST_RUNTIME_CONFIG_FILE,
restMethodsForStoredProcedure: null,
graphQLOperationForStoredProcedure: null
graphQLOperationForStoredProcedure: null,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

return ExecuteVerifyTest(options);
Expand Down Expand Up @@ -211,7 +231,11 @@ public Task AddEntityWithPolicyAndFieldProperties(
cacheEnabled: null,
cacheTtl: null,
restMethodsForStoredProcedure: null,
graphQLOperationForStoredProcedure: null
graphQLOperationForStoredProcedure: null,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

// Create VerifySettings and add all arguments to the method as parameters
Expand Down Expand Up @@ -244,7 +268,11 @@ public Task AddNewEntityWhenEntitiesWithSourceAsStoredProcedure()
cacheEnabled: null,
cacheTtl: null,
restMethodsForStoredProcedure: null,
graphQLOperationForStoredProcedure: null
graphQLOperationForStoredProcedure: null,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

return ExecuteVerifyTest(options);
Expand Down Expand Up @@ -276,7 +304,11 @@ public Task TestAddStoredProcedureWithRestMethodsAndGraphQLOperations()
cacheTtl: null,
config: TEST_RUNTIME_CONFIG_FILE,
restMethodsForStoredProcedure: new string[] { "Post", "Put", "Patch" },
graphQLOperationForStoredProcedure: "Query"
graphQLOperationForStoredProcedure: "Query",
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

return ExecuteVerifyTest(options);
Expand Down Expand Up @@ -304,7 +336,11 @@ public void AddEntityWithDescriptionAndVerifyInConfig()
cacheTtl: null,
config: TEST_RUNTIME_CONFIG_FILE,
restMethodsForStoredProcedure: null,
graphQLOperationForStoredProcedure: null
graphQLOperationForStoredProcedure: null,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

string config = INITIAL_CONFIG;
Expand Down Expand Up @@ -359,7 +395,11 @@ public void TestAddNewEntityWithSourceObjectHavingValidFields(
cacheTtl: null,
config: TEST_RUNTIME_CONFIG_FILE,
restMethodsForStoredProcedure: null,
graphQLOperationForStoredProcedure: null
graphQLOperationForStoredProcedure: null,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

RuntimeConfigLoader.TryParseConfig(INITIAL_CONFIG, out RuntimeConfig? runtimeConfig);
Expand Down Expand Up @@ -419,7 +459,11 @@ public Task TestAddNewSpWithDifferentRestAndGraphQLOptions(
cacheTtl: null,
config: TEST_RUNTIME_CONFIG_FILE,
restMethodsForStoredProcedure: restMethods,
graphQLOperationForStoredProcedure: graphQLOperation
graphQLOperationForStoredProcedure: graphQLOperation,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

VerifySettings settings = new();
Expand Down Expand Up @@ -455,7 +499,11 @@ public void TestAddStoredProcedureWithConflictingRestGraphQLOptions(
cacheTtl: null,
config: TEST_RUNTIME_CONFIG_FILE,
restMethodsForStoredProcedure: restMethods,
graphQLOperationForStoredProcedure: graphQLOperation
graphQLOperationForStoredProcedure: graphQLOperation,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

RuntimeConfigLoader.TryParseConfig(INITIAL_CONFIG, out RuntimeConfig? runtimeConfig);
Expand Down Expand Up @@ -494,7 +542,11 @@ public void TestAddEntityPermissionWithInvalidOperation(IEnumerable<string> perm
cacheTtl: null,
config: TEST_RUNTIME_CONFIG_FILE,
restMethodsForStoredProcedure: null,
graphQLOperationForStoredProcedure: null
graphQLOperationForStoredProcedure: null,
fieldsNameCollection: [],
fieldsAliasCollection: [],
fieldsDescriptionCollection: [],
fieldsPrimaryKeyCollection: []
);

RuntimeConfigLoader.TryParseConfig(INITIAL_CONFIG, out RuntimeConfig? runtimeConfig);
Expand Down
8 changes: 5 additions & 3 deletions src/Cli.Tests/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,11 @@ public void TestUpdateEntity()
CollectionAssert.AreEqual(new string[] { "todo_id" }, relationship.LinkingSourceFields);
CollectionAssert.AreEqual(new string[] { "id" }, relationship.LinkingTargetFields);

Assert.IsNotNull(entity.Mappings);
Assert.AreEqual("identity", entity.Mappings["id"]);
Assert.AreEqual("Company Name", entity.Mappings["name"]);
Assert.IsNotNull(entity.Fields);
Assert.AreEqual(2, entity.Fields.Count);
Assert.AreEqual(entity.Fields[0].Alias, "identity");
Assert.AreEqual(entity.Fields[1].Alias, "Company Name");
Assert.IsNull(entity.Mappings);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@
MyEntity: {
Source: {
Object: s001.book,
Type: View,
KeyFields: [
col1,
col2
]
Type: View
},
Fields: [
{
Name: col1,
PrimaryKey: true
},
{
Name: col2,
PrimaryKey: true
}
],
GraphQL: {
Singular: MyEntity,
Plural: MyEntities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@
MyEntity: {
Source: {
Object: s001.book,
Type: Table,
KeyFields: [
id,
name
]
Type: Table
},
Fields: [
{
Name: id,
PrimaryKey: true
},
{
Name: name,
PrimaryKey: true
}
],
GraphQL: {
Singular: MyEntity,
Plural: MyEntities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@
MyEntity: {
Source: {
Object: s001.book,
Type: View,
KeyFields: [
col1,
col2
]
Type: View
},
Fields: [
{
Name: col1,
PrimaryKey: true
},
{
Name: col2,
PrimaryKey: true
}
],
GraphQL: {
Singular: MyEntity,
Plural: MyEntities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
Object: s001.book,
Type: stored-procedure
},
Fields: [
{
Name: id,
PrimaryKey: true
},
{
Name: name,
PrimaryKey: true
}
],
GraphQL: {
Singular: MyEntity,
Plural: MyEntities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
Object: MyTable,
Type: Table
},
Fields: [
{
Name: id,
Alias: Identity,
PrimaryKey: false
},
{
Name: name,
Alias: Company Name,
PrimaryKey: false
}
],
GraphQL: {
Singular: MyEntity,
Plural: MyEntities,
Expand All @@ -53,11 +65,7 @@
}
]
}
],
Mappings: {
id: Identity,
name: Company Name
}
]
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@
Object: MyTable,
Type: Table
},
Fields: [
{
Name: Macaroni,
Alias: Mac & Cheese,
PrimaryKey: false
},
{
Name: region,
Alias: United State's Region,
PrimaryKey: false
},
{
Name: russian,
Alias: русский,
PrimaryKey: false
},
{
Name: chinese,
Alias: 中文,
PrimaryKey: false
}
],
GraphQL: {
Singular: MyEntity,
Plural: MyEntities,
Expand All @@ -53,13 +75,7 @@
}
]
}
],
Mappings: {
chinese: 中文,
Macaroni: Mac & Cheese,
region: United State's Region,
russian: русский
}
]
}
}
]
Expand Down
Loading
Loading