diff --git a/cloudformation/serverless/aws-serverless-httpapi_corsconfigurationobject.go b/cloudformation/serverless/aws-serverless-httpapi_corsconfigurationobject.go index 8d81492f34..d39527bdee 100644 --- a/cloudformation/serverless/aws-serverless-httpapi_corsconfigurationobject.go +++ b/cloudformation/serverless/aws-serverless-httpapi_corsconfigurationobject.go @@ -18,17 +18,17 @@ type HttpApi_CorsConfigurationObject struct { // AllowHeaders AWS CloudFormation Property // Required: false // See: https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration-object - AllowHeaders *string `json:"AllowHeaders,omitempty"` + AllowHeaders *[]string `json:"AllowHeaders,omitempty"` // AllowMethods AWS CloudFormation Property // Required: false // See: https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration-object - AllowMethods *string `json:"AllowMethods,omitempty"` + AllowMethods *[]string `json:"AllowMethods,omitempty"` - // AllowOrigin AWS CloudFormation Property + // AllowOrigins AWS CloudFormation Property // Required: false // See: https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration-object - AllowOrigin *string `json:"AllowOrigin,omitempty"` + AllowOrigins *[]string `json:"AllowOrigins,omitempty"` // ExposeHeaders AWS CloudFormation Property // Required: false @@ -38,7 +38,7 @@ type HttpApi_CorsConfigurationObject struct { // MaxAge AWS CloudFormation Property // Required: false // See: https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration-object - MaxAge *string `json:"MaxAge,omitempty"` + MaxAge *int `json:"MaxAge,omitempty"` // AWSCloudFormationDeletionPolicy represents a CloudFormation DeletionPolicy AWSCloudFormationDeletionPolicy policies.DeletionPolicy `json:"-"` diff --git a/generate/sam-2016-10-31.json b/generate/sam-2016-10-31.json index 9e383fac9c..d8c42d9ccb 100644 --- a/generate/sam-2016-10-31.json +++ b/generate/sam-2016-10-31.json @@ -2291,25 +2291,28 @@ "AllowMethods": { "Documentation": "https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration-object", "Required": false, - "PrimitiveType": "String", + "Type": "List", + "PrimitiveItemType": "String", "UpdateType": "Immutable" }, "AllowHeaders": { "Documentation": "https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration-object", "Required": false, - "PrimitiveType": "String", + "Type": "List", + "PrimitiveItemType": "String", "UpdateType": "Immutable" }, - "AllowOrigin": { + "AllowOrigins": { "Documentation": "https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration-object", "Required": false, - "PrimitiveType": "String", + "Type": "List", + "PrimitiveItemType": "String", "UpdateType": "Immutable" }, "MaxAge": { "Documentation": "https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration-object", "Required": false, - "PrimitiveType": "String", + "PrimitiveType": "Integer", "UpdateType": "Immutable" }, "AllowCredentials": { diff --git a/goformation_test.go b/goformation_test.go index da4066b46d..6b554f565a 100644 --- a/goformation_test.go +++ b/goformation_test.go @@ -491,6 +491,39 @@ var _ = Describe("Goformation", func() { }) + Context("with a template that defines an AWS::Serverless::HttpApi with a CorsConfiguration", func() { + + template, err := goformation.Open("test/yaml/aws-serverless-http-api-cors-configuration.yaml") + It("should successfully parse the template", func() { + Expect(err).To(BeNil()) + Expect(template).ShouldNot(BeNil()) + }) + + apis := template.GetAllServerlessHttpApiResources() + + It("should have exactly an API", func() { + Expect(apis).To(HaveLen(1)) + Expect(apis).To(HaveKey("HttpApiWithCorsConfiguration")) + }) + + api1 := apis["HttpApiWithCorsConfiguration"] + It("should parse a CorsConfiguration object", func() { + Expect(api1.CorsConfiguration.CorsConfigurationObject.AllowOrigins). + To(Equal(cloudformation.Strings("https://www.example.com"))) + Expect(api1.CorsConfiguration.CorsConfigurationObject.AllowMethods). + To(Equal(cloudformation.Strings("GET", "OPTIONS"))) + Expect(api1.CorsConfiguration.CorsConfigurationObject.AllowHeaders). + To(Equal(cloudformation.Strings("x-apigateway-header"))) + Expect(api1.CorsConfiguration.CorsConfigurationObject.ExposeHeaders). + To(Equal(cloudformation.Strings("*"))) + Expect(api1.CorsConfiguration.CorsConfigurationObject.AllowCredentials). + To(Equal(cloudformation.Bool(true))) + Expect(api1.CorsConfiguration.CorsConfigurationObject.MaxAge). + To(Equal(cloudformation.Int(300))) + }) + + }) + Context("with a Serverless template containing different CodeUri formats", func() { template, err := goformation.Open("test/yaml/aws-serverless-function-string-or-s3-location.yaml") diff --git a/schema/sam.go b/schema/sam.go index 6f7e17395f..0d703c6671 100644 --- a/schema/sam.go +++ b/schema/sam.go @@ -134112,13 +134112,22 @@ var SamSchema = `{ "type": "boolean" }, "AllowHeaders": { - "type": "string" + "items": { + "type": "string" + }, + "type": "array" }, "AllowMethods": { - "type": "string" + "items": { + "type": "string" + }, + "type": "array" }, - "AllowOrigin": { - "type": "string" + "AllowOrigins": { + "items": { + "type": "string" + }, + "type": "array" }, "ExposeHeaders": { "items": { @@ -134127,7 +134136,7 @@ var SamSchema = `{ "type": "array" }, "MaxAge": { - "type": "string" + "type": "number" } }, "type": "object" diff --git a/schema/sam.schema.json b/schema/sam.schema.json index 9f94712c58..a81f24365d 100644 --- a/schema/sam.schema.json +++ b/schema/sam.schema.json @@ -134107,13 +134107,22 @@ "type": "boolean" }, "AllowHeaders": { - "type": "string" + "items": { + "type": "string" + }, + "type": "array" }, "AllowMethods": { - "type": "string" + "items": { + "type": "string" + }, + "type": "array" }, - "AllowOrigin": { - "type": "string" + "AllowOrigins": { + "items": { + "type": "string" + }, + "type": "array" }, "ExposeHeaders": { "items": { @@ -134122,7 +134131,7 @@ "type": "array" }, "MaxAge": { - "type": "string" + "type": "number" } }, "type": "object" diff --git a/test/yaml/aws-serverless-http-api-cors-configuration.yaml b/test/yaml/aws-serverless-http-api-cors-configuration.yaml new file mode 100644 index 0000000000..e8b270f8af --- /dev/null +++ b/test/yaml/aws-serverless-http-api-cors-configuration.yaml @@ -0,0 +1,20 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: SAM template for testing AWS::Serverless::HttpApi.CorsConfigurationObject +Resources: + + HttpApiWithCorsConfiguration: + Type: AWS::Serverless::HttpApi + Properties: + CorsConfiguration: + AllowOrigins: + - "https://www.example.com" + AllowMethods: + - GET + - OPTIONS + AllowHeaders: + - x-apigateway-header + ExposeHeaders: + - "*" + AllowCredentials: true + MaxAge: 300