diff --git a/netbox/netbox/api.py b/netbox/netbox/api.py index 28403f181..9d65ba8b8 100644 --- a/netbox/netbox/api.py +++ b/netbox/netbox/api.py @@ -4,11 +4,22 @@ from rest_framework import authentication, exceptions from rest_framework.pagination import LimitOffsetPagination from rest_framework.permissions import DjangoObjectPermissions, SAFE_METHODS from rest_framework.renderers import BrowsableAPIRenderer +from rest_framework.schemas import coreapi from rest_framework.utils import formatting from users.models import Token +def is_custom_action(action): + return action not in { + 'retrieve', 'list', 'create', 'update', 'partial_update', 'destroy', 'bulk_destroy' + } + + +# Monkey-patch DRF to treat bulk_destroy() as a non-custom action (see #3436) +coreapi.is_custom_action = is_custom_action + + # # Renderers # diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index bd247070f..7e1966edb 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -472,6 +472,13 @@ REST_FRAMEWORK = { 'DEFAULT_VERSION': REST_FRAMEWORK_VERSION, 'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning', 'PAGE_SIZE': PAGINATE_COUNT, + 'SCHEMA_COERCE_METHOD_NAMES': { + # Default mappings + 'retrieve': 'read', + 'destroy': 'delete', + # Custom operations + 'bulk_destroy': 'bulk_delete', + }, 'VIEW_NAME_FUNCTION': 'netbox.api.get_view_name', }