{"record":{"id":"fafea02e04e555fa","repo":"windmill-labs/windmill","slug":"enum-variants-are-not-in-an-array","errorCode":null,"errorMessage":"enum variants are not in an array","messagePattern":"enum variants are not in an array","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/windmill-common/src/schema.rs","lineNumber":190,"sourceCode":"                                .ok_or(anyhow!(\"Expected array of strings for `type` field\"))?,\n                        )?,\n                        v,\n                    )\n                })\n                .collect::<Result<Vec<Vec<SchemaValidationRule>>, anyhow::Error>>()?;\n\n            schema_rules.push(SchemaValidationRule::IsUnionType(typ_arr));\n        } else {\n            return Err(anyhow!(\n                \"Unsupported value for type field, expected string or string array\"\n            )\n            .into());\n        }\n\n        if let Some(enum_variants) = val.get(\"enum\") {\n            let variants = enum_variants\n                .as_array()\n                .ok_or(anyhow!(\"enum variants are not in an array\"))?\n                .clone();\n            schema_rules.push(SchemaValidationRule::StrictEnum(variants));\n        }\n\n        Ok(schema_rules)\n    }\n\n    fn apply_rule(&self, key: &str, val: &Value, required: bool) -> Result<(), Error> {\n        if val.is_null() {\n            if !required {\n                return Ok(());\n            }\n            return Err(Error::ArgumentErr(format!(\"Argument {key} cannot be null\")));\n        }\n        match self {\n            SchemaValidationRule::IsNull => {\n                if !val.is_null() {\n                    return Err(Error::ArgumentErr(format!(","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-common/src/schema.rs#L172-L208","documentation":"When a property schema includes an `enum` keyword, Windmill requires its value to be a JSON array of allowed variants (converted to a StrictEnum validation rule). If `enum` is present but not an array, from_value rejects the schema. The check only fires when `enum` exists, so omitting it entirely is fine.","triggerScenarios":"from_value (via Schema::from_schema during app reduction) sees a property like {\"type\":\"string\",\"enum\":\"red\"} or {\"enum\": {\"a\":1}} — `enum` is any non-array JSON value.","commonSituations":"Copy-pasting an enum from a programming-language definition into the schema as a scalar, a generator emitting `enum` as a comma-separated string, or accidental JSON editing that dropped the brackets.","solutions":["Wrap the variants in a JSON array: \"enum\": [\"red\",\"green\",\"blue\"].","If you did not intend an enumeration, remove the `enum` key entirely.","Check the schema-generating code for a missing collect/wrap step around the variant list."],"exampleFix":"// before\n{\"status\": {\"type\": \"string\", \"enum\": \"active\"}}\n// after\n{\"status\": {\"type\": \"string\", \"enum\": [\"active\", \"inactive\"]}}","handlingStrategy":"validation","validationCode":"fn validate_enum_field(prop: &serde_json::Value) -> Result<(), String> {\n    if let Some(e) = prop.get(\"enum\") {\n        if !e.is_array() {\n            return Err(\"`enum` must be a JSON array of allowed values\".into());\n        }\n    }\n    Ok(())\n}","typeGuard":"fn has_valid_enum(prop: &serde_json::Value) -> bool {\n    prop.get(\"enum\").map(|e| e.is_array()).unwrap_or(true)\n}","tryCatchPattern":"match Schema::from_schema(&schema_str) {\n    Ok(s) => s,\n    Err(e) if e.to_string().contains(\"enum variants are not in an array\") => {\n        eprintln!(\"fix the `enum` key: it must be an array: {e}\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always write enum as an array, even for a single allowed value","Never paste language-level enums as scalars — serialize their variant list","Lint schemas so any `enum` key is checked with Array.isArray / Value::is_array"],"tags":["json-schema","enum","schema-validation","windmill"],"backgroundTag":"invalid-json-schema","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}