{"record":{"id":"f02a50016a89879b","repo":"larksuite/cli","slug":"array-field-has-incompatible-schema-constraint","errorCode":null,"errorMessage":"array field has incompatible schema constraint","messagePattern":"array field has incompatible schema constraint","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_data.go","lineNumber":144,"sourceCode":"\t\t\tv, err := parseFiniteFloatBits(raw, baseType.Bits())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"enum value %q is not a finite number\", raw)\n\t\t\t}\n\t\t\tnumberShape.Enum = append(numberShape.Enum, v)\n\t\t}\n\t\tif hasStringConstraints(schema) || hasItemConstraints(schema) || schema.format != \"\" {\n\t\t\treturn nil, fmt.Errorf(\"number field has incompatible schema constraint\")\n\t\t}\n\t\tshape = numberShape\n\tcase reflect.Slice, reflect.Array:\n\t\tif baseType == jsonRawMessageType {\n\t\t\treturn nil, fmt.Errorf(\"json.RawMessage requires an explicit Shape\")\n\t\t}\n\t\tif baseType.Elem().Kind() == reflect.Uint8 {\n\t\t\treturn nil, fmt.Errorf(\"byte slice or array %s requires an explicit Shape\", baseType)\n\t\t}\n\t\tif len(schema.enum) > 0 || hasStringConstraints(schema) || hasNumberConstraints(schema) || schema.format != \"\" {\n\t\t\treturn nil, fmt.Errorf(\"array field has incompatible schema constraint\")\n\t\t}\n\t\telementSchema := schemaTag{required: true}\n\t\telementShape, err := shapeForType(baseType.Elem(), elementSchema, input, active)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"array item: %w\", err)\n\t\t}\n\t\tshape = typedArrayShape{Items: elementShape, MinItems: schema.minItems, MaxItems: schema.maxItems}\n\tcase reflect.Struct:\n\t\tif implementsCustomEncoding(baseType) {\n\t\t\treturn nil, fmt.Errorf(\"custom JSON type %s requires an explicit Shape\", baseType)\n\t\t}\n\t\tif len(schema.enum) > 0 || hasStringConstraints(schema) || hasNumberConstraints(schema) || hasItemConstraints(schema) || schema.format != \"\" {\n\t\t\treturn nil, fmt.Errorf(\"object field has incompatible schema constraint\")\n\t\t}\n\t\tobject, err := compileStructShape(baseType, input, baseType.String(), active)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_data.go#L126-L162","documentation":"An array-typed field was tagged with schema constraints that only make sense for other kinds: enum values, string constraints (minLength/pattern-style), number constraints (minimum/maximum), or a format. An array shape supports only item constraints (minItems/maxItems), so the compiler rejects the combination as unsatisfiable.","triggerScenarios":"A struct field like `[]string `+\"`\"+`schema:\"enum=a,b\"`+\"`\"+` or `+\"`\"+`schema:\"format=date\"`+\"`\"+` with a slice/array type is processed by shapeForType's reflect.Slice/Array case during command registration.","commonSituations":"Copy-pasting a schema tag from a string field onto a slice field; adding `format:uri` intending it to apply to items; schema-tag-generating tools mislabeling array fields.","solutions":["Move the constraint to the element type by using an item-appropriate tag or modeling items as a named struct/string with the constraint.","Keep only minItems/maxItems (item constraints) on the array field and drop enum/format/string/number tags.","If a value set is intended, declare the field as a single string with enum, or give an explicit Output.Data.Shape with a constrained-items array."],"exampleFix":"// before\nIDs []string `json:\"ids\" schema:\"enum=user_1,user_2\"`\n\n// after\nIDs []string `json:\"ids\" schema:\"minItems=1\"` // enum belongs on a scalar field or explicit Shape","handlingStrategy":"validation","validationCode":"func arrayTagsValid(f reflect.StructField) bool {\n    if f.Type.Kind() != reflect.Slice && f.Type.Kind() != reflect.Array { return true }\n    tag := f.Tag.Get(\"schema\")\n    for _, bad := range []string{\"enum=\", \"format=\", \"minLength=\", \"maxLength=\", \"minimum=\", \"maximum=\"} {\n        if strings.Contains(tag, bad) { return false }\n    }\n    return true // only minItems=/maxItems= allowed on arrays\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep scalar constraints (enum, format, min/max length) on scalar fields only.","On arrays use only minItems/maxItems; constrain items via their element type or an explicit Shape.","Review schema tags whenever a field's Go type changes between scalar and slice."],"tags":["go","schema-tag","array","validation"],"backgroundTag":"incompatible-schema-constraint","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"}