vectordotdev/vector · error · syn::Error
`required_one_of` cannot be applied to a…
Error message
`required_one_of` cannot be applied to a `#[serde(flatten)]` field
What it means
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.
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
Example fix
// before
#[configurable_component]
struct Config {
#[serde(flatten)]
#[required_one_of]
extra: ExtraOptions,
}
// after
#[configurable_component]
struct Config {
#[serde(flatten)]
extra: ExtraOptions,
} Defensive patterns
Strategy: validation
Validate before calling
if field_has_attr(field, "required_one_of") && serde_arg_is(field, "flatten") {
panic!("required_one_of on flattened field");
} Prevention
- Do not attach group-validation attributes to #[serde(flatten)] fields
- Put intra-struct required-one-of rules inside the flattened type instead
When it happens
Trigger: Marking one field `#[serde(flatten)]` and also `#[required_one_of]` on a struct using the configurable derive, then running `cargo build`/`check`.
Common situations: 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.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- `required_one_of` cannot be applied to a `#[serde(skip)]`…
- enums must always have a tagging mode
- named struct fields must always have an ident
- `required_one_of` cannot be applied to a…
- `required_one_of` is not supported on newtype struct fields
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/fbff8eac86908f1c.
Report an issue: GitHub.
Appendix: source
Thrown at lib/vector-config-macros/src/configurable.rs:417
}
fn build_named_struct_generate_schema_fn(
container: &Container<'_>,
fields: &[Field<'_>],
) -> proc_macro2::TokenStream {
// Validate required_one_of usage before building groups.
// Scan ALL fields (including non-visible) so #[serde(skip)] fields are caught too.
for field in fields.iter() {
if field.required_one_of().is_some() {
if !field.visible() {
return syn::Error::new(
field.span(),
"`required_one_of` cannot be applied to a `#[serde(skip)]` field",
)
.to_compile_error();
}
if field.flatten() {
return syn::Error::new(
field.span(),
"`required_one_of` cannot be applied to a `#[serde(flatten)]` field",
)
.to_compile_error();
}
if !is_option_type(field.ty())
&& field.default_value().is_none()
&& container.default_value().is_none()
{
return syn::Error::new(
field.span(),
"`required_one_of` requires the field to be optional; use `Option<T>` or add `#[serde(default)]`",
)
.to_compile_error();
}
if field.skip_deserializing() {
return syn::Error::new(
field.span(),View on GitHub (pinned to bdb87aeaa4)