{"record":{"id":"93b1938612d7b9fd","repo":"windmill-labs/windmill","slug":"missing-required-field-on-schema","errorCode":null,"errorMessage":"Missing `required` field on schema","messagePattern":"Missing `required` field on schema","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/windmill-common/src/schema.rs","lineNumber":526,"sourceCode":"\n        Ok(())\n    }\n\n    pub fn from_schema(schema: &str) -> Result<Self, Error> {\n        let schema: Value = serde_json::from_str(schema)?;\n\n        if let Some(draft_version) = schema.get(\"$schema\") {\n            match draft_version.as_str() {\n                Some(\"https://json-schema.org/draft/2020-12/schema\") => (),\n                _ => return Err(anyhow!(\"Supplied schema draft version is unsuported\").into()),\n            }\n        } else {\n            return Err(anyhow!(\"No draft version supplied\").into());\n        }\n\n        let required: Vec<String> = schema\n            .get(\"required\")\n            .ok_or(anyhow!(\"Missing `required` field on schema\"))?\n            .as_array()\n            .ok_or(anyhow!(\"`required` field should be an array of strings\"))?\n            .into_iter()\n            .map(|v| {\n                v.as_str()\n                    .map(|s| s.to_string())\n                    .ok_or(anyhow!(\"required field key is not a string\"))\n            })\n            .collect::<Result<Vec<String>, anyhow::Error>>()?;\n\n        let properties = schema\n            .get(\"properties\")\n            .ok_or(anyhow!(\"Missing `properties` field on schema\"))?\n            .as_object()\n            .ok_or(anyhow!(\"`properties` field should be an object\"))?;\n\n        let mut rules = vec![];\n","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-common/src/schema.rs#L508-L544","documentation":"Raised by from_schema in windmill-common when the supplied JSON Schema has no `required` key. Windmill's restricted schema parser (draft 2020-12 only) demands an explicit required array and does not infer optionality, so a schema omitting it is rejected at parse time. This is a parser-capability guard on the schema input, not a data validation failure.","triggerScenarios":"Calling Schema::from_schema with a schema that has properties but no top-level `required` key, e.g. {\"$schema\":...,\"type\":\"object\",\"properties\":{...}} with no `required`.","commonSituations":"Schemas where nothing is mandatory (authors omit `required` instead of using an empty array), schemas generated from TypeScript types with no required members, and schemas trimmed down by hand.","solutions":["Add an explicit top-level \"required\": [] (or list the required property names).","Update the schema generator to always emit `required`, even when empty."],"exampleFix":"// before\n{\"$schema\": \"https://json-schema.org/draft/2020-12/schema\", \"properties\": {\"a\": {\"type\": \"string\"}}}\n// after\n{\"$schema\": \"https://json-schema.org/draft/2020-12/schema\", \"properties\": {\"a\": {\"type\": \"string\"}}, \"required\": []}","handlingStrategy":"validation","validationCode":"fn require_required_field(schema: &serde_json::Value) -> Result<(), String> {\n    if schema.get(\"required\").is_none() {\n        Err(\"add top-level `required` array (use [] if nothing is mandatory)\".into())\n    } else { Ok(()) }\n}","typeGuard":"fn has_required_field(schema: &serde_json::Value) -> bool {\n    schema.get(\"required\").is_some()\n}","tryCatchPattern":"match Schema::from_schema(&schema_str) {\n    Ok(s) => s,\n    Err(e) if e.to_string().contains(\"Missing `required` field\") => {\n        eprintln!(\"add a top-level `required` array, even if empty\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always emit `required` in generated schemas, defaulting to []","Never rely on the key being optional — this API requires it explicitly"],"tags":["json-schema","schema-validation","missing-field","windmill"],"backgroundTag":"missing-schema-required-field","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"}