Skip to content
Merged
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
boto3>=1.19.5,==1.*
jsonschema~=3.2
jsonschema<5,>=3.2 # TODO: evaluate risk of removing jsonschema 3.x support
87 changes: 87 additions & 0 deletions tests/validator/input/api/error_definitionuri_jsonschema3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
Transform: AWS::Serverless-2016-10-31
Resources:
# DefinitionUri is empty
ApiDefinitionUriEmpty:
Type: AWS::Serverless::Api
Properties:
DefinitionUri:
StageName: Stage name

# DefinitionUri is not a string or an object
ApiDefinitionUriNotStringOrObject:
Type: AWS::Serverless::Api
Properties:
DefinitionUri: 3
StageName: Stage name

# DefinitionUri Bucket missing
ApiDefinitionUriBucketMissing:
Type: AWS::Serverless::Api
Properties:
DefinitionUri:
Key: mykey
StageName: Stage name

# DefinitionUri Bucket empty
ApiDefinitionUriBucketEmpty:
Type: AWS::Serverless::Api
Properties:
DefinitionUri:
Bucket:
Key: mykey
StageName: Stage name

# DefinitionUri Bucket not string
ApiDefinitionUriBucketNotString:
Type: AWS::Serverless::Api
Properties:
DefinitionUri:
Bucket: 3
Key: mykey
StageName: Stage name

# DefinitionUri Bucket not string
ApiDefinitionUriBucketNotIntrinsic:
Type: AWS::Serverless::Api
Properties:
DefinitionUri:
Bucket:
Not: Intrinsic
Key: mykey
StageName: Stage name

# DefinitionUri Key missing
ApiDefinitionUriKeyMissing:
Type: AWS::Serverless::Api
Properties:
DefinitionUri:
Bucket: mybucket
StageName: Stage name

# DefinitionUri Key empty
ApiDefinitionUriKeyEmpty:
Type: AWS::Serverless::Api
Properties:
DefinitionUri:
Bucket: mybucket
Key:
StageName: Stage name

# DefinitionUri Key not string
ApiDefinitionUriKeyNotString:
Type: AWS::Serverless::Api
Properties:
DefinitionUri:
Bucket: mybucket
Key: 3
StageName: Stage name

# DefinitionUri Key not intrinsic
ApiDefinitionUriKeyNotStringIntrinsic:
Type: AWS::Serverless::Api
Properties:
DefinitionUri:
Bucket: mybucket
Key:
Not: Intrinsic
StageName: Stage name
4 changes: 3 additions & 1 deletion tests/validator/output/api/error_definitionuri.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"[Resources.ApiDefinitionUriBucketMissing.Properties.DefinitionUri] 'Bucket' is a required property",
"[Resources.ApiDefinitionUriBucketNotIntrinsic.Properties.DefinitionUri.Bucket] {'Not': 'Intrinsic'} is not of type 'string', 'intrinsic'",
"[Resources.ApiDefinitionUriBucketNotString.Properties.DefinitionUri.Bucket] 3 is not of type 'string', 'intrinsic'",
"[Resources.ApiDefinitionUriEmpty.Properties.DefinitionUri] Must not be empty",
"[Resources.ApiDefinitionUriKeyEmpty.Properties.DefinitionUri.Key] Must not be empty",
"[Resources.ApiDefinitionUriKeyMissing.Properties.DefinitionUri] 'Key' is a required property",
"[Resources.ApiDefinitionUriKeyNotString.Properties.DefinitionUri.Key] 3 is not of type 'string', 'intrinsic'",
"[Resources.ApiDefinitionUriKeyNotStringIntrinsic.Properties.DefinitionUri.Key] {'Not': 'Intrinsic'} is not of type 'string', 'intrinsic'"
"[Resources.ApiDefinitionUriKeyNotStringIntrinsic.Properties.DefinitionUri.Key] {'Not': 'Intrinsic'} is not of type 'string', 'intrinsic'",
"[Resources.ApiDefinitionUriNotStringOrObject.Properties.DefinitionUri] 3 is not of type 'string', 'object'"
]
10 changes: 10 additions & 0 deletions tests/validator/output/api/error_definitionuri_jsonschema3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
"[Resources.ApiDefinitionUriBucketEmpty.Properties.DefinitionUri.Bucket] Must not be empty",
"[Resources.ApiDefinitionUriBucketMissing.Properties.DefinitionUri] 'Bucket' is a required property",
"[Resources.ApiDefinitionUriBucketNotIntrinsic.Properties.DefinitionUri.Bucket] {'Not': 'Intrinsic'} is not of type 'string', 'intrinsic'",
"[Resources.ApiDefinitionUriBucketNotString.Properties.DefinitionUri.Bucket] 3 is not of type 'string', 'intrinsic'",
"[Resources.ApiDefinitionUriKeyEmpty.Properties.DefinitionUri.Key] Must not be empty",
"[Resources.ApiDefinitionUriKeyMissing.Properties.DefinitionUri] 'Key' is a required property",
"[Resources.ApiDefinitionUriKeyNotString.Properties.DefinitionUri.Key] 3 is not of type 'string', 'intrinsic'",
"[Resources.ApiDefinitionUriKeyNotStringIntrinsic.Properties.DefinitionUri.Key] {'Not': 'Intrinsic'} is not of type 'string', 'intrinsic'"
]
9 changes: 8 additions & 1 deletion tests/validator/test_validator_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import jsonschema
import os.path
from parameterized import parameterized
import pytest
Expand All @@ -12,6 +13,12 @@


class TestValidatorApi(TestValidatorBase):

# jsonschema 4.* is more restrictive than 3, so we need a separate check
# See https://github.com/aws/serverless-application-model/issues/2426
jsonschemaMajorVersion = int(jsonschema.__version__.split(".")[0])
_error_definitionuri = "error_definitionuri" if jsonschemaMajorVersion > 3 else "error_definitionuri_jsonschema3"

@parameterized.expand(
[
"error_accesslogsetting",
Expand All @@ -27,7 +34,7 @@ class TestValidatorApi(TestValidatorBase):
"error_canarysetting",
"error_cors",
"error_definitionbody",
"error_definitionuri",
_error_definitionuri,
"error_description",
"error_domain",
"error_endpointconfiguration",
Expand Down