Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support validation during generation (collect errors). #58

Open
nomisRev opened this issue Jul 10, 2024 · 0 comments
Open

Support validation during generation (collect errors). #58

nomisRev opened this issue Jul 10, 2024 · 0 comments

Comments

@nomisRev
Copy link
Owner

We can collect errors in some cases, but we want to stick to vanilla Kotlin. So we should create an requireAll variant, than can handle multiple require statements, but still throw IllegalStateException as expected by KotlinX Serialization, and Ktor.

All code below should be generated, this is purely an example/proposal. The final result may look completely different.

fun requireAll(vararg validation: Pair<String, () -> Unit>) = TODO()

data class Person(val name: String, val age: Int) {
  init {
    requireAll(
      Pair("Name must be of length between x and y") { name.length in x..y },
      Pair("Age must be between i and j") { age in i..j }
    )
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant