From 70586a7cc67879487053eefac6c948f8f8f45bab Mon Sep 17 00:00:00 2001 From: Ryan Brink <5607577+unredundant@users.noreply.github.com> Date: Fri, 14 Oct 2022 15:51:31 -0400 Subject: [PATCH] chore: show nested documentation on basic playground --- .../kompendium/playground/BasicPlayground.kt | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/playground/src/main/kotlin/io/bkbn/kompendium/playground/BasicPlayground.kt b/playground/src/main/kotlin/io/bkbn/kompendium/playground/BasicPlayground.kt index ca317baf8..87ecd6d33 100644 --- a/playground/src/main/kotlin/io/bkbn/kompendium/playground/BasicPlayground.kt +++ b/playground/src/main/kotlin/io/bkbn/kompendium/playground/BasicPlayground.kt @@ -9,6 +9,7 @@ import io.bkbn.kompendium.json.schema.definition.TypeDefinition import io.bkbn.kompendium.oas.payload.Parameter import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule import io.bkbn.kompendium.playground.util.ExampleResponse +import io.bkbn.kompendium.playground.util.ExceptionResponse import io.bkbn.kompendium.playground.util.Util.baseSpec import io.ktor.http.HttpStatusCode import io.ktor.serialization.kotlinx.json.json @@ -51,15 +52,21 @@ private fun Application.mainModule() { redoc(pageTitle = "Simple API Docs") route("/{id}") { - documentation() + idDocumentation() get { call.respond(HttpStatusCode.OK, ExampleResponse(true)) } + route("/profile") { + profileDocumentation() + get { + call.respond(HttpStatusCode.OK, ExampleResponse(true)) + } + } } } } -private fun Route.documentation() { +private fun Route.idDocumentation() { install(NotarizedRoute()) { parameters = listOf( Parameter( @@ -76,6 +83,38 @@ private fun Route.documentation() { responseType() description("Will return whether or not the user is real 😱") } + + canRespond { + responseType() + responseCode(HttpStatusCode.NotFound) + description("Indicates that a user with this id does not exist") + } + } + } +} + +private fun Route.profileDocumentation() { + install(NotarizedRoute()) { + parameters = listOf( + Parameter( + name = "id", + `in` = Parameter.Location.path, + schema = TypeDefinition.STRING + ) + ) + get = GetInfo.builder { + summary("Get a users profile") + description("A cool endpoint!") + response { + responseCode(HttpStatusCode.OK) + responseType() + description("Returns user profile information") + } + canRespond { + responseType() + responseCode(HttpStatusCode.NotFound) + description("Indicates that a user with this id does not exist") + } } } }