File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed
tools/cli/internal/openapi/filter Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ package filter
16
16
17
17
import (
18
18
"bytes"
19
+ "embed"
19
20
_ "embed"
20
21
"fmt"
21
22
goFormat "go/format"
@@ -29,8 +30,8 @@ import (
29
30
"golang.org/x/text/language"
30
31
)
31
32
32
- //go:embed go_sdk_code_sample.go.tmpl
33
- var goSDKTemplate string
33
+ //go:embed template/*
34
+ var templatesDir embed. FS
34
35
35
36
const codeSampleExtensionName = "x-codeSamples"
36
37
@@ -137,8 +138,11 @@ func (f *CodeSampleFilter) newGoSdkCodeSamplesForOperation(op *openapi3.Operatio
137
138
operationID := cases .Title (language .English , cases .NoLower ).String (op .OperationID )
138
139
tag := strings .ReplaceAll (op .Tags [0 ], " " , "" )
139
140
tag = strings .ReplaceAll (tag , "." , "" )
140
-
141
- t , err := template .New ("goSDK" ).Parse (goSDKTemplate )
141
+ file , err := templatesDir .ReadFile ("template/go_sdk_code_sample.go.tmpl" )
142
+ if err != nil {
143
+ return nil , err
144
+ }
145
+ t , err := template .New ("goSDK" ).Parse (string (file ))
142
146
if err != nil {
143
147
return nil , err
144
148
}
Original file line number Diff line number Diff line change
1
+ import (
2
+ "os"
3
+ "context"
4
+ "log"
5
+ sdk "go.mongodb.org/atlas-sdk/v{{ .Version }}/admin"
6
+ )
7
+
8
+ func main() {
9
+ ctx := context.Background()
10
+ clientID := os.Getenv("MONGODB_ATLAS_CLIENT_ID")
11
+ clientSecret := os.Getenv("MONGODB_ATLAS_CLIENT_SECRET")
12
+
13
+ // See https://dochub.mongodb.org/core/atlas-go-sdk-oauth
14
+ client, err := sdk.NewClient(
15
+ sdk.UseOAuthAuth(clientID, clientSecret),
16
+ sdk.UseBaseURL(url))
17
+
18
+ if err != nil {
19
+ log.Fatalf("Error: %v", err)
20
+ }
21
+
22
+ params = &sdk.{{ .OperationID }}ApiParams{}
23
+ {{ if eq .Method "DELETE" }} httpResp, err := client.{{ .Tag }}Api.
24
+ {{ .OperationID }}WithParams(ctx, params).
25
+ Execute(){{ else }} sdkResp, httpResp, err := client.{{ .Tag }}Api.
26
+ {{ .OperationID }}WithParams(ctx, params).
27
+ Execute(){{ end}}
28
+ }
You can’t perform that action at this time.
0 commit comments