Skip to content

Commit 8b6e9e1

Browse files
committed
Konform: Portable validations for Kotlin
Closes #106
1 parent f5cd262 commit 8b6e9e1

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

kotlin-jvm/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies {
3838
implementation("com.uchuhimo:konf:_")
3939
implementation("io.github.lucapiccinelli:konad:_")
4040
implementation("io.github.serpro69:kotlin-faker:_")
41+
implementation("io.konform:konform:_")
4142
implementation("it.skrape:skrapeit-core:_")
4243
implementation("it.skrape:skrapeit-http-fetcher:_")
4344
implementation("org.jetbrains.exposed:exposed-core:_")

kotlin-jvm/src/main/kotlin/playground/_main.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fun main() {
2020
playground.kodein.db.main()
2121
playground.konad.main()
2222
playground.konf.main()
23+
playground.konform.main()
2324
playground.kotlin.collections.main()
2425
playground.kotlinfaker.main()
2526
playground.kotlinio.main()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@file:Suppress("PackageDirectoryMismatch")
2+
3+
package playground.konform
4+
5+
import io.konform.validation.Validation
6+
import io.konform.validation.jsonschema.maxLength
7+
import io.konform.validation.jsonschema.maximum
8+
import io.konform.validation.jsonschema.minLength
9+
import io.konform.validation.jsonschema.minimum
10+
import playground.shouldBe
11+
12+
/**
13+
* Konform: Portable validations for Kotlin
14+
* - [GitHub](https://github.com/konform-kt/konform)
15+
* - [Website](https://www.konform.io/)
16+
*/
17+
fun main() {
18+
val invalidUser = UserProfile("A", -1)
19+
val validationResult = validateUser(invalidUser)
20+
validationResult[UserProfile::fullName] shouldBe listOf("must have at least 2 characters")
21+
validationResult[UserProfile::age] shouldBe listOf("must be at least '0'")
22+
validationResult.errors.size shouldBe 2
23+
}
24+
25+
26+
data class UserProfile(
27+
val fullName: String,
28+
val age: Int?
29+
)
30+
31+
val validateUser = Validation<UserProfile> {
32+
UserProfile::fullName {
33+
minLength(2)
34+
maxLength(100)
35+
}
36+
37+
UserProfile::age ifPresent {
38+
minimum(0)
39+
maximum(150)
40+
}
41+
}

versions.properties

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,16 @@ version.google.android.material=1.3.0
146146
## # available=1.4.0-alpha01
147147
## # available=1.4.0-alpha02
148148
## # available=1.4.0-beta01
149-
150149
version.google.dagger=2.35.1
151150
## # available=2.36
152-
153151
version.io.github.lucapiccinelli..konad=1.2.1
154-
155152
version.io.github.serpro69..kotlin-faker=1.7.1
156153
## # available=1.8.0-rc.0
157-
154+
version.io.konform..konform=0.3.0
158155
version.it.skrape..skrapeit-core=1.0.0-alpha8
159-
160156
version.it.skrape..skrapeit-http-fetcher=1.1.1
161-
162157
version.junit=5.7.2
163158
### available=5.8.0-M1
164-
165159
version.junit.junit=4.13.2
166160

167161
version.kotest=4.4.3

0 commit comments

Comments
 (0)