- Notifications
You must be signed in to change notification settings - Fork302
Allowformat
through GET validation filtering#535
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Allowformat
through GET validation filtering#535
Uh oh!
There was an error while loading.Please reload this page.
Conversation
codecovbot commentedDec 28, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
@@ Coverage Diff @@## master #535 +/- ##======================================= Coverage 94.33% 94.33% ======================================= Files 60 60 Lines 3725 3725 ======================================= Hits 3514 3514 Misses 211 211
Continue to review full report at Codecov.
|
Not sure how to understandhttps://jsonapi.org/format/#query-parameters whether it allows additional query parameters or not. Another way would be to changeURL_FORMAT_OVERRIDE. @n2ygk What do you think? |
JSON API version 1.1 Release candidate gets a bit more specific on query parameters, seehttps://jsonapi.org/format/1.1/#query-parameters-custom This means for a valid implementation of format query parameter, |
It says you can have additional "non-standard" query parameters but with the "additional requirement that they MUST contain at least one non a-z character" in order to avoid naming collisions. It's their version of an I personally don't like use of the |
What we can do is to allow query parameter which set by |
@serenecloud Are you open to adjust your PR ascommented? |
@sliverc I'm not sure what the change involves at this point. Changing to |
@serenecloud |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm not happy with hardcoding allowing "format" query parameter since that violates the jsonapi spec in that a non-standard QP has a "standard looking" name. Furthermore, anything that is not 'Application/vnd.api+json' is not jsonapi and it should only be used when the non-jsonapi DRF browseable API is used during development -- it should not be used in production.
@sliverc Does the Browseable API code respect the value ofFORMAT_SUFFIX_KWARG? Then perhapsquery_regex
could include the value of that kwarg. This still "breaks" jsonapi if the default is used.
Perhaps just document that if you intend to use the browseable API, you should subclass the QueryParameterValdationFilter and overridequery_regex
?
@n2ygk I am a bit confused on your comment as you have already upvoted mycomment and I thought you agreed with it. Browsable API can be used in production and we even document it this way in the README.md so it needs to work. We can simply ignore URL_FORMAT_OVERRIDE in QueryParameterValidationFilter if it is not changed from format to something JSON API valid but to be honest this rather sounds like "perfect is the enemy of good"... 😄 if someone wants to break json api spec we cannot stop them, but as long as our recommend configuration doesn't we are safe. |
n2ygk commentedFeb 18, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I upvoted your comment but the PR hardcodes "format" at0da5fc2 I'm happy with them breaking the spec explicitly as they like, but this makes the default be to allow And I missed that about using the browsable API in production. I guess to be "technical" that's not a JSONAPI interaction at that point. |
I'm not sure what I'm doing differently, but the browseable API seems to work for me with no special setup. Not sure why that is. Is the |
@n2ygk So to clarify are you ok with this PR being adjusted as I have outlined incomment? It is just rephrasing what is basically written in the previouscomment but includes how to do it. |
sliverc commentedFeb 18, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@n2ygk I think you need to configure another renderer like |
Let me quote your reply to sync up;-) I see what happened in my#535 (comment). If I just GET /resource in the browseable API, no format QP is sent in yet it seems to work right, I guess because of a default somewhere. If I explicitly add Per your#535 (comment) I still think that "silently" checking whether it's for hardcoded |
@n2ygk |
The client app won’t see the error. Jsonapi makes the point of beingclient-friendly by reporting useful errors. (Something needing improvementsin DJA). Let’s say I have an attribute called format and I meant‘filter[format]=api’ but instead I gave ‘format=api’....Better to make this explicitly configured. …On Tue, Feb 19, 2019 at 2:48 AM Oliver Sauder ***@***.***> wrote:@n2ygk <https://github.com/n2ygk> What we could do is to log a warning when URL_FORMAT_OVERRIDE <https://www.django-rest-framework.org/api-guide/settings/#url_format_override> is set to format and a uri contains a format query parameter, noting user to configure URL_FORMAT_OVERRIDE to contentFormat. How does this sound? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#535 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AEJ5d6_Vt0CSm-eZwM15F3p8anrE1-JDks5vO6wwgaJpZM4ZjXp1> . |
@n2ygk |
n2ygk commentedFeb 24, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@sliverc |
@n2ygk |
@sliverc Where'd we end up with this? I've lost track. |
@n2ygk This PR should be adjusted as outlined in#535 (comment) |
Closing in favor of#812 |
Uh oh!
There was an error while loading.Please reload this page.
Issue
The guides onhttps://django-rest-framework-json-api.readthedocs.io/en/stable/usage.html#configuration recommend including the
rest_framework_json_api.filters.QueryParameterValidationFilter
in initial configuration which is good advice, but by default, the Django REST Framework UI provides a dropdown which allows you to pickformat=api
orformat=vnd.api+json
Without allowing the
format
parameter through you get the following error:Description of the Change
This change adds
format
toquery_regex
Checklist
CHANGELOG.md
AUTHORS