mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Fix schema disabling for extra actions
This commit is contained in:
parent
3642fe0b30
commit
3feea10bae
|
@ -218,6 +218,10 @@ class EndpointEnumerator(object):
|
||||||
if callback.cls.schema is None:
|
if callback.cls.schema is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if 'schema' in callback.initkwargs:
|
||||||
|
if callback.initkwargs['schema'] is None:
|
||||||
|
return False
|
||||||
|
|
||||||
if path.endswith('.{format}') or path.endswith('.{format}/'):
|
if path.endswith('.{format}') or path.endswith('.{format}/'):
|
||||||
return False # Ignore .json style URLs.
|
return False # Ignore .json style URLs.
|
||||||
|
|
||||||
|
|
|
@ -157,6 +157,7 @@ class ViewInspector(object):
|
||||||
|
|
||||||
def __set__(self, instance, other):
|
def __set__(self, instance, other):
|
||||||
self.instance_schemas[instance] = other
|
self.instance_schemas[instance] = other
|
||||||
|
if other is not None:
|
||||||
other.view = instance
|
other.view = instance
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -99,6 +99,10 @@ class ExampleViewSet(ModelViewSet):
|
||||||
def custom_list_action_multiple_methods(self, request):
|
def custom_list_action_multiple_methods(self, request):
|
||||||
return super(ExampleViewSet, self).list(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):
|
def get_serializer(self, *args, **kwargs):
|
||||||
assert self.request
|
assert self.request
|
||||||
assert self.action
|
assert self.action
|
||||||
|
@ -745,6 +749,20 @@ class TestAutoSchema(TestCase):
|
||||||
assert len(fields) == 2
|
assert len(fields) == 2
|
||||||
assert "my_extra_field" in [f.name for f in fields]
|
assert "my_extra_field" in [f.name for f in fields]
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
|
||||||
|
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
|
||||||
|
|
||||||
@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
|
@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
|
||||||
def test_view_with_manual_schema(self):
|
def test_view_with_manual_schema(self):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user