question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger UI unwrapping Spring Data `Pageable` with wrong field names

See original GitHub issue

My controller is the following:

  @GetMapping
  public ResponseEntity getAll(final @PageableDefault(sort = "id") Pageable pageable) {
    return ResponseEntity.ok(null);
  }

The resulting Swagger UI is: screen shot 2018-08-15 at 17 54 22

It looks like it uses the Pageable getters to infer those parameters, bypassing springfox-data-rest configuration. Am I doing something wrong?

I am using Spring Boot 1.5.10.RELEASE and Springfox 2.9.2 with these dependencies:


    <springfox-swagger2.version>2.9.2</springfox-swagger2.version>

[...]

    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-core</artifactId>
      <version>${springfox-swagger2.version}</version>
    </dependency>

    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-spi</artifactId>
      <version>${springfox-swagger2.version}</version>
    </dependency>

    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-spring-web</artifactId>
      <version>${springfox-swagger2.version}</version>
    </dependency>

    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger2</artifactId>
      <version>${springfox-swagger2.version}</version>
    </dependency>

    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-data-rest</artifactId>
      <version>${springfox-swagger2.version}</version>
    </dependency>

    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-bean-validators</artifactId>
      <version>${springfox-swagger2.version}</version>
    </dependency>

    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-ui</artifactId>
      <version>${springfox-swagger2.version}</version>
    </dependency>

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:17
  • Comments:28 (4 by maintainers)

github_iconTop GitHub Comments

29reactions
hannes-angstcommented, Mar 11, 2019

Would be nice to have this feature.

What I came up a while ago was

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@ApiImplicitParams({
        @ApiImplicitParam(name = "page", dataType = "int", paramType = "query", defaultValue = "0", value = "Results page you want to retrieve (0..N)"),
        @ApiImplicitParam(name = "size", dataType = "int", paramType = "query", defaultValue = "20", value = "Number of records per page."),
        @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "Sorting criteria in the format: property(,asc|desc). "
                + "Default sort order is ascending. " + "Multiple sort criteria are supported.")})
public @interface ApiPageable {
}

and in the controller:

@ApiPageable
public ResponseEntity<Page<MyObject>> listBots(@NonNull Pageable pageable) {
    return ResponseEntity.ok(service.myObject(pageable));
}
21reactions
falknerdominikcommented, Aug 20, 2018

Hi, I can confirm this issue (with version 2.9.2). In the meantime I have solved it by providing implicit params (as shown below)

 @GetMapping("items")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query",
                    value = "Results page you want to retrieve (0..N)", defaultValue = "0"),
            @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query",
                    value = "Number of records per page.", defaultValue = "5"),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "Sorting criteria in the format: property(,asc|desc). " +
                            "Default sort order is ascending. " +
                            "Multiple sort criteria are supported.")
    })
    public List<Item> GetAll(
            @ApiIgnore(
                    "Ignored because swagger ui shows the wrong params, " +
                    "instead they are explained in the implicit params"
            ) Pageable pageable
    ) {
       // code
    }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger shows wrong id field using Spring Data Rest
I'm using Spring Boot + Spring DATA REST and Swagger (Springfox 2.7.0). Spring DATA REST follows HATEOAS principles, so id field should ...
Read more >
Swagger Documentation For Spring Pageable Interface
I am trying to provide an OpenAPI YAML from Spring Data Rest in order to generate client code. I noticed that something goes...
Read more >
docs/release-notes.md · serv/springfox - Gitee.com
Support for Swagger 2.0. The swagger-ui webjar no longer requires a JSP engine. Powerful ways to include or exclude API endpoints using springfox.documentation....
Read more >
Documenting a Spring Data REST API with Springfox and ...
A tutorial on how to document a REST API created with Spring Data REST using Springfox and Swagger.
Read more >
Fix list for IBM WebSphere Application Server traditional V9
PH39398, SESN8558E Message giving wrong error details ... Request (CSR) is created with an extra information in the Subject Alternate Name(SAN) field.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found