forked from sksamuel/hoplite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable path normalization by default
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.
- Loading branch information
1 parent
eac8a0b
commit 80c6ed8
Showing
19 changed files
with
107 additions
and
37 deletions.
There are no files selected for viewing
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 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 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 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
33 changes: 33 additions & 0 deletions
33
hoplite-core/src/main/kotlin/com/sksamuel/hoplite/decoder/AbstractUnnormalizedKeysDecoder.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.sksamuel.hoplite.decoder | ||
|
||
import com.sksamuel.hoplite.ConfigResult | ||
import com.sksamuel.hoplite.DecoderContext | ||
import com.sksamuel.hoplite.MapNode | ||
import com.sksamuel.hoplite.Node | ||
import com.sksamuel.hoplite.transform | ||
import kotlin.reflect.KType | ||
|
||
/** | ||
* A decoder which decodes based on unnormalized keys. | ||
* | ||
* This is useful for decoders that need to know the original key names. | ||
* | ||
* It restores the original key names from the node source key. | ||
*/ | ||
abstract class AbstractUnnormalizedKeysDecoder<T> : NullHandlingDecoder<T> { | ||
override fun safeDecode(node: Node, type: KType, context: DecoderContext): ConfigResult<T> { | ||
val unnormalizedNode = node.transform { | ||
val sourceKey = it.sourceKey | ||
when (it) { | ||
is MapNode -> it.copy(map = it.map.mapKeys { (k, v) -> | ||
(v.sourceKey ?: k).removePrefix("$sourceKey.") | ||
}) | ||
else -> it | ||
} | ||
} | ||
|
||
return safeDecodeUnnormalized(unnormalizedNode, type, context) | ||
} | ||
|
||
abstract fun safeDecodeUnnormalized(node: Node, type: KType, context: DecoderContext): ConfigResult<T> | ||
} |
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 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 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 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 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 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 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 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 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 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 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 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 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 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