Skip to content

Commit 7eb3587

Browse files
authored
fix: Raise Invalid Resource When DisableExecuteApiEndpoint: False And Has No DefinitionBody (#2285)
* Added Python3 Support for Translate CLI * Fixed disable_execute_api_endpoint: false Case * Formatted with Black * Added Fix for HttpApi * Added Unit Tests * Removed Function from Test Template * Updated Executable to be Python 3 Only
1 parent ac27136 commit 7eb3587

7 files changed

+25
-3
lines changed

bin/sam-translate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python
22

33
"""Convert SAM templates to CloudFormation templates.
44
@@ -26,7 +26,9 @@
2626
import sys
2727

2828
import boto3
29+
2930
from docopt import docopt
31+
from functools import reduce
3032

3133
my_path = os.path.dirname(os.path.abspath(__file__))
3234
sys.path.insert(0, my_path + "/..")

samtranslator/model/api/api_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def _add_endpoint_extension(self):
304304
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-api.html#sam-api-definitionbody
305305
For this reason, we always put DisableExecuteApiEndpoint into openapi object irrespective of origin of DefinitionBody.
306306
"""
307-
if self.disable_execute_api_endpoint and not self.definition_body:
307+
if self.disable_execute_api_endpoint is not None and not self.definition_body:
308308
raise InvalidResourceException(
309309
self.logical_id, "DisableExecuteApiEndpoint works only within 'DefinitionBody' property."
310310
)

samtranslator/model/api/http_api_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _add_endpoint_configuration(self):
141141
For this reason, we always put DisableExecuteApiEndpoint into openapi object.
142142
143143
"""
144-
if self.disable_execute_api_endpoint and not self.definition_body:
144+
if self.disable_execute_api_endpoint is not None and not self.definition_body:
145145
raise InvalidResourceException(
146146
self.logical_id, "DisableExecuteApiEndpoint works only within 'DefinitionBody' property."
147147
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Resources:
2+
ApiGatewayApi:
3+
Type: AWS::Serverless::Api
4+
Properties:
5+
StageName: prod
6+
DisableExecuteApiEndpoint: False
7+
DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Resources:
2+
ApiGatewayApi:
3+
Type: AWS::Serverless::HttpApi
4+
Properties:
5+
StageName: prod
6+
DisableExecuteApiEndpoint: False
7+
DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiGatewayApi] is invalid. DisableExecuteApiEndpoint works only within 'DefinitionBody' property."
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiGatewayApi] is invalid. DisableExecuteApiEndpoint works only within 'DefinitionBody' property."
3+
}

0 commit comments

Comments
 (0)