Add OpenAPI route and server

This commit is contained in:
2020-02-04 16:45:54 +01:00
parent 77658c5f6b
commit 42a41da066
6 changed files with 51 additions and 0 deletions

View File

@@ -186,6 +186,7 @@ fun Application.module(env: Env = PROD) {
commentConstitution(get())
voteArticle(get(), get(), get())
voteConstitution(get())
definition()
}
}

View 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"))
}
}

View 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
}