From 78aba78f0250ff4b0afa6ec45555c8f37771ca77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20ROCHER?= Date: Thu, 28 Jul 2016 15:50:31 +0200 Subject: [PATCH] Add a class owner dict to describe path parameters --- rest_framework/schemas.py | 8 +++++++- tests/test_schemas.py | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/rest_framework/schemas.py b/rest_framework/schemas.py index cd2c39258..a2e54347f 100644 --- a/rest_framework/schemas.py +++ b/rest_framework/schemas.py @@ -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 diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 8284c71c4..155ad1ff1 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -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') ] ) },