Skip to content

Commit 02f5a9c

Browse files
fix wind test
1 parent 2759c53 commit 02f5a9c

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

tools/cli/internal/openapi/filter/code_sample.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package filter
1616

1717
import (
1818
"bytes"
19+
"embed"
1920
_ "embed"
2021
"fmt"
2122
goFormat "go/format"
@@ -29,8 +30,8 @@ import (
2930
"golang.org/x/text/language"
3031
)
3132

32-
//go:embed go_sdk_code_sample.go.tmpl
33-
var goSDKTemplate string
33+
//go:embed template/*
34+
var templatesDir embed.FS
3435

3536
const codeSampleExtensionName = "x-codeSamples"
3637

@@ -137,8 +138,11 @@ func (f *CodeSampleFilter) newGoSdkCodeSamplesForOperation(op *openapi3.Operatio
137138
operationID := cases.Title(language.English, cases.NoLower).String(op.OperationID)
138139
tag := strings.ReplaceAll(op.Tags[0], " ", "")
139140
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))
142146
if err != nil {
143147
return nil, err
144148
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

0 commit comments

Comments
 (0)