-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Generate schema with respect to http_method_names provided by CBV #5085
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
Conversation
Hi @hurturk. Thanks for your contribution ! Do you think you could get a test case along with the PR ? |
Hi @xordoquy, I already included a test case that overrides ExampleViewSet to remove permission classes and to specify |
@hurturk woops, indeed. I'm getting some more coffee and I'm sorry for the previous comment. |
rest_framework/schemas.py
Outdated
return [method.upper() for method in callback.actions.keys()] | ||
return [ | ||
method.upper() for method in | ||
set(callback.actions.keys()).intersection(set(callback.cls().http_method_names)) |
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.
There's too much going on inline here.
I'd suggest:
- Pull each of those two sets out into variable assignments.
- Use the
&
operator, rather then.intersection(...)
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.
Nice work, tho one requested change.
Hi @tomchristie, thank you for taking time on this. I have moved them to variables as you've pointed, hope that looks better. |
rest_framework/schemas.py
Outdated
@@ -246,7 +246,9 @@ def get_allowed_methods(self, callback): | |||
Return a list of the valid HTTP methods for this endpoint. | |||
""" | |||
if hasattr(callback, 'actions'): | |||
return [method.upper() for method in callback.actions.keys()] | |||
actions = set(callback.actions.keys()) | |||
http_method_names = set(callback.cls().http_method_names) |
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.
We shouldn't need to instantiate the class, right?
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.
Right, looks defensive. I will remove that quick.
Seems good to me, yup. Don't think I'd realised that |
Thanks for your time on this! |
Description
This limits the schema generation by
http_method_names
attribute (Django CBV). I just updatedget_allowed_method
to have a set intersection check.Closes #4691.