Skip to content

Commit 64d4af0

Browse files
committed
remove JSONAPI prefix per django-json-api#471
1 parent f0bdbd4 commit 64d4af0

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

docs/usage.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ for `GET http://127.0.0.1:8000/nopage-entries?filter[bad]=1`:
177177
}
178178
```
179179

180-
#### `JSONAPIQueryValidationFilter`
181-
`JSONAPIQueryValidationFilter` validates query parameters to be one of the defined JSON:API query parameters
180+
#### `QueryValidationFilter`
181+
`QueryValidationFilter` validates query parameters to be one of the defined JSON:API query parameters
182182
(sort, include, filter, fields, page) and returns a `400 Bad Request`. If a non-matching query parameter
183183
is used. This can help the client identify misspelled query parameters, for example.
184184

@@ -216,7 +216,7 @@ from models import MyModel
216216
class MyViewset(ModelViewSet):
217217
queryset = MyModel.objects.all()
218218
serializer_class = MyModelSerializer
219-
filter_backends = (filters.JSONAPIQueryValidationFilter, filters.OrderingFilter,
219+
filter_backends = (filters.QueryValidationFilter, filters.OrderingFilter,
220220
django_filters.DjangoFilterBackend,)
221221
filterset_fields = {
222222
'id': ('exact', 'lt', 'gt', 'gte', 'lte', 'in'),

example/tests/test_filters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def test_filter_invalid_association_name(self):
251251
def test_filter_empty_association_name(self):
252252
"""
253253
test for filter with missing association name
254-
error texts are different depending on whether JSONAPIQueryValidationFilter is in use.
254+
error texts are different depending on whether QueryValidationFilter is in use.
255255
TODO: Just change the "invalid filter" to "invalid query parameter" in JSONAPIDjangoFilter?
256256
"""
257257
response = self.client.get(self.url, data={'filter[]': 'foobar'})
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .sort import OrderingFilter # noqa: F401
2-
from .queryvalidation import JSONAPIQueryValidationFilter # noqa: F401
2+
from .queryvalidation import QueryValidationFilter # noqa: F401

rest_framework_json_api/filters/filter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class JSONAPIDjangoFilter(DjangoFilterBackend):
4444
search_param = api_settings.SEARCH_PARAM
4545

4646
# Make this regex check for 'filter' as well as 'filter[...]'
47-
# Leave other incorrect usages of 'filter' to JSONAPIQueryValidationFilter.
47+
# Leave other incorrect usages of 'filter' to QueryValidationFilter.
4848
# See http://jsonapi.org/format/#document-member-names for allowed characters
4949
# and http://jsonapi.org/format/#document-member-names-reserved-characters for reserved
5050
# characters (for use in paths, lists or as delimiters).

rest_framework_json_api/filters/queryvalidation.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from rest_framework.filters import BaseFilterBackend
55

66

7-
class JSONAPIQueryValidationFilter(BaseFilterBackend):
7+
class QueryValidationFilter(BaseFilterBackend):
88
"""
99
A backend filter that performs strict validation of query parameters for
1010
jsonapi spec conformance and raises a 400 error if non-conforming usage is
@@ -15,18 +15,18 @@ class JSONAPIQueryValidationFilter(BaseFilterBackend):
1515
requirement that they MUST contain contain at least one non a-z character (U+0061 to U+007A).
1616
It is RECOMMENDED that a U+002D HYPHEN-MINUS, “-“, U+005F LOW LINE, “_”, or capital letter is
1717
used (e.g. camelCasing)." -- http://jsonapi.org/format/#query-parameters
18-
19-
TODO: For jsonapi error object conformance, must set jsonapi errors
20-
"parameter" for the ValidationError. This requires extending DRF/DJA Exceptions.
2118
"""
22-
# sort and include stand alone; filter, fields, page have []'s
19+
#: compiled regex that matches the allowed http://jsonapi.org/format/#query-parameters
20+
#: `sort` and `include` stand alone; `filter`, `fields`, and `page` have []'s
2321
query_regex = re.compile(r'^(sort|include)$|^(filter|fields|page)(\[[\w\.\-]+\])?$')
2422

2523
def validate_query_params(self, request):
2624
"""
2725
Validate that query params are in the list of valid query keywords
2826
Raises ValidationError if not.
2927
"""
28+
# TODO: For jsonapi error object conformance, must set jsonapi errors "parameter" for
29+
# the ValidationError. This requires extending DRF/DJA Exceptions.
3030
for qp in request.query_params.keys():
3131
if not self.query_regex.match(qp):
3232
raise ValidationError('invalid query parameter: {}'.format(qp))

0 commit comments

Comments
 (0)