Skip to content

Commit 407e119

Browse files
committed
rename mutable private methods and improve their docstrings
1 parent 7a6a088 commit 407e119

File tree

1 file changed

+42
-25
lines changed

1 file changed

+42
-25
lines changed

rest_framework_json_api/schemas/openapi.py

+42-25
Original file line numberDiff line numberDiff line change
@@ -468,17 +468,17 @@ def get_operation(self, path, method, action=None):
468468
# get request and response code schemas
469469
if method == 'GET':
470470
if is_list_view(path, method, self.view):
471-
self._get_collection_response(operation)
471+
self._add_get_collection_response(operation)
472472
else:
473-
self._get_item_response(operation)
473+
self._add_get_item_response(operation)
474474
elif method == 'POST':
475-
self._post_item_response(operation, path, action)
475+
self._add_post_item_response(operation, path, action)
476476
elif method == 'PATCH':
477-
self._patch_item_response(operation, path, action)
477+
self._add_patch_item_response(operation, path, action)
478478
elif method == 'DELETE':
479479
# should only allow deleting a resource, not a collection
480480
# TODO: implement delete of a relationship in future release.
481-
self._delete_item_response(operation, path, action)
481+
self._add_delete_item_response(operation, path, action)
482482
return operation
483483

484484
def get_operation_id(self, path, method):
@@ -528,18 +528,18 @@ def _get_sort_parameters(self, path, method):
528528
"""
529529
return [{'$ref': '#/components/parameters/sort'}]
530530

531-
def _get_collection_response(self, operation):
531+
def _add_get_collection_response(self, operation):
532532
"""
533-
jsonapi-structured 200 response for GET of a collection
533+
Add GET 200 response for a collection to operation
534534
"""
535535
operation['responses'] = {
536536
'200': self._get_toplevel_200_response(operation, collection=True)
537537
}
538538
self._add_get_4xx_responses(operation)
539539

540-
def _get_item_response(self, operation):
540+
def _add_get_item_response(self, operation):
541541
"""
542-
jsonapi-structured 200 response for GET of an item
542+
add GET 200 response for an item to operation
543543
"""
544544
operation['responses'] = {
545545
'200': self._get_toplevel_200_response(operation, collection=False)
@@ -548,7 +548,7 @@ def _get_item_response(self, operation):
548548

549549
def _get_toplevel_200_response(self, operation, collection=True):
550550
"""
551-
top-level JSONAPI GET 200 response
551+
return top-level JSONAPI GET 200 response
552552
553553
:param collection: True for collections; False for individual items.
554554
@@ -591,9 +591,9 @@ def _get_toplevel_200_response(self, operation, collection=True):
591591
}
592592
}
593593

594-
def _post_item_response(self, operation, path, action):
594+
def _add_post_item_response(self, operation, path, action):
595595
"""
596-
jsonapi-structured response for POST of an item
596+
add response for POST of an item to operation
597597
"""
598598
operation['requestBody'] = self.get_request_body(path, 'POST', action)
599599
operation['responses'] = {
@@ -610,19 +610,19 @@ def _post_item_response(self, operation, path, action):
610610
}
611611
self._add_post_4xx_responses(operation)
612612

613-
def _patch_item_response(self, operation, path, action):
613+
def _add_patch_item_response(self, operation, path, action):
614614
"""
615-
jsonapi-structured response for PATCH of an item
615+
Add PATCH response for an item to operation
616616
"""
617617
operation['requestBody'] = self.get_request_body(path, 'PATCH', action)
618618
operation['responses'] = {
619619
'200': self._get_toplevel_200_response(operation, collection=False)
620620
}
621621
self._add_patch_4xx_responses(operation)
622622

623-
def _delete_item_response(self, operation, path, action):
623+
def _add_delete_item_response(self, operation, path, action):
624624
"""
625-
jsonapi-structured response for DELETE of an item or relationship(s)
625+
add DELETE response for item or relationship(s) to operation
626626
"""
627627
# Only DELETE of relationships has a requestBody
628628
if action in ['rels', 'rel']:
@@ -773,6 +773,9 @@ def map_serializer(self, serializer):
773773
return result
774774

775775
def _add_async_response(self, operation):
776+
"""
777+
Add async response to operation
778+
"""
776779
operation['responses']['202'] = {
777780
'description': 'Accepted for [asynchronous processing]'
778781
'(https://jsonapi.org/recommendations/#asynchronous-processing)',
@@ -784,6 +787,9 @@ def _add_async_response(self, operation):
784787
}
785788

786789
def _failure_response(self, reason):
790+
"""
791+
Return failure response reason as the description
792+
"""
787793
return {
788794
'description': reason,
789795
'content': {
@@ -793,19 +799,26 @@ def _failure_response(self, reason):
793799
}
794800
}
795801

796-
def _generic_failure_responses(self, operation):
802+
def _add_generic_failure_responses(self, operation):
803+
"""
804+
Add generic failure response(s) to operation
805+
"""
797806
for code, reason in [('401', 'not authorized'), ]:
798807
operation['responses'][code] = self._failure_response(reason)
799808

800809
def _add_get_4xx_responses(self, operation):
801-
""" Add generic responses for get """
802-
self._generic_failure_responses(operation)
810+
"""
811+
Add generic 4xx GET responses to operation
812+
"""
813+
self._add_generic_failure_responses(operation)
803814
for code, reason in [('404', 'not found')]:
804815
operation['responses'][code] = self._failure_response(reason)
805816

806817
def _add_post_4xx_responses(self, operation):
807-
""" Add error responses for post """
808-
self._generic_failure_responses(operation)
818+
"""
819+
Add POST 4xx error responses to operation
820+
"""
821+
self._add_generic_failure_responses(operation)
809822
for code, reason in [
810823
('403', '[Forbidden](https://jsonapi.org/format/#crud-creating-responses-403)'),
811824
('404', '[Related resource does not exist]'
@@ -815,8 +828,10 @@ def _add_post_4xx_responses(self, operation):
815828
operation['responses'][code] = self._failure_response(reason)
816829

817830
def _add_patch_4xx_responses(self, operation):
818-
""" Add error responses for patch """
819-
self._generic_failure_responses(operation)
831+
"""
832+
Add PATCH 4xx error responses to operation
833+
"""
834+
self._add_generic_failure_responses(operation)
820835
for code, reason in [
821836
('403', '[Forbidden](https://jsonapi.org/format/#crud-updating-responses-403)'),
822837
('404', '[Related resource does not exist]'
@@ -827,7 +842,9 @@ def _add_patch_4xx_responses(self, operation):
827842
operation['responses'][code] = self._failure_response(reason)
828843

829844
def _add_delete_responses(self, operation):
830-
""" Add generic responses for delete """
845+
"""
846+
Add generic DELETE responses to operation
847+
"""
831848
# the 2xx statuses:
832849
operation['responses'] = {
833850
'200': {
@@ -844,7 +861,7 @@ def _add_delete_responses(self, operation):
844861
'description': '[no content](https://jsonapi.org/format/#crud-deleting-responses-204)',
845862
}
846863
# the 4xx errors:
847-
self._generic_failure_responses(operation)
864+
self._add_generic_failure_responses(operation)
848865
for code, reason in [
849866
('404', '[Resource does not exist]'
850867
'(https://jsonapi.org/format/#crud-deleting-responses-404)'),

0 commit comments

Comments
 (0)