From 14bee566b3b32659080e5b8f19e9b52f2ba8c4d1 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Mon, 20 Apr 2020 09:40:30 +0800 Subject: [PATCH] fix(swagger): fix incorrect Pageable schema --- komga/build.gradle.kts | 1 - .../swagger/PageableAnnotations.kt | 48 +++++++++++++++++++ .../swagger/PageableWithoutSort.kt | 13 ----- .../komga/interfaces/rest/BookController.kt | 9 ++-- .../komga/interfaces/rest/SeriesController.kt | 12 +++-- 5 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 komga/src/main/kotlin/org/gotson/komga/infrastructure/swagger/PageableAnnotations.kt delete mode 100644 komga/src/main/kotlin/org/gotson/komga/infrastructure/swagger/PageableWithoutSort.kt diff --git a/komga/build.gradle.kts b/komga/build.gradle.kts index 4f4cadee6..3f7ad0c49 100644 --- a/komga/build.gradle.kts +++ b/komga/build.gradle.kts @@ -53,7 +53,6 @@ dependencies { run { val springdocVersion = "1.3.3" implementation("org.springdoc:springdoc-openapi-ui:$springdocVersion") - implementation("org.springdoc:springdoc-openapi-data-rest:$springdocVersion") implementation("org.springdoc:springdoc-openapi-security:$springdocVersion") } diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/swagger/PageableAnnotations.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/swagger/PageableAnnotations.kt new file mode 100644 index 000000000..77e7fb53f --- /dev/null +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/swagger/PageableAnnotations.kt @@ -0,0 +1,48 @@ +package org.gotson.komga.infrastructure.swagger + +import io.swagger.v3.oas.annotations.Parameter +import io.swagger.v3.oas.annotations.Parameters +import io.swagger.v3.oas.annotations.enums.ParameterIn +import io.swagger.v3.oas.annotations.media.ArraySchema +import io.swagger.v3.oas.annotations.media.Content +import io.swagger.v3.oas.annotations.media.Schema + +@Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.FUNCTION) +@Parameters( + Parameter( + description = "Zero-based page index (0..N)", + `in` = ParameterIn.QUERY, + name = "page", + schema = Schema(type = "integer") + ), + Parameter( + description = "The size of the page to be returned", + `in` = ParameterIn.QUERY, + name = "size", + schema = Schema(type = "integer") + ) +) +annotation class PageableWithoutSortAsQueryParam + +@Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.FUNCTION) +@Parameters( + Parameter( + description = "Zero-based page index (0..N)", + `in` = ParameterIn.QUERY, + name = "page", + schema = Schema(type = "integer") + ), + Parameter( + description = "The size of the page to be returned", + `in` = ParameterIn.QUERY, + name = "size", + schema = Schema(type = "integer") + ), + Parameter( + description = "Sorting criteria in the format: property(,asc|desc). Default sort order is ascending. Multiple sort criteria are supported.", + `in` = ParameterIn.QUERY + , name = "sort" + , content = [Content(array = ArraySchema(schema = Schema(type = "string")))] + ) +) +annotation class PageableAsQueryParam diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/swagger/PageableWithoutSort.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/swagger/PageableWithoutSort.kt deleted file mode 100644 index 4318f9f1e..000000000 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/swagger/PageableWithoutSort.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.gotson.komga.infrastructure.swagger - -import io.swagger.v3.oas.annotations.Parameter -import io.swagger.v3.oas.annotations.Parameters -import io.swagger.v3.oas.annotations.enums.ParameterIn -import io.swagger.v3.oas.annotations.media.Schema - -@Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.FUNCTION) -@Parameters( - Parameter(description = "Zero-based page index (0..N)", `in` = ParameterIn.QUERY, name = "page", schema = Schema(type = "integer", defaultValue = "0")), - Parameter(description = "The size of the page to be returned", `in` = ParameterIn.QUERY, name = "size", schema = Schema(type = "integer", defaultValue = "20")) -) -annotation class PageableWithoutSort diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt index 81af0ea2b..0de84a146 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt @@ -22,12 +22,12 @@ import org.gotson.komga.domain.model.Series import org.gotson.komga.domain.persistence.BookRepository import org.gotson.komga.infrastructure.image.ImageType import org.gotson.komga.infrastructure.security.KomgaPrincipal -import org.gotson.komga.infrastructure.swagger.PageableWithoutSort +import org.gotson.komga.infrastructure.swagger.PageableAsQueryParam +import org.gotson.komga.infrastructure.swagger.PageableWithoutSortAsQueryParam import org.gotson.komga.interfaces.rest.dto.BookDto import org.gotson.komga.interfaces.rest.dto.BookMetadataUpdateDto import org.gotson.komga.interfaces.rest.dto.PageDto import org.gotson.komga.interfaces.rest.dto.toDto -import org.springdoc.api.annotations.ParameterObject import org.springframework.core.io.FileSystemResource import org.springframework.data.domain.Page import org.springframework.data.domain.PageRequest @@ -72,13 +72,14 @@ class BookController( private val asyncOrchestrator: AsyncOrchestrator ) { + @PageableAsQueryParam @GetMapping("api/v1/books") fun getAllBooks( @AuthenticationPrincipal principal: KomgaPrincipal, @RequestParam(name = "search", required = false) searchTerm: String?, @RequestParam(name = "library_id", required = false) libraryIds: List?, @RequestParam(name = "media_status", required = false) mediaStatus: List?, - @ParameterObject page: Pageable + @Parameter(hidden = true) page: Pageable ): Page { val pageRequest = PageRequest.of( page.pageNumber, @@ -123,7 +124,7 @@ class BookController( @Operation(description = "Return newly added or updated books.") - @PageableWithoutSort + @PageableWithoutSortAsQueryParam @GetMapping("api/v1/books/latest") fun getLatestSeries( @AuthenticationPrincipal principal: KomgaPrincipal, diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt index 3b6cf0dfc..399de64f6 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt @@ -17,7 +17,8 @@ import org.gotson.komga.domain.model.SeriesMetadata import org.gotson.komga.domain.persistence.BookRepository import org.gotson.komga.domain.persistence.SeriesRepository import org.gotson.komga.infrastructure.security.KomgaPrincipal -import org.gotson.komga.infrastructure.swagger.PageableWithoutSort +import org.gotson.komga.infrastructure.swagger.PageableAsQueryParam +import org.gotson.komga.infrastructure.swagger.PageableWithoutSortAsQueryParam import org.gotson.komga.interfaces.rest.dto.BookDto import org.gotson.komga.interfaces.rest.dto.SeriesDto import org.gotson.komga.interfaces.rest.dto.SeriesMetadataUpdateDto @@ -108,7 +109,7 @@ class SeriesController( } @Operation(description = "Return recently added or updated series.") - @PageableWithoutSort + @PageableWithoutSortAsQueryParam @GetMapping("/latest") fun getLatestSeries( @AuthenticationPrincipal principal: KomgaPrincipal, @@ -128,7 +129,7 @@ class SeriesController( } @Operation(description = "Return newly added series.") - @PageableWithoutSort + @PageableWithoutSortAsQueryParam @GetMapping("/new") fun getNewSeries( @AuthenticationPrincipal principal: KomgaPrincipal, @@ -148,7 +149,7 @@ class SeriesController( } @Operation(description = "Return recently updated series, but not newly added ones.") - @PageableWithoutSort + @PageableWithoutSortAsQueryParam @GetMapping("/updated") fun getUpdatedSeries( @AuthenticationPrincipal principal: KomgaPrincipal, @@ -191,12 +192,13 @@ class SeriesController( } ?: throw ResponseStatusException(HttpStatus.NOT_FOUND) } ?: throw ResponseStatusException(HttpStatus.NOT_FOUND) + @PageableAsQueryParam @GetMapping("{seriesId}/books") fun getAllBooksBySeries( @AuthenticationPrincipal principal: KomgaPrincipal, @PathVariable(name = "seriesId") id: Long, @RequestParam(name = "media_status", required = false) mediaStatus: List?, - @ParameterObject page: Pageable + @Parameter(hidden = true) page: Pageable ): Page { seriesRepository.findByIdOrNull(id)?.let { if (!principal.user.canAccessSeries(it)) throw ResponseStatusException(HttpStatus.UNAUTHORIZED)