Skip to content

Commit 45089c2

Browse files
engalarclaude
andcommitted
fix: implement generateDefJSON property mapping generation
generateDefJSON now derives propertyMappings and childSlots from MPK property definitions instead of returning a skeleton. This makes `mxcli widget init` produce usable .def.json files out of the box. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5a2bc46 commit 45089c2

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

cmd/mxcli/cmd_widget.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,65 @@ func generateDefJSON(mpkDef *mpk.WidgetDefinition, mdlName string) *executor.Wid
148148
if mpkDef.IsPluggable {
149149
widgetKind = "pluggable"
150150
}
151-
return &executor.WidgetDefinition{
151+
def := &executor.WidgetDefinition{
152152
WidgetID: mpkDef.ID,
153153
MDLName: mdlName,
154154
WidgetKind: widgetKind,
155155
TemplateFile: strings.ToLower(mdlName) + ".json",
156156
DefaultEditable: "Always",
157157
}
158+
159+
// Generate property mappings and child slots from MPK property definitions
160+
for _, p := range mpkDef.Properties {
161+
switch p.Type {
162+
case "widgets":
163+
container := strings.ToUpper(p.Key)
164+
if p.Key == "content" {
165+
container = "TEMPLATE"
166+
}
167+
def.ChildSlots = append(def.ChildSlots, executor.ChildSlotMapping{
168+
PropertyKey: p.Key,
169+
MDLContainer: container,
170+
Operation: "widgets",
171+
})
172+
case "datasource":
173+
def.PropertyMappings = append(def.PropertyMappings, executor.PropertyMapping{
174+
PropertyKey: p.Key,
175+
Source: "DataSource",
176+
Operation: "datasource",
177+
})
178+
case "attribute":
179+
def.PropertyMappings = append(def.PropertyMappings, executor.PropertyMapping{
180+
PropertyKey: p.Key,
181+
Source: "Attribute",
182+
Operation: "attribute",
183+
})
184+
case "association":
185+
def.PropertyMappings = append(def.PropertyMappings, executor.PropertyMapping{
186+
PropertyKey: p.Key,
187+
Source: "Association",
188+
Operation: "association",
189+
})
190+
case "selection":
191+
def.PropertyMappings = append(def.PropertyMappings, executor.PropertyMapping{
192+
PropertyKey: p.Key,
193+
Source: "Selection",
194+
Operation: "selection",
195+
Default: p.DefaultValue,
196+
})
197+
case "boolean", "integer", "decimal", "string", "enumeration":
198+
m := executor.PropertyMapping{
199+
PropertyKey: p.Key,
200+
Operation: "primitive",
201+
}
202+
if p.DefaultValue != "" {
203+
m.Value = p.DefaultValue
204+
}
205+
def.PropertyMappings = append(def.PropertyMappings, m)
206+
}
207+
}
208+
209+
return def
158210
}
159211

160212
func runWidgetInit(cmd *cobra.Command, args []string) error {

0 commit comments

Comments
 (0)