File tree Expand file tree Collapse file tree 4 files changed +44
-7
lines changed
src/main/kotlin/playground Expand file tree Collapse file tree 4 files changed +44
-7
lines changed Original file line number Diff line number Diff 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:_" )
Original file line number Diff line number Diff 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()
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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-
150149version.google.dagger =2.35.1
151150# # # available=2.36
152-
153151version.io.github.lucapiccinelli..konad =1.2.1
154-
155152version.io.github.serpro69..kotlin-faker =1.7.1
156153# # # available=1.8.0-rc.0
157-
154+ version.io.konform..konform = 0.3.0
158155version.it.skrape..skrapeit-core =1.0.0-alpha8
159-
160156version.it.skrape..skrapeit-http-fetcher =1.1.1
161-
162157version.junit =5.7.2
163158# ## available=5.8.0-M1
164-
165159version.junit.junit =4.13.2
166160
167161version.kotest =4.4.3
You can’t perform that action at this time.
0 commit comments