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

Breaking: change filters to compose as OR instead of AND #761

Closed
bart-degreed opened this issue May 15, 2020 · 1 comment · Fixed by #792
Closed

Breaking: change filters to compose as OR instead of AND #761

bart-degreed opened this issue May 15, 2020 · 1 comment · Fixed by #792

Comments

@bart-degreed
Copy link
Contributor

bart-degreed commented May 15, 2020

The current JsonApiDotNetCore documentation states:

Filters can be combined and will be applied using an AND operator. The following are equivalent query forms to get articles whose ordinal values are between 1-100.
GET /api/articles?filter[ordinal]=gt:1,lt:100 HTTP/1.1
GET /api/articles?filter[ordinal]=gt:1&filter[ordinal]=lt:100 HTTP/1.1

This violates the json:api official recommendations, which are using the OR operator in comma-separated parameters.

Multiple filter values can be combined in a comma-separated list. For example:
GET /comments?filter[post]=1,2 HTTP/1.1

While it does not explicitly state that OR must be used, the example only makes sense for an OR operator: get the comments that are attached to post 1 or 2. When AND was intended, it would mean: get the comments that are attached to both post 1 and 2, which makes no sense.

So I propose to change the existing behavior of JsonApiDotNetCore from AND to OR interpretation on comma-separated lists (or passing the same parameter multiple times, which is functionally equivalent):

GET /comments?filter[post]=1,2 HTTP/1.1
GET /comments?filter[post]=1&filter[post]=2 HTTP/1.1

would mean: comment.post must be 1 OR 2.

Note this proposal does not change the behavior of different parameters. So, for example:

GET /people?filter[name]=joe&filter[age]=gt:30 HTTP/1.1

would still require both conditions to match (AND).

@bart-degreed
Copy link
Contributor Author

In addition to this, we may want to extend the 'in' operator on filters to allow for specifying a range.

GET /api/articles?filter[ordinal]=in:1..100 HTTP/1.1

We may consider to extend syntax to indicate whether the begin and/or end are inclusive/exclusive:

GET /api/articles?filter[ordinal]=in:[1..100> HTTP/1.1

would mean: ordinal must be 1 or higher, up to (but not including) 100.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant