Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 Account Access Token)",
Copy link
Member

Choose a reason for hiding this comment

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

could the label be shorter but still helpful?

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.

CC @gssbzn since he proposed the name (before it was Service Account). Is Service Account too generic? Could Service Account mean something else than Access Token in this context?

Copy link
Member

Choose a reason for hiding this comment

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

i was about to propose that :-) if you see the screenshot in the PR description, it seems too long, but ok if we think this is the shortest label that makes it understable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see in the Spec we have Service accounts (oauth2) (https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/) so I can use Service accounts - oauth2 which is shorter but still long.
I am going to update it to Service accounts - oauth2 for consistency and see if it is still too long.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I asked our PM for his preference in https://mongodb.slack.com/archives/C02FHQ614UR/p1749032541122489. Let's wait and see

Copy link
Contributor

Choose a reason for hiding this comment

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

my fear with just service account is that you don't use the service account you need to get an access token, it would be good if we could link to how to get the access token but I'm not sure if that's possible on examples

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

would be good if we could link to how to get the access token but I'm not sure if that's possible on examples

This is the only way I have to add link:

Screenshot 2025-06-04 at 16 35 36

Copy link
Contributor

Choose a reason for hiding this comment

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

works for me

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Stephen's feedback
073f8eb

  1. Use the name "Service Accounts" for curl examples
  2. Include the AtlasCLI example first in the list

Source: source,
}
}
Expand Down Expand Up @@ -108,7 +131,8 @@ func (f *CodeSampleFilter) includeCodeSamplesForOperation(pathName, opMethod str
}

op.Extensions[codeSampleExtensionName] = []codeSample{
f.newCurlCodeSamplesForOperation(pathName, opMethod),
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

newAtlasCliCodeSamplesForOperation(op),
}
return nil
Expand Down
30 changes: 24 additions & 6 deletions tools/cli/internal/openapi/filter/code_sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ func TestCodeSampleFilter(t *testing.T) {
"x-codeSamples": []codeSample{
{
Lang: "cURL",
Label: "curl",
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
Label: "curl (Service Account Access Token)",
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: "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 @@ -141,8 +147,14 @@ func TestCodeSampleFilter(t *testing.T) {
"x-codeSamples": []codeSample{
{
Lang: "cURL",
Label: "curl",
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
Label: "curl (Service Account Access Token)",
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: "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 @@ -204,8 +216,14 @@ func TestCodeSampleFilter(t *testing.T) {
"x-codeSamples": []codeSample{
{
Lang: "cURL",
Label: "curl",
Source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n " +
Label: "curl (Service Account Access Token)",
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: "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