{"record":{"id":"a7bfd026454c5bca","repo":"vectordotdev/vector","slug":"required-one-of-requires-the-field-to-be-optiona","errorCode":null,"errorMessage":"`required_one_of` requires the field to be optional; use `Option<T>` or add `#[serde(default)]`","messagePattern":"`required_one_of` requires the field to be optional; use `Option<T>` or add `#\\[serde\\(default\\)\\]`","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"lib/vector-config-macros/src/configurable.rs","lineNumber":387,"sourceCode":"            if !field.visible() {\n                return syn::Error::new(\n                    field.span(),\n                    \"`required_one_of` cannot be applied to a `#[serde(skip)]` field\",\n                )\n                .to_compile_error();\n            }\n            if field.flatten() {\n                return syn::Error::new(\n                    field.span(),\n                    \"`required_one_of` cannot be applied to a `#[serde(flatten)]` field\",\n                )\n                .to_compile_error();\n            }\n            if !is_option_type(field.ty())\n                && field.default_value().is_none()\n                && container.default_value().is_none()\n            {\n                return syn::Error::new(\n                    field.span(),\n                    \"`required_one_of` requires the field to be optional; use `Option<T>` or add `#[serde(default)]`\",\n                )\n                .to_compile_error();\n            }\n            if field.skip_deserializing() {\n                return syn::Error::new(\n                    field.span(),\n                    \"`required_one_of` cannot be applied to a `#[serde(skip_deserializing)]` field; users cannot set its value\",\n                )\n                .to_compile_error();\n            }\n        }\n    }\n\n    // Collect required_one_of groups at macro-expansion time: group_name -> [serde field names].\n    let mut groups: std::collections::BTreeMap<String, Vec<String>> =\n        std::collections::BTreeMap::new();","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-config-macros/src/configurable.rs#L369-L405","documentation":"Compile-time error from `build_named_struct_generate_schema_fn`. A field in a `required_one_of` group may legitimately be absent (the group only requires ONE of its members), so each member must be optional: `Option<T>`, a field-level `#[serde(default)]`, or a container-level `#[serde(default)]`. If none of those hold, a missing group member could never deserialize and the macro rejects it.","triggerScenarios":"`#[configurable(required_one_of = [\"a\", \"b\"])]` on a plain `pub b: B` field (not Option) in a struct with no field or container default.","commonSituations":"Porting hand-written `#[serde(deny_unknown_fields)]`-style validation to the new required_one_of mechanism and forgetting that group members must be individually omittable.","solutions":["Wrap the field in `Option<T>`: `pub b: Option<B>`","Or add `#[serde(default)]` to the field so omission deserializes to Default","Or add `#[serde(default)]` on the whole struct (container default) if all fields can default"],"exampleFix":"// before\n#[configurable(required_one_of = [\"api_key\", \"credentials_path\"])]\npub credentials_path: PathBuf,\n\n// after\n#[configurable(required_one_of = [\"api_key\", \"credentials_path\"])]\npub credentials_path: Option<PathBuf>,","handlingStrategy":"validation","validationCode":"# CI gate: non-optional group members fail at compile time\ncargo check --workspace --all-targets","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make every required_one_of member Option<T> or add #[serde(default)]","Remember container-level #[serde(default)] on the struct also satisfies the check"],"tags":["rust","proc-macro","compile-time","serde","optional-fields","vector"],"backgroundTag":"required-field-not-optional","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}