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

AbstractLinks::transform() generates invalid "prev" / "next" links #96

Closed
ettoredn opened this issue Jul 1, 2020 · 3 comments
Closed

Comments

@ettoredn
Copy link

ettoredn commented Jul 1, 2020

AbstractLinks::transform() sets "prev" and "next" to null when there is only one page in the result set. This does not pass JSON:API schema validation.

For instance, the following response does not pass schema validation:

{
  "jsonapi": {
    "version": "1.0"
  },
  "links": {
    "self": "/v1/transactions?page%5Bnumber%5D=1&page%5Bsize%5D=100",
    "first": "/v1/transactions?page%5Bnumber%5D=1&page%5Bsize%5D=100",
    "last": "/v1/transactions?page%5Bnumber%5D=1&page%5Bsize%5D=100",
    "prev": null,
    "next": null
  },
  "data": [
    {
      "type": "transactions",
      "id": "1",
      "links": {
        "self": "/v1/transactions/1"
      },
      "attributes": {
        "timestamp": "2020-07-01T07:01:24.450+00:00",
        "symbol": "TSLA",
        "amount": -20,
        "price": 950.12
      }
    }
  ]
}

This is probably a problem with the spec itself that mandates each link be either a string or an object with href and meta, while at the same time stating that a pagination link key could be either omitted or null. Schema validation would pass if keys are omitted instead of being set to null.

@ettoredn
Copy link
Author

ettoredn commented Jul 1, 2020

json-api/json-api#887

@kocsismate
Copy link
Member

@ettoredn Yes, you're right, the problem is with the spec itself.

@kocsismate
Copy link
Member

Since I'm not going to backport fixes for the official schema, I've just added an optional constructor parameter for ResponseValidator to be able to provide a custom schema path which potentially has upstream fixes.

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

No branches or pull requests

2 participants