mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-07 13:54:47 +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
|
||||
templated path variables.
|
||||
"""
|
||||
path_descriptions = getattr(view, 'path_fields_descriptions', {})
|
||||
|
||||
fields = []
|
||||
|
||||
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)
|
||||
|
||||
return fields
|
||||
|
|
|
@ -36,6 +36,9 @@ class ExampleViewSet(ModelViewSet):
|
|||
|
||||
class ExampleView(APIView):
|
||||
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
|
||||
path_fields_descriptions = {
|
||||
'example_id': 'Description of example_id path parameter',
|
||||
}
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""get documentation"""
|
||||
|
@ -256,7 +259,7 @@ class TestSchemaAndSubSchemaGenerator(TestCase):
|
|||
url='/{example_id}/example-view/',
|
||||
action='post',
|
||||
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(
|
||||
|
@ -264,7 +267,7 @@ class TestSchemaAndSubSchemaGenerator(TestCase):
|
|||
action='get',
|
||||
description='get documentation',
|
||||
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