{"record":{"id":"818c755470f0c8cf","repo":"larksuite/cli","slug":"s-field-s-s-data-field-cannot-declare-defaul","errorCode":null,"errorMessage":"%s field %s (%s): Data field cannot declare default","messagePattern":"(.+?) field (.+?) \\((.+?)\\): Data field cannot declare default","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_data.go","lineNumber":232,"sourceCode":"\t\tfor _, option := range parts[1:] {\n\t\t\tswitch option {\n\t\t\tcase \"omitempty\":\n\t\t\t\tomitempty = true\n\t\t\tcase \"\":\n\t\t\tdefault:\n\t\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s has unsupported json option %q\", path, field.Name, option)\n\t\t\t}\n\t\t}\n\t\tif previous, exists := seen[name]; exists {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s JSON name %q duplicates field %s\", path, field.Name, name, previous)\n\t\t}\n\t\tseen[name] = field.Name\n\t\tschema, err := parseSchemaTag(field.Tag.Get(\"schema\"), field.Type, input)\n\t\tif err != nil {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): %w\", path, field.Name, name, err)\n\t\t}\n\t\tif !input && schema.defaultValue.Set {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): Data field cannot declare default\", path, field.Name, name)\n\t\t}\n\t\tif schema.required && omitempty {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): required Data field cannot use omitempty\", path, field.Name, name)\n\t\t}\n\t\tif schema.optional && !omitempty {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): optional Data field must use omitempty\", path, field.Name, name)\n\t\t}\n\t\tif isNilCapable(field.Type) && schema.nullable == nil {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): nil-capable field must declare nullable or nonnullable\", path, field.Name, name)\n\t\t}\n\t\tdescription := strings.TrimSpace(field.Tag.Get(\"doc\"))\n\t\tif input && description == \"\" {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): description is required via doc\", path, field.Name, name)\n\t\t}\n\t\tfieldShape, err := shapeForType(field.Type, schema, input, active)\n\t\tif err != nil {\n\t\t\treturn typedObjectShape{}, fmt.Errorf(\"%s field %s (%s): %w\", path, field.Name, name, err)\n\t\t}","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_data.go#L214-L250","documentation":"The `schema:` tag declared a default value on a field of an output/Data struct (compiled with input=false). Defaults only make sense for input values the caller may omit; output data always carries concrete values, so the compiler rejects defaults there.","triggerScenarios":"Compiling a Data (output) struct where a field's `schema:` tag contains a `default=...` option, e.g. `schema:\"default=10\"` on an output field.","commonSituations":"Copy-pasting field definitions between Input and Data structs; adding defaults 'for documentation' purposes on output types; refactoring a shared struct to be used both as input and output.","solutions":["Remove the `default=...` option from the Data struct field's schema tag","If a default is genuinely needed, move the field (or struct) to the Input type definition","Document the typical value in the `doc:` tag instead"],"exampleFix":"// before\n// Data struct field\nRetries int `json:\"retries\" schema:\"default=3\" doc:\"...\"`\n// after\nRetries int `json:\"retries\" schema:\"required\" doc:\"...\"`","handlingStrategy":"validation","validationCode":"// ensure no default= appears on Data struct fields\nif strings.Contains(f.Tag.Get(\"schema\"), \"default=\") && !isInput {\n    return fmt.Errorf(\"field %s: defaults only allowed on Input\", f.Name)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep Input and Data structs separate; never share one struct for both","Document typical values in doc: tags instead of schema defaults on outputs","Grep Data structs for `default=` before compiling"],"tags":["go","struct-tags","schema","output-shape"],"backgroundTag":"invalid-default-value","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"}