Открытый API 3 - Как прочитать свойства нумерации Spring Boot? - PullRequest
0 голосов
/ 04 февраля 2020

Я использую Spring Boot + Spring Rest Pagination + Open API 3.

@Operation(summary = "Find Contacts by name", description = "Name search by %name% format", tags = { "contact" })
@ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "successful operation", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Contact.class)))) })

@Parameter(in = ParameterIn.QUERY, description = "Zero-based page index (0..N)", name = "page"
, content = @Content(schema = @Schema(type = "integer", defaultValue = "0")))
@Parameter(in = ParameterIn.QUERY, description = "The size of the page to be returned", name = "size"
, content = @Content(schema = @Schema(type = "integer", defaultValue = "20")))
@Parameter(in = ParameterIn.QUERY, description = "Sorting criteria in the format: property(,asc|desc). "
        + "Default sort order is ascending. " + "Multiple sort criteria are supported."
        , name = "sort", content = @Content(array = @ArraySchema(schema = @Schema(type = "string"))))
@GetMapping(value = "/contacts")
public ResponseEntity<List<Contact>> findAll(Pagination pagination) {
    List<Contact> contacts = new ArrayList<>();
    contacts.add(Contact.builder().address1("Address1").address2("Address2").build());
    return new ResponseEntity<>(contacts, HttpStatus.OK);
}

Поскольку я использую Spring Boot Application. Я настроил следующие конфигурации:

# Added for Pagination 
spring.data.web.pageable.default-page-size=25
spring.data.web.pageable.page-parameter=page
spring.data.web.pageable.size-parameter=size 
spring.data.web.sort.sort-parameter=sort

Есть ли способ настроить вышеуказанные свойства для спецификации Open API 3, вместо того, чтобы делать это жестко?

1 Ответ

1 голос
/ 29 февраля 2020

Доступна поддержка Pageable для spring-data-commons. Проекты, использующие тип Pageable, должны добавить эту зависимость вместе с зависимостью springdo c -openapi-ui.

<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-data-rest</artifactId>
  <version>latest.version</version>
</dependency>

Более подробная информация доступна в FAQ:

...