aboutsummaryrefslogtreecommitdiff
path: root/server/core/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-01-17 12:50:23 +0100
committerLinnea Gräf <nea@nea.moe>2025-01-17 12:51:03 +0100
commitce6e008426c30cba493832d0866950c59f7c31c1 (patch)
tree9140e4639575a4e83e77bb5004791a6c25600168 /server/core/src
parente42bc6340771d87e2fb0263a4ad81528aeebec69 (diff)
downloadLocalTransactionLedger-ce6e008426c30cba493832d0866950c59f7c31c1.tar.gz
LocalTransactionLedger-ce6e008426c30cba493832d0866950c59f7c31c1.tar.bz2
LocalTransactionLedger-ce6e008426c30cba493832d0866950c59f7c31c1.zip
feat(server): Add openapi docs
Diffstat (limited to 'server/core/src')
-rw-r--r--server/core/src/main/kotlin/moe/nea/ledger/server/core/Application.kt19
-rw-r--r--server/core/src/main/kotlin/moe/nea/ledger/server/core/api/BaseApi.kt5
2 files changed, 22 insertions, 2 deletions
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>>()
+ }
}
}