jsonapi
jsonapi copied to clipboard
Standardize on underscoring query parameters
I was working on a PR to add "dasherized support" for the sort
and include
fields, in the same way I added it for the filter
field in https://github.com/beam-community/jsonapi/pull/282.
While I was doing that, I realized that it already works for include
, because the parse_include
function performs its own underscoring already, and doesn't need any help from the UnderscoreParameters
plug.
This was something that the parse_sort
function does not do, which I addressed by changing the UnderscoreParameters
plug in https://github.com/beam-community/jsonapi/pull/282.
So now we are in a state where certain query parameters always underscore their values, while others do not:
Query Parameter | Underscored? |
---|---|
fields |
Always |
filter |
Opt-in via replace_query_params |
include |
Always |
sort |
Never |
I think for version 2.0
of this library:
- All of the query parameters should always be underscored. It should be done by the
QueryParser
module. - The
UnderscoreParameters
module should go back to just doing theparams
, mostly undoing the work in https://github.com/beam-community/jsonapi/pull/282.
But in the mean time, there should still be a way to underscore the sort
query parameter. It looks like our options are:
- Add the
sort
underscoring in the same fashion as thefilter
underscoring by putting it behind thereplace_query_params
option. - Do it all of the time by adding a call to
underscore/1
in theQueryParser.parse_filter
function.
Let me know what you think is best, and I can prepare the PR.