Skip to content

Commit

Permalink
[#4] safely skip unsupported security definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
virajkanwade committed Aug 16, 2024
1 parent a254f73 commit 6a1e1bc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/fastapi_swagger2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def _map_oauth2_flow(flow_key: str, flow: Dict[str, Any]) -> Dict[str, Any]:
security_definitions = {}
operation_security = []
for security_requirement in flat_dependant.security_requirements:
skip: bool = False
# fastapi.security.* which gets model from fastapi.openapi.models
security_definition = jsonable_encoder(
security_requirement.security_scheme.model,
Expand All @@ -120,6 +121,7 @@ def _map_oauth2_flow(flow_key: str, flow: Dict[str, Any]) -> Dict[str, Any]:
if security_definition.get("scheme", "basic") == "basic":
security_definition = {"type": "basic"}
else:
skip = True
logger.warning(
f"fastapi_swagger2: Unable to handle security_definition: {security_definition}"
)
Expand Down Expand Up @@ -148,12 +150,14 @@ def _map_oauth2_flow(flow_key: str, flow: Dict[str, Any]) -> Dict[str, Any]:
{_security_name: security_requirement.scopes}
)
else:
skip = True
logger.warning(
f"fastapi_swagger2: Unable to handle security_definition: {security_definition}"
)
security_name = security_requirement.security_scheme.scheme_name
security_definitions[security_name] = security_definition
operation_security.append({security_name: security_requirement.scopes})
if not skip:
security_name = security_requirement.security_scheme.scheme_name
security_definitions[security_name] = security_definition
operation_security.append({security_name: security_requirement.scopes})
return security_definitions, operation_security


Expand Down

0 comments on commit 6a1e1bc

Please sign in to comment.