mongodb-atlas-cli icon indicating copy to clipboard operation
mongodb-atlas-cli copied to clipboard

Auto generation POC

Open fmenezes opened this issue 1 year ago • 11 comments

⚠️ DO NOT MERGE ⚠️

Jiras: CLOUDP-179039, CLOUDP-181608

This is a POC of auto-generating commands using openapi-generator-cli

Demo

https://github.com/mongodb/mongodb-atlas-cli/assets/1765216/bae365c3-8c8d-40a0-9e8e-89b077ea4882

Design

  • Some design choices were made considering scripted usage only and non-interactive commands.
  • All commands that pass a request body to the API have to pass a json via --file or standard input
  • Unlike our CLI today there is no --output instead all commands write json and have a --format that you can use to filter data (similar to docker inspect)
  • Watchers are possible to implement but require manual intervention (ref)
  • Docs are taken straight from the API, but can be customized (example)
  • commands are grouped following how our APIs are grouped, so there is no deep nesting for commands anymore
  • all generated commands are under atlas api

Considerations

  • I've used https://openapi-generator.tech/ to generate commands straight from open API spec, currently I'm downloading the transformed openapi spec that SDK is using, which is a requirement given we need our data types matching across given we use SDK in the generated code.
  • I'm using go.mod to fetch which version of SDK is currently used so regenerating commands would be dependent on SDK upgrades, as in a PR is opened to update SDK and we run make gen-openapi on the same PR

fmenezes avatar May 24 '23 14:05 fmenezes

Truly astonishing how close this looks compared to user written code.

wtrocki avatar Jun 02 '23 17:06 wtrocki

This PR has gone 30 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 30 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

github-actions[bot] avatar Jul 07 '23 00:07 github-actions[bot]

This PR has gone 30 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 30 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

github-actions[bot] avatar Aug 07 '23 00:08 github-actions[bot]

reopen

fmenezes avatar Sep 20 '23 14:09 fmenezes

@wtrocki I've decided to embrace our ideas and for json input/ouput works like a charm, fully functional now

fmenezes avatar Sep 22 '23 10:09 fmenezes

@fmenezes Since the last break we also squashed all oneOf objects into flattened structures. That also makes things much easier as it removes the need for a generator to pick types.

We still have problems with mutually exclusive fields that need to be figured out somehow otherwise end users have the burden of figuring out what fields to use. Right now we have manual validation. For example here: https://github.com/mongodb/mongodb-atlas-cli/pull/2208

wtrocki avatar Sep 22 '23 10:09 wtrocki

@fmenezes Since the last break we also squashed all oneOf objects into flattened structures. That also makes things much easier as it removes the need for a generator to pick types.

We still have problems with mutually exclusive fields that need to be figured out somehow otherwise end users have the burden of figuring out what fields to use. Right now we have manual validation. For example here: #2208

I'll talk to Product but I think our goal here is for scripting in which API errors would be expected, main point is people would be directed to API spec/SDK docs in order to understand things

fmenezes avatar Sep 22 '23 16:09 fmenezes

This PR has gone 30 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 30 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

github-actions[bot] avatar Dec 01 '23 00:12 github-actions[bot]

This PR has gone 30 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 30 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

github-actions[bot] avatar Feb 03 '24 00:02 github-actions[bot]

bump

tibulca avatar Feb 04 '24 21:02 tibulca

This PR has gone 30 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 30 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

github-actions[bot] avatar Mar 07 '24 00:03 github-actions[bot]