Closed (fixed)
Project:
JSON:API
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 Jan 2017 at 20:34 UTC
Updated:
29 May 2017 at 20:24 UTC
Jump to comment: Most recent
The JSON API spec demonstrates the sort query parameter as a list of fields to sort on, with hyphens indicating a field should be sorted in descending order:
/people?sort=age
/articles?sort=-created,title
The JSON API module, however, uses a different sort syntax. For example:
/node/article?sort[sort-created][path]=created&sort[sort-created][direction]=DESC
This is both more complex than the spec's syntax, and won't be compatible with other frameworks that utilize JSON API out-of-the-box.
Modify handling of the sort query parameter to match the official specification.
Comments
Comment #2
e0ipsoOur sorting options are more complex than what the spec anticipates. We may want to sort by a language variant of a field, for instance.
I feel very strongly that we need to support the spec compliant version. I'm not 100% sure about the best way to achieve that. We could introduce some shortcut syntax that gets expanded into the current syntax (if that is not already in place. See #2742769: [FEATURE] Add support for sort). Or maybe we should limit our sorting options to what the spec allows.
Thoughts?
Comment #3
wim leersThanks @hampercm for reporting this and @e0ipso for your thoughtful response. I will be digging through this and related code and will hopefully be able to post a suggestion/recommendation somewhere in the next few days.
In the mean time, keep the discussion going, don't wait for me :)
Comment #4
hampercm commented+1 on @e0ipso's idea of adding a shortcut syntax.
Comment #5
spleshkaIt seems like it had been done as a part of #2742769: [FEATURE] Add support for sort. We certainly can do something like this:
and it works! I've added shorthand info to the docs https://www.drupal.org/docs/8/modules/json-api/collections-filtering-sor.... Setting the issue status to Fixed. Feel free to reopen if you disagree.