An overview of things to validate.
Generic
Link Objects
Pagination Links
reach goal: if any of these is present then data for the document or relationship MUST be an array if present.
Document Links
Resource Links
Relationship Links
Spec Info
Document Links
Document links have self with is a string or a links object (href + optional meta).
They appear at the same level as the primary document (e.g. alongside the data included meta members). Documents that contain collections (data is an array) may also have pagination links.
example:
{
data: [],
links: { self: 'https://api.example.com/foos' }
}
Resource Links
Resource links have the same rules as document links, and appear at the top level of the resource. e.g. alongside type id attributes and relationships. Resources cannot have pagination links.
example:
{
data: {
type: 'foo',
id: '1',
attributes: {},
links: { self: 'https://api.example.com/foos/1' }
}
}
Relationship Links
Relationship links appear within the Relationship Object. They have more requirements than document and resource links. The related link is the most important aspect that is different. Relationships that represent collections may have pagination links. In ember-data we currently only utilize the related link. This is actually a bug, because we should fall back to the self link when related is not present and error if links is present without either.
{
data: {
type: 'foo',
id: '1',
relationships: {
bars: {
data: [],
links: {
related: 'https://api.example.com/foos/1/bars'
}
}
}
}
}
An overview of things to validate.
Generic
link objects.Link Objects
href// note the spec is too vague and could mean that eitherhreformetamust be present, cc @dgebmetaPagination Links
reach goal: if any of these is present then
datafor thedocumentorrelationshipMUST be anarrayif present.firstMUST be null, a string, or alink objectlastMUST be null, a string, or alink objectprevMUST be null, a string, or alink objectnextMUST be null, a string, or alink objectDocument Links
selfrelated(when the document is for a relationship)Resource Links
self// note: again, vague spec. Nothing else is described butselfis described as aMAY. We are going to be more strict: if you define links for a resource it MUST beselfRelationship Links
self// ember-data does not use thisrelated// note: ember-data only uses this, so we upgrade to a MUST from a MAYSpec Info
Document Links
Document links have
selfwith is astringor alinks object(href+ optionalmeta).They appear at the same level as the primary document (e.g. alongside the
dataincludedmetamembers). Documents that contain collections (datais an array) may also havepaginationlinks.example:
Resource Links
Resource links have the same rules as
documentlinks, and appear at the top level of the resource. e.g. alongsidetypeidattributesandrelationships. Resources cannot have pagination links.example:
Relationship Links
Relationship links appear within the
RelationshipObject. They have more requirements thandocumentandresourcelinks. Therelatedlink is the most important aspect that is different. Relationships that represent collections may have pagination links. Inember-datawe currently only utilize therelatedlink. This is actually a bug, because we should fall back to theselflink whenrelatedis not present and error iflinksis present without either.