question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace konstraint extensions by a validator Kotlin DSL

See original GitHub issue

In order to provide a more idiomatic Kotlin experience, I am wondering if we could replace konstraint extensions introduced by #16 (I don’t really like this kind of k prefixed to be honest) by a Kotlin DSL that would isolate more the Kotlin API from the Java one. I need to give it more thoughts but my initial proposal is the following:

val validator = validator<User> {
     constraint(User::name) {
          notNull()
          lessThanOrEqual(20)
     }
     constraint(User::email) {
          notNull()
          greaterThanOrEqual(5)
          lessThanOrEqual(50) //
          email()
     }
     constraint(User::age) {
          notNull()
          greaterThanOrEqual(0)
          lessThanOrEqual(200)
     }
}

Any thoughts? If you like it I can probably try to craft a PR.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hartmut-co-ukcommented, Jun 14, 2021

let me try to make time! (might not be within the next 2 weeks)

0reactions
makingcommented, Jul 14, 2021

Supported by 0329aa47f67c4071adc3cc576f9287faaddbdde7 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

YAVI (Yet Another ValIdation) Reference Documentation
The ValidatorBuilder#constraint is used to declare the constraints which should ... If you are using Kotlin, you can define a Validator with DSL...
Read more >
Chapter 11. DSL construction - Kotlin in Action
In this chapter, we'll discuss how you can design expressive and idiomatic APIs for your Kotlin classes through the use of domain-specific languages...
Read more >
Validation with Hibernate Validator - Quarkus
This command generates a Maven structure importing the RESTEasy Reactive/JAX-RS, Jackson and Hibernate Validator/Bean Validation extensions.
Read more >
Object validation in Ktor/Kotlin. Introduction | Nerd For Tech
The API is fluent but it doesn't have a DSL: Overall the API looked out-dated and it's also dependent on some Android specific...
Read more >
[HV-1796] Kotlin extension function on parameterized type ...
Method constraints validation. Kotlin. Presence of extension ... Given the following code making use of method constraint validation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found