Skip to content

Conversation

@jeroenvervaeke
Copy link
Member

@jeroenvervaeke jeroenvervaeke commented Nov 5, 2024

Proposed changes

Generate internal/autogeneration/L1/commands.go based on openapi spec.

Added the following make targets:

  • make update-openapi-spec, download the latest version of the openapi spec
  • make gen-l1-commands, re-generates commands based on openapi spec

Updating the L1 command should be as much effort as running: make update-openapi-spec && make gen-l1-commands

I'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

@jeroenvervaeke jeroenvervaeke changed the base branch from master to auto-generation November 5, 2024 15:11
@jeroenvervaeke jeroenvervaeke marked this pull request as ready for review November 5, 2024 15:25
@jeroenvervaeke jeroenvervaeke requested a review from a team as a code owner November 5, 2024 15:25
@jeroenvervaeke jeroenvervaeke marked this pull request as draft November 5, 2024 17:09
@jeroenvervaeke jeroenvervaeke marked this pull request as ready for review November 6, 2024 09:44
// limitations under the License.

//nolint:revive,stylecheck
package L1
Copy link
Collaborator

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

Copy link
Member Author

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
Copy link
Collaborator

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

Copy link
Member Author

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
Copy link
Collaborator

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

Suggested change
gen-L1-commands: ## Generate L1 commands
gen-api-commands: ## Generate commands under `atlas api`

Copy link
Member Author

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) {
Copy link
Collaborator

@fmenezes fmenezes Nov 6, 2024

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?

Copy link
Member Author

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)
Copy link
Collaborator

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?

Copy link
Member Author

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!

Copy link
Member Author

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.

@jeroenvervaeke jeroenvervaeke merged commit 9e131dd into auto-generation Nov 7, 2024
16 checks passed
@jeroenvervaeke jeroenvervaeke deleted the CLOUDP-280740 branch November 7, 2024 11:47
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.

3 participants