https://kotlinlang.org logo
Join Slack
Powered by
# akkurate
  • d

    dave08

    10/17/2023, 1:47 PM
    How do you validate on a List (doesn't seem like there's a section in the docs on this -- and it also seems that there's no specialized matchers list for this scope...)?
    Copy code
    val validateInstallActionList = dev.nesk.akkurate.Validator<List<InstallAction>> {
       // ....?        
    }
    (notice that Intellij had troubles importing
    Validator
    ...?)
    j
    • 2
    • 21
  • d

    dave08

    10/17/2023, 3:22 PM
    It would also be nice to have isEqualExceptForProperties(foo, prop2, prop3) // props list is vararg
    j
    p
    • 3
    • 6
  • d

    dave08

    10/18/2023, 12:45 PM
    Btw, the source code doesn't seem to be available when ctrl-clicking something in akkurate from my code... is there something missing when you upload to maven?
    j
    • 2
    • 1
  • r

    Ronny BrΓ€unlich

    10/20/2023, 6:34 AM
    Hello, I saw yesterday's annoucement of akkurate and took a quick glance at it. I was wondering why you've chosen to implement your own
    ValidationResult
    class instead of e.g. using Arrow's
    Either
    . I guess the latter would make for a better interoperability.
    p
    j
    • 3
    • 6
  • d

    dave08

    10/29/2023, 10:36 AM
    Just thinking out loud... maybe the Arrow adapter shouldn't just translate a ValidationResult to Either, but rather provide it's own
    .bind()
    and function with
    Raise
    that returns the success's value, or raises the error or exception... but then maybe both error types should be encapsulated in their own sealed interface? That would avoid the overhead of having to convert to Either just to bind or raise etc...
    πŸ’― 1
    j
    • 2
    • 1
  • j

    Johann Pardanaud

    10/30/2023, 1:18 PM
    Akkurate *0.4.0* just got released! ✨ In summary: β€’ The documentation is now searchable πŸ” β€’ New constraints to validate JVM dates β€’ Validating nullable iterables just got easier:
    Validator<List<Any>?> { each { ... } }
    β€’ The configuration of a
    Validator
    has been revamped to a DSL builder. What to expect in the next weeks 🦠 β€’ Better documentation: Kdoc for every public symbol, and server validation tutorials β€’ The first integration in a long series: arrow Arrow
    K 5
    p
    • 2
    • 2
  • j

    Johann Pardanaud

    11/11/2023, 6:03 PM
    The first tutorial is finally available! Discover how to do server-side validation with Akkurate 🎯 and Ktor ktor Let me know what you think about it. πŸ™‡β€β™‚οΈ Is it too long? Too complex? Or is it missing some things? I want to know πŸ™‚
    πŸ‘ 2
    πŸ‘πŸΎ 1
    πŸ‘πŸΌ 1
    p
    d
    • 3
    • 7
  • r

    rocketraman

    11/14/2023, 2:47 PM
    Thanks for the recent tutorial @Johann Pardanaud. One gap I see with using data classes in API interfaces is that immutable strongly-typed data classes aren't often a great fit for receiving "messy" data at the API level. For example, if a value is required, it has to be given a "default value" -- in your tutorial you used an empty String, but that introduces some noise into the data model. Furthermore, errors can be thrown in advance of validation -- kotlinx-serialization may not even be able to create the data class if the types or fields don't match. Also, implementing capabilities like
    PATCH
    is impossible to do with the same types, because the incoming data is incomplete, so even if the server-side code can deserialize it (unlikely), we still need to know which subset of fields was actually sent by the client. I had implemented https://github.com/rocketraman/kpropmap to deal with these scenarios in the past. The idea is to receive the data from the API in a flexible way, and then do validation and conversion to the strongly typed model on the server-side. Any thoughts on introducing a similar capability to Akkurate? I've long wanted, but haven't had the time to have kpropmap use KSP and kotlinx-serialization rather than runtime reflection, and Akkurate already uses these tools.
    j
    • 2
    • 3
  • j

    Johann Pardanaud

    11/17/2023, 4:04 PM
    I've started to work on the missing KDoc for all the library symbols, it will take some time but its on the right track. kodee happy Each constraint will contain a code example in its documentation, see `hasSizeEqualTo()` for example. Expect more documentation in the following weeks. You can keep track of the progression on GitHub issues.
    ❀️ 3
    πŸ‘πŸΎ 1
  • j

    Johann Pardanaud

    11/17/2023, 4:05 PM
    (also, Arrow's integration is on the way arrow)
    πŸ™Œ 1
  • j

    Johann Pardanaud

    11/29/2023, 12:44 PM
    Akkurate 0.5.0 just got released! πŸ₯³ This is a really small release, essentially it contains: β€’ A new configuration option to fail on the first constraint violation β€’ More documented symbols with KDoc β€’ Some improvements on the online documentation Now it's time for Arrow's integration πŸ’ͺ
    K 4
    πŸ‘πŸΎ 1
    πŸŽ‰ 1
    🀘 1
  • j

    Johann Pardanaud

    12/06/2023, 11:32 AM
    Feel free to give me some feedback about Arrow's integration πŸ™‚ https://kotlinlang.slack.com/archives/C5UPMM0A0/p1701862293655069
    p
    • 2
    • 2
  • j

    Johann Pardanaud

    12/12/2023, 1:22 PM
    πŸŽ‰ In release 0.6.0, Akkurate akkurate finally supports #arrow arrow https://akkurate.dev/docs/arrow-integration.html
    K 2
  • j

    Johann Pardanaud

    12/12/2023, 4:49 PM
    set the channel topic: akkurate The expressive validation library https://akkurate.dev
  • d

    dave08

    12/25/2023, 10:39 AM
    Just thinking... maybe it would be a good idea to have a variant of
    Validator { }
    that generates a
    Raise<NonEmptySet<ConstraintViolation>>.() -> T
    that way it could be used in an either without
    toEither()
    and
    bind(..)
    ?
    j
    • 2
    • 13
  • j

    Johann Pardanaud

    02/09/2024, 1:57 PM
    Long time no see! Akkurate 0.7.0 is finally released πŸ₯³ So, why did it took so much time for such a small release? I'm currently starting my own company (unrelated to Akkurate) and it takes a lot of time and work, which means I didn't have much time for Akkurate at the end. πŸ˜…
    K 2
  • j

    Johann Pardanaud

    05/27/2024, 8:56 AM
    Akkurate 0.8.0 has been released! akkurate What's new? ✨ You can now transform values before validating them, perfect for normalization:
    Copy code
    hashtags.each {
        // Trim hashtags for leading "#", and only then ensure that it's not empty
        map { it.trimStart('#') }.isNotEmpty()
    }
    New constraints:
    Copy code
    // Validate the type of a value
    someValue.isInstanceOf<String>()
    
    // Validate elements are unique in a collection
    someCollection.hasNoDuplicates()
    It is now easier than ever to validate a specific index of a collection:
    Copy code
    someCollection.first().isNotEmpty()
    someCollection.last().isNotEmpty()
    someCollection[index].isNotEmpty()
    What's next? πŸ”œ Probably Kotlin 2.0 and KMP 😏
    K 2
    πŸŽ‰ 1
    πŸ‘ 1
    a
    • 2
    • 1
  • c

    Cies

    06/19/2024, 1:42 PM
    I have two questions: (1) why is there an
    @Validate
    annotation given that Kotlin tries to avoid them (and the reflection based control flows that result from them) over explicit call chains; and (2) is it possible to inspect the validation constrains (in other words: are the validation constrains "just data" so we can write programs that, for instance, add a
    max-length=X
    attribute a HTML form element if there is a maxLength constraint on the field that backs up the form element)?
    j
    • 2
    • 2
  • j

    Johann Pardanaud

    09/10/2024, 3:17 PM
    Apparently I've found the issue and a fix, let me run additional checks, write tests, and release everything πŸ™‚
    ❀️ 1
    a
    • 2
    • 2
  • j

    Johann Pardanaud

    09/10/2024, 4:31 PM
    I've forgot to tell you, you can also use `map` to transform your data before validating it:
    Copy code
    map { it.map { it.id } }
        .hasNoDuplicates()
    πŸ‘πŸΌ 1
    • 1
    • 1
  • j

    Johann Pardanaud

    09/12/2024, 3:26 PM
    In response to popular request: the built-in constraints are now listed on a single page kodee floating
    πŸ‘πŸΌ 1
    πŸ‘ 2
  • j

    Johann Pardanaud

    09/24/2024, 6:16 PM
    akkurate Akkurate 0.10.0 has been released kodee happy In this release, you'll find: β€’ New constraints for kotlinx-datetime β€’ A new artifact to test your custom constraints And an official integration for Ktor is coming soon! ktor new
    ❀️ 3
    πŸ”₯ 1
  • a

    audax

    10/24/2024, 8:17 AM
    @Johann Pardanaud Akkurate works really well in our project. Thank you for solving our problem! ❀️
    kodee loving 3
    j
    a
    • 3
    • 30
  • c

    Cies

    11/04/2024, 9:42 AM
    I have a question, and I have no other place to ask it than here... I wonder if anyone has also run into this, or maybe even has an answer for this. Say we have a dto that backs a form submission:
    Copy code
    data class Person(val name: String?, val dateOfBirth: LocalDate?) {
      fun validate(): ValidationResult { ... }
    }
    When we submit an empty form
    name
    and
    dateOfBirth
    are
    null
    . Say this is fine for
    dateOfBirth
    (it's not a required field) and
    name
    fails validation. So we present the user with the validation errors and allow 'm to try again. Now user submits again with a
    name
    and the dto validates. Only all the required fields (in this case only one) are still nullable! So mapping the dto to db records (we use jOOQ for that) we have a lot of `!!`s, i.e.
    record.name = dto.name!!
    . Ideally I'd like the validate method to return a
    ValidatedPerson
    data class which has all required fields marked as non-nullable. And the only way I can imagine to have this, is by doing A LOT of boiler plate: defining the ``ValidatedPerson`` myself, mapping to it by hand, etc. This is so much work that I rather do the `!!`s on the mapping to the record. Like I said: just curious is you are doing something similar to me, or have found another way to handle this.
    j
    d
    a
    • 4
    • 20
  • j

    Johann Pardanaud

    11/16/2024, 9:38 AM
    kodee happy https://x.com/kotlin/status/1857095650355130469
    ❀️ 4
  • j

    Johann Pardanaud

    12/10/2024, 1:56 PM
    kodee excited https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1733838977631739
  • m

    mudasar187

    12/12/2024, 9:40 AM
    Hi! I am trying to test this library. But it seems like i cannot get the variable (property) from data class? From the docs i should get this ..?
    j
    • 2
    • 22
  • d

    dave08

    01/06/2025, 2:47 PM
    @Johann Pardanaud AFAIK
    otherwise { }
    only supports strings right? It's not so great when validating forms in Jetpack Compose where an error is an R.string.XXX (an Int...)... any chance of expanding that to support other types?
    j
    j
    • 3
    • 15
  • c

    Cies

    05/28/2025, 2:01 PM
    Question: why is the
    @Validate
    annotation needed?
    j
    • 2
    • 1
  • a

    Artem Kobzar

    06/11/2025, 9:11 AM
    Hi there. @Johann Pardanaud is there an ability to take a single validation for a property? I'm working on an example with akkurate for Spring Boot + Angular to share DTOs and validations and wondering if I can have something like this:
    Copy code
    @Validate
    data class Book(val title: String)
    
    val bookValidator = Validator<Book> { // this: Validatable<Book>
        title.hasLengthLowerThan(50)
    }
    
    val titleValidator = bookValidator::title // Validator.Runner<String>
    j
    • 2
    • 1