{"record":{"id":"9fc219953224fde2","repo":"larksuite/cli","slug":"args-field-s-s-json-tag-is-not-allowed-on-a","errorCode":null,"errorMessage":"Args field %s (--%s): json tag is not allowed on a CLI field","messagePattern":"Args field (.+?) \\(--(.+?)\\): json tag is not allowed on a CLI field","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":134,"sourceCode":"\t\t\t\tif inlineType.Kind() != reflect.Struct {\n\t\t\t\t\treturn fmt.Errorf(\"Args field %s: arg:\\\"inline\\\" must be a struct, got %s\", field.Name, field.Type)\n\t\t\t\t}\n\t\t\t\tif hasAnyTag(field, \"flag\", \"schema\", \"cli\", \"doc\", \"json\") {\n\t\t\t\t\treturn fmt.Errorf(\"Args field %s: arg:\\\"inline\\\" cannot declare public input tags\", field.Name)\n\t\t\t\t}\n\t\t\t\tif err := collectArgFields(inlineType, index, true, out, seenGo, supplements); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn fmt.Errorf(\"Args field %s: unknown arg mode %q\", field.Name, argMode)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif !flagNamePattern.MatchString(flagName) {\n\t\t\treturn fmt.Errorf(\"Args field %s: flag %q is not a canonical flag name\", field.Name, flagName)\n\t\t}\n\t\tif hasAnyTag(field, \"json\") {\n\t\t\treturn fmt.Errorf(\"Args field %s (--%s): json tag is not allowed on a CLI field\", field.Name, flagName)\n\t\t}\n\t\tvalueType, valueIndex, isProvided, err := unwrapProvided(field.Type)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Args field %s (--%s): %w\", field.Name, flagName, err)\n\t\t}\n\t\tschema, err := parseSchemaTag(field.Tag.Get(\"schema\"), valueType, true)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Args field %s (--%s): %w\", field.Name, flagName, err)\n\t\t}\n\t\tcli, err := parseCLITag(field.Tag.Get(\"cli\"))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Args field %s (--%s): %w\", field.Name, flagName, err)\n\t\t}\n\t\tvar shape typedValueShape\n\t\tsupplement, hasSupplement := supplements[flagName]\n\t\tif hasSupplement && supplement.Shape != nil {\n\t\t\tif schema.nullable != nil || schemaHasShapeConstraints(schema) {\n\t\t\t\treturn fmt.Errorf(\"Args field %s (--%s): InputField.Shape conflicts with schema constraints or nullable declaration\", field.Name, flagName)","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L116-L152","documentation":"When compiling a typed shortcut's Args struct, lark-cli rejects any field that carries a `json` struct tag. CLI input fields map to flags (declared via `flag`/`arg` plus `schema`, `cli`, `doc` tags), not to JSON serialization; a `json` tag usually signals the struct was copied from an API request/response type or is reused for wire encoding, which is forbidden so flag compilation stays deterministic.","triggerScenarios":"Registering a shortcut whose Args struct has a field like `Query string \\`flag:\"query\" schema:\"required\" json:\"query\"\\``. The error fires in collectArgFields during command-set startup, right after the flag name passes the canonical-name check.","commonSituations":"Copying a struct from an internal/service payload type into Args and leaving the json tags on; sharing one struct between JSON output and CLI input; IDE auto-completing json tags on new fields.","solutions":["Delete the `json:\"...\"` tag from the flagged Args field; CLI fields are never JSON-serialized.","If the struct must keep its json tags for API use, define a separate Args struct for the shortcut and convert between them.","Keep only the supported tags: flag/arg, schema, cli, doc."],"exampleFix":"// before\ntype Args struct {\n\tQuery string `flag:\"query\" schema:\"required\" json:\"query\"`\n}\n// after\ntype Args struct {\n\tQuery string `flag:\"query\" schema:\"required\" doc:\"Search query\"`\n}","handlingStrategy":"validation","validationCode":"for i := 0; i < reflect.TypeOf(Args{}).NumField(); i++ {\n\tif _, ok := reflect.TypeOf(Args{}).Field(i).Tag.Lookup(\"json\"); ok {\n\t\treturn fmt.Errorf(\"field %d has a forbidden json tag\", i)\n\t}\n}","typeGuard":"func hasNoJSONTag(t reflect.Type) bool {\n\tfor i := 0; i < t.NumField(); i++ {\n\t\tif _, ok := t.Field(i).Tag.Lookup(\"json\"); ok { return false }\n\t}\n\treturn true\n}","tryCatchPattern":null,"preventionTips":["Never reuse API request/response structs as shortcut Args; define dedicated Args structs.","Reserve json tags for wire-marshal types only; CLI fields use flag/arg, schema, cli, doc.","Add a unit test that compiles every shortcut's Args at init to surface tag violations early."],"tags":["cli","struct-tags","validation","go"],"backgroundTag":"invalid-struct-tag","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}