lots of stuff, no time to s-plain (#5)

This commit is contained in:
Ryan Brink
2021-04-12 21:15:10 -04:00
committed by GitHub
parent 492933d728
commit a7505483c4
40 changed files with 410 additions and 287 deletions

View File

@ -1,5 +1,4 @@
plugins {
kotlin("kapt")
application
}
@ -8,7 +7,6 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation(projects.kompendiumCore)
kapt(projects.kompendiumProcessor)
implementation(libs.bundles.ktor)
implementation(libs.bundles.logging)

View File

@ -2,47 +2,85 @@ package org.leafygreens.kompendium.playground
import io.ktor.application.Application
import io.ktor.application.call
import io.ktor.application.install
import io.ktor.features.ContentNegotiation
import io.ktor.jackson.jackson
import io.ktor.response.respond
import io.ktor.response.respondText
import io.ktor.routing.get
import io.ktor.routing.route
import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import org.leafygreens.kompendium.annotations.KompendiumContact
import org.leafygreens.kompendium.annotations.KompendiumInfo
import org.leafygreens.kompendium.annotations.KompendiumLicense
import org.leafygreens.kompendium.annotations.KompendiumModule
import org.leafygreens.kompendium.annotations.KompendiumServers
import org.leafygreens.kompendium.Kompendium.notarizedGet
import org.leafygreens.kompendium.Kompendium.notarizedPost
import org.leafygreens.kompendium.Kompendium.notarizedPut
import org.leafygreens.kompendium.Kompendium.openApiSpec
import org.leafygreens.kompendium.annotations.KompendiumField
import org.leafygreens.kompendium.models.meta.MethodInfo
import org.leafygreens.kompendium.models.oas.OpenApiSpecInfo
import org.leafygreens.kompendium.playground.KompendiumTOC.testIdGetInfo
import org.leafygreens.kompendium.playground.KompendiumTOC.testSingleGetInfo
import org.leafygreens.kompendium.playground.KompendiumTOC.testSinglePostInfo
import org.leafygreens.kompendium.playground.KompendiumTOC.testSinglePutInfo
@KompendiumInfo(
title = "Test API",
version = "0.0.1",
description = "An API for testing"
)
@KompendiumContact(
name = "Homer Simpson",
url = "https://en.wikipedia.org/wiki/The_Simpsons",
email = "chunkylover53@aol.com"
)
@KompendiumLicense(
name = "DOH",
url = "https://opensource.org/licenses/DOH"
)
@KompendiumServers(urls = [ "https://thesimpsonsquoteapi.glitch.me/quotes" ])
fun main() {
embeddedServer(
Netty,
port = 8080,
port = 8081,
module = Application::mainModule
).start(wait = true)
}
@KompendiumModule
data class A(val a: String, val aa: Int, val aaa: List<Long>)
data class B(
@KompendiumField(name = "AYY")
val a: A,
val b: Double,
)
data class C(val c: String)
data class D(val a: A, val b: B, val c: C)
object KompendiumTOC {
val testIdGetInfo = MethodInfo("Get Test", "Test for getting", tags = setOf("test", "example", "get"))
val testSingleGetInfo = MethodInfo("Another get test", "testing more")
val testSinglePostInfo = MethodInfo("Test post endpoint", "Post your tests here!")
val testSinglePutInfo = MethodInfo("Test put endpoint", "Put your tests here!")
}
fun Application.mainModule() {
install(ContentNegotiation) {
jackson()
}
routing {
route("/") {
route("/test") {
route("/{id}") {
notarizedGet(testIdGetInfo) {
call.respondText("get by id")
}
}
route("/single") {
notarizedGet(testSingleGetInfo) {
call.respondText("get single")
}
notarizedPost<A, B, C>(testSinglePostInfo) {
call.respondText("test post")
}
notarizedPut<A, B, D>(testSinglePutInfo) {
call.respondText { "hey" }
}
}
}
route("/openapi.json") {
get {
call.respondText("hi")
call.respond(openApiSpec.copy(
info = OpenApiSpecInfo(
title = "Test API",
version = "1.3.3.7",
description = "An amazing, fully-ish 😉 generated API spec"
)
))
}
}
}