allow custom type overrides (#83)

This commit is contained in:
Ryan Brink
2021-08-12 21:38:48 -04:00
committed by GitHub
parent 3d99bf35fd
commit b021935b10
7 changed files with 56 additions and 1 deletions

View File

@ -18,6 +18,8 @@ dependencies {
implementation(libs.bundles.ktorAuth)
implementation(libs.bundles.logging)
implementation("joda-time:joda-time:2.10.10")
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}

View File

@ -1,5 +1,6 @@
package io.bkbn.kompendium.playground
import io.bkbn.kompendium.Kompendium
import io.bkbn.kompendium.Notarized.notarizedDelete
import io.bkbn.kompendium.Notarized.notarizedException
import io.bkbn.kompendium.Notarized.notarizedGet
@ -7,7 +8,9 @@ import io.bkbn.kompendium.Notarized.notarizedPost
import io.bkbn.kompendium.Notarized.notarizedPut
import io.bkbn.kompendium.auth.KompendiumAuth.notarizedBasic
import io.bkbn.kompendium.models.meta.ResponseInfo
import io.bkbn.kompendium.models.oas.FormatSchema
import io.bkbn.kompendium.playground.PlaygroundToC.testAuthenticatedSingleGetInfo
import io.bkbn.kompendium.playground.PlaygroundToC.testCustomOverride
import io.bkbn.kompendium.playground.PlaygroundToC.testGetWithExamples
import io.bkbn.kompendium.playground.PlaygroundToC.testIdGetInfo
import io.bkbn.kompendium.playground.PlaygroundToC.testPostWithExamples
@ -36,8 +39,11 @@ import io.ktor.serialization.json
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.ktor.webjars.Webjars
import org.joda.time.DateTime
fun main() {
Kompendium.addCustomTypeSchema(DateTime::class, FormatSchema("date-time", "string"))
embeddedServer(
Netty,
port = 8081,
@ -114,6 +120,11 @@ fun Application.mainModule() {
call.respondText { "heya" }
}
}
route("custom_override") {
notarizedGet(testCustomOverride) {
call.respondText { DateTime.now().toString() }
}
}
authenticate("basic") {
route("/authenticated/single") {
notarizedGet(testAuthenticatedSingleGetInfo) {

View File

@ -3,6 +3,7 @@ package io.bkbn.kompendium.playground
import io.bkbn.kompendium.annotations.KompendiumField
import io.bkbn.kompendium.annotations.KompendiumParam
import io.bkbn.kompendium.annotations.ParamType
import org.joda.time.DateTime
data class ExampleParams(
@KompendiumParam(ParamType.PATH) val id: Int,
@ -30,3 +31,5 @@ data class ExampleResponse(val c: String)
data class ExceptionResponse(val message: String)
data class ExampleCreatedResponse(val id: Int, val c: String)
data class DateTimeWrapper(val dt: DateTime)

View File

@ -55,6 +55,15 @@ object PlaygroundToC {
description = "Returns a different sample"
)
)
val testCustomOverride = MethodInfo.GetInfo<Unit, DateTimeWrapper>(
summary = "custom schema test",
description = "testing",
tags = setOf("custom"),
responseInfo = ResponseInfo(
status = HttpStatusCode.OK,
description = "good tings"
)
)
val testSingleGetInfoWithThrowable = testSingleGetInfo.copy(
summary = "Show me the error baby 🙏",
canThrow = setOf(Exception::class)