Skip to content

Instantly share code, notes, and snippets.

@oharaandrew314
Created August 11, 2020 16:02
Show Gist options
  • Save oharaandrew314/63bd0847ce73d8ce8a0c430e20d0fc9d to your computer and use it in GitHub Desktop.
Save oharaandrew314/63bd0847ce73d8ce8a0c430e20d0fc9d to your computer and use it in GitHub Desktop.
import io.javalin.Javalin
import io.javalin.http.Context
import io.javalin.plugin.openapi.OpenApiOptions
import io.javalin.plugin.openapi.OpenApiPlugin
import io.javalin.plugin.openapi.annotations.OpenApi
import io.javalin.plugin.openapi.annotations.OpenApiParam
import io.javalin.plugin.openapi.ui.ReDocOptions
import io.javalin.plugin.openapi.ui.SwaggerOptions
import io.swagger.v3.oas.models.info.Info
object TestServer {
@JvmStatic
fun main(args: Array<String>) {
val app = Javalin.create { config ->
val applicationInfo = Info().apply {
title = "Test Server"
version = "1"
}
val options = OpenApiOptions(applicationInfo)
.path("/spec")
.reDoc(ReDocOptions("/redoc"))
.swagger(SwaggerOptions("/"))
config.registerPlugin(OpenApiPlugin(options))
}
app.get("/v1/users", ::searchByQuery)
app.get("/v1/users/:type/:value", ::searchByPath)
app.start(8080)
}
@OpenApi(
operationId = "searchByQueryV1",
queryParams = [
OpenApiParam("type", type = SearchType::class, required = true),
OpenApiParam("value", type = String::class, required = true)
]
)
private fun searchByQuery(ctx: Context) { }
@OpenApi(
operationId = "searchByPathV1",
pathParams = [
OpenApiParam("type", type = SearchType::class),
OpenApiParam("value", type = String::class)
]
)
private fun searchByPath(ctx: Context) { }
}
enum class SearchType { Id, Username, Email }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment