Skip to content

Commit

Permalink
chore: update generated action configs name (#1608)
Browse files Browse the repository at this point in the history
  • Loading branch information
RutZap authored Sep 24, 2024
1 parent ae987d9 commit 2679658
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
22 changes: 21 additions & 1 deletion tools/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (g *Generator) scaffoldTools() {
Config: &toolsproto.ActionConfig{
Id: action.Name,
ApiNames: g.Schema.FindApiNames(model.Name, action.Name),
Name: casing.ToSentenceCase(action.Name),
Name: makeActionName(action),
ActionName: action.GetName(),
ModelName: model.GetName(),
ActionType: action.GetType(),
Expand Down Expand Up @@ -723,6 +723,26 @@ func (g *Generator) makeTitle(action *proto.Action, model *proto.Model) *toolspr
return nil
}

// makeActionName will create a name for the action. Get, Read and List actions will have their prefixes removed;
// e.g.:
// getOrder => Order
// listOrders => Orders
// createOrder = Create order
// updateOrder => Update order
// readOrders => Orders
func makeActionName(action *proto.Action) string {
switch action.Type {
case proto.ActionType_ACTION_TYPE_GET:
return casing.ToSentenceCase(strings.TrimPrefix(action.Name, "get"))
case proto.ActionType_ACTION_TYPE_LIST:
return casing.ToSentenceCase(strings.TrimPrefix(action.Name, "list"))
case proto.ActionType_ACTION_TYPE_READ:
return casing.ToSentenceCase(strings.TrimPrefix(action.Name, "read"))
default:
return casing.ToSentenceCase(action.Name)
}
}

// getPageInfoResponses will return the responses for pageInfo (by default available on all autogenerated LIST actions)
func getPageInfoResponses() []*toolsproto.ResponseFieldConfig {
return []*toolsproto.ResponseFieldConfig{
Expand Down
12 changes: 6 additions & 6 deletions tools/testdata/blog/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
},
{
"id": "getCategory",
"name": "Get category",
"name": "Category",
"actionName": "getCategory",
"apiNames": ["Api"],
"modelName": "Category",
Expand Down Expand Up @@ -552,7 +552,7 @@
},
{
"id": "getPost",
"name": "Get post",
"name": "Post",
"actionName": "getPost",
"apiNames": ["Api"],
"modelName": "BlogPost",
Expand Down Expand Up @@ -747,7 +747,7 @@
},
{
"id": "listCategories",
"name": "List categories",
"name": "Categories",
"actionName": "listCategories",
"apiNames": ["Api"],
"modelName": "Category",
Expand Down Expand Up @@ -955,7 +955,7 @@
},
{
"id": "listComments",
"name": "List comments",
"name": "Comments",
"actionName": "listComments",
"apiNames": ["Api"],
"modelName": "Comment",
Expand Down Expand Up @@ -1242,7 +1242,7 @@
},
{
"id": "listPosts",
"name": "List posts",
"name": "Posts",
"actionName": "listPosts",
"apiNames": ["Api"],
"modelName": "BlogPost",
Expand Down Expand Up @@ -1553,7 +1553,7 @@
},
{
"id": "listPostsEmbeds",
"name": "List posts embeds",
"name": "Posts embeds",
"actionName": "listPostsEmbeds",
"apiNames": ["Api"],
"modelName": "BlogPost",
Expand Down
2 changes: 1 addition & 1 deletion tools/testdata/nested_outputs/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"tools": [
{
"id": "readInvoices",
"name": "Read invoices",
"name": "Invoices",
"actionName": "readInvoices",
"apiNames": ["Api"],
"modelName": "Invoice",
Expand Down

0 comments on commit 2679658

Please sign in to comment.