fix: serialization of api key auth location (#261)
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
### Added
|
||||
|
||||
### Changed
|
||||
- Fix serialization for api key location in api key auth configuration
|
||||
|
||||
### Remove
|
||||
|
||||
|
@ -18,6 +18,10 @@ sourdough {
|
||||
|
||||
dependencies {
|
||||
implementation(group = "org.jetbrains.kotlinx", "kotlinx-serialization-json", version = "1.3.2")
|
||||
|
||||
// TESTING
|
||||
|
||||
testImplementation(testFixtures(projects.kompendiumCore))
|
||||
}
|
||||
|
||||
testing {
|
||||
|
@ -1,20 +1,18 @@
|
||||
package io.bkbn.kompendium.oas.security
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.util.Locale
|
||||
|
||||
// TODO... is there even an official ktor api auth mechanism??
|
||||
|
||||
@Serializable
|
||||
@Suppress("UnusedPrivateMember")
|
||||
class ApiKeyAuth(val `in`: ApiKeyLocation, val name: String) : SecuritySchema {
|
||||
class ApiKeyAuth private constructor(val `in`: String, val name: String) : SecuritySchema {
|
||||
val type: String = "apiKey"
|
||||
|
||||
enum class ApiKeyLocation {
|
||||
HEADER,
|
||||
QUERY,
|
||||
COOKIE;
|
||||
constructor(location: ApiKeyLocation, name: String) : this(location.value, name)
|
||||
|
||||
override fun toString(): String = name.lowercase(Locale.getDefault())
|
||||
enum class ApiKeyLocation(val value: String) {
|
||||
HEADER("header"),
|
||||
QUERY("query"),
|
||||
COOKIE("cookie");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package io.bkbn.kompendium.oas.security
|
||||
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
private val json = Json { encodeDefaults = true }
|
||||
|
||||
class ApiKeyAuthTest : DescribeSpec({
|
||||
describe("ApiKeyAuth") {
|
||||
it("should produce correct json") {
|
||||
mapOf(
|
||||
ApiKeyAuth.ApiKeyLocation.HEADER to "header",
|
||||
ApiKeyAuth.ApiKeyLocation.COOKIE to "cookie",
|
||||
ApiKeyAuth.ApiKeyLocation.QUERY to "query",
|
||||
).forEach {
|
||||
val example = ApiKeyAuth(it.key, "test-name")
|
||||
|
||||
val json = json.encodeToString(ApiKeyAuth.serializer(), example)
|
||||
|
||||
json.shouldBe("""{"in":"${it.value}","name":"test-name","type":"apiKey"}""")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user