jmsperu commented on issue #15:
URL: https://github.com/apache/cloudstack-go/issues/15#issuecomment-4757543865

   Still reproduces on current `main` (2026). Minimal repro:
   
   ```go
   body := `{"id":"t1","name":"tmpl","childtemplates":{"foo":"bar"}}`
   var tmpl cloudstack.Template
   err := json.Unmarshal([]byte(body), &tmpl)
   // json: cannot unmarshal object into Go struct field alias.childtemplates 
of type []interface {}
   ```
   
   **Root cause:** `childtemplates` is declared `"type": "set"` in 
`listApis.json`, and the generator maps `set` → `[]interface{}` (`mapType`, 
generate.go). But some CloudStack/CloudPlatform versions return 
`childtemplates` as a JSON **object**, not an array, so `json.Unmarshal` fails 
— and because it is hit through the struct’s custom `UnmarshalJSON` (`type 
alias Template`), the whole template (and thus `listTemplates` / 
`GetTemplateID`) fails. The field appears as `[]interface{}` in 7 template 
structs (Template, CopyTemplateResponse, CreateTemplateResponse, 
PrepareTemplateResponse, RegisterTemplate, UpdateTemplateResponse, …).
   
   **Suggested fix:** narrowly special-case this field — make `childtemplates` 
`interface{}` instead of `[]interface{}` (interface{} accepts an object, an 
array, or null). It must be a field-level special-case, **not** a change to the 
`set`→`[]interface{}` mapping, which would touch ~100 unrelated fields. It is a 
small type change (slice → interface{}) on a field that is already opaque and 
currently unusable on the affected versions, so net it restores functionality.
   
   I have this fix + a regression test ready (the repro above passes after the 
change, fails before). Happy to open a PR if a maintainer is OK with the 
`interface{}` approach — flagging the minor type change for visibility before I 
do.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to