-
Couldn't load subscription status.
- Fork 88
CLOUDP-280740: Create a tool to generate L1 commands and tags #3372
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
Conversation
65cf2f7 to
331ca36
Compare
…ncluded in git this time...
internal/autogeneration/L1/l1.go
Outdated
| // limitations under the License. | ||
|
|
||
| //nolint:revive,stylecheck | ||
| package L1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of a package called L1 can we have a more meaningful name?
If these commands are expected to be under atlas api perhaps internal/api? or maybe internal/api/generated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion, I couldn't find a better name.
I've renamed everything.
| Required bool | ||
| } | ||
|
|
||
| type HTTPVerb string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we simply reuse http package here? we have http.MethodGet, http.MethodPost, etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, I've changed it
Makefile
Outdated
| go run ./tools/cli-generator | ||
|
|
||
| .PHONY: gen-l1-commands | ||
| gen-L1-commands: ## Generate L1 commands |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the L1 naming something not easy to navigate, especially by external contributors which would not have context
| gen-L1-commands: ## Generate L1 commands | |
| gen-api-commands: ## Generate commands under `atlas api` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed it
|
|
||
| func ToHTTPVerb(s string) (HTTPVerb, error) { | ||
| verb := HTTPVerb(strings.ToUpper(s)) | ||
| func ToHTTPVerb(s string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[q] why do we need this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To map from string to a http.Method[verb]
| }() | ||
|
|
||
| loader := openapi3.NewLoader() | ||
| return loader.LoadFromIoReader(file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[q] does it make sense to validate the spec? would the loader fail if download script broke in the middle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was assuming that load would validate, but apparently, the spec has a validate method. I'll add the validation!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've enabled spec validation. I had to disable example validation and regex validation because the spec is using a regex pattern that's not supported in Go.
Proposed changes
Generate
internal/autogeneration/L1/commands.gobased on openapi spec.Added the following make targets:
make update-openapi-spec, download the latest version of the openapi specmake gen-l1-commands, re-generates commands based on openapi specUpdating the L1 command should be as much effort as running:
make update-openapi-spec && make gen-l1-commandsI'm using https://github.com/bradleyjkemp/cupaloy for snapshot testing.
This will make it easier to keep track of changes in the generation code.
Also added tests to clean up HTML and markdown in the openapi descriptions
Jira ticket: CLOUDP-280740