{"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":377,"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":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-config-macros/src/configurable.rs#L359-L395","documentation":"Compile-time error from `build_named_struct_generate_schema_fn`. A `#[serde(flatten)]` field is merged into the parent object at deserialization time, so it has no top-level key of its own; a `oneOf` requirement keyed on the flattened field's name could never match. The macro rejects the combination up front.","triggerScenarios":"Applying `#[configurable(required_one_of(...))]` to a field that also carries `#[serde(flatten)]` in a Configurable-derived named struct.","commonSituations":"Config structs that flatten a shared sub-config (e.g. a common TLS or proxy block) and then try to include the flattened field in a required-one-of group during schema work.","solutions":["Move `required_one_of` to the concrete, non-flattened fields that actually represent the alternatives","Or stop flattening that field so it appears as a named key and can participate in the group","If the flattened inner type itself needs the constraint, put required_one_of on the inner struct's own fields"],"exampleFix":"// before\n#[configurable(required_one_of = [\"tls\"])]\n#[serde(flatten)]\npub tls: TlsConfig,\n\n// after\n// put the group on the real alternative fields instead\npub tls_enabled: Option<bool>,\npub tls_files: Option<TlsFiles>,","handlingStrategy":"validation","validationCode":"# CI gate: flatten conflicts fail at compile time\ncargo check --workspace --all-targets","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep required_one_of groups on concrete named fields, never on #[serde(flatten)] fields","Put constraints on the inner struct's own fields when flattening shared config"],"tags":["rust","proc-macro","compile-time","serde","flatten","schema-validation","vector"],"backgroundTag":"macro-attribute-conflict","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}