spring-projects / spring-projects/spring-data-rest

Wrong pagination links when baseURI() is set [DATAREST-191]

Open
#576 3 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

status: feedback-provided type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Sri opened DATAREST-191 and commented

Setting baseURI() fails to generate proper pagination links

@Override
		protected void configureRepositoryRestConfiguration(
			try {
				URI base = new URI("/api/v1");
				if (base != null) {
					config.setBaseUri();
				}
			} catch (URISyntaxException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

With about setting I see pagination links as

"links": [
       {
           "rel": "next",
           "href": "http://localhost:8080/dc/employees?page=1&size=20"
       },
       {
           "rel": "search",
           "href": "/api/vi/employees/search"
       }
   ],

However digging in code found that PagedResourcesAssembler has its baseURI, so tried to override it as

@Override
@Bean
public PagedResourcesAssembler<Object> pagedResourcesAssembler() {
     UriComponents uriComponents = null;
     try {
          uriComponents = baseURI() == null ? null : UriComponentsBuilder
                            .fromUri(baseURI()).build();
     } catch (URISyntaxException e) {
          e.printStackTrace();
     }
     return new PagedResourcesAssembler<Object>(pageableResolver(),
                   uriComponents);
}

but this didn't help either...

"links": [
        {
            "rel": "next",
            "href": "/api/vi/?page=1&size=20"
        },
        {
            "rel": "search",
            "href": "/api/vi/employees/search"
        }
    ]

Affects: 2.0 M1 (Codd)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.