Add OpenAPI route and server
This commit is contained in:
@@ -186,6 +186,7 @@ fun Application.module(env: Env = PROD) {
|
||||
commentConstitution(get())
|
||||
voteArticle(get(), get(), get())
|
||||
voteConstitution(get())
|
||||
definition()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
src/main/kotlin/fr/dcproject/routes/OpenAPI.kt
Normal file
18
src/main/kotlin/fr/dcproject/routes/OpenAPI.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
package fr.dcproject.routes
|
||||
|
||||
import fr.dcproject.utils.readResource
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.response.respondText
|
||||
import io.ktor.routing.Route
|
||||
import io.ktor.routing.get
|
||||
import io.ktor.util.KtorExperimentalAPI
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
@KtorExperimentalAPI
|
||||
fun Route.definition() {
|
||||
get("/") {
|
||||
call.respondText("/openApi.yaml".readResource(), ContentType("text", "yaml"))
|
||||
}
|
||||
}
|
||||
7
src/main/kotlin/fr/dcproject/utils/Resources.kt
Normal file
7
src/main/kotlin/fr/dcproject/utils/Resources.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package fr.dcproject.utils
|
||||
|
||||
fun String.readResource(callbak: (String) -> Unit = {}): String {
|
||||
val content = callbak::class.java.getResource(this).readText()
|
||||
callbak(content)
|
||||
return content
|
||||
}
|
||||
Reference in New Issue
Block a user