in samtranslator/utils/py27hash_fix.py [0:0]
def _template_has_api_resource(template): # type: ignore[no-untyped-def]
"""
Returns true if the template contains at lease one explicit or implicit AWS::Serverless::Api resource
"""
for resource_dict in template.get("Resources", {}).values():
if isinstance(resource_dict, dict) and resource_dict.get("Type") == "AWS::Serverless::Api":
# i.e. an excplicit API is defined in the template
return True
if isinstance(resource_dict, dict) and resource_dict.get("Type") in [
"AWS::Serverless::Function",
"AWS::Serverless::StateMachine",
]:
events = resource_dict.get("Properties", {}).get("Events", {})
if isinstance(events, dict):
for event_dict in events.values():
# An explicit or implicit API is referenced
if event_dict and isinstance(event_dict, dict) and event_dict.get("Type") == "Api":
return True
return False