Skip to content

Commit

Permalink
Add support in all types under itesm keyword (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvirsegev authored May 29, 2023
1 parent d55bb29 commit 16d1950
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion port/resource_port_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,41 @@ func convert(prop map[string]interface{}, bp *cli.Blueprint) (interface{}, error
case "string", "number", "boolean":
return prop["value"], nil
case "array":
return prop["items"], nil
var itemsArray []interface{}
if itemsType, ok := bp.Schema.Properties[prop["name"].(string)].Items["type"]; ok {

for _, item := range prop["items"].([]interface{}) {
convertItem := item.(string)
switch itemsType {
case "number":
convertItem, err := strconv.ParseFloat(item.(string), 64)
if err != nil {
return nil, fmt.Errorf("failed to convert item to number")
}
itemsArray = append(itemsArray, convertItem)
case "boolean":
convertItem, err := strconv.ParseBool(item.(string))
if err != nil {
return nil, fmt.Errorf("failed to convert item to boolean")
}
itemsArray = append(itemsArray, convertItem)
case "object":
convertItem := make(map[string]interface{})
err := json.Unmarshal([]byte(item.(string)), &convertItem)
if err != nil {
return nil, fmt.Errorf("failed to convert item to object")
}
itemsArray = append(itemsArray, convertItem)
default:
itemsArray = append(itemsArray, convertItem)
}
}

return itemsArray, nil
} else {
return prop["items"], nil
}

case "object":
obj := make(map[string]interface{})
err := json.Unmarshal([]byte(prop["value"].(string)), &obj)
Expand Down

0 comments on commit 16d1950

Please sign in to comment.