Skip to content

Commit 3cc58f8

Browse files
CLOUDP-322242: Add Service account curl example to OAS
1 parent a7801ac commit 3cc58f8

17 files changed

+35868
-5277
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: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ 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)
5959
source := "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
6060
"--header \"Accept: application/vnd.atlas." + version + "+json\" \\\n "
@@ -72,7 +72,30 @@ func (f *CodeSampleFilter) newCurlCodeSamplesForOperation(pathName, opMethod str
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/vnd.atlas." + version + "+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 Account)",
7699
Source: source,
77100
}
78101
}
@@ -108,7 +131,8 @@ func (f *CodeSampleFilter) includeCodeSamplesForOperation(pathName, opMethod str
108131
}
109132

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

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ func TestCodeSampleFilter(t *testing.T) {
7878
"x-codeSamples": []codeSample{
7979
{
8080
Lang: "cURL",
81-
Label: "curl",
81+
Label: "curl (Service Account)",
82+
Source: "curl --header \"Authorization: Bearer {ACCESS-TOKEN}\" \\\n " +
83+
"--header \"Accept: application/vnd.atlas.2025-01-01+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
84+
},
85+
{
86+
Lang: "cURL",
87+
Label: "curl (Digest)",
8288
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
8389
"--header \"Accept: application/vnd.atlas.2025-01-01+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
8490
},
@@ -141,7 +147,13 @@ func TestCodeSampleFilter(t *testing.T) {
141147
"x-codeSamples": []codeSample{
142148
{
143149
Lang: "cURL",
144-
Label: "curl",
150+
Label: "curl (Service Account)",
151+
Source: "curl --header \"Authorization: Bearer {ACCESS-TOKEN}\" \\\n " +
152+
"--header \"Accept: application/vnd.atlas.preview+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
153+
},
154+
{
155+
Lang: "cURL",
156+
Label: "curl (Digest)",
145157
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
146158
"--header \"Accept: application/vnd.atlas.preview+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
147159
},
@@ -204,7 +216,13 @@ func TestCodeSampleFilter(t *testing.T) {
204216
"x-codeSamples": []codeSample{
205217
{
206218
Lang: "cURL",
207-
Label: "curl",
219+
Label: "curl (Service Account)",
220+
Source: "curl --header \"Authorization: Bearer {ACCESS-TOKEN}\" \\\n " +
221+
"--header \"Accept: application/vnd.atlas.2025-01-01.upcoming+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
222+
},
223+
{
224+
Lang: "cURL",
225+
Label: "curl (Digest)",
208226
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
209227
"--header \"Accept: application/vnd.atlas.2025-01-01.upcoming+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
210228
},

0 commit comments

Comments
 (0)