spring-projects / spring-hateoas

Spring HATEOAS - Library to support implementing representations for hyper-text driven REST web services.
https://spring.io/projects/spring-hateoas
Apache License 2.0
1.04k stars 477 forks source link

CurieProvider with multiple curies and namespaces assigned manually. #626

Open pjdabrowski opened 7 years ago

pjdabrowski commented 7 years ago

I am trying to use multiple curies like this:

@Bean
  public CurieProvider curieProvider() {

    return new DefaultCurieProvider(HashMap.ofEntries(
        Tuple.of("h3h3", new UriTemplate("http://localhost:8080/rest-api#{rel}")),
        Tuple.of("h4h4", new UriTemplate("http://localhost:8080/rest-api#{rel}-revision")))
                                           .toJavaMap(), "h3h3");
  }

With resources annotated like this:

@Relation(value = "h3h3:lineup", collectionRelation = "h3h3:lineups")
public class LineupResource extends ResourceSupport {}

@Relation(value = "h3h3:thing", collectionRelation = "h3h3:things")
public class ThingResource extends ResourceSupport {}

For collections this scenario works perfectly fine. But in case of GET on single resource curies section is missing in response payload because CurieProvider.getNamespacedRelFrom is equal to my link rel: https://github.com/spring-projects/spring-hateoas/blob/6bed9bec403f2ca45f4fd319c6ee3d79738f36f7/src/main/java/org/springframework/hateoas/hal/Jackson2HalModule.java#L174

Get response:

{
  "code": "L1",
  "_links": {
    "self": {
      "href": "http://192.168.209.95:8080/lineups/L1"
    },
    "h3h3:things": {
      "href": "http://192.168.209.95:8080/lineups/L1/things"
    }
  }
}

Is it intended behavior?

gregturn commented 7 years ago

I'll have to look closer. My knowledge on curies is a bit lacking (Oliver coded this piece).