Feature/examplebodies (#44)
This commit is contained in:
@ -30,7 +30,10 @@ import org.leafygreens.kompendium.annotations.KompendiumField
|
||||
import org.leafygreens.kompendium.annotations.PathParam
|
||||
import org.leafygreens.kompendium.annotations.QueryParam
|
||||
import org.leafygreens.kompendium.auth.KompendiumAuth.notarizedBasic
|
||||
import org.leafygreens.kompendium.models.meta.MethodInfo
|
||||
import org.leafygreens.kompendium.models.meta.MethodInfo.GetInfo
|
||||
import org.leafygreens.kompendium.models.meta.MethodInfo.PostInfo
|
||||
import org.leafygreens.kompendium.models.meta.MethodInfo.PutInfo
|
||||
import org.leafygreens.kompendium.models.meta.MethodInfo.DeleteInfo
|
||||
import org.leafygreens.kompendium.models.meta.RequestInfo
|
||||
import org.leafygreens.kompendium.models.meta.ResponseInfo
|
||||
import org.leafygreens.kompendium.models.oas.OpenApiSpecInfo
|
||||
@ -38,6 +41,7 @@ import org.leafygreens.kompendium.models.oas.OpenApiSpecInfoContact
|
||||
import org.leafygreens.kompendium.models.oas.OpenApiSpecInfoLicense
|
||||
import org.leafygreens.kompendium.models.oas.OpenApiSpecServer
|
||||
import org.leafygreens.kompendium.playground.KompendiumTOC.testAuthenticatedSingleGetInfo
|
||||
import org.leafygreens.kompendium.playground.KompendiumTOC.testGetWithExamples
|
||||
import org.leafygreens.kompendium.playground.KompendiumTOC.testIdGetInfo
|
||||
import org.leafygreens.kompendium.playground.KompendiumTOC.testSingleDeleteInfo
|
||||
import org.leafygreens.kompendium.playground.KompendiumTOC.testSingleGetInfo
|
||||
@ -86,8 +90,8 @@ fun main() {
|
||||
}
|
||||
|
||||
var featuresInstalled = false
|
||||
fun Application.mainModule() {
|
||||
// only install once in case of auto reload
|
||||
|
||||
fun Application.configModule() {
|
||||
if (!featuresInstalled) {
|
||||
install(ContentNegotiation) {
|
||||
jackson {
|
||||
@ -120,33 +124,42 @@ fun Application.mainModule() {
|
||||
}
|
||||
featuresInstalled = true
|
||||
}
|
||||
}
|
||||
|
||||
fun Application.mainModule() {
|
||||
configModule()
|
||||
routing {
|
||||
openApi(oas)
|
||||
redoc(oas)
|
||||
swaggerUI()
|
||||
route("/potato/spud") {
|
||||
notarizedGet(testGetWithExamples) {
|
||||
call.respond(HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
route("/test") {
|
||||
route("/{id}") {
|
||||
notarizedGet<ExampleParams, ExampleResponse>(testIdGetInfo) {
|
||||
notarizedGet(testIdGetInfo) {
|
||||
call.respondText("get by id")
|
||||
}
|
||||
}
|
||||
route("/single") {
|
||||
notarizedGet<Unit, ExampleResponse>(testSingleGetInfo) {
|
||||
notarizedGet(testSingleGetInfo) {
|
||||
call.respondText("get single")
|
||||
}
|
||||
notarizedPost<Unit, ExampleRequest, ExampleCreatedResponse>(testSinglePostInfo) {
|
||||
notarizedPost(testSinglePostInfo) {
|
||||
call.respondText("test post")
|
||||
}
|
||||
notarizedPut<JustQuery, ExampleRequest, ExampleCreatedResponse>(testSinglePutInfo) {
|
||||
notarizedPut(testSinglePutInfo) {
|
||||
call.respondText { "hey" }
|
||||
}
|
||||
notarizedDelete<Unit, Unit>(testSingleDeleteInfo) {
|
||||
notarizedDelete(testSingleDeleteInfo) {
|
||||
call.respondText { "heya" }
|
||||
}
|
||||
}
|
||||
authenticate("basic") {
|
||||
route("/authenticated/single") {
|
||||
notarizedGet<Unit, Unit>(testAuthenticatedSingleGetInfo) {
|
||||
notarizedGet(testAuthenticatedSingleGetInfo) {
|
||||
call.respond(HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
@ -186,7 +199,16 @@ data class ExceptionResponse(val message: String)
|
||||
data class ExampleCreatedResponse(val id: Int, val c: String)
|
||||
|
||||
object KompendiumTOC {
|
||||
val testIdGetInfo = MethodInfo(
|
||||
val testGetWithExamples = GetInfo<Unit, ExampleResponse>(
|
||||
summary = "Example Parameters",
|
||||
description = "A test for setting parameter examples",
|
||||
responseInfo = ResponseInfo(
|
||||
status = 200,
|
||||
description = "nice",
|
||||
examples = mapOf("test" to ExampleResponse(c = "spud"))
|
||||
),
|
||||
)
|
||||
val testIdGetInfo = GetInfo<ExampleParams, ExampleResponse>(
|
||||
summary = "Get Test",
|
||||
description = "Test for the getting",
|
||||
tags = setOf("test", "sample", "get"),
|
||||
@ -195,7 +217,7 @@ object KompendiumTOC {
|
||||
description = "Returns sample info"
|
||||
)
|
||||
)
|
||||
val testSingleGetInfo = MethodInfo(
|
||||
val testSingleGetInfo = GetInfo<Unit, ExampleResponse>(
|
||||
summary = "Another get test",
|
||||
description = "testing more",
|
||||
tags = setOf("anotherTest", "sample"),
|
||||
@ -208,7 +230,7 @@ object KompendiumTOC {
|
||||
summary = "Show me the error baby 🙏",
|
||||
canThrow = setOf(Exception::class)
|
||||
)
|
||||
val testSinglePostInfo = MethodInfo(
|
||||
val testSinglePostInfo = PostInfo<Unit, ExampleRequest, ExampleCreatedResponse>(
|
||||
summary = "Test post endpoint",
|
||||
description = "Post your tests here!",
|
||||
requestInfo = RequestInfo(
|
||||
@ -219,7 +241,7 @@ object KompendiumTOC {
|
||||
description = "Worlds most complex response"
|
||||
)
|
||||
)
|
||||
val testSinglePutInfo = MethodInfo(
|
||||
val testSinglePutInfo = PutInfo<JustQuery, ExampleRequest, ExampleCreatedResponse>(
|
||||
summary = "Test put endpoint",
|
||||
description = "Put your tests here!",
|
||||
requestInfo = RequestInfo(
|
||||
@ -230,7 +252,7 @@ object KompendiumTOC {
|
||||
description = "What we give you when u do the puts"
|
||||
)
|
||||
)
|
||||
val testSingleDeleteInfo = MethodInfo(
|
||||
val testSingleDeleteInfo = DeleteInfo<Unit, Unit>(
|
||||
summary = "Test delete endpoint",
|
||||
description = "testing my deletes",
|
||||
responseInfo = ResponseInfo(
|
||||
@ -239,7 +261,7 @@ object KompendiumTOC {
|
||||
mediaTypes = emptyList()
|
||||
)
|
||||
)
|
||||
val testAuthenticatedSingleGetInfo = MethodInfo(
|
||||
val testAuthenticatedSingleGetInfo = GetInfo<Unit, Unit>(
|
||||
summary = "Another get test",
|
||||
description = "testing more",
|
||||
tags = setOf("anotherTest", "sample"),
|
||||
|
Reference in New Issue
Block a user