aws-cloudformation / cloudformation-cli

The CloudFormation Provider Development Toolkit allows you to author your own resource providers and modules that can be used by CloudFormation.
Apache License 2.0
316 stars 157 forks source link

"type" has to be singular by flattener code but can be an array by schema validation #1059

Open kddejong opened 4 months ago

kddejong commented 4 months ago

This is to track if we should support multiple types or fix the code in cloudformation-cli to support multiple types. Right now the flatenner will fail when doing the following. Additionally the schema allows for multiple types.

{
  "type": ["array", "object"],
  "properties": {
    "a": {}
  },
  "items": {
    "properties": {
      "b": {}
    }
  }
}

https://github.com/aws-cloudformation/cloudformation-cli/blob/f0e376989c1b5a106c97b25b78e98f46bdb5995f/src/rpdk/core/jsonutils/flattener.py#L19-L23

Schema definition: https://github.com/aws-cloudformation/cloudformation-resource-schema/blob/master/src/main/resources/schema/schema#L145-L155

{
    "type": {
      "anyOf": [
        { "$ref": "#/definitions/simpleTypes" },
        {
          "type": "array",
          "items": { "$ref": "#/definitions/simpleTypes" },
          "minItems": 1,
          "uniqueItems": true
        }
      ]
    }
}
ericzbeard commented 4 months ago

Are there any existing types that do this?

kddejong commented 4 months ago

Not if they are using the cloudformation-cli cause it would fail.

This shows up the most as a result of inline policies or definitions (like step functions).

"type": [
    "object",
    "string"
   ]

There are some other random multi types... none that specify array and objects together. In general the flattener is used in a lot of places in the cloudformation-cli and we make an assumption that we only support singular types.