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

Basic links validation #3

Merged
merged 3 commits into from Sep 9, 2018

Conversation

Projects
None yet
2 participants
@kennethlarsen
Contributor

kennethlarsen commented Sep 8, 2018

This adds basic object validation to links. A lot of the structure seemed to change after I made this so let me know if something looks odd.

@runspired

Amazing start! thanks so much!

Show resolved Hide resolved tests/unit/invalid-document-test.js Outdated
Show resolved Hide resolved tests/unit/invalid-resource-test.js Outdated
@runspired

This comment has been minimized.

Show comment
Hide comment
@runspired

runspired Sep 9, 2018

Collaborator

An overview of things to validate.

Generic

  • links is an object if present
  • links has at least one member
  • links only contains members that are strings or link objects.

Link Objects

  • link objects MUST contain self // note the spec is too vague and could mean that either self or meta must be present, cc @dgeb
  • link objects MAY contain meta
  • link object contain no other members

Pagination Links

reach goal: if any of these is present then data for the document or relationship MUST be an array if present.

  • If any of the below is present, all must be present.
  • first MUST be null, a string, or a link object
  • last MUST be null, a string, or a link object
  • prev MUST be null, a string, or a link object
  • next MUST be null, a string, or a link object

Document Links

  • document links MAY contain pagination-links
  • document links MAY contain self
  • document links MAY contain related (when the document is for a relationship)
  • no other members

Resource Links

  • resource links MAY contain self
  • no other members

Relationship Links

  • relationship links MAY contain pagination-links if for a collection // we should warn for this though as ember-data cannot use them (yet)
  • relationship links MAY contain self
  • relationship links MAY contain related
  • no other members

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'
         }
       }
    }
  }
}
Collaborator

runspired commented Sep 9, 2018

An overview of things to validate.

Generic

  • links is an object if present
  • links has at least one member
  • links only contains members that are strings or link objects.

Link Objects

  • link objects MUST contain self // note the spec is too vague and could mean that either self or meta must be present, cc @dgeb
  • link objects MAY contain meta
  • link object contain no other members

Pagination Links

reach goal: if any of these is present then data for the document or relationship MUST be an array if present.

  • If any of the below is present, all must be present.
  • first MUST be null, a string, or a link object
  • last MUST be null, a string, or a link object
  • prev MUST be null, a string, or a link object
  • next MUST be null, a string, or a link object

Document Links

  • document links MAY contain pagination-links
  • document links MAY contain self
  • document links MAY contain related (when the document is for a relationship)
  • no other members

Resource Links

  • resource links MAY contain self
  • no other members

Relationship Links

  • relationship links MAY contain pagination-links if for a collection // we should warn for this though as ember-data cannot use them (yet)
  • relationship links MAY contain self
  • relationship links MAY contain related
  • no other members

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'
         }
       }
    }
  }
}

@runspired runspired merged commit ae244ad into ember-data:master Sep 9, 2018

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment