{"record":{"id":"507a30b74624b316","repo":"larksuite/cli","slug":"schema-token-optional-does-not-accept-a-value","errorCode":null,"errorMessage":"schema token optional does not accept a value","messagePattern":"schema token optional does not accept a value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":420,"sourceCode":"\tseen := make(map[string]struct{})\n\tfor _, token := range strings.Split(raw, \";\") {\n\t\tif token == \"\" || token != strings.TrimSpace(token) {\n\t\t\treturn result, fmt.Errorf(\"schema contains blank or untrimmed token %q\", token)\n\t\t}\n\t\tkey, value, hasValue := strings.Cut(token, \"=\")\n\t\tif _, duplicate := seen[key]; duplicate {\n\t\t\treturn result, fmt.Errorf(\"schema token %q is duplicated\", key)\n\t\t}\n\t\tseen[key] = struct{}{}\n\t\tswitch key {\n\t\tcase \"required\":\n\t\t\tif hasValue {\n\t\t\t\treturn result, fmt.Errorf(\"schema token required does not accept a value\")\n\t\t\t}\n\t\t\tresult.required = true\n\t\tcase \"optional\":\n\t\t\tif hasValue {\n\t\t\t\treturn result, fmt.Errorf(\"schema token optional does not accept a value\")\n\t\t\t}\n\t\t\tresult.optional = true\n\t\tcase \"nullable\", \"nonnullable\":\n\t\t\tif hasValue {\n\t\t\t\treturn result, fmt.Errorf(\"schema token %s does not accept a value\", key)\n\t\t\t}\n\t\t\tif result.nullable != nil {\n\t\t\t\treturn result, fmt.Errorf(\"schema cannot declare both nullable and nonnullable\")\n\t\t\t}\n\t\t\tv := key == \"nullable\"\n\t\t\tresult.nullable = &v\n\t\tcase \"default\":\n\t\t\tif !hasValue || value == \"\" {\n\t\t\t\treturn result, fmt.Errorf(\"schema default requires a JSON literal\")\n\t\t\t}\n\t\t\tif !input {\n\t\t\t\treturn result, fmt.Errorf(\"Data field cannot declare default\")\n\t\t\t}","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L402-L438","documentation":"Thrown by parseSchemaTag when the optional token carries a value, e.g. `optional=false`. Like required, optional is a bare marker with no value; exactly one of required/optional must be declared without a value.","triggerScenarios":"A tag like `schema:\"optional=true\"`; parseSchemaTag finds key optional with hasValue true. Also note TestParseSchemaTagPreservesExplicitZeroFalseAndEmptyDefaults implies false/empty defaults are preserved elsewhere — but the optional token itself never accepts a value.","commonSituations":"Trying to express 'not optional' via optional=false instead of writing required; template engines emitting key=value for all boolean flags.","solutions":["Write the bare token `optional`","Replace `optional=false` with `required`","Remove the `=value` suffix"],"exampleFix":"// before\nName string `cli:\"--name;schema:\\\"optional=false\\\"\"`\n// after\nName string `cli:\"--name;schema:\\\"required\\\"\"`","handlingStrategy":"validation","validationCode":"if key == \"optional\" && strings.Contains(token, \"=\") {\n    return fmt.Errorf(\"optional must be a bare token; use required to negate\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Express negation with the other marker (optional=false -> required)","Lint for `optional=` in struct tags","Keep tag vocabulary minimal: required, optional, nullable, nonnullable"],"tags":["cli","schema","tags","grammar","validation"],"backgroundTag":"schema-validation-failed","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"}