jsonapi icon indicating copy to clipboard operation
jsonapi copied to clipboard

Standardize on underscoring query parameters

Open TylerPachal opened this issue 1 year ago • 2 comments

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 the params, 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:

  1. Add the sort underscoring in the same fashion as the filter underscoring by putting it behind the replace_query_params option.
  2. Do it all of the time by adding a call to underscore/1 in the QueryParser.parse_filter function.

Let me know what you think is best, and I can prepare the PR.

TylerPachal avatar Jan 11 '23 14:01 TylerPachal