feat: v3 locations (#292)
This commit is contained in:
@ -71,7 +71,7 @@ private fun Application.mainModule() {
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
authenticate("basic") {
|
||||
route("/{id}") {
|
||||
idDocumentation()
|
||||
locationDocumentation()
|
||||
get {
|
||||
call.respond(HttpStatusCode.OK, ExampleResponse(true))
|
||||
}
|
||||
@ -80,7 +80,7 @@ private fun Application.mainModule() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Route.idDocumentation() {
|
||||
private fun Route.locationDocumentation() {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
|
@ -47,7 +47,7 @@ private fun Application.mainModule() {
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
|
||||
route("/{id}") {
|
||||
idDocumentation()
|
||||
locationDocumentation()
|
||||
get {
|
||||
call.respond(HttpStatusCode.OK, ExampleResponse(true))
|
||||
}
|
||||
@ -55,7 +55,7 @@ private fun Application.mainModule() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Route.idDocumentation() {
|
||||
private fun Route.locationDocumentation() {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
|
@ -54,7 +54,7 @@ private fun Application.mainModule() {
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
|
||||
route("/{id}") {
|
||||
idDocumentation()
|
||||
locationDocumentation()
|
||||
get {
|
||||
call.respond(
|
||||
HttpStatusCode.OK,
|
||||
@ -68,7 +68,7 @@ private fun Application.mainModule() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Route.idDocumentation() {
|
||||
private fun Route.locationDocumentation() {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
|
@ -13,7 +13,6 @@ import io.bkbn.kompendium.playground.util.Util.baseSpec
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.engine.embeddedServer
|
||||
import io.ktor.server.netty.Netty
|
||||
@ -55,7 +54,7 @@ private fun Application.mainModule() {
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
|
||||
route("/{id}") {
|
||||
idDocumentation()
|
||||
locationDocumentation()
|
||||
get {
|
||||
throw RuntimeException("This wasn't your fault I promise <3")
|
||||
}
|
||||
@ -63,7 +62,7 @@ private fun Application.mainModule() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Route.idDocumentation() {
|
||||
private fun Route.locationDocumentation() {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
|
@ -43,7 +43,7 @@ private fun Application.mainModule() {
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
|
||||
route("/{id}") {
|
||||
idDocumentation()
|
||||
locationDocumentation()
|
||||
get {
|
||||
call.respond(HttpStatusCode.OK, ExampleResponse(true))
|
||||
}
|
||||
@ -51,7 +51,7 @@ private fun Application.mainModule() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Route.idDocumentation() {
|
||||
private fun Route.locationDocumentation() {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
|
@ -82,7 +82,7 @@ private fun Application.mainModule() {
|
||||
authenticate("basic") {
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
route("/{id}") {
|
||||
idDocumentation()
|
||||
locationDocumentation()
|
||||
get {
|
||||
call.respond(HttpStatusCode.OK, ExampleResponse(true))
|
||||
}
|
||||
@ -91,7 +91,7 @@ private fun Application.mainModule() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Route.idDocumentation() {
|
||||
private fun Route.locationDocumentation() {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
|
@ -46,7 +46,7 @@ private fun Application.mainModule() {
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
|
||||
route("/{id}") {
|
||||
idDocumentation()
|
||||
locationDocumentation()
|
||||
get {
|
||||
call.respond(HttpStatusCode.OK, ExampleResponse(true))
|
||||
}
|
||||
@ -54,7 +54,7 @@ private fun Application.mainModule() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Route.idDocumentation() {
|
||||
private fun Route.locationDocumentation() {
|
||||
install(NotarizedRoute()) {
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
|
@ -0,0 +1,80 @@
|
||||
package io.bkbn.kompendium.playground
|
||||
|
||||
import io.bkbn.kompendium.core.metadata.GetInfo
|
||||
import io.bkbn.kompendium.core.plugin.NotarizedApplication
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||
import io.bkbn.kompendium.locations.NotarizedLocations
|
||||
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.Listing
|
||||
import io.bkbn.kompendium.playground.util.Util.baseSpec
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.engine.embeddedServer
|
||||
import io.ktor.server.locations.Locations
|
||||
import io.ktor.server.locations.get
|
||||
import io.ktor.server.netty.Netty
|
||||
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.server.response.respondText
|
||||
import io.ktor.server.routing.routing
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
fun main() {
|
||||
embeddedServer(
|
||||
Netty,
|
||||
port = 8081,
|
||||
module = Application::mainModule
|
||||
).start(wait = true)
|
||||
}
|
||||
|
||||
private fun Application.mainModule() {
|
||||
install(Locations)
|
||||
install(ContentNegotiation) {
|
||||
json(Json {
|
||||
serializersModule = KompendiumSerializersModule.module
|
||||
encodeDefaults = true
|
||||
explicitNulls = false
|
||||
})
|
||||
}
|
||||
install(NotarizedApplication()) {
|
||||
spec = baseSpec
|
||||
}
|
||||
install(NotarizedLocations()) {
|
||||
locations = mapOf(
|
||||
Listing::class to NotarizedLocations.LocationMetadata(
|
||||
parameters = listOf(
|
||||
Parameter(
|
||||
name = "name",
|
||||
`in` = Parameter.Location.path,
|
||||
schema = TypeDefinition.STRING
|
||||
),
|
||||
Parameter(
|
||||
name = "page",
|
||||
`in` = Parameter.Location.path,
|
||||
schema = TypeDefinition.INT
|
||||
)
|
||||
),
|
||||
get = GetInfo.builder {
|
||||
summary("Get user by id")
|
||||
description("A very neat endpoint!")
|
||||
response {
|
||||
responseCode(HttpStatusCode.OK)
|
||||
responseType<ExampleResponse>()
|
||||
description("Will return whether or not the user is real 😱")
|
||||
}
|
||||
}
|
||||
),
|
||||
)
|
||||
}
|
||||
routing {
|
||||
redoc(pageTitle = "Simple API Docs")
|
||||
get<Listing> { listing ->
|
||||
call.respondText("Listing ${listing.name}, page ${listing.page}")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package io.bkbn.kompendium.playground.util
|
||||
|
||||
import io.ktor.server.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.server.locations.Location
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@ -14,3 +16,12 @@ data class CustomTypeResponse(
|
||||
|
||||
@Serializable
|
||||
data class ExceptionResponse(val message: String)
|
||||
|
||||
@Location("/list/{name}/page/{page}")
|
||||
data class Listing(val name: String, val page: Int)
|
||||
|
||||
@Location("/type/{name}") data class Type(val name: String) {
|
||||
// In these classes we have to include the `name` property matching the parent.
|
||||
@Location("/edit") data class Edit(val parent: Type)
|
||||
@Location("/other/{page}") data class Other(val parent: Type, val page: Int)
|
||||
}
|
||||
|
Reference in New Issue
Block a user