{"record":{"id":"a84bcd882796b328","repo":"vectordotdev/vector","slug":"required-one-of-is-not-supported-on-enum-variant","errorCode":null,"errorMessage":"`required_one_of` is not supported on enum variant fields","messagePattern":"`required_one_of` is not supported on enum variant fields","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"lib/vector-config-macros/src/configurable.rs","lineNumber":841,"sourceCode":"\n    quote! {\n        #(#mapped_custom_attributes)*\n    }\n}\n\nfn get_field_schema_ty<'a>(field: &'a Field<'a>) -> &'a syn::Type {\n    // If there's a delegated type being used for field (de)serialization, that's ultimately the type\n    // we use to declare the schema, because we have to generate the schema for whatever type is\n    // actually being (de)serialized, not the final type that the intermediate value ends up getting\n    // converted to.\n    //\n    // Otherwise, we just use the actual field type.\n    field.delegated_ty().unwrap_or_else(|| field.ty())\n}\n\nfn generate_named_enum_field(field: &Field<'_>) -> proc_macro2::TokenStream {\n    if field.required_one_of().is_some() {\n        return syn::Error::new(\n            field.span(),\n            \"`required_one_of` is not supported on enum variant fields\",\n        )\n        .to_compile_error();\n    }\n    let field_name = field.ident().expect(\"field should be named\");\n    let field_ty = field.ty();\n    let field_already_contained = format!(\n        \"schema properties already contained entry for `{field_name}`, this should not occur\"\n    );\n    let field_key = field.name().to_string();\n\n    let field_schema = generate_struct_field(field);\n\n    // Fields that have no default value are inherently required.  Unlike fields on a normal\n    // struct, we can't derive a default value for an individual field because `serde`\n    // doesn't allow even specifying a default value for an enum overall, only structs.\n    let spanned_is_optional = quote_spanned! {field.span()=>","sourceCodeStart":823,"sourceCodeEnd":859,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-config-macros/src/configurable.rs#L823-L859","documentation":"Compile-time error from `generate_named_enum_field` in vector-config-macros. Struct-style enum variants are represented as subschemas keyed by field name, but `required_one_of` groups are only wired up for named struct containers; putting one on a field inside an enum variant has no codegen path, so it is rejected to avoid silently ignored constraints.","triggerScenarios":"`#[configurable(required_one_of(...))]` on a field of a struct variant: `enum E { V { #[configurable(required_one_of = ...)] field: T } }` where the enum derives Configurable.","commonSituations":"Trying to express 'one of these two fields must be set' inside a variant (e.g. alternative auth fields per variant) when the mechanism only exists at the named-struct level.","solutions":["Move the fields into a nested named struct and put required_one_of there, then use that struct as the variant's payload","Or express the constraint with separate enum variants, one per required field combination","Or drop required_one_of and validate at deserialization time with a custom TryFrom"],"exampleFix":"// before\nenum Auth { Key { #[configurable(required_one_of = [\"k\"])] key: Option<String> } }\n\n// after\n#[derive(Configurable)]\nstruct KeyAuth { #[configurable(required_one_of = [\"key\", \"token\"])] key: Option<String>, token: Option<String> }\nenum Auth { Key(KeyAuth) }","handlingStrategy":"validation","validationCode":"# CI gate: enum-variant usage fails at compile time\ncargo check --workspace --all-targets","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model per-variant constraints as nested named structs or as separate variants","Remember required_one_of is only wired up for named struct containers"],"tags":["rust","proc-macro","compile-time","enums","schema-validation","vector"],"backgroundTag":"macro-attribute-misplaced","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}