com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable.ResponseCode.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-kotlin-openapi-maven-plugin Show documentation
Show all versions of quarkus-kotlin-openapi-maven-plugin Show documentation
A Maven plugin to use the OpenAPI generator.
package com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable
import com.ancientlightstudios.quarkus.kotlin.openapi.utils.SpecIssue
import jakarta.ws.rs.core.Response
sealed interface ResponseCode {
object Default : ResponseCode {
override fun toString() = "Default"
}
@JvmInline
value class HttpStatusCode(val value: Int) : ResponseCode {
override fun toString() = value.toString()
fun statusCodeReason() = Response.Status.fromStatusCode(value)?.reasonPhrase ?: "status${this}"
fun statusCodeName() = Response.Status.fromStatusCode(value)?.name ?: "status${this}"
}
companion object {
fun fromString(value: String) = when (value) {
"default" -> Default
else -> value.toIntOrNull()?.let { HttpStatusCode(it) }
?: SpecIssue("invalid response code '$value'.")
}
}
}