hashicorp / aws-cloudformation-resource-schema-sdk-go

This package provides AWS CloudFormation Resource Schema functionality in Go
Mozilla Public License 2.0
4 stars 2 forks source link

Support for `allOf`, `anyOf` and `oneOf` keywords #16

Closed ewbankkit closed 3 years ago

ewbankkit commented 3 years ago

Support schema composition via the allOf, anyOf and oneOf keywords.

ewbankkit commented 3 years ago

Some example usage:

In a property definition
    "Action": {
      "type": "object",
      "properties": {
        "Operation": {
          "description": "Step action operation",
          "type": "string"
        },
        "Parameters": {
          "anyOf": [
            {
              "$ref": "#/definitions/RecipeParameters"
            },
            {
              "$ref": "#/definitions/ParameterMap"
            }
          ]
        }
      },
      "additionalProperties": false,
      "required": ["Operation"]
    },

    "FilterAndOperator": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "Tags"
          ],
          "properties": {
            "Prefix": {
              "description": "Prefix identifies one or more objects to which the rule applies.",
              "$ref": "#/definitions/FilterPrefix"
            },
            "Tags": {
              "description": "All of these tags must exist in the object's tag set in order for the rule to apply.",
              "type": "array",
              "uniqueItems": true,
              "minItems": 1,
              "items": {
                "$ref": "#/definitions/FilterTag"
              }
            }
          }
        }
      ]
    }

    "CapacityProvider": {
      "description": "If using ec2 auto-scaling, the name of the associated capacity provider. Otherwise FARGATE, FARGATE_SPOT.",
      "type": "string",
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "FARGATE",
            "FARGATE_SPOT"
          ]
        },
        {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        }
      ]
    },

    "OneDriveUsers": {
      "type": "object",
      "properties": {
        "OneDriveUserList": {
          "$ref": "#/definitions/OneDriveUserList"
        },
        "OneDriveUserS3Path": {
          "$ref": "#/definitions/S3Path"
        }
      },
      "additionalProperties": false,
      "oneOf": [
        {
          "required": [
            "OneDriveUserList"
          ]
        },
        {
          "required": [
            "OneDriveUserS3Path"
          ]
        }
      ]
    },
At the top level
    "anyOf": [
        {
            "required": [
                "FirehoseArn",
                "RoleArn",
                "OutputFormat"
            ]
        },
        {
            "allOf": [
                {
                    "required": [
                        "FirehoseArn",
                        "RoleArn",
                        "OutputFormat"
                    ]
                },
                {
                    "oneOf": [
                        {
                            "required": ["IncludeFilters"]
                        },
                        {
                            "required": ["ExcludeFilters"]
                        }
                    ]
                }
            ]
        }
    ],

  "allOf": [
    {
      "required": [
        "EC2InstanceType",
        "Name"
      ]
    },
    {
      "oneOf": [
        {
          "required": [
            "BuildId"
          ]
        },
        {
          "required": [
            "ScriptId"
          ]
        }
      ]
    },
    {
      "oneOf": [
        {
          "required": [
            "RuntimeConfiguration"
          ]
        },
        {
          "required": [
            "ServerLaunchParameters",
            "ServerLaunchPath"
          ]
        }
      ]
    }
  ],
ewbankkit commented 3 years ago

Don't do anything with the top-level occurrences - How they are meant to work is not (yet) documented: https://github.com/aws-cloudformation/cloudformation-resource-schema/issues/94.

ewbankkit commented 3 years ago

At this stage we will only address the nested anyOf, allOf and oneOf with required.