|
|
|
@ -79,7 +79,8 @@ def get_openapi_security_definitions( |
|
|
|
flat_dependant: Dependant, |
|
|
|
) -> Tuple[Dict[str, Any], List[Dict[str, Any]]]: |
|
|
|
security_definitions = {} |
|
|
|
operation_security = [] |
|
|
|
# Use a dict to merge scopes for same security scheme |
|
|
|
operation_security_dict: Dict[str, List[str]] = {} |
|
|
|
for security_requirement in flat_dependant.security_requirements: |
|
|
|
security_definition = jsonable_encoder( |
|
|
|
security_requirement.security_scheme.model, |
|
|
|
@ -88,7 +89,15 @@ def get_openapi_security_definitions( |
|
|
|
) |
|
|
|
security_name = security_requirement.security_scheme.scheme_name |
|
|
|
security_definitions[security_name] = security_definition |
|
|
|
operation_security.append({security_name: security_requirement.scopes}) |
|
|
|
# Merge scopes for the same security scheme |
|
|
|
if security_name not in operation_security_dict: |
|
|
|
operation_security_dict[security_name] = [] |
|
|
|
for scope in security_requirement.scopes or []: |
|
|
|
if scope not in operation_security_dict[security_name]: |
|
|
|
operation_security_dict[security_name].append(scope) |
|
|
|
operation_security = [ |
|
|
|
{name: scopes} for name, scopes in operation_security_dict.items() |
|
|
|
] |
|
|
|
return security_definitions, operation_security |
|
|
|
|
|
|
|
|
|
|
|
|