Skip to content

Commit

Permalink
Fix schema disabling for extra actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan P Kilby committed May 31, 2018
1 parent e1302f8 commit df1d4b7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions rest_framework/schemas/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ def should_include_endpoint(self, path, callback):
if callback.cls.schema is None:
return False

if 'schema' in callback.initkwargs:
if callback.initkwargs['schema'] is None:
return False

if path.endswith('.{format}') or path.endswith('.{format}/'):
return False # Ignore .json style URLs.

Expand Down
3 changes: 2 additions & 1 deletion rest_framework/schemas/inspectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def __get__(self, instance, owner):

def __set__(self, instance, other):
self.instance_schemas[instance] = other
other.view = instance
if other is not None:
other.view = instance

@property
def view(self):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def custom_list_action(self, request):
def custom_list_action_multiple_methods(self, request):
return super(ExampleViewSet, self).list(self, request)

@action(detail=False, schema=None)
def excluded_action(self, request):
pass

def get_serializer(self, *args, **kwargs):
assert self.request
assert self.action
Expand Down Expand Up @@ -737,6 +741,19 @@ def extra_action(self, pk, **kwargs):
assert len(fields) == 2
assert "my_extra_field" in [f.name for f in fields]

def test_viewset_action_with_null_schema(self):
class CustomViewSet(GenericViewSet):
@action(detail=True, schema=None)
def extra_action(self, pk, **kwargs):
pass

router = SimpleRouter()
router.register(r'detail', CustomViewSet, base_name='detail')

generator = SchemaGenerator()
view = generator.create_view(router.urls[0].callback, 'GET')
assert view.schema is None

def test_view_with_manual_schema(self):

path = '/example'
Expand Down

0 comments on commit df1d4b7

Please sign in to comment.