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
11 changes: 10 additions & 1 deletion samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ApiGatewayApiKey,
)
from samtranslator.model.route53 import Route53RecordSetGroup
from samtranslator.model.exceptions import InvalidResourceException, InvalidTemplateException
from samtranslator.model.exceptions import InvalidResourceException, InvalidTemplateException, InvalidDocumentException
from samtranslator.model.s3_utils.uri_parser import parse_s3_uri
from samtranslator.region_configuration import RegionConfiguration
from samtranslator.swagger.swagger import SwaggerEditor
Expand Down Expand Up @@ -980,6 +980,15 @@ def _openapi_postprocess(self, definition_body):
# add schema for the headers in options section for openapi3
if field in ["responses"]:
options_path = definition_body["paths"][path]["options"]
if options_path and not isinstance(options_path.get(field), dict):
raise InvalidDocumentException(
[
InvalidTemplateException(
"Value of responses in options method for path {} must be a "
"dictionary according to Swagger spec.".format(path)
)
]
)
if (
options_path
and options_path.get(field).get("200")
Expand Down
13 changes: 13 additions & 0 deletions tests/translator/input/error_api_invalid_openapi_path.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Resources:
ApiWithInvalidPath:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Cors: "'*'"
OpenApiVersion: 3.0.1
DefinitionBody:
openapi: 3.0.1
info:
title: test invalid paths Api
paths:
/foo:
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Resources:
ApiWithInvalidPath:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Cors: "'*'"
OpenApiVersion: 3.0.1
DefinitionBody:
openapi: 3.0.1
info:
title: test invalid paths Api
paths:
/foo:
options:
responses:
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Resources:
ApiWithInvalidPath:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Cors: "'*'"
OpenApiVersion: 3.0.1
DefinitionBody:
openapi: 3.0.1
info:
title: test invalid paths Api
paths:
/foo:
options:
responses: invalid
3 changes: 3 additions & 0 deletions tests/translator/output/error_api_invalid_openapi_path.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of '/foo' path must be a dictionary according to Swagger spec."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of responses in options method for path /foo must be a dictionary according to Swagger spec."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of responses in options method for path /foo must be a dictionary according to Swagger spec."
}