Add OpenAPI route and server
This commit is contained in:
1
.env
1
.env
@@ -3,6 +3,7 @@ NAME=dc-project
|
|||||||
DATABASE_URL=jdbc:postgresql:dc-project
|
DATABASE_URL=jdbc:postgresql:dc-project
|
||||||
|
|
||||||
APP_PORT=8080
|
APP_PORT=8080
|
||||||
|
OPENAPI_PORT=8181
|
||||||
|
|
||||||
ELASTIC_REST=9200
|
ELASTIC_REST=9200
|
||||||
ELASTIC_NODES=9300
|
ELASTIC_NODES=9300
|
||||||
|
|||||||
16
.idea/runConfigurations/Start_OpenAPI.xml
generated
Normal file
16
.idea/runConfigurations/Start_OpenAPI.xml
generated
Normal 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>
|
||||||
@@ -2,6 +2,14 @@
|
|||||||
# Add the "-d" flag at the end for detached execution
|
# Add the "-d" flag at the end for detached execution
|
||||||
version: '3.7'
|
version: '3.7'
|
||||||
services:
|
services:
|
||||||
|
openapi:
|
||||||
|
container_name: openapi_${NAME}
|
||||||
|
image: swaggerapi/swagger-ui
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- ${OPENAPI_PORT}:8080
|
||||||
|
environment:
|
||||||
|
URL: "http://localhost:8080"
|
||||||
|
|
||||||
app:
|
app:
|
||||||
container_name: app_${NAME}
|
container_name: app_${NAME}
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ fun Application.module(env: Env = PROD) {
|
|||||||
commentConstitution(get())
|
commentConstitution(get())
|
||||||
voteArticle(get(), get(), get())
|
voteArticle(get(), get(), get())
|
||||||
voteConstitution(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