larksuite/cli · error
%s field %s (%s): required Data field cannot use omitempty
Error message
%s field %s (%s): required Data field cannot use omitempty
What it means
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.
Source
Thrown at shortcuts/common/typed_compile_data.go:235
omitempty = true
case "":
default:
return typedObjectShape{}, fmt.Errorf("%s field %s has unsupported json option %q", path, field.Name, option)
}
}
if previous, exists := seen[name]; exists {
return typedObjectShape{}, fmt.Errorf("%s field %s JSON name %q duplicates field %s", path, field.Name, name, previous)
}
seen[name] = field.Name
schema, err := parseSchemaTag(field.Tag.Get("schema"), field.Type, input)
if err != nil {
return typedObjectShape{}, fmt.Errorf("%s field %s (%s): %w", path, field.Name, name, err)
}
if !input && schema.defaultValue.Set {
return typedObjectShape{}, fmt.Errorf("%s field %s (%s): Data field cannot declare default", path, field.Name, name)
}
if schema.required && omitempty {
return typedObjectShape{}, fmt.Errorf("%s field %s (%s): required Data field cannot use omitempty", path, field.Name, name)
}
if schema.optional && !omitempty {
return typedObjectShape{}, fmt.Errorf("%s field %s (%s): optional Data field must use omitempty", path, field.Name, name)
}
if isNilCapable(field.Type) && schema.nullable == nil {
return typedObjectShape{}, fmt.Errorf("%s field %s (%s): nil-capable field must declare nullable or nonnullable", path, field.Name, name)
}
description := strings.TrimSpace(field.Tag.Get("doc"))
if input && description == "" {
return typedObjectShape{}, fmt.Errorf("%s field %s (%s): description is required via doc", path, field.Name, name)
}
fieldShape, err := shapeForType(field.Type, schema, input, active)
if err != nil {
return typedObjectShape{}, fmt.Errorf("%s field %s (%s): %w", path, field.Name, name, err)
}
shape.Fields = append(shape.Fields, typedValueField{Name: name, Description: description, Required: schema.required, Shape: fieldShape})
}
return shape, nilView on GitHub (pinned to 7fd6ef3c07)
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
Example fix
// before Name string `json:"name,omitempty" schema:"required" doc:"..."` // after Name string `json:"name" schema:"required" doc:"..."`
Defensive patterns
Strategy: validation
Validate before calling
if strings.Contains(f.Tag.Get("schema"), "required") && strings.Contains(f.Tag.Get("json"), "omitempty") {
return fmt.Errorf("field %s: required cannot use omitempty", f.Name)
} Prevention
- 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
When it happens
Trigger: Compiling a Data/Input struct where a field has both `schema:"required"` and `json:"x,omitempty"`, via compileStructShape.
Common situations: 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.
Related errors
- %s field %s (%s): %w
- %s field %s (%s): Data field cannot declare default
- %s field %s (%s): optional Data field must use omitempty
- %s field %s (%s): nil-capable field must declare nullable or
- L1: inputSchema must not be nil
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/5a7b64e9e6a87a27.
Report an issue: GitHub.