From 4ee238c4a4e6c55a3504c258569879c7cf4a5a5e Mon Sep 17 00:00:00 2001 From: fangshuyu Date: Thu, 4 Jun 2026 17:25:45 +0800 Subject: [PATCH] Fix missing help text for drive files patch --- cmd/schema/schema.go | 6 +++--- cmd/schema/schema_test.go | 19 +++++++++++++++++++ cmd/service/service.go | 4 ++-- cmd/service/service_test.go | 13 +++++++++++++ internal/registry/method_desc.go | 19 +++++++++++++++++++ internal/registry/registry_test.go | 18 ++++++++++++++++++ 6 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 internal/registry/method_desc.go diff --git a/cmd/schema/schema.go b/cmd/schema/schema.go index 5276052e..a9c5db5b 100644 --- a/cmd/schema/schema.go +++ b/cmd/schema/schema.go @@ -70,7 +70,7 @@ func printResourceList(w io.Writer, spec map[string]interface{}, mode core.Stric for _, methodName := range sortedKeys(methods) { m, _ := methods[methodName].(map[string]interface{}) httpMethod := registry.GetStrFromMap(m, "httpMethod") - desc := registry.GetStrFromMap(m, "description") + desc := registry.GetMethodDescription(name, resName, methodName, m) danger := "" if d, _ := m["danger"].(bool); d { danger = fmt.Sprintf(" %s[danger]%s", output.Red, output.Reset) @@ -94,7 +94,7 @@ func printMethodDetail(w io.Writer, spec map[string]interface{}, resName, method methodPath := registry.GetStrFromMap(method, "path") fullPath := servicePath + "/" + methodPath httpMethod := registry.GetStrFromMap(method, "httpMethod") - desc := registry.GetStrFromMap(method, "description") + desc := registry.GetMethodDescription(specName, resName, methodName, method) isFileUpload, fileFieldNames := hasFileFields(method) fmt.Fprintf(w, "%s%s.%s.%s%s\n\n", output.Bold, specName, resName, methodName, output.Reset) @@ -679,7 +679,7 @@ func runPrettyMode(out io.Writer, parts []string, mode core.StrictMode) error { for _, mName := range sortedKeys(methods) { m, _ := methods[mName].(map[string]interface{}) httpMethod := registry.GetStrFromMap(m, "httpMethod") - desc := registry.GetStrFromMap(m, "description") + desc := registry.GetMethodDescription(serviceName, resName, mName, m) fmt.Fprintf(out, " %-7s %s%s%s %s%s%s\n", httpMethod, output.Bold, mName, output.Reset, output.Dim, desc, output.Reset) } fmt.Fprintf(out, "\n%sUsage: lark-cli schema %s.%s.%s\n", output.Dim, serviceName, resName, output.Reset) diff --git a/cmd/schema/schema_test.go b/cmd/schema/schema_test.go index cb9e51c8..9fcf5be8 100644 --- a/cmd/schema/schema_test.go +++ b/cmd/schema/schema_test.go @@ -196,6 +196,25 @@ func TestSchemaCmd_PrettyUnchanged_KeyTextPresent(t *testing.T) { } } +func TestPrintMethodDetail_UsesDescriptionOverrideWhenMetadataIsEmpty(t *testing.T) { + spec := map[string]interface{}{ + "name": "drive", + "servicePath": "/open-apis/drive/v1", + } + method := map[string]interface{}{ + "httpMethod": "PATCH", + "path": "files/{file_token}", + "description": "", + } + + var out bytes.Buffer + printMethodDetail(&out, spec, "files", "patch", method) + + if !strings.Contains(out.String(), "修改文件标题") { + t.Fatalf("pretty output = %q, want to contain %q", out.String(), "修改文件标题") + } +} + func TestSchemaCmd_UnknownService(t *testing.T) { f, _, _, _ := cmdutil.TestFactory(t, &core.CliConfig{ AppID: "test-app", AppSecret: "test-secret", Brand: core.BrandFeishu, diff --git a/cmd/service/service.go b/cmd/service/service.go index 50a6e97b..95f09ea5 100644 --- a/cmd/service/service.go +++ b/cmd/service/service.go @@ -140,10 +140,10 @@ func NewCmdServiceMethod(f *cmdutil.Factory, spec, method map[string]interface{} } func NewCmdServiceMethodWithContext(ctx context.Context, f *cmdutil.Factory, spec, method map[string]interface{}, name, resName string, runF func(*ServiceMethodOptions) error) *cobra.Command { - desc := registry.GetStrFromMap(method, "description") + specName := registry.GetStrFromMap(spec, "name") + desc := registry.GetMethodDescription(specName, resName, name, method) httpMethod := registry.GetStrFromMap(method, "httpMethod") risk := registry.GetStrFromMap(method, "risk") - specName := registry.GetStrFromMap(spec, "name") schemaPath := fmt.Sprintf("%s.%s.%s", specName, resName, name) opts := &ServiceMethodOptions{ diff --git a/cmd/service/service_test.go b/cmd/service/service_test.go index 172ed7f8..9f5d28c2 100644 --- a/cmd/service/service_test.go +++ b/cmd/service/service_test.go @@ -166,6 +166,19 @@ func TestNewCmdServiceMethod_POSTHasDataFlag(t *testing.T) { } } +func TestNewCmdServiceMethod_UsesDescriptionOverrideWhenMetadataIsEmpty(t *testing.T) { + f := &cmdutil.Factory{} + cmd := NewCmdServiceMethod(f, driveSpec(), + map[string]interface{}{"description": "", "httpMethod": "PATCH"}, "patch", "files", nil) + + if cmd.Short != "修改文件标题" { + t.Fatalf("Short = %q, want %q", cmd.Short, "修改文件标题") + } + if !strings.Contains(cmd.Long, "修改文件标题") { + t.Fatalf("Long = %q, want to contain %q", cmd.Long, "修改文件标题") + } +} + func TestNewCmdServiceMethod_RunFCallback(t *testing.T) { f, _, _, _ := cmdutil.TestFactory(t, testConfig) diff --git a/internal/registry/method_desc.go b/internal/registry/method_desc.go new file mode 100644 index 00000000..6f7a6048 --- /dev/null +++ b/internal/registry/method_desc.go @@ -0,0 +1,19 @@ +// Copyright (c) 2026 Lark Technologies Pte. Ltd. +// SPDX-License-Identifier: MIT + +package registry + +import "strings" + +var methodDescriptionOverrides = map[string]string{ + "drive.files.patch": "修改文件标题", +} + +// GetMethodDescription returns the method description from metadata, falling back +// to a curated override when the upstream meta has an empty description. +func GetMethodDescription(service, resource, method string, meta map[string]interface{}) string { + if desc := strings.TrimSpace(GetStrFromMap(meta, "description")); desc != "" { + return desc + } + return methodDescriptionOverrides[service+"."+resource+"."+method] +} diff --git a/internal/registry/registry_test.go b/internal/registry/registry_test.go index a2482a8f..acc8089a 100644 --- a/internal/registry/registry_test.go +++ b/internal/registry/registry_test.go @@ -223,6 +223,24 @@ func TestFilterScopes_TooFewParts(t *testing.T) { } } +func TestGetMethodDescription_UsesOverrideWhenMetadataIsEmpty(t *testing.T) { + got := GetMethodDescription("drive", "files", "patch", map[string]interface{}{ + "description": " ", + }) + if got != "修改文件标题" { + t.Fatalf("GetMethodDescription() = %q, want %q", got, "修改文件标题") + } +} + +func TestGetMethodDescription_PrefersMetadataDescription(t *testing.T) { + got := GetMethodDescription("drive", "files", "patch", map[string]interface{}{ + "description": "Rename a file", + }) + if got != "Rename a file" { + t.Fatalf("GetMethodDescription() = %q, want %q", got, "Rename a file") + } +} + // --- Auto-approve functions --- func TestLoadAutoApproveSet(t *testing.T) {