Skip to content

feat: autogenerate go SDK example in the codeSample #772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 16, 2025

Conversation

andreaangiolillo
Copy link
Collaborator

@andreaangiolillo andreaangiolillo commented Jun 13, 2025

Proposed changes

This PR adds autogenerated example of the GO SDK in the openapi specification.

You can preview how the documentation will look using this bump.sh link

Redocly:

Screenshot 2025-06-13 at 14 42 26

@andreaangiolillo andreaangiolillo marked this pull request as ready for review June 13, 2025 12:37
@andreaangiolillo andreaangiolillo requested a review from a team as a code owner June 13, 2025 12:37
@@ -15,10 +15,14 @@
package filter

import (
"fmt"
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 changes were in this file. The files under tests were autogenerated.

@@ -121,6 +125,41 @@ func newAtlasCliCodeSamplesForOperation(op *openapi3.Operation) codeSample {
}
}

func (f *CodeSampleFilter) newGoSdkCodeSamplesForOperation(op *openapi3.Operation, opMethod string) codeSample {
version := strings.ReplaceAll(apiVersion(f.metadata.targetVersion), "-", "") + "001"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This field represents the SDK version. The value is formatted as YYYY-MM-DD-001, where 001 indicates the first SDK release for that API version. The last three digits are incremented for subsequent releases, but 001 will always be available as the initial version for each API version.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A bit curious on how this version stays in sync with the latest SDK version:

  1. Is this reference to the SDK version always being published before SDK?
  2. Or there is a mechanism for reading the latest SDK version?

Copy link
Collaborator Author

@andreaangiolillo andreaangiolillo Jun 13, 2025

Choose a reason for hiding this comment

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

No, neither of those options apply. I generate the SDK version by combining the API version in the format YYYY-DD.MM with 001 as the suffix, which represents the first release for any new API version and is always present. Subsequent releases for the same API version will follow the format YYYY-DD.MM-002, YYYY-DD.MM-003, and so on, but the example will always use the initial 001 release.
If I merge this, I will then create a ticket to improve this to check for the release in the sdk repo but I don't think is critical for the initial example since the 001 is always present.

@andreaangiolillo andreaangiolillo requested review from a team, wtrocki and EspenAlbert June 13, 2025 12:41
Comment on lines 45 to 46
sdk.UseBaseURL(url),
sdk.UseDebug(true))
Copy link
Collaborator

Choose a reason for hiding this comment

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

not for regular users

Copy link
Collaborator Author

@andreaangiolillo andreaangiolillo Jun 16, 2025

Choose a reason for hiding this comment

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

Thanks, I will update it. I was re-using the example we have in https://github.com/mongodb/atlas-sdk-go/blob/6e94e42d2d395dfab18b67bc0ebf2e5437df3b1e/examples/db_users/db_users.go#L28. Maybe I should update also the example there?

Copy link
Collaborator

Choose a reason for hiding this comment

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

check https://github.com/mongodb/atlas-sdk-go/blob/8971b03030c6ed9fc5f52c87d7d16be59e1eb498/examples/service_account_management/sa_management.go is a bit closer to a good enough example

Maybe I should update also the example there?

If you want, I'm not sure if that example wanted to show more than it needs to but for simplicity on openapi let's keep it simple here

@andreaangiolillo andreaangiolillo requested a review from gssbzn June 16, 2025 13:31
Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

LGTM

)

const goSDKTemplate = `import (
Copy link
Collaborator

Choose a reason for hiding this comment

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

[follow up] conmsider creating a sdk.go.tmpl file and using embedded here, using a template file will give you some code highlighting

@andreaangiolillo andreaangiolillo merged commit c435669 into main Jun 16, 2025
10 checks passed
@andreaangiolillo andreaangiolillo deleted the test_sdk_example branch June 16, 2025 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants