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

org.http4k.contract.simple.SimpleJson.kt Maven / Gradle / Ivy

There is a newer version: 5.31.0.0
Show newest version
package org.http4k.contract.simple

import org.http4k.contract.ContractRenderer
import org.http4k.contract.ContractRoute
import org.http4k.contract.ErrorResponseRenderer
import org.http4k.contract.JsonErrorResponseRenderer
import org.http4k.contract.PathSegments
import org.http4k.contract.Tag
import org.http4k.contract.security.Security
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.core.with
import org.http4k.format.Json

class SimpleJson(private val json: Json) : ContractRenderer, ErrorResponseRenderer by JsonErrorResponseRenderer(json) {
    private fun render(pathSegments: PathSegments, route: ContractRoute) =
        route.method.toString() + ":" + route.describeFor(pathSegments) to json.string(route.meta.summary)

    override fun description(contractRoot: PathSegments, security: Security?, routes: List, tags: Set): Response =
        Response(OK)
            .with(json { body().toLens().of(obj("resources" to obj(routes.map { render(contractRoot, it) }))) })
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy