Skip to main content

Semantic Model

Gateway prefix: ${API_BASE}/metadata/models/...

The semantic model APIs generate metadata entities (Entity + Field) from “natural language + simplified field configuration” and automatically create the corresponding table structure on the specified data source.

DTO structure (GeneratedSchema)

Controller: DataModelController.saveModel
Backend DTO definition (simplified):

  • GeneratedSchema
    • entity: string, required, entity name (also used as table name)
    • fields: GeneratedField[], optional, field list
  • GeneratedField
    • name: string, required, field name (also used as column name)
    • type: string, required, field type (see mapping below)
    • label: string, optional, display label
    • choices: Choice[], optional, enum/options (currently only used at UI layer)
  • Choice
    • id: any, optional
    • name: string, optional

Note: the server automatically fills in schemaName, dataSourceId, etc. based on the tenant’s default data source (named primary).

Field type mapping (type -> FieldDto.DataType)

The backend uses mapDataType for type mapping:

  • "string"STRING
  • "number"INTEGER (default integer, can be refined later)
  • "date"DATE
  • "enum"STRING
  • "file"STRING
  • others/unknown → STRING

Save generated model

  • Method: POST /models
  • Permissions: admin / tenant:admin
  • Request headers:
    • Authorization: Bearer <token>
    • X-Tenant-Id: <tenantId>
    • Content-Type: application/json
  • Request body: GeneratedSchema

Example:

curl -X POST \
"${API_BASE}/metadata/models" \
-H "Authorization: Bearer <token>" \
-H "X-Tenant-Id: tenant-abc123" \
-H "Content-Type: application/json" \
-d '{
"entity": "crm_leads",
"fields": [
{ "name": "name", "type": "string", "label": "Lead Name" },
{ "name": "email", "type": "string", "label": "Email" },
{ "name": "status", "type": "enum", "label": "Status",
"choices": [
{ "id": "new", "name": "New" },
{ "id": "contacted", "name": "Contacted" }
]
}
]
}'

Successful response:

{
"success": true,
"message": "Model saved successfully",
"data": {
"id": "en_xxx",
"name": "crm_leads",
"tableName": "crm_leads",
"schemaName": "public",
"dataSourceId": "ds_primary",
"fields": [
{ "name": "name", "dataType": "STRING", "columnName": "name" },
{ "name": "email", "dataType": "STRING", "columnName": "email" },
{ "name": "status", "dataType": "STRING", "columnName": "status" }
]
}
}

Notes:

  • The controller calls EntityService.createEntity(entityDto, true) and enables DDL creation (creates the physical table).
  • If you need more precise types (such as DECIMAL, DOUBLE), you can later update fields via the entity management APIs.