Skip to content

feat: Support x-xgen-atlascli in Atlas CLI example generation - #1396

Merged
andreaangiolillo merged 4 commits into
mainfrom
sage-bot/CLOUDP-427938/sage-CLOUDP-427938-1785145516322
Jul 27, 2026
Merged

feat: Support x-xgen-atlascli in Atlas CLI example generation#1396
andreaangiolillo merged 4 commits into
mainfrom
sage-bot/CLOUDP-427938/sage-CLOUDP-427938-1785145516322

Conversation

@mongodb-sage-bot

@mongodb-sage-bot mongodb-sage-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

The OpenAPI spec examples are generated by foascli as part of the CD
pipeline. The Atlas CLI code sample (atlas api <tag> <operationId> --help) previously honored only the x-xgen-operation-id-override
extension, but atlascli also supports the x-xgen-atlascli extension to
override the operation ID used to build the command name.

This adds support for the x-xgen-atlascli extension in the Atlas CLI
code sample generation. The operation ID is read from the nested
override.operationId field and, mirroring atlascli's command
generation, takes priority over x-xgen-operation-id-override when both
are present.

Jira ticket: CLOUDP-427938

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works

Changes to Spectral

  • I have read the README file for Spectral Updates

Important

MongoDB Contribution Guidelines

This pull request was generated by sage-bot on behalf of andrea.angiolillo@mongodb.com (ticket assignee). The assignee must self-review the changes before requesting review from another engineer.
The assignee is not allowed to merge their own PR without approval from another engineer.

## Proposed changes

The OpenAPI spec examples are generated by foascli as part of the CD
pipeline. The Atlas CLI code sample (`atlas api <tag> <operationId>
--help`) previously honored only the `x-xgen-operation-id-override`
extension, but atlascli also supports the `x-xgen-atlascli` extension to
override the operation ID used to build the command name.

This adds support for the `x-xgen-atlascli` extension in the Atlas CLI
code sample generation. The operation ID is read from the nested
`override.operationId` field and, mirroring atlascli's command
generation, takes priority over `x-xgen-operation-id-override` when both
are present.

_Jira ticket:_ CLOUDP-427938

## Checklist

- [ ] I have signed the [MongoDB CLA](https://www.mongodb.com/legal/contributor-agreement)
- [x] I have added tests that prove my fix is effective or that my feature works

### Changes to Spectral
- [ ] I have read the [README](../tools/spectral/README.md) file for Spectral Updates
@mongodb-sage-bot

Copy link
Copy Markdown
Contributor Author

Sage Bot can help with this pull request. Just @sage-bot in comments and I'll start working on changes in this branch.
Learn more about Sage Bot

Comment thread tools/foas/openapi/filter/code_sample.go Outdated
@mongodb-sage-bot

mongodb-sage-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Git diff is blocked by policy, but my edits are complete and verified through the Read tool. The changes are focused and consistent.

Removed the x-xgen-atlascli priority override in the Atlas CLI code sample generation in tools/foas/openapi/filter/code_sample.go; now the Atlas CLI sample (atlas api ... --help) is only emitted when an operation does not define the x-xgen-atlascli extension, since atlascli owns command generation in that case, per @andreaangiolillo's review. Also deleted the now-unused atlasCliOperationIDOverride helper and updated the corresponding test case to assert no Atlas CLI sample is produced when the extension is present.

Address @andreaangiolillo's review feedback on the Atlas CLI example
generation. Instead of letting the x-xgen-atlascli operationId override
take priority over x-xgen-operation-id-override, the Atlas CLI code
sample is now only generated when the operation does not define the
x-xgen-atlascli extension, since atlascli owns the command generation in
that case.

Removed the atlasCliOperationIDOverride helper and the priority block in
newAtlasCliCodeSamplesForOperation, and gated the Atlas CLI sample in
includeCodeSamplesForOperation on the absence of the extension. Updated
the corresponding test case to assert that no Atlas CLI sample is emitted
when x-xgen-atlascli is set.
Comment thread tools/foas/openapi/filter/code_sample_test.go
@mongodb-sage-bot

mongodb-sage-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

The changes are complete and verified via the Read tool.

Updated the x-xgen-atlascli test fixture in tools/foas/openapi/filter/code_sample_test.go to use the realistic {"skip": true} shape instead of the non-representative override.operationId form, matching how the extension actually appears in the OpenAPI spec, as @andreaangiolillo pointed out. The test still asserts no Atlas CLI code sample is emitted when the extension is present.

@andreaangiolillo andreaangiolillo changed the title CLOUDP-427938: Support x-xgen-atlascli in Atlas CLI example generation feat: Support x-xgen-atlascli in Atlas CLI example generation Jul 27, 2026
Update the "stable api with x-xgen-atlascli skips the Atlas CLI code
sample" test case to define the extension as {"skip": true}, matching
how x-xgen-atlascli appears in the OpenAPI spec, per @andreaangiolillo's
review feedback. The previous fixture used a non-representative
override.operationId shape. Behavior is unchanged: the code sample
filter still emits no Atlas CLI sample when the extension is present.
Comment thread tools/foas/openapi/filter/code_sample.go
@mongodb-sage-bot

mongodb-sage-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

My changes are complete. Both the source logic and test cases are in place.

Refined the x-xgen-atlascli handling in tools/foas/openapi/filter/code_sample.go so the Atlas CLI code sample is emitted both when the extension is missing and when it's present with "skip": false, and is only suppressed when the extension sets "skip": true. Added a skipAtlasCliCodeSample helper that checks the skip flag and a new test case for the "skip": false path (sample emitted) alongside the existing "skip": true case (sample suppressed), addressing @andreaangiolillo's feedback.

Refine the x-xgen-atlascli handling in the Atlas CLI code sample
generation so the sample is emitted both when the extension is
missing and when it is present with "skip: false". The Atlas CLI
sample is now suppressed only when the extension explicitly sets
"skip: true", where atlascli owns command generation.

Introduces a skipAtlasCliCodeSample helper that inspects the
extension's "skip" flag, and adds a test case covering the
"skip: false" path (sample emitted) alongside the existing
"skip: true" case (sample suppressed), as requested by
@andreaangiolillo.

@andreaangiolillo andreaangiolillo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@andreaangiolillo
andreaangiolillo marked this pull request as ready for review July 27, 2026 11:09
@andreaangiolillo
andreaangiolillo requested a review from a team as a code owner July 27, 2026 11:09
@andreaangiolillo
andreaangiolillo merged commit 67c7f16 into main Jul 27, 2026
17 checks passed
@andreaangiolillo
andreaangiolillo deleted the sage-bot/CLOUDP-427938/sage-CLOUDP-427938-1785145516322 branch July 27, 2026 11:16
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.

2 participants