document top level collectiom (#24)
This commit is contained in:
@ -7,7 +7,6 @@ import io.ktor.application.call
|
||||
import io.ktor.application.install
|
||||
import io.ktor.features.ContentNegotiation
|
||||
import io.ktor.html.respondHtml
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.jackson.jackson
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.response.respondText
|
||||
@ -32,9 +31,9 @@ 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.annotations.KompendiumRequest
|
||||
import org.leafygreens.kompendium.annotations.KompendiumResponse
|
||||
import org.leafygreens.kompendium.models.meta.MethodInfo
|
||||
import org.leafygreens.kompendium.models.meta.RequestInfo
|
||||
import org.leafygreens.kompendium.models.meta.ResponseInfo
|
||||
import org.leafygreens.kompendium.models.oas.OpenApiSpecInfo
|
||||
import org.leafygreens.kompendium.models.oas.OpenApiSpecInfoContact
|
||||
import org.leafygreens.kompendium.models.oas.OpenApiSpecInfoLicense
|
||||
@ -54,38 +53,6 @@ fun main() {
|
||||
).start(wait = true)
|
||||
}
|
||||
|
||||
data class ExampleParams(val a: String, val aa: Int)
|
||||
|
||||
data class ExampleNested(val nesty: String)
|
||||
|
||||
@KompendiumResponse(KompendiumHttpCodes.NO_CONTENT, "Entity was deleted successfully")
|
||||
object DeleteResponse
|
||||
|
||||
@KompendiumRequest("Example Request")
|
||||
data class ExampleRequest(
|
||||
@KompendiumField(name = "field_name")
|
||||
val fieldName: ExampleNested,
|
||||
val b: Double,
|
||||
val aaa: List<Long>
|
||||
)
|
||||
|
||||
private const val HTTP_OK = 200
|
||||
private const val HTTP_CREATED = 201
|
||||
|
||||
@KompendiumResponse(HTTP_OK, "A Successful Endeavor")
|
||||
data class ExampleResponse(val c: String)
|
||||
|
||||
@KompendiumResponse(HTTP_CREATED, "Created Successfully")
|
||||
data class ExampleCreatedResponse(val id: Int, val c: String)
|
||||
|
||||
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!")
|
||||
val testSingleDeleteInfo = MethodInfo("Test delete endpoint", "testing my deletes")
|
||||
}
|
||||
|
||||
fun Application.mainModule() {
|
||||
install(ContentNegotiation) {
|
||||
jackson {
|
||||
@ -120,6 +87,74 @@ fun Application.mainModule() {
|
||||
}
|
||||
}
|
||||
|
||||
data class ExampleParams(val a: String, val aa: Int)
|
||||
|
||||
data class ExampleNested(val nesty: String)
|
||||
|
||||
object DeleteResponse
|
||||
|
||||
data class ExampleRequest(
|
||||
@KompendiumField(name = "field_name")
|
||||
val fieldName: ExampleNested,
|
||||
val b: Double,
|
||||
val aaa: List<Long>
|
||||
)
|
||||
|
||||
data class ExampleResponse(val c: String)
|
||||
|
||||
data class ExampleCreatedResponse(val id: Int, val c: String)
|
||||
|
||||
object KompendiumTOC {
|
||||
val testIdGetInfo = MethodInfo(
|
||||
summary = "Get Test",
|
||||
description = "Test for the getting",
|
||||
tags = setOf("test", "sample", "get"),
|
||||
responseInfo = ResponseInfo(
|
||||
status = KompendiumHttpCodes.OK,
|
||||
description = "Returns sample info"
|
||||
)
|
||||
)
|
||||
val testSingleGetInfo = MethodInfo(
|
||||
summary = "Another get test",
|
||||
description = "testing more",
|
||||
tags = setOf("anotherTest", "sample"),
|
||||
responseInfo = ResponseInfo(
|
||||
status = KompendiumHttpCodes.OK,
|
||||
description = "Returns a different sample"
|
||||
)
|
||||
)
|
||||
val testSinglePostInfo = MethodInfo(
|
||||
summary = "Test post endpoint",
|
||||
description = "Post your tests here!",
|
||||
requestInfo = RequestInfo(
|
||||
description = "Simple request body"
|
||||
),
|
||||
responseInfo = ResponseInfo(
|
||||
status = KompendiumHttpCodes.CREATED,
|
||||
description = "Worlds most complex response"
|
||||
)
|
||||
)
|
||||
val testSinglePutInfo = MethodInfo(
|
||||
summary = "Test put endpoint",
|
||||
description = "Put your tests here!",
|
||||
requestInfo = RequestInfo(
|
||||
description = "Info needed to perform this put request"
|
||||
),
|
||||
responseInfo = ResponseInfo(
|
||||
status = KompendiumHttpCodes.CREATED,
|
||||
description = "What we give you when u do the puts"
|
||||
)
|
||||
)
|
||||
val testSingleDeleteInfo = MethodInfo(
|
||||
summary = "Test delete endpoint",
|
||||
description = "testing my deletes",
|
||||
responseInfo = ResponseInfo(
|
||||
status = KompendiumHttpCodes.NO_CONTENT,
|
||||
description = "Signifies that your item was deleted succesfully"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun Routing.openApi() {
|
||||
route("/openapi.json") {
|
||||
get {
|
||||
@ -162,8 +197,7 @@ fun Routing.redoc() {
|
||||
call.respondHtml {
|
||||
head {
|
||||
title {
|
||||
// TODO Make this load project title
|
||||
+"Docs"
|
||||
+"${openApiSpec.info.title}"
|
||||
}
|
||||
meta {
|
||||
charset = "utf-8"
|
||||
@ -183,7 +217,7 @@ fun Routing.redoc() {
|
||||
}
|
||||
}
|
||||
body {
|
||||
// TODO Make this its own DSL class
|
||||
// TODO needs to mirror openApi route
|
||||
unsafe { +"<redoc spec-url='/openapi.json'></redoc>" }
|
||||
script {
|
||||
src = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"
|
||||
|
Reference in New Issue
Block a user