@@ -468,17 +468,17 @@ def get_operation(self, path, method, action=None):
468
468
# get request and response code schemas
469
469
if method == 'GET' :
470
470
if is_list_view (path , method , self .view ):
471
- self ._get_collection_response (operation )
471
+ self ._add_get_collection_response (operation )
472
472
else :
473
- self ._get_item_response (operation )
473
+ self ._add_get_item_response (operation )
474
474
elif method == 'POST' :
475
- self ._post_item_response (operation , path , action )
475
+ self ._add_post_item_response (operation , path , action )
476
476
elif method == 'PATCH' :
477
- self ._patch_item_response (operation , path , action )
477
+ self ._add_patch_item_response (operation , path , action )
478
478
elif method == 'DELETE' :
479
479
# should only allow deleting a resource, not a collection
480
480
# 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 )
482
482
return operation
483
483
484
484
def get_operation_id (self , path , method ):
@@ -528,18 +528,18 @@ def _get_sort_parameters(self, path, method):
528
528
"""
529
529
return [{'$ref' : '#/components/parameters/sort' }]
530
530
531
- def _get_collection_response (self , operation ):
531
+ def _add_get_collection_response (self , operation ):
532
532
"""
533
- jsonapi-structured 200 response for GET of a collection
533
+ Add GET 200 response for a collection to operation
534
534
"""
535
535
operation ['responses' ] = {
536
536
'200' : self ._get_toplevel_200_response (operation , collection = True )
537
537
}
538
538
self ._add_get_4xx_responses (operation )
539
539
540
- def _get_item_response (self , operation ):
540
+ def _add_get_item_response (self , operation ):
541
541
"""
542
- jsonapi-structured 200 response for GET of an item
542
+ add GET 200 response for an item to operation
543
543
"""
544
544
operation ['responses' ] = {
545
545
'200' : self ._get_toplevel_200_response (operation , collection = False )
@@ -548,7 +548,7 @@ def _get_item_response(self, operation):
548
548
549
549
def _get_toplevel_200_response (self , operation , collection = True ):
550
550
"""
551
- top-level JSONAPI GET 200 response
551
+ return top-level JSONAPI GET 200 response
552
552
553
553
:param collection: True for collections; False for individual items.
554
554
@@ -591,9 +591,9 @@ def _get_toplevel_200_response(self, operation, collection=True):
591
591
}
592
592
}
593
593
594
- def _post_item_response (self , operation , path , action ):
594
+ def _add_post_item_response (self , operation , path , action ):
595
595
"""
596
- jsonapi-structured response for POST of an item
596
+ add response for POST of an item to operation
597
597
"""
598
598
operation ['requestBody' ] = self .get_request_body (path , 'POST' , action )
599
599
operation ['responses' ] = {
@@ -610,19 +610,19 @@ def _post_item_response(self, operation, path, action):
610
610
}
611
611
self ._add_post_4xx_responses (operation )
612
612
613
- def _patch_item_response (self , operation , path , action ):
613
+ def _add_patch_item_response (self , operation , path , action ):
614
614
"""
615
- jsonapi-structured response for PATCH of an item
615
+ Add PATCH response for an item to operation
616
616
"""
617
617
operation ['requestBody' ] = self .get_request_body (path , 'PATCH' , action )
618
618
operation ['responses' ] = {
619
619
'200' : self ._get_toplevel_200_response (operation , collection = False )
620
620
}
621
621
self ._add_patch_4xx_responses (operation )
622
622
623
- def _delete_item_response (self , operation , path , action ):
623
+ def _add_delete_item_response (self , operation , path , action ):
624
624
"""
625
- jsonapi-structured response for DELETE of an item or relationship(s)
625
+ add DELETE response for item or relationship(s) to operation
626
626
"""
627
627
# Only DELETE of relationships has a requestBody
628
628
if action in ['rels' , 'rel' ]:
@@ -773,6 +773,9 @@ def map_serializer(self, serializer):
773
773
return result
774
774
775
775
def _add_async_response (self , operation ):
776
+ """
777
+ Add async response to operation
778
+ """
776
779
operation ['responses' ]['202' ] = {
777
780
'description' : 'Accepted for [asynchronous processing]'
778
781
'(https://jsonapi.org/recommendations/#asynchronous-processing)' ,
@@ -784,6 +787,9 @@ def _add_async_response(self, operation):
784
787
}
785
788
786
789
def _failure_response (self , reason ):
790
+ """
791
+ Return failure response reason as the description
792
+ """
787
793
return {
788
794
'description' : reason ,
789
795
'content' : {
@@ -793,19 +799,26 @@ def _failure_response(self, reason):
793
799
}
794
800
}
795
801
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
+ """
797
806
for code , reason in [('401' , 'not authorized' ), ]:
798
807
operation ['responses' ][code ] = self ._failure_response (reason )
799
808
800
809
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 )
803
814
for code , reason in [('404' , 'not found' )]:
804
815
operation ['responses' ][code ] = self ._failure_response (reason )
805
816
806
817
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 )
809
822
for code , reason in [
810
823
('403' , '[Forbidden](https://jsonapi.org/format/#crud-creating-responses-403)' ),
811
824
('404' , '[Related resource does not exist]'
@@ -815,8 +828,10 @@ def _add_post_4xx_responses(self, operation):
815
828
operation ['responses' ][code ] = self ._failure_response (reason )
816
829
817
830
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 )
820
835
for code , reason in [
821
836
('403' , '[Forbidden](https://jsonapi.org/format/#crud-updating-responses-403)' ),
822
837
('404' , '[Related resource does not exist]'
@@ -827,7 +842,9 @@ def _add_patch_4xx_responses(self, operation):
827
842
operation ['responses' ][code ] = self ._failure_response (reason )
828
843
829
844
def _add_delete_responses (self , operation ):
830
- """ Add generic responses for delete """
845
+ """
846
+ Add generic DELETE responses to operation
847
+ """
831
848
# the 2xx statuses:
832
849
operation ['responses' ] = {
833
850
'200' : {
@@ -844,7 +861,7 @@ def _add_delete_responses(self, operation):
844
861
'description' : '[no content](https://jsonapi.org/format/#crud-deleting-responses-204)' ,
845
862
}
846
863
# the 4xx errors:
847
- self ._generic_failure_responses (operation )
864
+ self ._add_generic_failure_responses (operation )
848
865
for code , reason in [
849
866
('404' , '[Resource does not exist]'
850
867
'(https://jsonapi.org/format/#crud-deleting-responses-404)' ),
0 commit comments