{"record":{"id":"5a7b64e9e6a87a27","repo":"larksuite/cli","slug":"s-field-s-s-required-data-field-cannot-use-o","errorCode":null,"errorMessage":"%s field %s (%s): required Data field cannot use omitempty","messagePattern":"(.+?) field (.+?) \\((.+?)\\): required Data field cannot use omitempty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_data.go","lineNumber":235,"sourceCode":"\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}\n\t\tshape.Fields = append(shape.Fields, typedValueField{Name: name, Description: description, Required: schema.required, Shape: fieldShape})\n\t}\n\treturn shape, nil","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_data.go#L217-L253","documentation":"A field marked `schema:\"required\"` also uses `omitempty` in its json tag. A required field must always be serialized; omitempty tells the encoder to skip it when empty, which contradicts the requiredness and could produce payloads missing a mandatory key.","triggerScenarios":"Compiling a Data/Input struct where a field has both `schema:\"required\"` and `json:\"x,omitempty\"`, via compileStructShape.","commonSituations":"Adding `schema:\"required\"` to a previously optional field without removing omitempty; copy-paste of tags from an optional sibling field; lint autofix adding omitempty everywhere.","solutions":["Remove `omitempty` from the json tag (required fields are always serialized)","Or, if the field is genuinely optional, replace `required` with `optional` in the schema tag"],"exampleFix":"// before\nName string `json:\"name,omitempty\" schema:\"required\" doc:\"...\"`\n// after\nName string `json:\"name\" schema:\"required\" doc:\"...\"`","handlingStrategy":"validation","validationCode":"if strings.Contains(f.Tag.Get(\"schema\"), \"required\") && strings.Contains(f.Tag.Get(\"json\"), \"omitempty\") {\n    return fmt.Errorf(\"field %s: required cannot use omitempty\", f.Name)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair required with plain json tags and optional with omitempty as a fixed convention","Review tag edits in pairs (schema + json) so they never diverge"],"tags":["go","struct-tags","schema","required-field"],"backgroundTag":"required-field-with-omitempty","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"}