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

org.http4k.contract.openapi.v2.OpenApi2SecurityRenderer.kt Maven / Gradle / Ivy

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

import org.http4k.contract.openapi.Render
import org.http4k.contract.openapi.RenderModes
import org.http4k.contract.openapi.SecurityRenderer
import org.http4k.contract.openapi.rendererFor
import org.http4k.contract.security.ApiKeySecurity
import org.http4k.contract.security.BasicAuthSecurity
import org.http4k.contract.security.ImplicitOAuthSecurity

/**
 * Compose the supported Security models
 */
val OpenApi2SecurityRenderer = SecurityRenderer(ApiKeySecurity.renderer, BasicAuthSecurity.renderer, ImplicitOAuthSecurity.renderer)

val ApiKeySecurity.Companion.renderer
    get() = rendererFor> {
        object : RenderModes {
            override fun  full(): Render = {
                obj(it.name to obj(
                    "type" to string("apiKey"),
                    "in" to string(it.param.meta.location),
                    "name" to string(it.param.meta.name)
                ))
            }

            override fun  ref(): Render = { obj(it.name to array(emptyList())) }
        }
    }

val BasicAuthSecurity.Companion.renderer
    get() = rendererFor {
        object : RenderModes {
            override fun  full(): Render = {
                obj(it.name to obj(
                    "type" to string("basic")
                ))
            }

            override fun  ref(): Render = { obj(it.name to array(emptyList())) }
        }
    }

val ImplicitOAuthSecurity.Companion.renderer
    get() = rendererFor {
        object : RenderModes {
            override fun  full(): Render = {
                obj(it.name to
                    obj(
                        listOfNotNull(
                            "type" to string("oauth2"),
                            "flow" to string("implicit"),
                            "authorizationUrl" to string(it.authorizationUrl.toString())
                        ) + it.extraFields.map { it.key to string(it.value) }
                    )
                )
            }

            override fun  ref(): Render = { obj(it.name to array(emptyList())) }
        }
    }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy