Skip to content

Commit c7188d1

Browse files
CLOUDP-322242: Add Service account curl example to OAS (#742)
1 parent a7801ac commit c7188d1

17 files changed

+55044
-24453
lines changed

.github/scripts/split_spec.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -eou pipefail
33

44
echo "Running FOAS CLI versions command"
5-
foascli versions -s openapi-foas.json -o ./openapi/v2/versions.json --env "${target_env:?}" --stability-level stable --stability-level preview
5+
foascli versions -s openapi-foas.json -o ./openapi/v2/versions.json --env "${target_env:?}" --stability-level stable --stability-level preview --stability-level upcoming
66

77
echo "Running FOAS CLI split command with the following --env=${target_env:?} and -o=./openapi/v2/openapi.json"
88

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ func (f *CodeSampleFilter) Apply() error {
5454
return nil
5555
}
5656

57-
func (f *CodeSampleFilter) newCurlCodeSamplesForOperation(pathName, opMethod string) codeSample {
57+
func (f *CodeSampleFilter) newDigestCurlCodeSamplesForOperation(pathName, opMethod string) codeSample {
5858
version := apiVersion(f.metadata.targetVersion)
59-
source := "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
59+
source := "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n " +
6060
"--header \"Accept: application/vnd.atlas." + version + "+json\" \\\n "
6161

6262
switch opMethod {
@@ -65,14 +65,37 @@ func (f *CodeSampleFilter) newCurlCodeSamplesForOperation(pathName, opMethod str
6565
case "DELETE":
6666
source += "-X " + opMethod + " \"https://cloud.mongodb.com" + pathName + "\""
6767
case "POST", "PATCH", "PUT":
68-
source += "--header \"Content-Type: application/vnd.atlas." + version + "+json\" \\\n "
68+
source += "--header \"Content-Type: application/json\" \\\n "
6969
source += "-X " + opMethod + " \"https://cloud.mongodb.com" + pathName + "\" \\\n "
7070
source += "-d " + "'{ <Payload> }'"
7171
}
7272

7373
return codeSample{
7474
Lang: "cURL",
75-
Label: "curl",
75+
Label: "curl (Digest)",
76+
Source: source,
77+
}
78+
}
79+
80+
func (f *CodeSampleFilter) newServiceAccountCurlCodeSamplesForOperation(pathName, opMethod string) codeSample {
81+
version := apiVersion(f.metadata.targetVersion)
82+
source := "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n " +
83+
"--header \"Accept: application/vnd.atlas." + version + "+json\" \\\n "
84+
85+
switch opMethod {
86+
case "GET":
87+
source += "-X " + opMethod + " \"https://cloud.mongodb.com" + pathName + "?pretty=true\""
88+
case "DELETE":
89+
source += "-X " + opMethod + " \"https://cloud.mongodb.com" + pathName + "\""
90+
case "POST", "PATCH", "PUT":
91+
source += "--header \"Content-Type: application/json\" \\\n "
92+
source += "-X " + opMethod + " \"https://cloud.mongodb.com" + pathName + "\" \\\n "
93+
source += "-d " + "'{ <Payload> }'"
94+
}
95+
96+
return codeSample{
97+
Lang: "cURL",
98+
Label: "curl (Service Accounts)",
7699
Source: source,
77100
}
78101
}
@@ -108,8 +131,9 @@ func (f *CodeSampleFilter) includeCodeSamplesForOperation(pathName, opMethod str
108131
}
109132

110133
op.Extensions[codeSampleExtensionName] = []codeSample{
111-
f.newCurlCodeSamplesForOperation(pathName, opMethod),
112134
newAtlasCliCodeSamplesForOperation(op),
135+
f.newServiceAccountCurlCodeSamplesForOperation(pathName, opMethod),
136+
f.newDigestCurlCodeSamplesForOperation(pathName, opMethod),
113137
}
114138
return nil
115139
}

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

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,22 @@ func TestCodeSampleFilter(t *testing.T) {
7676
Extensions: map[string]any{
7777
"x-sunset": "9999-12-31",
7878
"x-codeSamples": []codeSample{
79+
{
80+
Lang: "cURL",
81+
Label: "Atlas CLI",
82+
Source: "atlas api testOperationID --help",
83+
},
7984
{
8085
Lang: "cURL",
81-
Label: "curl",
82-
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
86+
Label: "curl (Service Accounts)",
87+
Source: "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n " +
8388
"--header \"Accept: application/vnd.atlas.2025-01-01+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
8489
},
8590
{
86-
Lang: "cURL",
87-
Label: "Atlas CLI",
88-
Source: "atlas api testOperationID --help",
91+
Lang: "cURL",
92+
Label: "curl (Digest)",
93+
Source: "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n " +
94+
"--header \"Accept: application/vnd.atlas.2025-01-01+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
8995
},
9096
},
9197
},
@@ -139,16 +145,22 @@ func TestCodeSampleFilter(t *testing.T) {
139145
Extensions: map[string]any{
140146
"x-sunset": "9999-12-31",
141147
"x-codeSamples": []codeSample{
148+
{
149+
Lang: "cURL",
150+
Label: "Atlas CLI",
151+
Source: "atlas api testOperationID --help",
152+
},
142153
{
143154
Lang: "cURL",
144-
Label: "curl",
145-
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
155+
Label: "curl (Service Accounts)",
156+
Source: "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n " +
146157
"--header \"Accept: application/vnd.atlas.preview+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
147158
},
148159
{
149-
Lang: "cURL",
150-
Label: "Atlas CLI",
151-
Source: "atlas api testOperationID --help",
160+
Lang: "cURL",
161+
Label: "curl (Digest)",
162+
Source: "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n " +
163+
"--header \"Accept: application/vnd.atlas.preview+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
152164
},
153165
},
154166
},
@@ -202,16 +214,22 @@ func TestCodeSampleFilter(t *testing.T) {
202214
Extensions: map[string]any{
203215
"x-sunset": "9999-12-31",
204216
"x-codeSamples": []codeSample{
217+
{
218+
Lang: "cURL",
219+
Label: "Atlas CLI",
220+
Source: "atlas api testOperationID --help",
221+
},
205222
{
206223
Lang: "cURL",
207-
Label: "curl",
208-
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
224+
Label: "curl (Service Accounts)",
225+
Source: "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n " +
209226
"--header \"Accept: application/vnd.atlas.2025-01-01.upcoming+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
210227
},
211228
{
212-
Lang: "cURL",
213-
Label: "Atlas CLI",
214-
Source: "atlas api testOperationID --help",
229+
Lang: "cURL",
230+
Label: "curl (Digest)",
231+
Source: "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n " +
232+
"--header \"Accept: application/vnd.atlas.2025-01-01.upcoming+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
215233
},
216234
},
217235
},

0 commit comments

Comments
 (0)