0

I have a class UserMetasource extending ResourceSupport (from Spring Hateoas):

public class UserMetasource extends ResourceSupport {

    public UserMetasource() {
        this.add(linkTo(methodOn(UserController.class).getRoles("roles")));
    }

}

Then, in a a controller, I return a UserMetasource:

@GetMapping("/usermeta")
public UserMetasource getUM() {
    return new UserMetasource();
}

This is returning this JSON:

{
  links: {
    roles: {
      href: "bla bla bla"
    }
  }
}

So good, so far. Now, I have added Swagger to my project:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.4.0</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.4.0</version>
</dependency>

And I have annotated the endpoint like this:

@GetMapping("/usermeta")
@ApiOperation(value = "Get UM", response = UserMetasource.class)
public UserMetasource getUM() {
    return new UserMetasource();
}

and now, JSON returned is this one:

{
  _links: {
    roles: {
      href: "bla bla bla"
    }
  }
}

Note that _links starts with underscore. Why is that? Is it possible to avoid that? I want links to be always without underscore.

Héctor
  • 24,444
  • 35
  • 132
  • 243
  • is it annotating the resource that causes the change, or just importing swagger? what happens if you leave swagger imported but remove `@ApiOperation(value = "Get UM", response = UserMetasource.class)` – Will M. May 24 '18 at 20:34
  • 1
    _" I want links to be always without underscore."_ Are you sure? Because the HAL standard is with underscore, so I would go with that. – a better oliver May 29 '18 at 12:28
  • @WillM. Just importing swagger causes the change – Héctor May 29 '18 at 13:44
  • @Héctor try checking your maven dependency tree with and without the import and look for unintended changes. – Will M. May 29 '18 at 15:52

0 Answers0