Skip to content

Commit

Permalink
chore: more schema tests for invalid Type (#2677)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffa authored Nov 29, 2022
1 parent 8bb5437 commit 5e3741c
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 3 deletions.
4 changes: 2 additions & 2 deletions samtranslator/schema/any_cfn_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

constr = pydantic.constr

# Match anything not containing Serverless
# Anything goes if has string Type but is not AWS::Serverless::*
class Resource(LenientBaseModel):
Type: constr(regex=r"^((?!::Serverless::).)*$") # type: ignore
Type: constr(regex=r"^(?!AWS::Serverless::).+$") # type: ignore
2 changes: 1 addition & 1 deletion samtranslator/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5577,7 +5577,7 @@
"properties": {
"Type": {
"title": "Type",
"pattern": "^((?!::Serverless::).)*$",
"pattern": "^(?!AWS::Serverless::).+$",
"type": "string"
}
},
Expand Down
19 changes: 19 additions & 0 deletions tests/translator/input/schema_validation_3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Resources:
UnknownType1:
Type: AWS::Foo::Bar

UnknownType2:
Type: AWS::Foo::Bar
Properties:
Turtle: Train

UnknownType3:
Type: Foo::Bar::Egg
Properties:
Turtle: Train

UnknownType4:
Type: Foo::Bar::Egg

UnknownType5:
Type: Foo::Serverless::Egg
25 changes: 25 additions & 0 deletions tests/translator/output/aws-cn/schema_validation_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"Resources": {
"UnknownType1": {
"Type": "AWS::Foo::Bar"
},
"UnknownType2": {
"Properties": {
"Turtle": "Train"
},
"Type": "AWS::Foo::Bar"
},
"UnknownType3": {
"Properties": {
"Turtle": "Train"
},
"Type": "Foo::Bar::Egg"
},
"UnknownType4": {
"Type": "Foo::Bar::Egg"
},
"UnknownType5": {
"Type": "Foo::Serverless::Egg"
}
}
}
25 changes: 25 additions & 0 deletions tests/translator/output/aws-us-gov/schema_validation_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"Resources": {
"UnknownType1": {
"Type": "AWS::Foo::Bar"
},
"UnknownType2": {
"Properties": {
"Turtle": "Train"
},
"Type": "AWS::Foo::Bar"
},
"UnknownType3": {
"Properties": {
"Turtle": "Train"
},
"Type": "Foo::Bar::Egg"
},
"UnknownType4": {
"Type": "Foo::Bar::Egg"
},
"UnknownType5": {
"Type": "Foo::Serverless::Egg"
}
}
}
25 changes: 25 additions & 0 deletions tests/translator/output/schema_validation_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"Resources": {
"UnknownType1": {
"Type": "AWS::Foo::Bar"
},
"UnknownType2": {
"Properties": {
"Turtle": "Train"
},
"Type": "AWS::Foo::Bar"
},
"UnknownType3": {
"Properties": {
"Turtle": "Train"
},
"Type": "Foo::Bar::Egg"
},
"UnknownType4": {
"Type": "Foo::Bar::Egg"
},
"UnknownType5": {
"Type": "Foo::Serverless::Egg"
}
}
}

0 comments on commit 5e3741c

Please sign in to comment.