-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Description:
While SAM supports adding CORS definitions to OpenAPI templates by utilizing the Cors
property for AWS::Serverless::Api
, it does only support it for OpenAPI 2.0. For OpenAPI 3.0 the CORS stuff gets added, but is incompatible with OpenAPI 3.0 causing the deployment to fail. That's because the structure of "operation objects" changed between OpenAPI 2.0 and OpenAPI 3.0 and SAM isn't aware of that.
Steps to reproduce the issue:
- Create
AWS::Serverless::Api
resource with theCors
property set and a definition body consisting of an OpenAPI 3 definition like the following one:
api:
Type: 'AWS::Serverless::Api'
Properties:
Cors: www.example.tld
StageName: v1
DefinitionBody:
openapi: 3.0.1
info:
version: 0.0.1
title: example
paths:
/mypath:
get:
responses:
'200':
description: Default response
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
uri:
Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${someFunction.Arn}/invocations"
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
- Try to deploy this API.
Observed result:
Deployment fails with
Errors found during import: Unable to put integration response on 'OPTIONS' for resource at path '/mypath': Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression specified: mypath.test] Additionally, these warnings were found: Parse issue: attribute paths.'/mypath'(options).responses.200.Access-Control-Allow-Origin.type is unexpected Parse issue: attribute paths.'/mypath'(options).responses.200.Access-Control-Allow-Methods.type is unexpected Parse issue: attribute paths.'/mypath'(options).produces is unexpected Parse issue: attribute paths.'/mypath'(options).consumes is unexpected
Expected result:
Deployment succeeds.