mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-07 22:04:48 +03:00
Add a class owner dict to describe path parameters
This commit is contained in:
parent
29afba67e1
commit
78aba78f02
|
@ -246,10 +246,16 @@ class SchemaGenerator(object):
|
||||||
Return a list of `coreapi.Field` instances corresponding to any
|
Return a list of `coreapi.Field` instances corresponding to any
|
||||||
templated path variables.
|
templated path variables.
|
||||||
"""
|
"""
|
||||||
|
path_descriptions = getattr(view, 'path_fields_descriptions', {})
|
||||||
|
|
||||||
fields = []
|
fields = []
|
||||||
|
|
||||||
for variable in uritemplate.variables(path):
|
for variable in uritemplate.variables(path):
|
||||||
field = coreapi.Field(name=variable, location='path', required=True)
|
field = coreapi.Field(name=variable,
|
||||||
|
location='path',
|
||||||
|
required=True,
|
||||||
|
description=path_descriptions.get(variable, ''),
|
||||||
|
)
|
||||||
fields.append(field)
|
fields.append(field)
|
||||||
|
|
||||||
return fields
|
return fields
|
||||||
|
|
|
@ -36,6 +36,9 @@ class ExampleViewSet(ModelViewSet):
|
||||||
|
|
||||||
class ExampleView(APIView):
|
class ExampleView(APIView):
|
||||||
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
|
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
|
||||||
|
path_fields_descriptions = {
|
||||||
|
'example_id': 'Description of example_id path parameter',
|
||||||
|
}
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
"""get documentation"""
|
"""get documentation"""
|
||||||
|
@ -256,7 +259,7 @@ class TestSchemaAndSubSchemaGenerator(TestCase):
|
||||||
url='/{example_id}/example-view/',
|
url='/{example_id}/example-view/',
|
||||||
action='post',
|
action='post',
|
||||||
fields=[
|
fields=[
|
||||||
coreapi.Field('example_id', required=True, location='path')
|
coreapi.Field('example_id', required=True, location='path', description='Description of example_id path parameter')
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'read': coreapi.Link(
|
'read': coreapi.Link(
|
||||||
|
@ -264,7 +267,7 @@ class TestSchemaAndSubSchemaGenerator(TestCase):
|
||||||
action='get',
|
action='get',
|
||||||
description='get documentation',
|
description='get documentation',
|
||||||
fields=[
|
fields=[
|
||||||
coreapi.Field('example_id', required=True, location='path')
|
coreapi.Field('example_id', required=True, location='path', description='Description of example_id path parameter')
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user