Skip to content
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

feat: create and generate template from template data for teams #238

Merged

Conversation

k3llymariee
Copy link
Contributor

@k3llymariee k3llymariee commented May 3, 2024

Continuing to work just with the teams data in the OpenAPI spec, generate a template based on the template data to add resource commands to the root command.

Note that the subcommands are based off of the spec's operationId (e.g. get-team and post-team vs get and create) and the flags for each subcommand are based off the param values (e.g. team-key and project-key vs team and project). I plan to update this is in the next PR where we add the remaining resources from the openapi spec.

running teams --help
image

running teams get-team --help
image

checking that required flags are set:
image

return use
return strcase.ToKebab(op.OperationID)

// TODO: work with operation ID & response type to stripe out resource name and update post -> create, get -> list, etc.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

see comment in main description - going to bring this back in but for now, to remove duplicate subcommands, using just the OperationId

Comment on lines +56 to +60
func jsonString(s string) string {
bs, _ := json.Marshal(s)
return string(bs)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have all kinds of markdown stuff in the descriptions of resources and endpoints that was causing the template to throw errors - marshaling to json and returning that string to help!

@@ -29,6 +29,7 @@ type TemplateData struct {

type ResourceData struct {
Name string
DisplayName string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can also pass in functions to the template to handle converting these values from camel/kebab, which I might do in a refactor

"strings"

"github.com/getkin/kin-openapi/openapi3"
"github.com/iancoleman/strcase"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hoping it's ok to use this (..stripe does 🙃)

@k3llymariee k3llymariee marked this pull request as ready for review May 3, 2024 00:13
@k3llymariee k3llymariee requested a review from dbolson May 3, 2024 00:16
)
{{ end }}

// Operation commands{{ range $resName, $resData := .Resources }}{{ range $opName, $opData := $resData.Operations }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you break these range calls out into separate lines to more easily see the nesting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it'll add an extra line between then comment and the following commands which bothers me only very slightly 🙃

@k3llymariee k3llymariee merged commit bf2f0a1 into main May 3, 2024
2 checks passed
@k3llymariee k3llymariee deleted the kelly/sc-241153/generate-resource-cmds-from-template branch May 3, 2024 16:45
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