diff --git a/cloudformation/serverless/aws-serverless-function_iampolicydocument.go b/cloudformation/serverless/aws-serverless-function_iampolicydocument.go index faa7520ff4..bfb1ef4fc5 100644 --- a/cloudformation/serverless/aws-serverless-function_iampolicydocument.go +++ b/cloudformation/serverless/aws-serverless-function_iampolicydocument.go @@ -13,7 +13,7 @@ type Function_IAMPolicyDocument struct { // Statement AWS CloudFormation Property // Required: true // See: http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html - Statement []interface{} `json:"Statement"` + Statement *Function_Statement `json:"Statement"` // Version AWS CloudFormation Property // Required: true diff --git a/cloudformation/serverless/aws-serverless-statemachine_iampolicydocument.go b/cloudformation/serverless/aws-serverless-statemachine_iampolicydocument.go index ba4a0e5df9..5d2918f4a5 100644 --- a/cloudformation/serverless/aws-serverless-statemachine_iampolicydocument.go +++ b/cloudformation/serverless/aws-serverless-statemachine_iampolicydocument.go @@ -13,7 +13,7 @@ type StateMachine_IAMPolicyDocument struct { // Statement AWS CloudFormation Property // Required: true // See: http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html - Statement []interface{} `json:"Statement"` + Statement *StateMachine_Statement `json:"Statement"` // Version AWS CloudFormation Property // Required: true diff --git a/cloudformation/serverless/function_statement.go b/cloudformation/serverless/function_statement.go new file mode 100644 index 0000000000..c4140b2696 --- /dev/null +++ b/cloudformation/serverless/function_statement.go @@ -0,0 +1,76 @@ +// Code generated by "go generate". Please don't change this file directly. + +package serverless + +import ( + "bytes" + "encoding/json" + "io" + "sort" + + "github.com/awslabs/goformation/v6/cloudformation/utils" +) + +// Function_Statement is a helper struct that can hold either a Json or Json value +type Function_Statement struct { + Json *interface{} + + JsonArray *[]interface{} +} + +func (r Function_Statement) value() interface{} { + ret := []interface{}{} + + if r.Json != nil { + ret = append(ret, r.Json) + } + + if r.JsonArray != nil { + ret = append(ret, r.JsonArray) + } + + sort.Sort(utils.ByJSONLength(ret)) // Heuristic to select best attribute + if len(ret) > 0 { + return ret[0] + } + + return nil +} + +func (r Function_Statement) MarshalJSON() ([]byte, error) { + return json.Marshal(r.value()) +} + +// Hook into the marshaller +func (r *Function_Statement) UnmarshalJSON(b []byte) error { + + // Unmarshal into interface{} to check it's type + var typecheck interface{} + if err := json.Unmarshal(b, &typecheck); err != nil { + return err + } + + switch val := typecheck.(type) { + + case interface{}: + r.Json = &val + + case []interface{}: + r.JsonArray = &val + + case map[string]interface{}: + val = val // This ensures val is used to stop an error + + reader := bytes.NewReader(b) + decoder := json.NewDecoder(reader) + decoder.DisallowUnknownFields() + reader.Seek(0, io.SeekStart) + + case []interface{}: + + json.Unmarshal(b, &r.JsonArray) + + } + + return nil +} diff --git a/cloudformation/serverless/statemachine_statement.go b/cloudformation/serverless/statemachine_statement.go new file mode 100644 index 0000000000..c43cee7de8 --- /dev/null +++ b/cloudformation/serverless/statemachine_statement.go @@ -0,0 +1,76 @@ +// Code generated by "go generate". Please don't change this file directly. + +package serverless + +import ( + "bytes" + "encoding/json" + "io" + "sort" + + "github.com/awslabs/goformation/v6/cloudformation/utils" +) + +// StateMachine_Statement is a helper struct that can hold either a Json or Json value +type StateMachine_Statement struct { + Json *interface{} + + JsonArray *[]interface{} +} + +func (r StateMachine_Statement) value() interface{} { + ret := []interface{}{} + + if r.Json != nil { + ret = append(ret, r.Json) + } + + if r.JsonArray != nil { + ret = append(ret, r.JsonArray) + } + + sort.Sort(utils.ByJSONLength(ret)) // Heuristic to select best attribute + if len(ret) > 0 { + return ret[0] + } + + return nil +} + +func (r StateMachine_Statement) MarshalJSON() ([]byte, error) { + return json.Marshal(r.value()) +} + +// Hook into the marshaller +func (r *StateMachine_Statement) UnmarshalJSON(b []byte) error { + + // Unmarshal into interface{} to check it's type + var typecheck interface{} + if err := json.Unmarshal(b, &typecheck); err != nil { + return err + } + + switch val := typecheck.(type) { + + case interface{}: + r.Json = &val + + case []interface{}: + r.JsonArray = &val + + case map[string]interface{}: + val = val // This ensures val is used to stop an error + + reader := bytes.NewReader(b) + decoder := json.NewDecoder(reader) + decoder.DisallowUnknownFields() + reader.Seek(0, io.SeekStart) + + case []interface{}: + + json.Unmarshal(b, &r.JsonArray) + + } + + return nil +} diff --git a/generate/sam-2016-10-31.json b/generate/sam-2016-10-31.json index d8c42d9ccb..3a1d17d5df 100644 --- a/generate/sam-2016-10-31.json +++ b/generate/sam-2016-10-31.json @@ -1414,8 +1414,8 @@ "Statement": { "Documentation": "http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html", "Required": true, - "Type": "List", - "ItemType": "Json", + "PrimitiveTypes": ["Json"], + "PrimitiveItemTypes": ["Json"], "UpdateType": "Immutable" }, "Version": { @@ -2515,8 +2515,8 @@ "Statement": { "Documentation": "http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html", "Required": true, - "Type": "List", - "ItemType": "Json", + "PrimitiveTypes": ["Json"], + "PrimitiveItemTypes": ["Json"], "UpdateType": "Immutable" }, "Version": { diff --git a/schema/sam.go b/schema/sam.go index 0d703c6671..a76f84d6ea 100644 --- a/schema/sam.go +++ b/schema/sam.go @@ -133441,10 +133441,19 @@ var SamSchema = `{ "additionalProperties": false, "properties": { "Statement": { - "items": { - "type": "object" - }, - "type": "array" + "anyOf": [ + { + "type": [ + "object" + ] + }, + { + "items": { + "type": "object" + }, + "type": "array" + } + ] }, "Version": { "type": "string" @@ -134747,10 +134756,19 @@ var SamSchema = `{ "additionalProperties": false, "properties": { "Statement": { - "items": { - "type": "object" - }, - "type": "array" + "anyOf": [ + { + "type": [ + "object" + ] + }, + { + "items": { + "type": "object" + }, + "type": "array" + } + ] }, "Version": { "type": "string" diff --git a/schema/sam.schema.json b/schema/sam.schema.json index a81f24365d..15a6ab1b65 100644 --- a/schema/sam.schema.json +++ b/schema/sam.schema.json @@ -133436,10 +133436,19 @@ "additionalProperties": false, "properties": { "Statement": { - "items": { - "type": "object" - }, - "type": "array" + "anyOf": [ + { + "type": [ + "object" + ] + }, + { + "items": { + "type": "object" + }, + "type": "array" + } + ] }, "Version": { "type": "string" @@ -134742,10 +134751,19 @@ "additionalProperties": false, "properties": { "Statement": { - "items": { - "type": "object" - }, - "type": "array" + "anyOf": [ + { + "type": [ + "object" + ] + }, + { + "items": { + "type": "object" + }, + "type": "array" + } + ] }, "Version": { "type": "string"