{"record":{"id":"fbff8eac86908f1c","repo":"vectordotdev/vector","slug":"required-one-of-cannot-be-applied-to-a-serde-fbff8e","errorCode":null,"errorMessage":"`required_one_of` cannot be applied to a `#[serde(flatten)]` field","messagePattern":"`required_one_of` cannot be applied to a `#\\[serde\\(flatten\\)\\]` field","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"lib/vector-config-macros/src/configurable.rs","lineNumber":417,"sourceCode":"}\n\nfn build_named_struct_generate_schema_fn(\n    container: &Container<'_>,\n    fields: &[Field<'_>],\n) -> proc_macro2::TokenStream {\n    // Validate required_one_of usage before building groups.\n    // Scan ALL fields (including non-visible) so #[serde(skip)] fields are caught too.\n    for field in fields.iter() {\n        if field.required_one_of().is_some() {\n            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(),","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config-macros/src/configurable.rs#L399-L435","documentation":"During the same pre-schema validation in the `Configurable` derive, a field with `#[serde(flatten)]` cannot carry `required_one_of`. Flattened fields absorb arbitrary keys at deserialization time, so the derive cannot generate a meaningful schema entry or enforce an at-least-one-of group over them; the combination is rejected at compile time.","triggerScenarios":"Marking one field `#[serde(flatten)]` and also `#[required_one_of]` on a struct using the configurable derive, then running `cargo build`/`check`.","commonSituations":"Flattening an embedded options struct while trying to require one of its keys at the outer level; merging configs where the flattened field accidentally retains a validation attribute.","solutions":["Remove `required_one_of` from the flattened field","If one of the flattened struct's members must be required, move the validation into the flattened type itself","Replace `#[serde(flatten)]` with explicit named fields if group validation over them is required"],"exampleFix":"// before\n#[configurable_component]\nstruct Config {\n  #[serde(flatten)]\n  #[required_one_of]\n  extra: ExtraOptions,\n}\n// after\n#[configurable_component]\nstruct Config {\n  #[serde(flatten)]\n  extra: ExtraOptions,\n}","handlingStrategy":"validation","validationCode":"if field_has_attr(field, \"required_one_of\") && serde_arg_is(field, \"flatten\") {\n    panic!(\"required_one_of on flattened field\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not attach group-validation attributes to #[serde(flatten)] fields","Put intra-struct required-one-of rules inside the flattened type instead"],"tags":["rust","proc-macro","serde","schema"],"backgroundTag":"conflicting-config-options","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"}