Skip to content

Commit

Permalink
feat(schema): serverless http api cors configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
konoui authored and rubenfonseca committed Sep 2, 2022
1 parent 81b9d25 commit a90bb03
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 20 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions generate/sam-2016-10-31.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
33 changes: 33 additions & 0 deletions goformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 14 additions & 5 deletions schema/sam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -134127,7 +134136,7 @@ var SamSchema = `{
"type": "array"
},
"MaxAge": {
"type": "string"
"type": "number"
}
},
"type": "object"
Expand Down
19 changes: 14 additions & 5 deletions schema/sam.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -134122,7 +134131,7 @@
"type": "array"
},
"MaxAge": {
"type": "string"
"type": "number"
}
},
"type": "object"
Expand Down
20 changes: 20 additions & 0 deletions test/yaml/aws-serverless-http-api-cors-configuration.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a90bb03

Please sign in to comment.