Skip to content

Commit e133638

Browse files
authored
Added example for pagination in schemas. (#7275)
1 parent 812f254 commit e133638

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

rest_framework/pagination.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,16 @@ def get_paginated_response_schema(self, schema):
236236
'next': {
237237
'type': 'string',
238238
'nullable': True,
239+
'format': 'uri',
240+
'example': 'http://api.example.org/accounts/?{page_query_param}=4'.format(
241+
page_query_param=self.page_query_param)
239242
},
240243
'previous': {
241244
'type': 'string',
242245
'nullable': True,
246+
'format': 'uri',
247+
'example': 'http://api.example.org/accounts/?{page_query_param}=2'.format(
248+
page_query_param=self.page_query_param)
243249
},
244250
'results': schema,
245251
},
@@ -403,10 +409,16 @@ def get_paginated_response_schema(self, schema):
403409
'next': {
404410
'type': 'string',
405411
'nullable': True,
412+
'format': 'uri',
413+
'example': 'http://api.example.org/accounts/?{offset_param}=400&{limit_param}=100'.format(
414+
offset_param=self.offset_query_param, limit_param=self.limit_query_param),
406415
},
407416
'previous': {
408417
'type': 'string',
409418
'nullable': True,
419+
'format': 'uri',
420+
'example': 'http://api.example.org/accounts/?{offset_param}=200&{limit_param}=100'.format(
421+
offset_param=self.offset_query_param, limit_param=self.limit_query_param),
410422
},
411423
'results': schema,
412424
},

tests/test_pagination.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,14 @@ def test_get_paginated_response_schema(self):
281281
'next': {
282282
'type': 'string',
283283
'nullable': True,
284+
'format': 'uri',
285+
'example': 'http://api.example.org/accounts/?page=4',
284286
},
285287
'previous': {
286288
'type': 'string',
287289
'nullable': True,
290+
'format': 'uri',
291+
'example': 'http://api.example.org/accounts/?page=2',
288292
},
289293
'results': unpaginated_schema,
290294
},
@@ -588,10 +592,14 @@ def test_get_paginated_response_schema(self):
588592
'next': {
589593
'type': 'string',
590594
'nullable': True,
595+
'format': 'uri',
596+
'example': 'http://api.example.org/accounts/?offset=400&limit=100',
591597
},
592598
'previous': {
593599
'type': 'string',
594600
'nullable': True,
601+
'format': 'uri',
602+
'example': 'http://api.example.org/accounts/?offset=200&limit=100',
595603
},
596604
'results': unpaginated_schema,
597605
},

0 commit comments

Comments
 (0)