Skip to content

Add StringOrDefault type support in various constraints and config#360

Merged
twisti-dev merged 9 commits into
version/26.1from
feat/more-config-types
May 27, 2026
Merged

Add StringOrDefault type support in various constraints and config#360
twisti-dev merged 9 commits into
version/26.1from
feat/more-config-types

Conversation

@twisti-dev
Copy link
Copy Markdown
Contributor

This pull request extends the configuration constraints system to support new wrapper types such as StringOrDefault, DurationOrDisabled, IntOr, and DoubleOr. 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:

  • Added constraint factories for StringOrDefault to support annotations like @Contains, @EndsWith, @MaxLength, and @MinLength, enabling these constraints to be applied to wrapped string values. [1] [2] [3] [4] [5]
  • Added constraint factories for DurationOrDisabled to support @MaxDuration and @MinDuration annotations, allowing duration constraints to be applied to optional or disabled durations. [1] [2]
  • Added constraint factories for IntOr and DoubleOr to support number-related constraints (@MaxNumber, @MinNumber, @PositiveNumber, @NegativeNumber) for these wrapper types. [1] [2] [3] [4]

Constraint utility improvements:

  • Added utility functions like toStringOrDefaultAware and updated existing utilities (e.g., configSizeOrNull, asPathOrNull) to handle new wrapper types, ensuring consistent behavior across the codebase. [1] [2] [3]
  • Updated the DisallowValues constraint to use the new utility for string conversion, improving its compatibility with wrapper types.

Project version update:

  • Bumped the project version from 3.16.0 to 3.17.0 in gradle.properties.

…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
@twisti-dev twisti-dev self-assigned this May 27, 2026
Copilot AI review requested due to automatic review settings May 27, 2026 18:58
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 StringOrDefault type 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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

- 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
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ API/ABI changes detected!

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 push

After updating, the CI will pass. Make sure the changes are backward compatible.

2 similar comments
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ API/ABI changes detected!

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 push

After updating, the CI will pass. Make sure the changes are backward compatible.

@github-actions
Copy link
Copy Markdown
Contributor

⚠️ API/ABI changes detected!

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 push

After updating, the CI will pass. Make sure the changes are backward compatible.

@twisti-dev twisti-dev merged commit 33f998f into version/26.1 May 27, 2026
7 checks passed
@twisti-dev twisti-dev deleted the feat/more-config-types branch May 27, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants