Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
<!-- next-header -->
## [Unreleased] - ReleaseDate

### Fixes

- `Environment::convert_case` now applies the case conversion to each nested key segment

## [0.15.22] - 2026-03-17

### Documentation
Expand Down
6 changes: 5 additions & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ impl Source for Environment {

#[cfg(feature = "convert-case")]
if let Some(convert_case) = convert_case {
key = key.to_case(*convert_case);
key = key
.split('.')
.map(|segment| segment.to_case(*convert_case))
.collect::<Vec<_>>()
.join(".");
}

let value = if self.try_parsing {
Expand Down
32 changes: 32 additions & 0 deletions tests/testsuite/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,38 @@ fn test_parse_nested_kebab() {
);
}

#[test]
#[cfg(feature = "convert-case")]
fn test_parse_nested_upper_camel() {
use config::Case;

#[derive(Deserialize, Debug)]
struct TestConfig {
#[serde(rename = "Otel")]
otel: Inner,
}

#[derive(Deserialize, Debug)]
struct Inner {
#[serde(rename = "Endpoint")]
endpoint: String,
}

temp_env::with_var("CONFIG_OTEL__ENDPOINT", Some("from env"), || {
let environment = Environment::default()
.prefix("CONFIG")
.prefix_separator("_")
.separator("__")
.convert_case(Case::UpperCamel);

let config = Config::builder().add_source(environment).build().unwrap();

let config: TestConfig = config.try_deserialize().unwrap();

assert_eq!(config.otel.endpoint, "from env");
});
}

#[test]
fn test_parse_string() {
// using a struct in an enum here to make serde use `deserialize_any`
Expand Down