larksuite/cli · error

L2: required key %q in %q not found in its properties

Error message

L2: required key %q in %q not found in its properties

What it means

L2 schema lint failure: an object's required list names a key that does not exist in its properties. The sub-object required-exists invariant guarantees required keys are declared fields.

Source

Thrown at internal/schema/lint.go:134

func walkForL2(props *OrderedProps, errs *[]error) {
	if props == nil {
		return
	}
	for _, k := range props.Order {
		p := props.Map[k]
		if p.Format == "binary" && p.Type != "string" {
			*errs = append(*errs, fmt.Errorf("L2: field %q has format: binary but type = %q (want string)", k, p.Type))
		}
		if p.Minimum != nil && p.Maximum != nil && *p.Minimum >= *p.Maximum {
			*errs = append(*errs, fmt.Errorf("L2: field %q minimum (%v) >= maximum (%v)", k, *p.Minimum, *p.Maximum))
		}
		if n := len(p.EnumDescriptions); n > 0 && n != len(p.Enum) {
			*errs = append(*errs, fmt.Errorf("L2: field %q enumDescriptions length (%d) != enum length (%d)", k, n, len(p.Enum)))
		}
		if len(p.Required) > 0 && p.Properties != nil {
			for _, r := range p.Required {
				if _, ok := p.Properties.Map[r]; !ok {
					*errs = append(*errs, fmt.Errorf("L2: required key %q in %q not found in its properties", r, k))
				}
			}
		}
		if p.Properties != nil {
			walkForL2(p.Properties, errs)
		}
	}
}

// validatePropertyTypes walks an OrderedProps tree and asserts:
//   - every Property.Type is in validJSONSchemaTypes (or empty for nested objects with only properties)
//   - array Properties have Items
//
// Errors are appended to *errs.
func validatePropertyTypes(props *OrderedProps, errs *[]error) {
	if props == nil {
		return
	}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Fix the required key spelling to match an existing property name
  2. Remove the stale required entry if the property no longer exists
  3. Add the missing property to the nested object's properties
  4. Re-run lint to confirm all required keys resolve

Example fix

// before
Property{Required: ["task_id"], Properties: {Map: {"id": ...}}}
// after
Property{Required: ["id"], Properties: {Map: {"id": ...}}}
Defensive patterns

Strategy: validation

Validate before calling

for _, r := range p.Required {
  if _, ok := p.Properties.Map[r]; !ok {
    return fmt.Errorf("required key %q missing in properties of %q", r, name)
  }
}

Type guard

func requiredKeysExist(p *Property) bool {
  for _, r := range p.Required {
    if p.Properties == nil {
      return false
    }
    if _, ok := p.Properties.Map[r]; !ok { return false }
  }
  return true
}

Prevention

When it happens

Trigger: walkForL2 visits a property p with non-empty p.Required and non-nil p.Properties, and a required key r is not found in p.Properties.Map.

Common situations: Renaming a property without updating the required list; copying required keys from the parent object into a nested object; upstream metadata listing a field as required that the schema omitted.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/d475b19d4f06d54f. Report an issue: GitHub.