{"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":427,"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":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config-macros/src/configurable.rs#L409-L445","documentation":"A `required_one_of` field must be able to be absent without failing ordinary deserialization; otherwise the group logic would always error even when another field in the group was provided. The derive therefore requires the field to be `Option<T>`, or to have a field-level or container-level `#[serde(default)]`, and emits this compile error otherwise.","triggerScenarios":"Marking a non-Option field `#[required_one_of]` with no `#[serde(default)]` on the field and no `#[serde(default)]` on the container, then compiling a struct using the configurable derive.","commonSituations":"Adding `required_one_of` to a required `String`/`u64` field thinking it means 'required' rather than 'at least one of'; copying the attribute onto an existing mandatory field during a config refactor.","solutions":["Change the field type to `Option<T>`","Or add `#[serde(default)]` to the field (requires `T: Default`)","Or add `#[serde(default)]` at the container level if all fields default","Use plain required-field semantics (no attribute) if the field must always be present"],"exampleFix":"// before\n#[configurable_component]\nstruct Config {\n  #[required_one_of]\n  endpoint: String,\n  #[required_one_of]\n  socket: String,\n}\n// after\n#[configurable_component]\nstruct Config {\n  #[required_one_of]\n  endpoint: Option<String>,\n  #[required_one_of]\n  socket: Option<String>,\n}","handlingStrategy":"validation","validationCode":"// a required_one_of field must be Option<T> or have a serde default\nfn ok_for_required_one_of<T: Default>(f: &Field) -> bool {\n    is_option_type(&f.ty) || f.default_value().is_some()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make every required_one_of field Option<T> by convention","Add #[serde(default)] at field or container level when defaults exist","Remember required_one_of means 'at least one of', not 'required'"],"tags":["rust","proc-macro","serde","config-validation"],"backgroundTag":"missing-required-config-field","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}