Skip to content

Commit

Permalink
chore(api): Address depecrations of the Konform library
Browse files Browse the repository at this point in the history
Update code that uses Konform API that was deprecated in 0.9.0 [1].

[1]: https://github.com/konform-kt/konform/releases/tag/v0.9.0

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Nov 25, 2024
1 parent a8586cb commit f165294
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.apoapsis.ortserver.api.v1.model

import io.konform.validation.Validation
import io.konform.validation.jsonschema.pattern
import io.konform.validation.constraints.pattern

import java.util.EnumSet

Expand Down
2 changes: 1 addition & 1 deletion api/v1/model/src/commonMain/kotlin/Organization.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.apoapsis.ortserver.api.v1.model

import io.konform.validation.Validation
import io.konform.validation.jsonschema.pattern
import io.konform.validation.constraints.pattern

import kotlinx.serialization.Serializable

Expand Down
2 changes: 1 addition & 1 deletion api/v1/model/src/commonMain/kotlin/Product.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.apoapsis.ortserver.api.v1.model

import io.konform.validation.Validation
import io.konform.validation.jsonschema.pattern
import io.konform.validation.constraints.pattern

import kotlinx.serialization.Serializable

Expand Down
8 changes: 4 additions & 4 deletions api/v1/model/src/commonMain/kotlin/Repository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ data class CreateRepository(
val validate: ValidatorFunc<CreateRepository> = { obj ->
Validation {
CreateRepository::url {
addConstraint("malformed URL") {
constrain("malformed URL") {
Repository.isValidUrl(it)
} hint Repository.INVALID_URL_MESSAGE

addConstraint("URL cannot contain userinfo") {
constrain("URL cannot contain userinfo") {
!Repository.hasUserInfo(it)
} hint Repository.USER_INFO_MESSAGE
}
Expand All @@ -93,14 +93,14 @@ data class UpdateRepository(
val validate: ValidatorFunc<UpdateRepository> = { obj ->
Validation {
UpdateRepository::url {
addConstraint("malformed URL") {
constrain("malformed URL") {
when (it) {
is OptionalValue.Present -> Repository.isValidUrl(it.value)
is OptionalValue.Absent -> true
}
} hint Repository.INVALID_URL_MESSAGE

addConstraint("URL cannot contain userinfo") {
constrain("URL cannot contain userinfo") {
when (it) {
is OptionalValue.Present -> !Repository.hasUserInfo(it.valueOrThrow)
is OptionalValue.Absent -> true
Expand Down
2 changes: 1 addition & 1 deletion api/v1/model/src/commonMain/kotlin/Secret.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.eclipse.apoapsis.ortserver.api.v1.model

import io.konform.validation.Validation
import io.konform.validation.jsonschema.pattern
import io.konform.validation.constraints.pattern

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ typealias ValidatorFunc<T> = (T) -> ValidationResult<T>
/**
* An extension function for validating [OptionalValue] objects against a given regex [pattern].
*/
fun ValidationBuilder<OptionalValue<String>>.optionalPattern(pattern: Regex) = addConstraint(
"must match the expected pattern",
pattern.pattern
fun ValidationBuilder<OptionalValue<String>>.optionalPattern(pattern: Regex) = constrain(
"must match the expected pattern '${pattern.pattern}'"
) {
when (it) {
is OptionalValue.Present -> it.value.matches(pattern)
Expand Down

0 comments on commit f165294

Please sign in to comment.