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

1
.env
View File

@@ -3,6 +3,7 @@ NAME=dc-project
DATABASE_URL=jdbc:postgresql:dc-project
APP_PORT=8080
OPENAPI_PORT=8181
ELASTIC_REST=9200
ELASTIC_NODES=9300

View File

@@ -0,0 +1,16 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Start OpenAPI" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
<deployment type="docker-compose.yml">
<settings>
<option name="commandLineOptions" value="--build" />
<option name="services">
<list>
<option value="openapi" />
</list>
</option>
<option name="sourceFilePath" value="docker-compose.yml" />
</settings>
</deployment>
<method v="2" />
</configuration>
</component>

View File

@@ -2,6 +2,14 @@
# Add the "-d" flag at the end for detached execution
version: '3.7'
services:
openapi:
container_name: openapi_${NAME}
image: swaggerapi/swagger-ui
restart: always
ports:
- ${OPENAPI_PORT}:8080
environment:
URL: "http://localhost:8080"
app:
container_name: app_${NAME}

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
}