Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/scripts/split_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eou pipefail

echo "Running FOAS CLI versions command"
foascli versions -s openapi-foas.json -o ./openapi/v2/versions.json --env "${target_env:?}" --stability-level stable --stability-level preview
foascli versions -s openapi-foas.json -o ./openapi/v2/versions.json --env "${target_env:?}" --stability-level stable --stability-level preview --stability-level upcoming
Copy link
Collaborator Author

@andreaangiolillo andreaangiolillo Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive by fix to list upcoming api versions in the version.json file


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

Expand Down
34 changes: 29 additions & 5 deletions tools/cli/internal/openapi/filter/code_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func (f *CodeSampleFilter) Apply() error {
return nil
}

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

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

return codeSample{
Lang: "cURL",
Label: "curl",
Label: "curl (Digest)",
Source: source,
}
}

func (f *CodeSampleFilter) newServiceAccountCurlCodeSamplesForOperation(pathName, opMethod string) codeSample {
version := apiVersion(f.metadata.targetVersion)
source := "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n " +
"--header \"Accept: application/vnd.atlas." + version + "+json\" \\\n "

switch opMethod {
case "GET":
source += "-X " + opMethod + " \"https://cloud.mongodb.com" + pathName + "?pretty=true\""
case "DELETE":
source += "-X " + opMethod + " \"https://cloud.mongodb.com" + pathName + "\""
case "POST", "PATCH", "PUT":
source += "--header \"Content-Type: application/json\" \\\n "
source += "-X " + opMethod + " \"https://cloud.mongodb.com" + pathName + "\" \\\n "
source += "-d " + "'{ <Payload> }'"
}

return codeSample{
Lang: "cURL",
Label: "curl (Service Accounts)",
Source: source,
}
}
Expand Down Expand Up @@ -108,8 +131,9 @@ func (f *CodeSampleFilter) includeCodeSamplesForOperation(pathName, opMethod str
}

op.Extensions[codeSampleExtensionName] = []codeSample{
f.newCurlCodeSamplesForOperation(pathName, opMethod),
newAtlasCliCodeSamplesForOperation(op),
f.newServiceAccountCurlCodeSamplesForOperation(pathName, opMethod),
f.newDigestCurlCodeSamplesForOperation(pathName, opMethod),
Comment on lines +135 to +136
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main change is here

}
return nil
}
48 changes: 33 additions & 15 deletions tools/cli/internal/openapi/filter/code_sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,22 @@ func TestCodeSampleFilter(t *testing.T) {
Extensions: map[string]any{
"x-sunset": "9999-12-31",
"x-codeSamples": []codeSample{
{
Lang: "cURL",
Label: "Atlas CLI",
Source: "atlas api testOperationID --help",
},
{
Lang: "cURL",
Label: "curl",
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
Label: "curl (Service Accounts)",
Source: "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n " +
"--header \"Accept: application/vnd.atlas.2025-01-01+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
},
{
Lang: "cURL",
Label: "Atlas CLI",
Source: "atlas api testOperationID --help",
Lang: "cURL",
Label: "curl (Digest)",
Source: "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n " +
"--header \"Accept: application/vnd.atlas.2025-01-01+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
},
},
},
Expand Down Expand Up @@ -139,16 +145,22 @@ func TestCodeSampleFilter(t *testing.T) {
Extensions: map[string]any{
"x-sunset": "9999-12-31",
"x-codeSamples": []codeSample{
{
Lang: "cURL",
Label: "Atlas CLI",
Source: "atlas api testOperationID --help",
},
{
Lang: "cURL",
Label: "curl",
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
Label: "curl (Service Accounts)",
Source: "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n " +
"--header \"Accept: application/vnd.atlas.preview+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
},
{
Lang: "cURL",
Label: "Atlas CLI",
Source: "atlas api testOperationID --help",
Lang: "cURL",
Label: "curl (Digest)",
Source: "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n " +
"--header \"Accept: application/vnd.atlas.preview+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
},
},
},
Expand Down Expand Up @@ -202,16 +214,22 @@ func TestCodeSampleFilter(t *testing.T) {
Extensions: map[string]any{
"x-sunset": "9999-12-31",
"x-codeSamples": []codeSample{
{
Lang: "cURL",
Label: "Atlas CLI",
Source: "atlas api testOperationID --help",
},
{
Lang: "cURL",
Label: "curl",
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
Label: "curl (Service Accounts)",
Source: "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n " +
"--header \"Accept: application/vnd.atlas.2025-01-01.upcoming+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
},
{
Lang: "cURL",
Label: "Atlas CLI",
Source: "atlas api testOperationID --help",
Lang: "cURL",
Label: "curl (Digest)",
Source: "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n " +
"--header \"Accept: application/vnd.atlas.2025-01-01.upcoming+json\" \\\n " + "-X GET \"https://cloud.mongodb.com/test?pretty=true\"",
},
},
},
Expand Down
Loading
Loading