File tree 2 files changed +51
-1
lines changed
2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -525,7 +525,7 @@ def map_serializer(self, serializer):
525
525
if isinstance (field , serializers .HiddenField ):
526
526
continue
527
527
528
- if field .required :
528
+ if field .required and not serializer . partial :
529
529
required .append (self .get_field_name (field ))
530
530
531
531
schema = self .map_field (field )
Original file line number Diff line number Diff line change @@ -403,6 +403,56 @@ class View(generics.GenericAPIView):
403
403
assert list (schema ['properties' ]['nested' ]['properties' ].keys ()) == ['number' ]
404
404
assert schema ['properties' ]['nested' ]['required' ] == ['number' ]
405
405
406
+ def test_response_body_partial_serializer (self ):
407
+ path = '/'
408
+ method = 'GET'
409
+
410
+ class ItemSerializer (serializers .Serializer ):
411
+ text = serializers .CharField ()
412
+
413
+ def __init__ (self , * args , ** kwargs ):
414
+ super ().__init__ (* args , ** kwargs )
415
+ self .partial = True
416
+
417
+ class View (generics .GenericAPIView ):
418
+ serializer_class = ItemSerializer
419
+
420
+ view = create_view (
421
+ View ,
422
+ method ,
423
+ create_request (path ),
424
+ )
425
+ inspector = AutoSchema ()
426
+ inspector .view = view
427
+
428
+ responses = inspector .get_responses (path , method )
429
+ assert responses == {
430
+ '200' : {
431
+ 'description' : '' ,
432
+ 'content' : {
433
+ 'application/json' : {
434
+ 'schema' : {
435
+ 'type' : 'array' ,
436
+ 'items' : {
437
+ '$ref' : '#/components/schemas/Item'
438
+ },
439
+ },
440
+ },
441
+ },
442
+ },
443
+ }
444
+ components = inspector .get_components (path , method )
445
+ assert components == {
446
+ 'Item' : {
447
+ 'type' : 'object' ,
448
+ 'properties' : {
449
+ 'text' : {
450
+ 'type' : 'string' ,
451
+ },
452
+ },
453
+ }
454
+ }
455
+
406
456
def test_list_response_body_generation (self ):
407
457
"""Test that an array schema is returned for list views."""
408
458
path = '/'
You can’t perform that action at this time.
0 commit comments