aboutsummaryrefslogtreecommitdiff
path: root/server/swagger/src/main
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-01-17 15:30:04 +0100
committerLinnea Gräf <nea@nea.moe>2025-01-17 15:30:04 +0100
commitaa7e28e799ce19f04c6c33782ea8d25ef4c3bb98 (patch)
treea84f850c1f88ce3c8a16b2fdb5de52fba3ad0edb /server/swagger/src/main
parentf49de9677285ba6287d049a6187ff00bf90ee77f (diff)
downloadLocalTransactionLedger-aa7e28e799ce19f04c6c33782ea8d25ef4c3bb98.tar.gz
LocalTransactionLedger-aa7e28e799ce19f04c6c33782ea8d25ef4c3bb98.tar.bz2
LocalTransactionLedger-aa7e28e799ce19f04c6c33782ea8d25ef4c3bb98.zip
feat(Server): Add frontend starter
Diffstat (limited to 'server/swagger/src/main')
-rw-r--r--server/swagger/src/main/kotlin/moe/nea/ledger/server/core/api/OpenApiModel.kt19
-rw-r--r--server/swagger/src/main/kotlin/moe/nea/ledger/server/core/api/docs.kt16
2 files changed, 34 insertions, 1 deletions
diff --git a/server/swagger/src/main/kotlin/moe/nea/ledger/server/core/api/OpenApiModel.kt b/server/swagger/src/main/kotlin/moe/nea/ledger/server/core/api/OpenApiModel.kt
index ebee503..8392c5c 100644
--- a/server/swagger/src/main/kotlin/moe/nea/ledger/server/core/api/OpenApiModel.kt
+++ b/server/swagger/src/main/kotlin/moe/nea/ledger/server/core/api/OpenApiModel.kt
@@ -3,6 +3,7 @@ package moe.nea.ledger.server.core.api
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import kotlinx.serialization.KSerializer
+import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
@@ -41,10 +42,26 @@ data class OpenApiOperation(
val description: String,
val operationId: String,
val deprecated: Boolean,
-// val parameters: List<Parameter>,
+ val parameters: List<OpenApiParameter>,
val responses: Map<@Serializable(HttpStatusCodeIntAsString::class) HttpStatusCode, OpenApiResponse>
)
+@Serializable
+data class OpenApiParameter(
+ @SerialName("in") val location: ParameterLocation,
+ val name: String,
+ val description: String,
+ val schema: JsonSchema?,
+)
+
+@Serializable
+enum class ParameterLocation {
+ @SerialName("query")
+ QUERY,
+ @SerialName("path")
+ PATH,
+}
+
object HttpStatusCodeIntAsString : KSerializer<HttpStatusCode> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("HttpStatusCodeIntAsString", PrimitiveKind.STRING)
diff --git a/server/swagger/src/main/kotlin/moe/nea/ledger/server/core/api/docs.kt b/server/swagger/src/main/kotlin/moe/nea/ledger/server/core/api/docs.kt
index 5d222ee..c1b550d 100644
--- a/server/swagger/src/main/kotlin/moe/nea/ledger/server/core/api/docs.kt
+++ b/server/swagger/src/main/kotlin/moe/nea/ledger/server/core/api/docs.kt
@@ -190,6 +190,7 @@ class DocumentationOperationContext(val route: DocumentationContext) {
var deprecated: Boolean = false
var operationId: String = ""
val tags: MutableList<String> = mutableListOf()
+ val parameters: MutableList<OpenApiParameter> = mutableListOf()
fun tag(vararg tag: String) {
tags.addAll(tag)
}
@@ -198,6 +199,20 @@ class DocumentationOperationContext(val route: DocumentationContext) {
tag.mapTo(tags) { it.intoTag() }
}
+ inline fun <reified T : Any> queryParameter(name: String, description: String = "") {
+ parameter(ParameterLocation.QUERY, name, description, jsonSchema<T>())
+ }
+
+ fun parameter(
+ location: ParameterLocation, name: String,
+ description: String = "", schema: JsonSchema? = null
+ ) {
+ parameters.add(OpenApiParameter(
+ location, name, description,
+ schema
+ ))
+ }
+
fun intoJson(): OpenApiOperation {
return OpenApiOperation(
tags = tags.map { Tag(it) },
@@ -205,6 +220,7 @@ class DocumentationOperationContext(val route: DocumentationContext) {
description = description,
operationId = operationId,
deprecated = deprecated,
+ parameters = parameters,
responses = responses.mapValues {
it.value.intoJson()
}