Skip to content

Tagged enums require tag set in both TOML and Env sources #118

@RapidPencil

Description

@RapidPencil

Say you have a serde tagged enum by #[confik(forward_serde(tag = "type"))] in the configuration:

use confik::Configuration;

#[derive(Debug, Clone, Configuration)]
#[confik(forward_serde(tag = "type", rename_all = "snake_case"))]
enum Config {
    Foo(Foo),
    Bar(Bar),
}

#[derive(Debug, Clone, Configuration)]
struct Foo {
    foo: String,
}

#[derive(Debug, Clone, Configuration)]
struct Bar {
    bar: String,
}

fn main() {
    let config = Config::builder()
        .override_with(confik::FileSource::new("config.toml"))
        .override_with(confik::EnvSource::new().allow_secrets())
        .try_build()
        .unwrap();
}

with config.toml

type = "foo"
foo = "hello"

and environment variable

TYPE=foo

The above works.
However, remove either of type = "foo" from config.toml or TYPE=foo from the environment, and this fails with an error:

(...)
missing field `type`
(...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug-upstreamBug exists, but only fixable in upstream crate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions