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
@@ -17,6 +17,7 @@ func funcs() template.FuncMap {
|
|||||||
"toLower": strings.ToLower,
|
"toLower": strings.ToLower,
|
||||||
"hasGet": hasGet,
|
"hasGet": hasGet,
|
||||||
"hasPost": hasPost,
|
"hasPost": hasPost,
|
||||||
|
"getCollectionOutput": getCollectionOutput,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,3 +41,10 @@ func contains(list []string, needle string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
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{}
|
result := map[string]types.Action{}
|
||||||
for name, action := range schema.CollectionActions {
|
for name, action := range schema.CollectionActions {
|
||||||
if action.Output != "" {
|
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 {
|
if schemas.Schema(&schema.Version, output) != nil {
|
||||||
result[name] = action
|
result[name] = action
|
||||||
}
|
}
|
||||||
|
@@ -53,11 +53,11 @@ type {{.schema.CodeName}}Operations interface {
|
|||||||
{{if (and (eq $value.Input "") (eq $value.Output ""))}}
|
{{if (and (eq $value.Input "") (eq $value.Output ""))}}
|
||||||
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (error)
|
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (error)
|
||||||
{{else if (and (eq $value.Input "") (ne $value.Output ""))}}
|
{{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 ""))}}
|
{{else if (and (ne $value.Input "") (eq $value.Output ""))}}
|
||||||
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (error)
|
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (error)
|
||||||
{{else}}
|
{{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}}
|
||||||
{{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)
|
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, nil, nil)
|
||||||
return err
|
return err
|
||||||
{{else if (and (eq $value.Input "") (ne $value.Output ""))}}
|
{{else if (and (eq $value.Input "") (ne $value.Output ""))}}
|
||||||
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (*{{.Output | capitalize}}, error) {
|
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error) {
|
||||||
resp := &{{.Output | capitalize}}{}
|
resp := &{{getCollectionOutput $value.Output $.schema.CodeName}}{}
|
||||||
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, nil, resp)
|
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, nil, resp)
|
||||||
return resp, err
|
return resp, err
|
||||||
{{else if (and (ne $value.Input "") (eq $value.Output ""))}}
|
{{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)
|
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, input, nil)
|
||||||
return err
|
return err
|
||||||
{{else}}
|
{{else}}
|
||||||
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (*{{.Output | capitalize}}, error) {
|
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error) {
|
||||||
resp := &{{.Output | capitalize}}{}
|
resp := &{{getCollectionOutput $value.Output $.schema.CodeName}}{}
|
||||||
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, input, resp)
|
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, input, resp)
|
||||||
return resp, err
|
return resp, err
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Reference in New Issue
Block a user