diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/MangaController.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/MangaController.kt index 162333dfc..5b546153f 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/MangaController.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/MangaController.kt @@ -8,6 +8,7 @@ package suwayomi.tachidesk.manga.controller * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import io.javalin.http.Context +import io.javalin.http.HttpCode import suwayomi.tachidesk.manga.impl.CategoryManga import suwayomi.tachidesk.manga.impl.Chapter import suwayomi.tachidesk.manga.impl.Library @@ -40,7 +41,8 @@ object MangaController { ) }, withResults = { - json("OK") + json(HttpCode.OK) + httpCode(HttpCode.NOT_FOUND) } ) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/util/DocumentationDsl.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/util/DocumentationDsl.kt index 4fa594221..3ea4c3f19 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/util/DocumentationDsl.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/util/DocumentationDsl.kt @@ -1,6 +1,7 @@ package suwayomi.tachidesk.server.util import io.javalin.http.Context +import io.javalin.http.HttpCode import io.javalin.plugin.openapi.dsl.DocumentedHandler import io.javalin.plugin.openapi.dsl.OpenApiDocumentation import io.javalin.plugin.openapi.dsl.documented @@ -114,19 +115,27 @@ sealed class Param { class ResultsBuilder { val results = mutableListOf>() - inline fun json(status: String) { - results += ResultType.MimeType(status, "application/json", T::class.java) + inline fun json(code: HttpCode) { + results += ResultType.MimeType(code, "application/json", T::class.java) } - inline fun plainText(status: String) { - results += ResultType.MimeType(status, "text/plain", String::class.java) + fun plainText(code: HttpCode) { + results += ResultType.MimeType(code, "text/plain", String::class.java) + } + fun httpCode(code: HttpCode) { + results += ResultType.StatusCode(code) } } sealed class ResultType { abstract fun applyTo(documentation: OpenApiDocumentation) - data class MimeType(val status: String, val mime: String, private val clazz: Class) : ResultType() { + data class MimeType(val code: HttpCode, val mime: String, private val clazz: Class) : ResultType() { + override fun applyTo(documentation: OpenApiDocumentation) { + documentation.result(code.status.toString(), clazz) + } + } + data class StatusCode(val code: HttpCode) : ResultType() { override fun applyTo(documentation: OpenApiDocumentation) { - documentation.result(status, clazz) + documentation.result(code.status.toString()) } } }