From e1336387d1af300e17407628fc1a00ed5a2c3ecf Mon Sep 17 00:00:00 2001 From: Dhaval Mehta <20968146+dhaval-mehta@users.noreply.github.com> Date: Fri, 24 Apr 2020 19:43:13 +0530 Subject: [PATCH] Added `example` for pagination in schemas. (#7275) --- rest_framework/pagination.py | 12 ++++++++++++ tests/test_pagination.py | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 1a1ba2f65..a73f2e526 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -236,10 +236,16 @@ class PageNumberPagination(BasePagination): 'next': { 'type': 'string', 'nullable': True, + 'format': 'uri', + 'example': 'http://api.example.org/accounts/?{page_query_param}=4'.format( + page_query_param=self.page_query_param) }, 'previous': { 'type': 'string', 'nullable': True, + 'format': 'uri', + 'example': 'http://api.example.org/accounts/?{page_query_param}=2'.format( + page_query_param=self.page_query_param) }, 'results': schema, }, @@ -403,10 +409,16 @@ class LimitOffsetPagination(BasePagination): 'next': { 'type': 'string', 'nullable': True, + 'format': 'uri', + 'example': 'http://api.example.org/accounts/?{offset_param}=400&{limit_param}=100'.format( + offset_param=self.offset_query_param, limit_param=self.limit_query_param), }, 'previous': { 'type': 'string', 'nullable': True, + 'format': 'uri', + 'example': 'http://api.example.org/accounts/?{offset_param}=200&{limit_param}=100'.format( + offset_param=self.offset_query_param, limit_param=self.limit_query_param), }, 'results': schema, }, diff --git a/tests/test_pagination.py b/tests/test_pagination.py index cd84c8151..c028f0ea8 100644 --- a/tests/test_pagination.py +++ b/tests/test_pagination.py @@ -281,10 +281,14 @@ class TestPageNumberPagination: 'next': { 'type': 'string', 'nullable': True, + 'format': 'uri', + 'example': 'http://api.example.org/accounts/?page=4', }, 'previous': { 'type': 'string', 'nullable': True, + 'format': 'uri', + 'example': 'http://api.example.org/accounts/?page=2', }, 'results': unpaginated_schema, }, @@ -588,10 +592,14 @@ class TestLimitOffset: 'next': { 'type': 'string', 'nullable': True, + 'format': 'uri', + 'example': 'http://api.example.org/accounts/?offset=400&limit=100', }, 'previous': { 'type': 'string', 'nullable': True, + 'format': 'uri', + 'example': 'http://api.example.org/accounts/?offset=200&limit=100', }, 'results': unpaginated_schema, },