Skip to content

Commit c4628b2

Browse files
authored
chore: Export SDK functions needed by Terraform UntypedAPICall func (#601)
1 parent 55b8c8f commit c4628b2

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

admin/client.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ var (
3434
// APIClient manages communication with the MongoDB Atlas Administration API API
3535
// In most cases there should be only one, shared, APIClient.
3636
type APIClient struct {
37-
cfg *Configuration
38-
common service // Reuse a single struct instead of allocating one for each service on the heap.
37+
cfg *Configuration
38+
common service // Reuse a single struct instead of allocating one for each service on the heap.
39+
UntypedClient UntypedClient // Make API calls without using a typed model.
3940

4041
// API Services
4142

@@ -154,6 +155,7 @@ func NewAPIClient(cfg *Configuration) *APIClient {
154155
c := &APIClient{}
155156
c.cfg = cfg
156157
c.common.client = c
158+
c.UntypedClient.client = c
157159

158160
// API Services
159161
c.AWSClustersDNSApi = (*AWSClustersDNSApiService)(&c.common)
@@ -356,7 +358,8 @@ type formFile struct {
356358
// prepareRequest build the request
357359
func (c *APIClient) prepareRequest(
358360
ctx context.Context,
359-
path string, method string,
361+
path string,
362+
method string,
360363
postBody any,
361364
headerParams map[string]string,
362365
queryParams url.Values,
@@ -689,3 +692,27 @@ func FormatErrorMessageWithDetails(status, path, method string, v ApiError) stri
689692
method, path, status, v.GetErrorCode(),
690693
v.GetDetail(), v.GetReason(), v.GetParameters(), badRequestDetailString)
691694
}
695+
696+
type UntypedClient struct {
697+
client *APIClient
698+
}
699+
700+
func (u *UntypedClient) PrepareRequest(
701+
ctx context.Context,
702+
path string,
703+
method string,
704+
postBody any,
705+
headerParams map[string]string,
706+
queryParams url.Values,
707+
formParams url.Values,
708+
formFiles []formFile) (localVarRequest *http.Request, err error) {
709+
return u.client.prepareRequest(ctx, path, method, postBody, headerParams, queryParams, formParams, formFiles)
710+
}
711+
712+
func (u *UntypedClient) CallAPI(request *http.Request) (*http.Response, error) {
713+
return u.client.callAPI(request)
714+
}
715+
716+
func (u *UntypedClient) MakeApiError(res *http.Response, httpMethod, httpPath string) error {
717+
return u.client.makeApiError(res, httpMethod, httpPath)
718+
}

tools/config/go-templates/client.mustache

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var (
4040
type APIClient struct {
4141
cfg *Configuration
4242
common service // Reuse a single struct instead of allocating one for each service on the heap.
43+
UntypedClient UntypedClient // Make API calls without using a typed model.
4344
4445
// API Services
4546
{{#apiInfo}}
@@ -66,6 +67,7 @@ func NewAPIClient(cfg *Configuration) *APIClient {
6667
c := &APIClient{}
6768
c.cfg = cfg
6869
c.common.client = c
70+
c.UntypedClient.client = c
6971

7072
{{#apiInfo}}
7173
// API Services
@@ -227,7 +229,8 @@ type formFile struct {
227229
// prepareRequest build the request
228230
func (c *APIClient) prepareRequest(
229231
ctx context.Context,
230-
path string, method string,
232+
path string,
233+
method string,
231234
postBody any,
232235
headerParams map[string]string,
233236
queryParams url.Values,
@@ -579,3 +582,27 @@ func FormatErrorMessageWithDetails(status, path, method string, v ApiError) stri
579582
method, path, status, v.GetErrorCode(),
580583
v.GetDetail(), v.GetReason(), v.GetParameters(), badRequestDetailString)
581584
}
585+
586+
type UntypedClient struct {
587+
client *APIClient
588+
}
589+
590+
func (u *UntypedClient) PrepareRequest(
591+
ctx context.Context,
592+
path string,
593+
method string,
594+
postBody any,
595+
headerParams map[string]string,
596+
queryParams url.Values,
597+
formParams url.Values,
598+
formFiles []formFile) (localVarRequest *http.Request, err error) {
599+
return u.client.prepareRequest(ctx, path, method, postBody, headerParams, queryParams, formParams, formFiles)
600+
}
601+
602+
func (u *UntypedClient) CallAPI(request *http.Request) (*http.Response, error) {
603+
return u.client.callAPI(request)
604+
}
605+
606+
func (u *UntypedClient) MakeApiError(res *http.Response, httpMethod, httpPath string) error {
607+
return u.client.makeApiError(res, httpMethod, httpPath)
608+
}

0 commit comments

Comments
 (0)