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

com.ancientlightstudios.example.features.server.JsonRequiredMapContext.kt Maven / Gradle / Ivy

There is a newer version: 0.4.14
Show newest version
// THIS IS A GENERATED FILE. DO NOT EDIT!
package com.ancientlightstudios.example.features.server

import com.ancientlightstudios.example.custom.*
import com.ancientlightstudios.example.features.server.model.OperationError
import com.ancientlightstudios.example.features.server.model.SimpleObject
import com.ancientlightstudios.quarkus.kotlin.openapi.*
import com.ancientlightstudios.quarkus.kotlin.openapi.extension.*
import com.fasterxml.jackson.databind.ObjectMapper
import jakarta.ws.rs.core.HttpHeaders
import org.jboss.resteasy.reactive.RestResponse

class JsonRequiredMapContext(
    val request: Maybe, 
    private val objectMapper: ObjectMapper, 
    private val headers: HttpHeaders
) : RequestContext, ResponseWithGenericStatus {

    override fun status(
        status: Int, 
        mediaType: String?, 
        body: Any?, 
        vararg headers: Pair
    ): Nothing = throw RequestHandledSignal(RestResponse.ResponseBuilder.create(status).entity(body)
            .type(mediaType).apply {
                headers.forEach {
                        headers(it.first, it.second)
                    }
            }.build())

    fun ok(body: Map): Nothing = status(200, "application/json", body.asJson {
                it.asJson()
            }.asString(objectMapper))

    fun badRequest(body: OperationError): Nothing = status(400, "application/json", body.asJson().asString(objectMapper))

    override fun rawHeaderValue(name: String) = headers.getRequestHeader(name)?.firstOrNull()

    override fun rawHeaderValues(name: String) = (headers.getRequestHeader(name) ?: listOf())

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy