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

[Feature] Remove deprecated WithImpl and Impl service methods #1003

Merged
merged 6 commits into from
Aug 1, 2024
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
37 changes: 5 additions & 32 deletions .codegen/api.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ type {{.PascalName}}Interface interface {
{{.CamelName}}APIUtilities
{{end -}}

// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use Mock{{.PascalName}}Interface instead.
WithImpl(impl {{.PascalName}}Service) {{.PascalName}}Interface

// Impl returns low-level {{.PascalName}} API implementation
// Deprecated: use Mock{{.PascalName}}Interface instead.
Impl() {{.PascalName}}Service

{{range .Subservices}}
{{.Comment " // " 80}}
{{.PascalName}}() {{.PascalName}}Interface
Expand Down Expand Up @@ -111,7 +102,7 @@ controlPlane *{{.ControlPlaneService.PascalName}}API,
{{end -}}
) *{{.PascalName}}API {
return &{{.PascalName}}API{
{{.PascalName}}Service: &{{.CamelName}}Impl{
{{.CamelName}}Impl: {{.CamelName}}Impl{
client: client,
{{- if .IsDataPlane}}
dataPlaneService: oauth2.NewDataPlaneService(),
Expand All @@ -126,9 +117,7 @@ controlPlane *{{.ControlPlaneService.PascalName}}API,

{{.Comment "// " 80}}
type {{.PascalName}}API struct {
// impl contains low-level REST API interface, that could be overridden
// through WithImpl({{.PascalName}}Service)
{{.PascalName}}Service
{{.CamelName}}Impl

{{range .Subservices}}
{{.Comment " // " 80}}
Expand All @@ -142,22 +131,6 @@ func (a *{{.ParentService.PascalName}}API) {{.PascalName}}() {{.PascalName}}Inte
}
{{end}}

// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use Mock{{.PascalName}}Interface instead.
func (a *{{.PascalName}}API) WithImpl(impl {{.PascalName}}Service) {{.PascalName}}Interface {
a.{{.PascalName}}Service = impl
return a
}

// Impl returns low-level {{.PascalName}} API implementation
// Deprecated: use Mock{{.PascalName}}Interface instead.
func (a *{{.PascalName}}API) Impl() {{.PascalName}}Service {
return a.{{.PascalName}}Service
}



{{range .Waits}}
// {{.PascalName}} repeatedly calls [{{.Method.Service.PascalName}}API.{{.Poll.PascalName}}] and waits to reach {{range $i, $e := .Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state
func (a *{{.Method.Service.PascalName}}API) {{.PascalName}}(ctx context.Context{{range .Binding}}, {{.PollField.CamelName}} {{template "type" .PollField.Entity}}{{end}},
Expand Down Expand Up @@ -236,7 +209,7 @@ methods from the nested service interface.
{{if $hasWaiter -}}
{{.Comment "// " 80}}
func (a *{{.Service.PascalName}}API) {{.PascalName}}(ctx context.Context{{if .Request}}, {{.Request.CamelName}} {{.Request.PascalName}}{{end}}) {{ template "wait-response-type" . }} {
{{if not .Response.IsEmpty }}{{.Response.CamelName}}, {{end}}err := a.{{.Service.PascalName}}Service.{{.PascalName}}(ctx{{if .Request}}, {{.Request.CamelName}}{{end}})
{{if not .Response.IsEmpty }}{{.Response.CamelName}}, {{end}}err := a.{{.Service.CamelName}}Impl.{{.PascalName}}(ctx{{if .Request}}, {{.Request.CamelName}}{{end}})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -298,7 +271,7 @@ func (a *{{.Service.PascalName}}API) {{.PascalName}}(ctx context.Context{{if .Re
{{- end}}
getNextPage := func(ctx context.Context, req {{ template "paginated-request-type" . }}) (*{{ .Response.PascalName }}, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "pagination")
return a.{{.Service.PascalName}}Service.{{.PascalName}}(ctx{{if .Request}}, req{{end}})
return a.{{.Service.CamelName}}Impl.{{.PascalName}}(ctx{{if .Request}}, req{{end}})
}
getItems := func(resp *{{ .Response.PascalName }}) []{{ template "type" .Pagination.Entity }} {
return {{if .Pagination.Results}}resp.{{.Pagination.Results.PascalName}}{{else}}resp{{end}}
Expand Down Expand Up @@ -411,7 +384,7 @@ func (a *{{.Service.PascalName}}API) GetBy{{range .NamedIdMap.NamePath}}{{.Pasca
{{end}}{{if .Shortcut}}
{{.Comment "// " 80}}
func (a *{{.Service.PascalName}}API) {{.Shortcut.PascalName}}(ctx context.Context{{range .Shortcut.Params}}, {{.CamelName}} {{template "type" .Entity}}{{end}}) {{ template "response-type" . }} {
return a.{{.Service.PascalName}}Service.{{.PascalName}}(ctx, {{.Request.PascalName}}{
return a.{{.Service.CamelName}}Impl.{{.PascalName}}(ctx, {{.Request.PascalName}}{
{{- range .Shortcut.Params}}
{{.PascalName}}: {{.CamelName}},{{end}}
})
Expand Down
122 changes: 13 additions & 109 deletions service/billing/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading