Add StringOrDefault type support in various constraints and config#360
Conversation
…traints - introduce StringOrDefault type handling in configSizeOrNull, asPathOrNull, and other constraints - implement factory methods for StringOrDefault in Contains, EndsWith, MaxLength, MinLength, and others - update DisallowValues and other constraints to utilize StringOrDefault for validation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c83e4b3be
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR extends the Surf API core configuration constraint/serialization layer to support additional “wrapper” config types (notably StringOrDefault, plus constraint support for DurationOrDisabled, IntOr, and DoubleOr) so existing annotations work consistently with these wrappers.
Changes:
- Added
StringOrDefaulttype and registered its Configurate serializer. - Added new constraint factories so number/string/duration constraints can validate
IntOr/DoubleOr/DurationOrDisabled/StringOrDefault. - Added small constraint utilities updates and bumped the project version to
3.17.0.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/type/StringOrDefault.kt | Introduces the new StringOrDefault wrapper type and its serializer. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/serializer/SpongeConfigSerializers.kt | Registers the new serializer and constraint factories in the object mapper. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/StartsWith.kt | Adds StringOrDefault constraint factory for @StartsWith. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/Range.kt | Adds IntOr/DoubleOr constraint factories for @Range. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/PositiveNumber.kt | Adds IntOr/DoubleOr constraint factories for @PositiveNumber. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/NegativeNumber.kt | Adds IntOr/DoubleOr constraint factories for @NegativeNumber. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/MinNumber.kt | Adds IntOr/DoubleOr constraint factories for @MinNumber. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/MaxNumber.kt | Adds IntOr/DoubleOr constraint factories for @MaxNumber. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/MinLength.kt | Adds StringOrDefault constraint factory for @MinLength. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/MaxLength.kt | Adds StringOrDefault constraint factory for @MaxLength. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/Contains.kt | Adds StringOrDefault constraint factory for @Contains. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/EndsWith.kt | Adds StringOrDefault constraint factory for @EndsWith. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/MinDuration.kt | Adds DurationOrDisabled constraint factory for @MinDuration. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/MaxDuration.kt | Adds DurationOrDisabled constraint factory for @MaxDuration. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/ExistingFile.kt | Extends path conversion helper to support StringOrDefault. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/DisallowValues.kt | Uses a new helper to stringify wrapper values for disallow checks. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/ConstraintsUtils.kt | Adds toStringOrDefaultAware() helper for wrapper-aware string conversion. |
| surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/constraints/CollectionConstraintUtils.kt | Extends configSizeOrNull() to support StringOrDefault. |
| surf-api-core/surf-api-core/api/surf-api-core.api | Updates ABI dump to include the new public type. |
| gradle.properties | Bumps project version to 3.17.0. |
- change value type from String to String? in StringOrDefault data class - modify or() method to return default when value is null - update USE_DEFAULT constant to use null instead of a marker string - adjust serialization to handle nullable StringOrDefault instances
- implement toString method to return DEFAULT_MARKER for null values
- replace toStringOrDefaultAware with toString for value comparison - ensure consistent handling of nullable values in DisallowValues constraint
…d for value comparison
…t/more-config-types
|
This PR contains changes that modified the public API. To update the reference ABI dumps: ./gradlew updateKotlinAbi
git add **/api/**
git commit -m "Update ABI reference"
git pushAfter updating, the CI will pass. Make sure the changes are backward compatible. |
2 similar comments
|
This PR contains changes that modified the public API. To update the reference ABI dumps: ./gradlew updateKotlinAbi
git add **/api/**
git commit -m "Update ABI reference"
git pushAfter updating, the CI will pass. Make sure the changes are backward compatible. |
|
This PR contains changes that modified the public API. To update the reference ABI dumps: ./gradlew updateKotlinAbi
git add **/api/**
git commit -m "Update ABI reference"
git pushAfter updating, the CI will pass. Make sure the changes are backward compatible. |
This pull request extends the configuration constraints system to support new wrapper types such as
StringOrDefault,DurationOrDisabled,IntOr, andDoubleOr. It introduces new constraint factories and utility functions to ensure that constraints like min/max length, min/max number, and others work seamlessly with these types. Additionally, it makes minor improvements and bug fixes to existing constraint logic.Constraint support for new wrapper types:
StringOrDefaultto support annotations like@Contains,@EndsWith,@MaxLength, and@MinLength, enabling these constraints to be applied to wrapped string values. [1] [2] [3] [4] [5]DurationOrDisabledto support@MaxDurationand@MinDurationannotations, allowing duration constraints to be applied to optional or disabled durations. [1] [2]IntOrandDoubleOrto support number-related constraints (@MaxNumber,@MinNumber,@PositiveNumber,@NegativeNumber) for these wrapper types. [1] [2] [3] [4]Constraint utility improvements:
toStringOrDefaultAwareand updated existing utilities (e.g.,configSizeOrNull,asPathOrNull) to handle new wrapper types, ensuring consistent behavior across the codebase. [1] [2] [3]DisallowValuesconstraint to use the new utility for string conversion, improving its compatibility with wrapper types.Project version update:
3.16.0to3.17.0ingradle.properties.