From 2679658635ef168f1069ea38a3989a75b3e017df Mon Sep 17 00:00:00 2001 From: Radu Gruia Date: Tue, 24 Sep 2024 15:42:49 +0100 Subject: [PATCH] chore: update generated action configs name (#1608) --- tools/generator.go | 22 +++++++++++++++++++++- tools/testdata/blog/tools.json | 12 ++++++------ tools/testdata/nested_outputs/tools.json | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/tools/generator.go b/tools/generator.go index eaf33505f..f3194df88 100644 --- a/tools/generator.go +++ b/tools/generator.go @@ -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(), @@ -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{ diff --git a/tools/testdata/blog/tools.json b/tools/testdata/blog/tools.json index ffa43164b..ec4377f18 100644 --- a/tools/testdata/blog/tools.json +++ b/tools/testdata/blog/tools.json @@ -460,7 +460,7 @@ }, { "id": "getCategory", - "name": "Get category", + "name": "Category", "actionName": "getCategory", "apiNames": ["Api"], "modelName": "Category", @@ -552,7 +552,7 @@ }, { "id": "getPost", - "name": "Get post", + "name": "Post", "actionName": "getPost", "apiNames": ["Api"], "modelName": "BlogPost", @@ -747,7 +747,7 @@ }, { "id": "listCategories", - "name": "List categories", + "name": "Categories", "actionName": "listCategories", "apiNames": ["Api"], "modelName": "Category", @@ -955,7 +955,7 @@ }, { "id": "listComments", - "name": "List comments", + "name": "Comments", "actionName": "listComments", "apiNames": ["Api"], "modelName": "Comment", @@ -1242,7 +1242,7 @@ }, { "id": "listPosts", - "name": "List posts", + "name": "Posts", "actionName": "listPosts", "apiNames": ["Api"], "modelName": "BlogPost", @@ -1553,7 +1553,7 @@ }, { "id": "listPostsEmbeds", - "name": "List posts embeds", + "name": "Posts embeds", "actionName": "listPostsEmbeds", "apiNames": ["Api"], "modelName": "BlogPost", diff --git a/tools/testdata/nested_outputs/tools.json b/tools/testdata/nested_outputs/tools.json index c39a76174..94b21cf18 100644 --- a/tools/testdata/nested_outputs/tools.json +++ b/tools/testdata/nested_outputs/tools.json @@ -2,7 +2,7 @@ "tools": [ { "id": "readInvoices", - "name": "Read invoices", + "name": "Invoices", "actionName": "readInvoices", "apiNames": ["Api"], "modelName": "Invoice",