-
Notifications
You must be signed in to change notification settings - Fork 3
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: generic api request function #218
feat: generic api request function #218
Conversation
@@ -1,42 +0,0 @@ | |||
package cmd_test |
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.
file was changed & moved not deleted
@@ -1,19 +1,18 @@ | |||
// this file WILL be generated (sc-241153) | |||
|
|||
package cmd |
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.
changes here are just due to moving the files
"ldcli/internal/errors" | ||
) | ||
|
||
type Client interface { |
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.
made a new interface for testing but had an issue with passing in data to the mock client, will try to tackle in follow up PR
var val interface{} | ||
switch p.Type { | ||
case "string": | ||
val = viper.GetString(p.Name) | ||
case "boolean": | ||
val = viper.GetBool(p.Name) | ||
case "int": | ||
val = viper.GetInt(p.Name) |
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 think it's actually ok to just grab all of these as string since we're just passing them into the query param or url anyway
cmd/resources/resource_cmds_test.go
Outdated
require.NoError(t, err) | ||
assert.Contains(t, string(output), "Create a team.") | ||
}) | ||
// TODO: add back test when mock client is added |
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.
You can use t.Skip("reason")
instead of commenting-out the code so we'll see the skipped test when running the rest of the tests.
cmd/resources/resources.go
Outdated
if val != "" { | ||
switch p.In { | ||
case "path": | ||
urlParms = append(urlParms, fmt.Sprintf("%v", val)) |
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.
Since val
is a string, I don't think we need the Sprintf
.
cmd/resources/resources.go
Outdated
@@ -97,41 +112,81 @@ func (op *OperationCmd) initFlags() error { | |||
return nil | |||
} | |||
|
|||
func (op *OperationCmd) makeRequest(cmd *cobra.Command, args []string) error { | |||
paramVals := map[string]interface{}{} | |||
func formatURL(baseURI, path string, urlParams []string) 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.
Could you make this more descriptive about how it's interpolating the placeholders in the URL with the urlParams?
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.
changed to buildURLWithParams
cmd/resources/resources.go
Outdated
jsonData, | ||
) | ||
if err != nil { | ||
out, err := output.CmdOutputSingular( |
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.
You can use a simpler function now.
cmd/resources/resources.go
Outdated
path := formatURL(viper.GetString(cliflags.BaseURIFlag), op.Path, urlParms) | ||
|
||
contentType := "application/json" | ||
if op.SupportsSemanticPatch && viper.GetBool("semantic-patch") { |
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 don't think we need to check op.SupportsSemanticPatch
here since viper will ignore the flag if it hasn't been set above.
Adds a new client and method to make generic API requests based on the openapi operation structs we'll be creating for each endpoint.