Commit 806b0b34 by Tom Christie

Include nested objects in metadata for OPTIONS. Closes #3156. Closes #2915.

parent 81709a2c
...@@ -133,6 +133,8 @@ class SimpleMetadata(BaseMetadata): ...@@ -133,6 +133,8 @@ class SimpleMetadata(BaseMetadata):
if getattr(field, 'child', None): if getattr(field, 'child', None):
field_info['child'] = self.get_field_info(field.child) field_info['child'] = self.get_field_info(field.child)
elif getattr(field, 'fields', None):
field_info['children'] = self.get_serializer_info(field)
if not field_info.get('read_only') and hasattr(field, 'choices'): if not field_info.get('read_only') and hasattr(field, 'choices'):
field_info['choices'] = [ field_info['choices'] = [
......
...@@ -8,7 +8,7 @@ import sys ...@@ -8,7 +8,7 @@ import sys
import pytest import pytest
PYTEST_ARGS = { PYTEST_ARGS = {
'default': ['tests', '--tb=short', '-s', '--cov', 'rest_framework'], 'default': ['tests', '--tb=short', '-s'],
'fast': ['tests', '--tb=short', '-q', '-s'], 'fast': ['tests', '--tb=short', '-q', '-s'],
} }
...@@ -87,6 +87,14 @@ if __name__ == "__main__": ...@@ -87,6 +87,14 @@ if __name__ == "__main__":
if len(sys.argv) > 1: if len(sys.argv) > 1:
pytest_args = sys.argv[1:] pytest_args = sys.argv[1:]
first_arg = pytest_args[0] first_arg = pytest_args[0]
try:
pytest_args.remove('--coverage')
except ValueError:
pass
else:
pytest_args = ['--cov', 'rest_framework'] + pytest_args
if first_arg.startswith('-'): if first_arg.startswith('-'):
# `runtests.py [flags]` # `runtests.py [flags]`
pytest_args = ['tests'] + pytest_args pytest_args = ['tests'] + pytest_args
......
...@@ -59,6 +59,10 @@ class TestMetadata: ...@@ -59,6 +59,10 @@ class TestMetadata:
On generic views OPTIONS should return an 'actions' key with metadata On generic views OPTIONS should return an 'actions' key with metadata
on the fields that may be supplied to PUT and POST requests. on the fields that may be supplied to PUT and POST requests.
""" """
class NestedField(serializers.Serializer):
a = serializers.IntegerField()
b = serializers.IntegerField()
class ExampleSerializer(serializers.Serializer): class ExampleSerializer(serializers.Serializer):
choice_field = serializers.ChoiceField(['red', 'green', 'blue']) choice_field = serializers.ChoiceField(['red', 'green', 'blue'])
integer_field = serializers.IntegerField( integer_field = serializers.IntegerField(
...@@ -72,6 +76,7 @@ class TestMetadata: ...@@ -72,6 +76,7 @@ class TestMetadata:
child=serializers.IntegerField() child=serializers.IntegerField()
) )
) )
nested_field = NestedField()
class ExampleView(views.APIView): class ExampleView(views.APIView):
"""Example view.""" """Example view."""
...@@ -140,6 +145,26 @@ class TestMetadata: ...@@ -140,6 +145,26 @@ class TestMetadata:
'read_only': False 'read_only': False
} }
} }
},
'nested_field': {
'type': 'nested object',
'required': True,
'read_only': False,
'label': 'Nested field',
'children': {
'a': {
'type': 'integer',
'required': True,
'read_only': False,
'label': 'A'
},
'b': {
'type': 'integer',
'required': True,
'read_only': False,
'label': 'B'
}
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment