Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generator to handle collection as an output #129

Merged
merged 1 commit into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions generator/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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)
}
5 changes: 4 additions & 1 deletion generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions generator/type_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}
Expand Down Expand Up @@ -129,17 +129,17 @@ 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 ""))}}
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (error) {
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}}
Expand Down