Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion samtranslator/model/eventsources/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from samtranslator.model import ResourceMacro, PropertyType
from samtranslator.model.eventsources import FUNCTION_EVETSOURCE_METRIC_PREFIX
from samtranslator.model.types import is_type, list_of, dict_of, one_of, is_str
from samtranslator.model.intrinsics import ref, fnGetAtt, fnSub, make_shorthand, make_conditional
from samtranslator.model.intrinsics import is_intrinsic, ref, fnGetAtt, fnSub, make_shorthand, make_conditional
from samtranslator.model.tags.resource_tagging import get_tag_list

from samtranslator.model.s3 import S3Bucket
Expand Down Expand Up @@ -767,6 +767,14 @@ def _add_swagger_integration(self, api, function, intrinsics_resolver):
model=method_model, method=self.Method, path=self.Path
),
)
if not is_intrinsic(api_models) and not isinstance(api_models, dict):
raise InvalidEventException(
self.relative_id,
"Unable to set RequestModel [{model}] on API method [{method}] for path [{path}] "
"because the related API Models defined is of invalid type.".format(
model=method_model, method=self.Method, path=self.Path
),
)
if not isinstance(method_model, str):
raise InvalidEventException(
self.relative_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Models:
- Invalid_value

MyFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs12.x
InlineCode: |
exports.handler = async (event, context, callback) => {
return {
statusCode: 200,
body: 'Success'
}
}
Events:
None:
Type: Api
Properties:
RequestModel:
Model: User
Required: true
RestApiId:
Ref: MyApi
Method: get
Path: /none

Outputs:
ApiUrl:
Description: "API endpoint URL for Prod environment"
Value:
Fn::Sub: 'https://${MyApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}/Prod/'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MyApi] is invalid. Type of property 'Models' is invalid. Resource with id [MyFunction] is invalid. Event with id [None] is invalid. Unable to set RequestModel [User] on API method [get] for path [/none] because the related API Models defined is of invalid type."
}