mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 08:29:59 +03:00
Handle pagination
This commit is contained in:
parent
34aa586820
commit
159c92ffbd
|
@ -185,6 +185,9 @@ class AutoSchema(ViewInspector):
|
||||||
|
|
||||||
return component_name
|
return component_name
|
||||||
|
|
||||||
|
def get_paginated_component_name(self, serializer):
|
||||||
|
return 'Paginated' + self.get_component_name(serializer)
|
||||||
|
|
||||||
def get_error_component_name(self, serializer):
|
def get_error_component_name(self, serializer):
|
||||||
return self.get_component_name(serializer) + 'Error'
|
return self.get_component_name(serializer) + 'Error'
|
||||||
|
|
||||||
|
@ -695,6 +698,9 @@ class AutoSchema(ViewInspector):
|
||||||
def _get_reference(self, serializer):
|
def _get_reference(self, serializer):
|
||||||
return {'$ref': '#/components/schemas/{}'.format(self.get_component_name(serializer))}
|
return {'$ref': '#/components/schemas/{}'.format(self.get_component_name(serializer))}
|
||||||
|
|
||||||
|
def _get_paginated_reference(self, serializer):
|
||||||
|
return {'$ref': '#/components/schemas/{}'.format(self.get_paginated_component_name(serializer))}
|
||||||
|
|
||||||
def _get_error_reference(self, serializer):
|
def _get_error_reference(self, serializer):
|
||||||
return {'$ref': '#/components/schemas/{}'.format(self.get_error_component_name(serializer))}
|
return {'$ref': '#/components/schemas/{}'.format(self.get_error_component_name(serializer))}
|
||||||
|
|
||||||
|
@ -742,7 +748,9 @@ class AutoSchema(ViewInspector):
|
||||||
}
|
}
|
||||||
paginator = self.get_paginator()
|
paginator = self.get_paginator()
|
||||||
if paginator:
|
if paginator:
|
||||||
response_schema = paginator.get_paginated_response_schema(response_schema)
|
pagination_schema = paginator.get_paginated_response_schema(response_schema)
|
||||||
|
self.components[self.get_paginated_component_name(serializer)] = pagination_schema
|
||||||
|
response_schema = self._get_paginated_reference(serializer)
|
||||||
else:
|
else:
|
||||||
response_schema = item_schema
|
response_schema = item_schema
|
||||||
status_code = '201' if method == 'POST' else '200'
|
status_code = '201' if method == 'POST' else '200'
|
||||||
|
|
|
@ -472,13 +472,7 @@ class TestOperationIntrospection(TestCase):
|
||||||
'content': {
|
'content': {
|
||||||
'application/json': {
|
'application/json': {
|
||||||
'schema': {
|
'schema': {
|
||||||
'type': 'object',
|
'$ref': '#/components/schemas/PaginatedItem',
|
||||||
'item': {
|
|
||||||
'type': 'array',
|
|
||||||
'items': {
|
|
||||||
'$ref': '#/components/schemas/Item'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -486,6 +480,15 @@ class TestOperationIntrospection(TestCase):
|
||||||
}
|
}
|
||||||
components = inspector.get_components(path, method)
|
components = inspector.get_components(path, method)
|
||||||
assert components == {
|
assert components == {
|
||||||
|
'PaginatedItem': {
|
||||||
|
'type': 'object',
|
||||||
|
'item': {
|
||||||
|
'type': 'array',
|
||||||
|
'items': {
|
||||||
|
'$ref': '#/components/schemas/Item'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
'Item': {
|
'Item': {
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
'properties': {
|
'properties': {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user