From aa7e28e799ce19f04c6c33782ea8d25ef4c3bb98 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 17 Jan 2025 15:30:04 +0100 Subject: feat(Server): Add frontend starter --- .../moe/nea/ledger/server/core/api/OpenApiModel.kt | 19 ++++++++++++++++++- .../kotlin/moe/nea/ledger/server/core/api/docs.kt | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'server/swagger/src') 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, + val parameters: List, 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 { 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 = mutableListOf() + val parameters: MutableList = 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 queryParameter(name: String, description: String = "") { + parameter(ParameterLocation.QUERY, name, description, jsonSchema()) + } + + 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() } -- cgit