All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable.ResponseCode.kt Maven / Gradle / Ivy

There is a newer version: 0.4.14
Show newest version
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'.")

        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy