fix: Align errorMessage param type in validate and requireNotNull as same as their suspend counterparts#628
Open
Vijay0710 wants to merge 1 commit into
Open
Conversation
This file contains hidden or 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
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.
🎯 Goal
validateandrequireNotNullaccepted a lazy lambdacrossinline errorMessage: () -> Stringwhile their suspend counterparts
suspendValidateandsuspendRequireNotNullaccepted a plainString. This inconsistency made the API surface asymmetric and the existing KDocs activelymisleading — they still described
errorMessageas a lambda even after the implementationdiverged. This PR aligns the non-suspend functions with the suspend ones and corrects the stale
documentation.
🛠 Implementation details
errorMessageinvalidateandrequireNotNullfromcrossinline errorMessage: () -> StringtoerrorMessage: StringcallsInPlace(errorMessage, ...)contract clause from both functions@param errorMessageKDoc invalidate: was "A lambda that provides the error messagewhen validation fails" → now "The error message when validation fails."
@param errorMessageKDoc inrequireNotNull: was "A lambda that provides the errormessage when the selected value is null" → now "The error message when the selected value
is null."
ResponseTransformerTestfrom trailing lambda syntax to plainString.apidump files via./gradlew apiDump✍️ Explain examples
Before:
apiResponse.validate({ it.length > 2 }) { "Too short" } apiResponse.requireNotNull({ it.field }) { "Value is null" }After:
apiResponse.validate({ it.length > 2 }, errorMessage = "Too short") apiResponse.requireNotNull({ it.field }, "Value is null") // Suspend variants were already consistent — unchanged: apiResponse.suspendValidate({ it.length > 2 }, "Too short") apiResponse.suspendRequireNotNull({ it.field }, "Value is null")