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: generate remaining resources commands from openapi spec #244

Merged
merged 14 commits into from
May 6, 2024

Conversation

k3llymariee
Copy link
Contributor

@k3llymariee k3llymariee commented May 6, 2024

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=11036841

there 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 😅

@@ -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) == "" {
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 a few PUT endpoints that also don't return a response body

Comment on lines +49 to +51
if len(maybeResources.Items) == 0 {
return "No items found", nil
}
Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

@k3llymariee k3llymariee May 6, 2024

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

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

@k3llymariee k3llymariee marked this pull request as ready for review May 6, 2024 21:35
@k3llymariee k3llymariee requested a review from dbolson May 6, 2024 21:35
Copy link
Contributor

@dbolson dbolson left a 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.

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" {
Copy link
Contributor

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")

}

// if the schema is nil, there is no response body for the request
if schema != nil {
Copy link
Contributor

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 {
    ...

Comment on lines +49 to +51
if len(maybeResources.Items) == 0 {
return "No items found", nil
}
Copy link
Contributor

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?

@k3llymariee k3llymariee merged commit e78e32b into main May 6, 2024
2 checks passed
@k3llymariee k3llymariee deleted the kelly/sc-241298/generate-entire-openapi-spec branch May 6, 2024 23:31
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