diff --git a/generator/funcs.go b/generator/funcs.go index 274b43b7f..4d191c76b 100644 --- a/generator/funcs.go +++ b/generator/funcs.go @@ -11,12 +11,13 @@ import ( func funcs() template.FuncMap { return template.FuncMap{ - "capitalize": convert.Capitalize, - "unCapitalize": convert.Uncapitalize, - "upper": strings.ToUpper, - "toLower": strings.ToLower, - "hasGet": hasGet, - "hasPost": hasPost, + "capitalize": convert.Capitalize, + "unCapitalize": convert.Uncapitalize, + "upper": strings.ToUpper, + "toLower": strings.ToLower, + "hasGet": hasGet, + "hasPost": hasPost, + "getCollectionOutput": getCollectionOutput, } } @@ -40,3 +41,10 @@ func contains(list []string, needle string) bool { } return false } + +func getCollectionOutput(output, codeName string) string { + if output == "collection" { + return codeName + "Collection" + } + return convert.Capitalize(output) +} diff --git a/generator/generator.go b/generator/generator.go index 6de266463..5c6b54362 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -126,7 +126,10 @@ func getCollectionActions(schema *types.Schema, schemas *types.Schemas) map[stri result := map[string]types.Action{} for name, action := range schema.CollectionActions { if action.Output != "" { - output := strings.TrimSuffix(action.Output, "Collection") + output := action.Output + if action.Output == "collection" { + output = strings.ToLower(schema.CodeName) + } if schemas.Schema(&schema.Version, output) != nil { result[name] = action } diff --git a/generator/type_template.go b/generator/type_template.go index b5a887df4..b0098671f 100644 --- a/generator/type_template.go +++ b/generator/type_template.go @@ -53,11 +53,11 @@ type {{.schema.CodeName}}Operations interface { {{if (and (eq $value.Input "") (eq $value.Output ""))}} Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (error) {{else if (and (eq $value.Input "") (ne $value.Output ""))}} - Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (*{{.Output | capitalize}}, error) + Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error) {{else if (and (ne $value.Input "") (eq $value.Output ""))}} Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (error) {{else}} - Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (*{{.Output | capitalize}}, error) + Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error) {{end}} {{end}} } @@ -129,8 +129,8 @@ func (c *{{.schema.CodeName}}Client) Delete(container *{{.schema.CodeName}}) err err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, nil, nil) return err {{else if (and (eq $value.Input "") (ne $value.Output ""))}} - func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (*{{.Output | capitalize}}, error) { - resp := &{{.Output | capitalize}}{} + func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error) { + resp := &{{getCollectionOutput $value.Output $.schema.CodeName}}{} err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, nil, resp) return resp, err {{else if (and (ne $value.Input "") (eq $value.Output ""))}} @@ -138,8 +138,8 @@ func (c *{{.schema.CodeName}}Client) Delete(container *{{.schema.CodeName}}) err err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, input, nil) return err {{else}} - func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (*{{.Output | capitalize}}, error) { - resp := &{{.Output | capitalize}}{} + func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error) { + resp := &{{getCollectionOutput $value.Output $.schema.CodeName}}{} err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, input, resp) return resp, err {{end}}