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

add operation_keys to get_summary_and_description method #334

Closed
wants to merge 1 commit into from

Conversation

Amoki
Copy link
Contributor

@Amoki Amoki commented Mar 20, 2019

I use operation_keys to override the get_operation_id method and be able to configure my operation ids with less overhead than method_decoration + swagger_decorator + operation_id.
eg:

class UserViewSet(ModelViewSet):
    queryset = User.objects.all()
    operations = {
        "list": "getUsers",
        "read": "getUser",
        "create": "createUser",
        "delete": "deleteUser",
    }

I'd like to do something similar with the description and summary for each path but the method get_summary_and_description don't have access to the operation_keys.

I use `operation_keys` to override the `get_operation_id` method and be able to configure my operation ids with less overhead than method_decoration + swagger_decorator + operation_id.
eg: 
```
class UserViewSet(ModelViewSet):
    queryset = User.objects.all()
    operations = {
        "list": "getUsers",
        "read": "getUser",
        "create": "createUser",
        "delete": "deleteUser",
    }
```
I'd like to do something similar with the description and summary for each path but the method `get_summary_and_description` don't have access to the operation_keys.
@axnsan12
Copy link
Owner

Can't you use self.view.action?

@Amoki
Copy link
Contributor Author

Amoki commented Mar 20, 2019

Unfortunately, retrieving the action is more complex than that: https://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas/generators.py#L412
Operation keys have also more information

@axnsan12
Copy link
Owner

Fair enough. In that case, I would rather move the operation_keys parameter to the SwaggerAutoSchema constructor and set it as an instance attribute, to make it available to any method which might need it without changing all signatures.

Any change to method signatures must also take backward compatibility into account, both for callers and for overriders.

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

Successfully merging this pull request may close these issues.

2 participants