Skip to content
New issue

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

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

Already on GitHub? # to your account

Generate nicer SDK getters #2122

Closed
johanbrandhorst opened this issue Jun 2, 2022 · 2 comments
Closed

Generate nicer SDK getters #2122

johanbrandhorst opened this issue Jun 2, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@johanbrandhorst
Copy link
Collaborator

johanbrandhorst commented Jun 2, 2022

Is your feature request related to a problem? Please describe.
When using the SDK, the result getters all return interface{} when they have a concrete type available. This is a poor experience for the user. See

func (n SessionReadResult) GetItem() interface{} {
return n.Item
}
and
func (n SessionListResult) GetItems() interface{} {
return n.Items
}
for examples.

Describe the solution you'd like
I would like the generated code to use typed returns.

Additional context
This was raised as a concern by internal users of our SDK. The template for this part of the generated SDK is here:

var structTemplate = template.Must(template.New("").Parse(
fmt.Sprint(`// Code generated by "make api"; DO NOT EDIT.
package {{ .Package }}
import (
"context"
"fmt"
"time"
"github.com/kr/pretty"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/scopes"
)
type {{ .Name }} struct { {{ range .Fields }}
{{ .Name }} {{ .FieldType }} `, "`json:\"{{ .ProtoName }},omitempty\"`", `{{ end }}
{{ if .CreateResponseTypes }}
response *api.Response
{{ else if ( eq .Name "Error" ) }}
response *Response
{{ end }}
}
{{ if .CreateResponseTypes }}
type {{ .Name }}ReadResult struct {
Item *{{ .Name }}
response *api.Response
}
func (n {{ .Name }}ReadResult) GetItem() interface{} {
return n.Item
}
func (n {{ .Name }}ReadResult) GetResponse() *api.Response {
return n.response
}
type {{ .Name }}CreateResult = {{ .Name }}ReadResult
type {{ .Name }}UpdateResult = {{ .Name }}ReadResult
type {{ .Name }}DeleteResult struct {
response *api.Response
}
// GetItem will always be nil for {{ .Name }}DeleteResult
func (n {{ .Name }}DeleteResult) GetItem() interface{} {
return nil
}
func (n {{ .Name }}DeleteResult) GetResponse() *api.Response {
return n.response
}
type {{ .Name }}ListResult struct {
Items []*{{ .Name }}
response *api.Response
}
func (n {{ .Name }}ListResult) GetItems() interface{} {
return n.Items
}
func (n {{ .Name }}ListResult) GetResponse() *api.Response {
return n.response
}
{{ end }}
`)))

@johanbrandhorst johanbrandhorst added the enhancement New feature or request label Jun 2, 2022
@covetocove
Copy link
Contributor

Thank you for raising this item @johanbrandhorst! We'll keep this item open to gauge interest from the community to inform its priority on our roadmap.

@jefferai
Copy link
Member

jefferai commented Sep 5, 2022

Closing as #2238 has been merged

@jefferai jefferai closed this as completed Sep 5, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants