Skip to content

Commit 8d3efe8

Browse files
authored
chore: more typed schema pass-throughs (#3072)
1 parent f55b9a5 commit 8d3efe8

File tree

5 files changed

+312
-131
lines changed

5 files changed

+312
-131
lines changed

samtranslator/internal/schema_source/aws_serverless_application.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
ResourceAttributes,
1111
SamIntrinsicable,
1212
get_prop,
13+
passthrough_prop,
1314
)
1415

16+
PROPERTIES_STEM = "sam-resource-application"
17+
1518
location = get_prop("sam-property-application-applicationlocationobject")
16-
properties = get_prop("sam-resource-application")
19+
properties = get_prop(PROPERTIES_STEM)
1720

1821

1922
class Location(BaseModel):
@@ -23,10 +26,22 @@ class Location(BaseModel):
2326

2427
class Properties(BaseModel):
2528
Location: Union[str, Location] = properties("Location")
26-
NotificationARNs: Optional[PassThroughProp] = properties("NotificationARNs")
27-
Parameters: Optional[PassThroughProp] = properties("Parameters")
29+
NotificationARNs: Optional[PassThroughProp] = passthrough_prop(
30+
PROPERTIES_STEM,
31+
"NotificationARNs",
32+
["AWS::CloudFormation::Stack", "Properties", "NotificationARNs"],
33+
)
34+
Parameters: Optional[PassThroughProp] = passthrough_prop(
35+
PROPERTIES_STEM,
36+
"Parameters",
37+
["AWS::CloudFormation::Stack", "Properties", "Parameters"],
38+
)
2839
Tags: Optional[Dict[str, Any]] = properties("Tags")
29-
TimeoutInMinutes: Optional[PassThroughProp] = properties("TimeoutInMinutes")
40+
TimeoutInMinutes: Optional[PassThroughProp] = passthrough_prop(
41+
PROPERTIES_STEM,
42+
"TimeoutInMinutes",
43+
["AWS::CloudFormation::Stack", "Properties", "TimeoutInMinutes"],
44+
)
3045

3146

3247
class Resource(ResourceAttributes):

samtranslator/internal/schema_source/aws_serverless_layerversion.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,57 @@
1010
ResourceAttributes,
1111
SamIntrinsicable,
1212
get_prop,
13+
passthrough_prop,
1314
)
1415

15-
contenturi = get_prop("sam-property-layerversion-layercontent")
16-
properties = get_prop("sam-resource-layerversion")
16+
PROPERTIES_STEM = "sam-resource-layerversion"
17+
CONTENT_URI_STEM = "sam-property-layerversion-layercontent"
18+
19+
contenturi = get_prop(CONTENT_URI_STEM)
20+
properties = get_prop(PROPERTIES_STEM)
1721

1822

1923
class ContentUri(BaseModel):
20-
Bucket: PassThroughProp = contenturi("Bucket")
21-
Key: PassThroughProp = contenturi("Key")
22-
Version: Optional[PassThroughProp] = contenturi("Version")
24+
Bucket: PassThroughProp = passthrough_prop(
25+
CONTENT_URI_STEM,
26+
"Bucket",
27+
["AWS::Lambda::LayerVersion.Content", "S3Bucket"],
28+
)
29+
Key: PassThroughProp = passthrough_prop(
30+
CONTENT_URI_STEM,
31+
"Key",
32+
["AWS::Lambda::LayerVersion.Content", "S3Key"],
33+
)
34+
Version: Optional[PassThroughProp] = passthrough_prop(
35+
CONTENT_URI_STEM,
36+
"Version",
37+
["AWS::Lambda::LayerVersion.Content", "S3ObjectVersion"],
38+
)
2339

2440

