Skip to content

Commit 911b207

Browse files
Added examples to schema of CursorPagination (#8687)
* Added examples to schema of CursorPagination Fix #8686 Added missing examples for CursorPagination class to disable warnings in https://github.com/tfranzel/drf-spectacular and make it consistent with other pagination classes. * Adapted test case for paginated response schema
1 parent d507cd8 commit 911b207

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

rest_framework/pagination.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,10 +898,16 @@ def get_paginated_response_schema(self, schema):
898898
'next': {
899899
'type': 'string',
900900
'nullable': True,
901+
'format': 'uri',
902+
'example': 'http://api.example.org/accounts/?{cursor_query_param}=cD00ODY%3D"'.format(
903+
cursor_query_param=self.cursor_query_param)
901904
},
902905
'previous': {
903906
'type': 'string',
904907
'nullable': True,
908+
'format': 'uri',
909+
'example': 'http://api.example.org/accounts/?{cursor_query_param}=cj0xJnA9NDg3'.format(
910+
cursor_query_param=self.cursor_query_param)
905911
},
906912
'results': schema,
907913
},

tests/test_pagination.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,10 +922,14 @@ def test_get_paginated_response_schema(self):
922922
'next': {
923923
'type': 'string',
924924
'nullable': True,
925+
'format': 'uri',
926+
'example': 'http://api.example.org/accounts/?cursor=cD00ODY%3D"'
925927
},
926928
'previous': {
927929
'type': 'string',
928930
'nullable': True,
931+
'format': 'uri',
932+
'example': 'http://api.example.org/accounts/?cursor=cj0xJnA9NDg3'
929933
},
930934
'results': unpaginated_schema,
931935
},

0 commit comments

Comments
 (0)