diff options
Diffstat (limited to 'server/core')
3 files changed, 25 insertions, 5 deletions
diff --git a/server/core/build.gradle.kts b/server/core/build.gradle.kts index 87f613a..deee068 100644 --- a/server/core/build.gradle.kts +++ b/server/core/build.gradle.kts @@ -4,17 +4,17 @@ plugins { application } -val ktor_version = "3.0.3" dependencies { - implementation(platform("io.ktor:ktor-bom:$ktor_version")) + declareKtorVersion() implementation("io.ktor:ktor-server-netty") implementation("io.ktor:ktor-server-status-pages") implementation("io.ktor:ktor-server-content-negotiation") - implementation("io.ktor:ktor-server-openapi") implementation("io.ktor:ktor-serialization-kotlinx-json") implementation("io.ktor:ktor-server-compression") + implementation("sh.ondr:kotlin-json-schema:0.1.1") implementation(project(":database:impl")) + implementation(project(":server:swagger")) runtimeOnly("ch.qos.logback:logback-classic:1.5.16") runtimeOnly("org.xerial:sqlite-jdbc:3.45.3.0") diff --git a/server/core/src/main/kotlin/moe/nea/ledger/server/core/Application.kt b/server/core/src/main/kotlin/moe/nea/ledger/server/core/Application.kt index 0ea6ed3..f00f26d 100644 --- a/server/core/src/main/kotlin/moe/nea/ledger/server/core/Application.kt +++ b/server/core/src/main/kotlin/moe/nea/ledger/server/core/Application.kt @@ -8,8 +8,12 @@ import io.ktor.server.plugins.compression.Compression import io.ktor.server.plugins.contentnegotiation.ContentNegotiation import io.ktor.server.routing.route import io.ktor.server.routing.routing +import kotlinx.serialization.json.Json import moe.nea.ledger.database.Database +import moe.nea.ledger.server.core.api.Documentation +import moe.nea.ledger.server.core.api.Info import moe.nea.ledger.server.core.api.apiRouting +import moe.nea.ledger.server.core.api.openApiDocsJson import java.io.File fun main(args: Array<String>) { @@ -19,8 +23,18 @@ fun main(args: Array<String>) { fun Application.module() { install(Compression) + install(Documentation) { + info = Info( + "Ledger Analysis Server", + "Your local API for loading ledger data", + "TODO: buildconfig" + ) + } install(ContentNegotiation) { - json() + json(Json { + this.explicitNulls = false + this.encodeDefaults = true + }) // cbor() } val database = Database(File(System.getProperty("ledger.databasefolder"))) @@ -29,6 +43,9 @@ fun Application.module() { route("/api") { this.apiRouting(database) } + route("/api.json") { + openApiDocsJson() + } } } diff --git a/server/core/src/main/kotlin/moe/nea/ledger/server/core/api/BaseApi.kt b/server/core/src/main/kotlin/moe/nea/ledger/server/core/api/BaseApi.kt index 264f74b..ad05118 100644 --- a/server/core/src/main/kotlin/moe/nea/ledger/server/core/api/BaseApi.kt +++ b/server/core/src/main/kotlin/moe/nea/ledger/server/core/api/BaseApi.kt @@ -3,7 +3,6 @@ package moe.nea.ledger.server.core.api import io.ktor.server.response.respond import io.ktor.server.response.respondText import io.ktor.server.routing.Route -import io.ktor.server.routing.Routing import io.ktor.server.routing.get import moe.nea.ledger.database.DBLogEntry import moe.nea.ledger.database.Database @@ -21,5 +20,9 @@ fun Route.apiRouting(database: Database) { Profile(it[DBLogEntry.playerId], it[DBLogEntry.profileId]) } call.respond(profiles) + }.docs { + respondsOk { + schema<List<Profile>>() + } } } |