Skip to content

Error parsing relationship links #22

Closed
@fcastilloes

Description

@fcastilloes

Given this sample code:

$jsonapi = '{
  "data": [{
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON API paints my bikeshed!"
    },
    "relationships": {
      "comments": {
        "links": {
          "custom": "http://example.com/articles/1/custom",
          "self": "http://example.com/articles/1/relationships/comments",
          "related": {
            "href": "http://example.com/articles/1/comments",
            "meta": {
              "count": 10
            }
          },
          "first": "http://example.com/articles/1/comments?page=1",
          "last": "http://example.com/articles/1/comments?page=10",
          "prev": "http://example.com/articles/1/comments?page=1",
          "next": "http://example.com/articles/1/comments?page=2"
        }
      }
    }
  }]
}';


$manager = new \Art4\JsonApiClient\Utils\Manager();
$document = $manager->parse($jsonapi);

print_r($document->asArray(true));

The related link produces:

Uncaught exception 'Art4\JsonApiClient\Exception\ValidationException' with message 'property "related" has to be a string, "object" given.'

Even thought the spec states that a link MUST be represented as either a string or a link object. Also note the related link is taken directly from an example in the spec so it should be valid.

Also, if I remove the related link, the string validates but the client discards the custom link. The spec states in the Relationship section that a links object contains at least one of self and related. Links sections doesn't add limitations to the contents of the links member more than the representation as a string or link object, so I conclude I should be able to add any link with any name I choose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions