@@ -73,10 +73,11 @@ def get_schema(self, request=None, public=False):
7373 security_schemes_schemas = {}
7474 root_security_requirements = []
7575
76- for auth_class in api_settings .DEFAULT_AUTHENTICATION_CLASSES :
77- req = auth_class .openapi_security_requirement (None , None )
78- if req :
79- root_security_requirements += req
76+ if api_settings .DEFAULT_AUTHENTICATION_CLASSES :
77+ for auth_class in api_settings .DEFAULT_AUTHENTICATION_CLASSES :
78+ req = auth_class .openapi_security_requirement (None , None )
79+ if req :
80+ root_security_requirements += req
8081
8182 # Iterate endpoints generating per method path operations.
8283 paths = {}
@@ -721,6 +722,34 @@ def get_tags(self, path, method):
721722
722723 return [path .split ('/' )[0 ].replace ('_' , '-' )]
723724
725+ def get_security_schemes (self , path , method ):
726+ """
727+ Get components.schemas.securitySchemes required by this path.
728+ returns dict of securitySchemes.
729+ """
730+ schemes = {}
731+ for auth_class in self .view .authentication_classes :
732+ if hasattr (auth_class , 'openapi_security_scheme' ):
733+ schemes .update (auth_class .openapi_security_scheme ())
734+ return schemes
735+
736+ def get_security_requirements (self , path , method ):
737+ """
738+ Get Security Requirement Object list for this operation.
739+ Returns a list of security requirement objects based on the view's authentication classes
740+ unless this view's authentication classes are the same as the root-level defaults.
741+ """
742+ # references the securityScheme names described above in get_security_schemes()
743+ security = []
744+ if self .view .authentication_classes == api_settings .DEFAULT_AUTHENTICATION_CLASSES :
745+ return None
746+ for auth_class in self .view .authentication_classes :
747+ if hasattr (auth_class , 'openapi_security_requirement' ):
748+ req = auth_class .openapi_security_requirement (self .view , method )
749+ if req :
750+ security += req
751+ return security
752+
724753 def _get_path_parameters (self , path , method ):
725754 warnings .warn (
726755 "Method `_get_path_parameters()` has been renamed to `get_path_parameters()`. "
@@ -816,31 +845,3 @@ def _allows_filters(self, path, method):
816845 RemovedInDRF314Warning , stacklevel = 2
817846 )
818847 return self .allows_filters (path , method )
819-
820- def get_security_schemes (self , path , method ):
821- """
822- Get components.schemas.securitySchemes required by this path.
823- returns dict of securitySchemes.
824- """
825- schemes = {}
826- for auth_class in self .view .authentication_classes :
827- if hasattr (auth_class , 'openapi_security_scheme' ):
828- schemes .update (auth_class .openapi_security_scheme ())
829- return schemes
830-
831- def get_security_requirements (self , path , method ):
832- """
833- Get Security Requirement Object list for this operation.
834- Returns a list of security requirement objects based on the view's authentication classes
835- unless this view's authentication classes are the same as the root-level defaults.
836- """
837- # references the securityScheme names described above in get_security_schemes()
838- security = []
839- if self .view .authentication_classes == api_settings .DEFAULT_AUTHENTICATION_CLASSES :
840- return None
841- for auth_class in self .view .authentication_classes :
842- if hasattr (auth_class , 'openapi_security_requirement' ):
843- req = auth_class .openapi_security_requirement (self .view , method )
844- if req :
845- security += req
846- return security
0 commit comments