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

HATEOAS Link.withSelfRel() ignores basePath [DATAREST-1464]

Open
#1,827 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

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

Description

Dickurt opened DATAREST-1464 and commented

It appears that the org.springframework.hateoas.Link withSelfRel() method is ignoring DATAREST's basePath configuration. The following code snippet should clarify what I mean.

application.properties

spring.data.rest.basePath=/api

DummyController.java

@BasePathAwareController
public class DummyController {

  @RequestMapping(method = GET, value = "/test")
  public @ResponseBody ResponseEntity<?> test() {
    final CollectionModel<String> resources = new CollectionModel<>(Collections.emptyList());
    resources.add(linkTo(methodOn(DummyController.class).test()).withSelfRel());
    
    return ResponseEntity.ok(resources);
  }
}

Actual output

{
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/test"
    }
  }
}

Expected output

{
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/api/test"
    }
  }
}

It must be my bad understanding of the configuration at hand, but I could find no sources for the proper way to do it, so I assumed it was a bug


No further details from DATAREST-1464

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.