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

Support marking a link as part of an array #39

Merged
merged 3 commits into from
Oct 14, 2016

Conversation

chrissimon-au
Copy link
Contributor

This permits defining a link as part of an array - even if there is only a single link with that rel name. Partially this was done to support following the recommendation from http://stateless.co/hal_specification.html:

Note:
If you're unsure whether the link should be singular, assume it will be multiple. If you pick singular and find you need to change it, you will need to create a new link relation or face breaking existing clients.

In particular, we intend to use this for adding curies to the _links array, as all examples of curies show them as an array of links, even when there is only a single link, e.g.

"_links": {
  "curies": [
    {
      "name": "doc",
      "href": "http://haltalk.herokuapp.com/docs/{rel}",
      "templated": true
    }
  ],

  "doc:latest-posts": {
    "href": "/posts/latest"
  }
}

…ers as an array of links even if there is only a single one defined.
@samuelabj
Copy link
Contributor

Thanks @chrissimon-au. Would you mind adding tests to confirm a single rel without IsRelArray still renders a single link and singular rel with IsRelArray renders an array?

@chrissimon-au
Copy link
Contributor Author

No problem - apologies for not including them in the first place!

The case where a single rel without isRelArray renders a single link is covered by existing test cases - the first two models in GetLinkTestModels.

Have updated the PR to add a unit test to confirm that isRelArray is stored properly on Link, and two more test cases to GetLinkTestModels:

  1. to confirm that isRelArray:true will cause an array of a single link
  2. to confirm that isRelArray:true on a link where there is more than one with the same rel will not impact on it being rendered as an array

Let me know if you'd like more tests.

samuelabj added a commit that referenced this pull request Oct 13, 2016
@samuelabj samuelabj merged commit 850c689 into visualeyes:master Oct 14, 2016
@samuelabj
Copy link
Contributor

Forgot to say thanks for adding the tests!

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

Successfully merging this pull request may close these issues.

None yet

2 participants