2541
class Properties(BaseModel):
26-
CompatibleArchitectures: Optional[PassThroughProp] = properties("CompatibleArchitectures")
27-
CompatibleRuntimes: Optional[PassThroughProp] = properties("CompatibleRuntimes")
42+
CompatibleArchitectures: Optional[PassThroughProp] = passthrough_prop(
43+
PROPERTIES_STEM,
44+
"CompatibleArchitectures",
45+
["AWS::Lambda::LayerVersion", "Properties", "CompatibleArchitectures"],
46+
)
47+
CompatibleRuntimes: Optional[PassThroughProp] = passthrough_prop(
48+
PROPERTIES_STEM,
49+
"CompatibleRuntimes",
50+
["AWS::Lambda::LayerVersion", "Properties", "CompatibleRuntimes"],
51+
)
2852
ContentUri: Union[str, ContentUri] = properties("ContentUri")
29-
Description: Optional[PassThroughProp] = properties("Description")
53+
Description: Optional[PassThroughProp] = passthrough_prop(
54+
PROPERTIES_STEM,
55+
"Description",
56+
["AWS::Lambda::LayerVersion", "Properties", "Description"],
57+
)
3058
LayerName: Optional[PassThroughProp] = properties("LayerName")
31-
LicenseInfo: Optional[PassThroughProp] = properties("LicenseInfo")
59+
LicenseInfo: Optional[PassThroughProp] = passthrough_prop(
60+
PROPERTIES_STEM,
61+
"LicenseInfo",
62+
["AWS::Lambda::LayerVersion", "Properties", "LicenseInfo"],
63+
)
3264
RetentionPolicy: Optional[SamIntrinsicable[str]] = properties("RetentionPolicy")
3365

3466

samtranslator/internal/schema_source/aws_serverless_simpletable.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,63 @@
55
from typing_extensions import Literal
66

77
from samtranslator.internal.schema_source.aws_serverless_connector import EmbeddedConnector
8-
from samtranslator.internal.schema_source.common import BaseModel, PassThroughProp, ResourceAttributes, get_prop
8+
from samtranslator.internal.schema_source.common import (
9+
BaseModel,
10+
PassThroughProp,
11+
ResourceAttributes,
12+
get_prop,
13+
passthrough_prop,
14+
)
915

10-
primarykey = get_prop("sam-property-simpletable-primarykeyobject")
11-
properties = get_prop("sam-resource-simpletable")
16+
PROPERTIES_STEM = "sam-resource-simpletable"
17+
PRIMARY_KEY_STEM = "sam-property-simpletable-primarykeyobject"
18+
19+
primarykey = get_prop(PRIMARY_KEY_STEM)
20+
properties = get_prop(PROPERTIES_STEM)
1221

1322

1423
class PrimaryKey(BaseModel):
15-
Name: PassThroughProp = primarykey("Name")
16-
Type: PassThroughProp = primarykey("Type")
24+
Name: PassThroughProp = passthrough_prop(
25+
PRIMARY_KEY_STEM,
26+
"Name",
27+
["AWS::DynamoDB::Table.AttributeDefinition", "AttributeName"],
28+
)
29+
Type: PassThroughProp = passthrough_prop(
30+
PRIMARY_KEY_STEM,
31+
"Type",
32+
["AWS::DynamoDB::Table.AttributeDefinition", "AttributeType"],
33+
)
1734

1835

1936
SSESpecification = Optional[PassThroughProp]
2037

2138

2239
class Properties(BaseModel):
2340
PrimaryKey: Optional[PrimaryKey] = properties("PrimaryKey")
24-
ProvisionedThroughput: Optional[PassThroughProp] = properties("ProvisionedThroughput")
25-
SSESpecification: Optional[SSESpecification] = properties("SSESpecification")
26-
TableName: Optional[PassThroughProp] = properties("TableName")
41+
ProvisionedThroughput: Optional[PassThroughProp] = passthrough_prop(
42+
PROPERTIES_STEM,
43+
"ProvisionedThroughput",
44+
["AWS::DynamoDB::Table", "Properties", "ProvisionedThroughput"],
45+
)
46+
SSESpecification: Optional[SSESpecification] = passthrough_prop(
47+
PROPERTIES_STEM,
48+
"SSESpecification",
49+
["AWS::DynamoDB::Table", "Properties", "SSESpecification"],
50+
)
51+
TableName: Optional[PassThroughProp] = passthrough_prop(
52+
PROPERTIES_STEM,
53+
"TableName",
54+
["AWS::DynamoDB::Table", "Properties", "TableName"],
55+
)
2756
Tags: Optional[Dict[str, Any]] = properties("Tags")
2857

2958

3059
class Globals(BaseModel):
31-
SSESpecification: Optional[SSESpecification] = properties("SSESpecification")
60+
SSESpecification: Optional[SSESpecification] = passthrough_prop(
61+
PROPERTIES_STEM,
62+
"SSESpecification",
63+
["AWS::DynamoDB::Table", "Properties", "SSESpecification"],
64+
)
3265

3366

3467
class Resource(ResourceAttributes):

0 commit comments

Comments
 (0)