Skip to content

Commit 8066335

Browse files
authored
fix: Raise correct exception when Domain BasePath contains non-str items (#2756)
1 parent 19fd6d8 commit 8066335

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

samtranslator/model/api/api_generator.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
ApiGatewayApiKey,
1818
)
1919
from samtranslator.model.route53 import Route53RecordSetGroup
20-
from samtranslator.model.exceptions import InvalidDocumentException, InvalidResourceException, InvalidTemplateException
20+
from samtranslator.model.exceptions import (
21+
ExpectedType,
22+
InvalidDocumentException,
23+
InvalidResourceException,
24+
InvalidTemplateException,
25+
)
2126
from samtranslator.model.s3_utils.uri_parser import parse_s3_uri
2227
from samtranslator.region_configuration import RegionConfiguration
2328
from samtranslator.schema.common import PassThrough
@@ -524,6 +529,7 @@ def _construct_api_domain(
524529
basepath_mapping.Stage = ref(rest_api.logical_id + ".Stage")
525530
basepath_resource_list.extend([basepath_mapping])
526531
else:
532+
sam_expect(basepaths, self.logical_id, "Domain.BasePath").to_be_a_list_of(ExpectedType.STRING)
527533
for basepath in basepaths:
528534
# Remove possible leading and trailing '/' because a base path may only
529535
# contain letters, numbers, and one of "$-_.+!*'()"

tests/translator/input/error_api_with_custom_domains_invalid.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,14 @@ Resources:
7777
OpenApiVersion: 3.0.1
7878
StageName: Prod
7979
Domain: !Ref MyDomainName # this should be a map after solution
80+
81+
MyApiWithIncorrectBasePathItemType:
82+
Type: AWS::Serverless::Api
83+
Properties:
84+
OpenApiVersion: 3.0.1
85+
StageName: Prod
86+
Domain:
87+
DomainName: api-example.com
88+
CertificateArn: my-api-cert-arn
89+
BasePath:
90+
- 3 # this should not be a number
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 4. Resource with id [MyApi] is invalid. EndpointConfiguration for Custom Domains must be one of ['EDGE', 'REGIONAL', 'PRIVATE']. Resource with id [MyApiInvalidDomainType] is invalid. Property 'Domain' should be a map. Resource with id [MyApiMissingCertificateArn] is invalid. Property 'Domain.CertificateArn' is required. Resource with id [ServerlessRestApi] is invalid. Property 'Domain.DomainName' is required."
2+
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 5. Resource with id [MyApi] is invalid. EndpointConfiguration for Custom Domains must be one of ['EDGE', 'REGIONAL', 'PRIVATE']. Resource with id [MyApiInvalidDomainType] is invalid. Property 'Domain' should be a map. Resource with id [MyApiMissingCertificateArn] is invalid. Property 'Domain.CertificateArn' is required. Resource with id [MyApiWithIncorrectBasePathItemType] is invalid. Property 'Domain.BasePath[0]' should be a string. Resource with id [ServerlessRestApi] is invalid. Property 'Domain.DomainName' is required."
33
}

0 commit comments

Comments
 (0)