mongodb-atlas-cli
mongodb-atlas-cli copied to clipboard
Auto generation POC
⚠️ 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 todocker 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 runmake gen-openapi
on the same PR
Truly astonishing how close this looks compared to user written code.
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!
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!
reopen
@wtrocki I've decided to embrace our ideas and for json input/ouput works like a charm, fully functional now
@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
@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
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!
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!
bump
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!