mirror of
https://github.com/rancher/norman.git
synced 2025-09-17 15:49:53 +00:00
Update generator to handle collection as an output
This commit is contained in:
committed by
Craig Jellick
parent
5c92744615
commit
9f2b71df50
@@ -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)
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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}}
|
||||
|
Reference in New Issue
Block a user