@@ -427,9 +427,9 @@ def get_operation(self, path, method):
427
427
# get request and response code schemas
428
428
if method == "GET" :
429
429
if is_list_view (path , method , self .view ):
430
- self ._add_get_collection_response (operation )
430
+ self ._add_get_collection_response (operation , path )
431
431
else :
432
- self ._add_get_item_response (operation )
432
+ self ._add_get_item_response (operation , path )
433
433
elif method == "POST" :
434
434
self ._add_post_item_response (operation , path )
435
435
elif method == "PATCH" :
@@ -487,25 +487,29 @@ def _get_sort_parameters(self, path, method):
487
487
"""
488
488
return [{"$ref" : "#/components/parameters/sort" }]
489
489
490
- def _add_get_collection_response (self , operation ):
490
+ def _add_get_collection_response (self , operation , path ):
491
491
"""
492
492
Add GET 200 response for a collection to operation
493
493
"""
494
494
operation ["responses" ] = {
495
- "200" : self ._get_toplevel_200_response (operation , collection = True )
495
+ "200" : self ._get_toplevel_200_response (
496
+ operation , path , "GET" , collection = True
497
+ )
496
498
}
497
499
self ._add_get_4xx_responses (operation )
498
500
499
- def _add_get_item_response (self , operation ):
501
+ def _add_get_item_response (self , operation , path ):
500
502
"""
501
503
add GET 200 response for an item to operation
502
504
"""
503
505
operation ["responses" ] = {
504
- "200" : self ._get_toplevel_200_response (operation , collection = False )
506
+ "200" : self ._get_toplevel_200_response (
507
+ operation , path , "GET" , collection = False
508
+ )
505
509
}
506
510
self ._add_get_4xx_responses (operation )
507
511
508
- def _get_toplevel_200_response (self , operation , collection = True ):
512
+ def _get_toplevel_200_response (self , operation , path , method , collection = True ):
509
513
"""
510
514
return top-level JSON:API GET 200 response
511
515
@@ -516,10 +520,12 @@ def _get_toplevel_200_response(self, operation, collection=True):
516
520
if collection :
517
521
data = {
518
522
"type" : "array" ,
519
- "items" : get_reference (self , self .view .get_serializer ()),
523
+ "items" : get_reference (
524
+ self , self .get_response_serializer (path , method )
525
+ ),
520
526
}
521
527
else :
522
- data = get_reference (self , self .view . get_serializer ( ))
528
+ data = get_reference (self , self .get_response_serializer ( path , method ))
523
529
524
530
return {
525
531
"description" : operation ["operationId" ],
@@ -555,7 +561,9 @@ def _add_post_item_response(self, operation, path):
555
561
"""
556
562
operation ["requestBody" ] = self .get_request_body (path , "POST" )
557
563
operation ["responses" ] = {
558
- "201" : self ._get_toplevel_200_response (operation , collection = False )
564
+ "201" : self ._get_toplevel_200_response (
565
+ operation , path , "POST" , collection = False
566
+ )
559
567
}
560
568
operation ["responses" ]["201" ]["description" ] = (
561
569
"[Created](https://jsonapi.org/format/#crud-creating-responses-201). "
@@ -574,7 +582,9 @@ def _add_patch_item_response(self, operation, path):
574
582
"""
575
583
operation ["requestBody" ] = self .get_request_body (path , "PATCH" )
576
584
operation ["responses" ] = {
577
- "200" : self ._get_toplevel_200_response (operation , collection = False )
585
+ "200" : self ._get_toplevel_200_response (
586
+ operation , path , "PATCH" , collection = False
587
+ )
578
588
}
579
589
self ._add_patch_4xx_responses (operation )
580
590
@@ -591,7 +601,7 @@ def get_request_body(self, path, method):
591
601
"""
592
602
A request body is required by JSON:API for POST, PATCH, and DELETE methods.
593
603
"""
594
- serializer = self .get_serializer (path , method )
604
+ serializer = self .get_request_serializer (path , method )
595
605
if not isinstance (serializer , (serializers .BaseSerializer ,)):
596
606
return {}
597
607
is_relationship = isinstance (self .view , views .RelationshipView )
0 commit comments