mirror of
https://github.com/gotson/komga.git
synced 2025-12-22 00:13:30 +01:00
fix(swagger): fix incorrect Pageable schema
This commit is contained in:
parent
9bf37db38d
commit
14bee566b3
5 changed files with 60 additions and 23 deletions
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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<Long>?,
|
||||
@RequestParam(name = "media_status", required = false) mediaStatus: List<Media.Status>?,
|
||||
@ParameterObject page: Pageable
|
||||
@Parameter(hidden = true) page: Pageable
|
||||
): Page<BookDto> {
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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<Media.Status>?,
|
||||
@ParameterObject page: Pageable
|
||||
@Parameter(hidden = true) page: Pageable
|
||||
): Page<BookDto> {
|
||||
seriesRepository.findByIdOrNull(id)?.let {
|
||||
if (!principal.user.canAccessSeries(it)) throw ResponseStatusException(HttpStatus.UNAUTHORIZED)
|
||||
|
|
|
|||
Loading…
Reference in a new issue