Compare commits

...

1 Commits

Author SHA1 Message Date
fangshuyu
4ee238c4a4 Fix missing help text for drive files patch 2026-06-04 17:25:45 +08:00
6 changed files with 74 additions and 5 deletions

View File

@@ -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.<method>%s\n", output.Dim, serviceName, resName, output.Reset)

View File

@@ -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,

View File

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

View File

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

View File

@@ -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]
}

View File

@@ -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) {