Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links don't get inserted for inlined _embedded associations [DATAREST-464] #843

Closed
spring-projects-issues opened this issue Jan 22, 2015 · 7 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Jan 22, 2015

Evgeniy Zakharchenko opened DATAREST-464 and commented

Let's consider authors and books relations from spring-data-rest-webmvc module tests.

Here is an example of the authors rel output:

{
  "_embedded": {
    "authors": [
      {
        "name": "Ollie",
        "_embedded": {
          "books": [
            {
              "title": "Spring Data"
            },
            {
              "title": "Spring Data (Second Edition)"
            }
          ]
        },
        "_links": {
          "self": {
            "href": "http://localhost/authors/1"
          }
        }
      }
    ]
  }
}

Since we inlined books into authors resource we do not show the books association link in the links section for a given author. (according to DATAREST-317)

Issue: It brakes further navigation (discoverability). It's not possible to navigate to the associated book resource from the authors collection.

Solution: to show links for inlined resources
Here is an example:

{
  "_embedded": {
    "authors": [
      {
        "name": "Ollie",
        "_embedded": {
          "books": [
            {
              "title": "Spring Data (Second Edition)",
              "_links": {
                "self": {
                  "href": "http://localhost/books/2-2{?projection}",
                  "templated": true
                },
                "authors": {
                  "href": "http://localhost/books/2-2/authors"
                }
              }
            }
          ]
        },
        "_links": {
          "self": {
            "href": "http://localhost/authors/1"
          }
        }
      }
    ]
  }
}

This is actually how HAL suggests it to be http://stateless.co/hal_specification.html

A pull request is underway


Affects: 2.2.1 (Evans SR1)

Issue Links:

  • DATAREST-302 Handle resource links of resources inlined using @Projection
    ("duplicates")

Backported to: 2.3.1 (Fowler SR1), 2.2.3 (Evans SR3)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 22, 2015

Evgeniy Zakharchenko commented

Added a link to the pull request

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 4, 2015

Evgeniy Zakharchenko commented

Any comments ?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 17, 2015

Greg Turnquist commented

Looks great at the start. I'll try to find some time and walk through your pull request and provide feedback. Sorry you haven't heard sooner. We are a relatively small team

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 17, 2015

Greg Turnquist commented

Inspecting

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 24, 2015

Greg Turnquist commented

I've been reading over the HAL spec as well as their blog site repeatedly. I have yet to find an example of one _embedded found inside another, as you propose up above. To actually generate an inlined resource-within-resource, I have sample project at https://github.com/gregturn/spring-data-rest-sample. If you run the java-based maven version, which has an excerpt projection, then curl localhost:8080/persons will produce:

{
  "_embedded" : {
    "persons" : [ {
      "firstName" : "Frodo",
      "lastName" : "Baggins",
      "addresses" : [ {
        "street" : "Bag End",
        "state" : "The Shire",
        "country" : "Middle Earth"
      }, {
        "street" : "The Undying Lands",
        "state" : "Ships",
        "country" : "Elven Lands"
      } ],
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/persons/1{?projection}",
          "templated" : true
        },
        "addresses" : {
          "href" : "http://localhost:8080/persons/1/addresses"
        }
      }
    } ]
  }
}

Ther is top level _embedded depicting the container of Person resources. "addresses" is inlined with data. To get to this resource of addresses, an "addresses" link is shown at the bottom, localhost:8080/persons/1/addresses. Navigate to that, and you'll find another top level container of _embedded, with each one serving up it's self link.

I've built apps on top of Spring Data REST with JavaScript, and to have "addresses" also wrapped with _embedded would introduce a bit of a hiccup to hop over that.

The spec itself simply states: "The reserved '_embedded' property is OPTIONAL It is an object whose property names are link relation types (as defined by [RFC5988]) and values are either a Resource Object or an array of Resource Objects."

By default, i.e. no excerpt projections, the "addresses" is provided as a link with no inlined data, hence it meets the spec's requirements. When it comes to "inlining", I can't find anything in the spec that carries this extra level of semantics, and hence doesn't seem to violate the spec.

Bottom line: I don't see this as a hard requirement. Perhap an option, but then I have to shake out if we need to manage different versions of things and whether or not it's necessary.

Thoughts?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 2, 2015

Greg Turnquist commented

Already patched by 2697c6a

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 2, 2015

Greg Turnquist commented

This has already been resolved by zEvg@f1462d0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants