-
Notifications
You must be signed in to change notification settings - Fork 1
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: generate remaining resources commands from openapi spec #244
feat: generate remaining resources commands from openapi spec #244
Conversation
@@ -301,7 +267,13 @@ func (op *OperationCmd) makeRequest(cmd *cobra.Command, args []string) error { | |||
return errors.NewError(output.CmdOutputError(viper.GetString(cliflags.OutputFlag), err)) | |||
} | |||
|
|||
output, err := output.CmdOutput("get", viper.GetString(cliflags.OutputFlag), res) | |||
if string(res) == "" { |
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.
we have a few PUT
endpoints that also don't return a response body
if len(maybeResources.Items) == 0 { | ||
return "No items found", nil | ||
} |
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.
sneaking this in here - noticed that we panic if no items are returned in a response body
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.
Does this only happen when there is not response body?
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.
it happens when a response body is returned but the items are empty
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.
What's an example? Is it something we would possibly want to show in the command's response?
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.
if you ran ldcli teams list
and your account had no teams, the json response would be:
{
"items": [],
"_links": {
"self": {
"href": "/api/v2/teams?limit=20",
"type": "application/json"
}
},
"totalCount": 0
}
return action | ||
} | ||
|
||
func isListResponse(op *openapi3.Operation, spec *openapi3.T) bool { |
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 love this but don't have a better way of determining when to use list
vs get
inviteCmd, err := NewInviteCmd(client) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cmd.AddCommand(createCmd) |
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.
leaving members Invite in here for now.. not sure how we want to handle aliases in the New World
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'll play around with this, but we can merge to unblock.
cmd/resources/resource_utils.go
Outdated
func removeResourceFromOperationId(resourceName, operationId string) string { | ||
// operations use both singular (Team) and plural (Teams) resource names, whereas resource names are (usually) plural | ||
var singularResourceName string | ||
if string(resourceName[len(resourceName)-1]) == "s" { |
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.
This could be easier to read with strings.HasSuffix("teams", "s")
and then use strings.TrimRight("teams", "s")
cmd/resources/resource_utils.go
Outdated
} | ||
|
||
// if the schema is nil, there is no response body for the request | ||
if schema != nil { |
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.
Reversing the nil check would remove a layer of indentation.
if schema == nil {
return false
}
for propName := range schema.Value.Properties {
...
if len(maybeResources.Items) == 0 { | ||
return "No items found", nil | ||
} |
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.
Does this only happen when there is not response body?
for a full list of commands/subcommands/flags, which might be more helpful than reviewing the output (
resource_cmds.go
): https://docs.google.com/spreadsheets/d/1VDiDi8sb4MfySWNJzl8rjm1uOGdCrvNBUimIJfYzCZY/edit#gid=11036841there are probably still a few commands/flags to clean up but if I don't put this up for review now it'll never go up 😅