com.ancientlightstudios.quarkus.kotlin.openapi.extension.UUIDSupport.kt Maven / Gradle / Ivy
package com.ancientlightstudios.quarkus.kotlin.openapi.extension
import com.ancientlightstudios.quarkus.kotlin.openapi.*
import com.fasterxml.jackson.databind.JsonNode
import java.util.*
fun Maybe.asUUID(): Maybe = onNotNull {
try {
success(UUID.fromString(value))
} catch (e: IllegalArgumentException) {
failure(ValidationError("Invalid UUID.", context))
}
}
@JvmName("asUuidFromJson")
fun Maybe.asUUID(): Maybe = asString().asUUID()
@JvmName("asStringFromUUID")
fun UUID.asString(): String = toString()
fun UUID.asJson(): JsonNode = asString().asJson()