Skip to content

Commit cd4aab3

Browse files
feat: add field configuration to entity and populate fields based on column descriptions and primary keys
1 parent 26dc7bf commit cd4aab3

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/app/models/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ export interface IRelationship {
248248
'linking.target.fields'?: string[];
249249
}
250250

251+
/**
252+
* Field configuration for entity
253+
*/
254+
export interface IFieldConfig {
255+
name: string;
256+
description?: string;
257+
'primary-key'?: boolean;
258+
}
259+
251260
/**
252261
* Entity configuration
253262
*/
@@ -260,6 +269,7 @@ export interface IEntityConfig {
260269
mcp?: IEntityMcpConfig | boolean;
261270
mappings?: Record<string, string>;
262271
relationships?: Record<string, IRelationship>;
272+
fields?: IFieldConfig[];
263273
}
264274

265275
/**

src/app/pages/config-wizard/tabs/entities-tab/entities-tab.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ import { SchemaImporterService } from '../../../../services/schema-importer.serv
801801
</button>
802802
}
803803
<a
804-
href="https://learn.microsoft.com/en-us/azure/data-api-builder/configuration/fields"
804+
href="https://learn.microsoft.com/en-us/azure/data-api-builder/mcp/how-to-add-descriptions"
805805
target="_blank"
806806
rel="noopener noreferrer"
807807
class="ms-2 text-decoration-none"

src/app/services/config-builder.service.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,36 @@ export class ConfigBuilderService {
227227
config.mcp = entity.mcp;
228228
}
229229

230+
// Add fields if columns have descriptions or are primary keys
231+
if (entity.columns && entity.columns.length > 0) {
232+
const fields = entity.columns
233+
.map((col) => {
234+
const field: { name: string; description?: string; 'primary-key'?: boolean } = {
235+
name: col.name,
236+
};
237+
238+
if (col.description && col.description.trim()) {
239+
field.description = col.description.trim();
240+
}
241+
242+
if (col.isPrimaryKey) {
243+
field['primary-key'] = true;
244+
}
245+
246+
// Only include fields that have a description or are primary keys
247+
return col.description?.trim() || col.isPrimaryKey ? field : null;
248+
})
249+
.filter((field) => field !== null) as Array<{
250+
name: string;
251+
description?: string;
252+
'primary-key'?: boolean;
253+
}>;
254+
255+
if (fields.length > 0) {
256+
config.fields = fields;
257+
}
258+
}
259+
230260
return config;
231261
}
232262

0 commit comments

Comments
 (0)