{"record":{"id":"81324a790aede998","repo":"vectordotdev/vector","slug":"required-one-of-is-not-supported-on-newtype-stru","errorCode":null,"errorMessage":"`required_one_of` is not supported on newtype struct fields","messagePattern":"`required_one_of` is not supported on newtype struct fields","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"lib/vector-config-macros/src/configurable.rs","lineNumber":595,"sourceCode":"        // Don't map this field if it's marked to be skipped for both serialization and deserialization.\n        .filter(|field| field.visible())\n        .map(generate_tuple_struct_field);\n\n    quote! {\n        fn generate_schema(schema_gen: &::std::cell::RefCell<::vector_config::schema::SchemaGenerator>) -> std::result::Result<::vector_config::schema::SchemaObject, ::vector_config::GenerateError> {\n            let mut subschemas = ::std::collections::Vec::new();\n\n            #(#mapped_fields)*\n\n            Ok(::vector_config::schema::generate_tuple_schema(&subschemas))\n        }\n    }\n}\n\nfn build_newtype_struct_generate_schema_fn(fields: &[Field<'_>]) -> proc_macro2::TokenStream {\n    for field in fields.iter() {\n        if field.required_one_of().is_some() {\n            return syn::Error::new(\n                field.span(),\n                \"`required_one_of` is not supported on newtype struct fields\",\n            )\n            .to_compile_error();\n        }\n    }\n\n    // Map the fields normally, but we should end up with a single field at the end.\n    let mut mapped_fields = fields\n        .iter()\n        // Don't map this field if it's marked to be skipped for both serialization and deserialization.\n        .filter(|field| field.visible())\n        .map(|field| generate_struct_field(field, &[]))\n        .collect::<Vec<_>>();\n\n    if mapped_fields.len() != 1 {\n        panic!(\"newtype structs should never have more than one field\");\n    }","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config-macros/src/configurable.rs#L577-L613","documentation":"Same family as the tuple-struct check: `#[configurable]` rejects `required_one_of` on newtype struct fields. A newtype struct has a single unnamed field, so the 'at least one of several keys' schema concept cannot be represented and the macro emits a compile error.","triggerScenarios":"Applying `#[configurable]` to a newtype struct like `struct Port(u16);` whose inner field is annotated with `required_one_of`.","commonSituations":"Wrapping a primitive for type safety (newtype pattern) and blindly carrying over field attributes from the original named struct.","solutions":["Remove the `required_one_of` attribute from the newtype's inner field.","Put `required_one_of` on the enclosing named struct's fields instead.","Redefine the type as a named struct if one-of validation between fields is needed."],"exampleFix":"// before\n#[configurable]\nstruct Endpoint(#[configurable(required_one_of = [\"host\"])] String);\n\n// after\n#[configurable]\nstruct Endpoint {\n    #[configurable(required_one_of = [\"host\", \"address\"])]\n    host: String,\n}","handlingStrategy":"validation","validationCode":"// keep newtypes attribute-free: #[configurable(transparent)] where possible","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use #[configurable(transparent)] for newtype wrappers.","Place one-of constraints on the outer named struct, not the newtype inner field."],"tags":["rust","proc-macro","compile-time","schema"],"backgroundTag":"unsupported-operation","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"}