New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement idiomatic environment variable handling #414
Draft
rocketraman
wants to merge
4
commits into
sksamuel:master
Choose a base branch
from
rocketraman:rg/env-var-idiomatic
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Mar 29, 2024
rocketraman
force-pushed
the
rg/env-var-idiomatic
branch
2 times, most recently
from
April 1, 2024 13:48
fafb6a4
to
45e0f94
Compare
rocketraman
force-pushed
the
rg/env-var-idiomatic
branch
3 times, most recently
from
April 4, 2024 03:40
5448e02
to
7bcd7ab
Compare
Draft
The purpose of the path normalizer is to normalize all inbound paths by making them lower case, and removing any "-" characters. Normalizing paths means sources with different idiomatic approaches to defining key values will all map correctly to the defined config classes. The only downside to this is multiple config attributes in the same class that differ only by case can no longer be disambiguated. This should be a rare case and the advantages are more than worth losing this "feature". We also add a LowercaseParameterMapper by default which can handle the normalized paths.
With path normalization (and even before path normalization), it was possible for the reported path to not match the input value. For example, with environment variables, the environment variable may have been `FOO__BAR`, but the report showed `FOO.BAR`, which makes it harder for users to trace the report back to the original source. We now add a `sourceKey` attribute to `Node` and report on it, to show user's the key value as it was originally present in the source.
rocketraman
force-pushed
the
rg/env-var-idiomatic
branch
2 times, most recently
from
April 4, 2024 14:13
a258928
to
7e2b213
Compare
Remove both the `SnakeCaseParamMapper` and `KebabCaseParamMapper` by default, add the `PathNormalizer` by default. Add removal of `_` to path normalizer. Fix some issues with the `HikariDataSourceDecoder` when enabling path normalization by default -- that decoder requires the original key case as its props are case-sensitive. Create an abstract `UnnormalizedKeysDecoder` which has the ability to restore the case of keys via the `sourceKey`. Fix breaking explicit sealed types with normalization because the discriminator field defaults to `_type` which normalizes to `type`. Disable normalization if the field name matches the discriminator field name, and the node is a `MapNode`. Fix reporting for strict mode to use the `sourceKey` value, so that reporting matches the source value, not the normalized value. Update Preprocessor implementations to correctly copy the source key when new Map and Array nodes are created.
rocketraman
force-pushed
the
rg/env-var-idiomatic
branch
from
April 4, 2024 17:50
7e2b213
to
f0f6b50
Compare
rocketraman
force-pushed
the
rg/env-var-idiomatic
branch
from
April 4, 2024 17:57
f0f6b50
to
29ff9c4
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Leverage the capability exposed by #413 to implement idiomatic environment variable handling.
Fixes #410.
I've tried to implement this in a backward compatible way, but if we are ok with breaking compatibility for 3.0, given the new path normalization capability, we could replace the existing logic for env vars and simplify it down to always apply env vars with the new logic, removing the
EnvironmentVariableOverridePropertySource
and simplifyingEnvironmentVariablesPropertySource
to remove all the config vals, which is what I understood from #413 (comment).This PR is stacked on top of #413 and will be rebased and moved out of draft once that PR is merged.