From 8011612186d8f9fde4c03fccee0f1ef0cb0a8b1b Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Sat, 6 Jul 2024 09:22:24 -0700 Subject: [PATCH] Allow Transform section to have the full transform def --- src/cfnlint/context/context.py | 2 +- .../schemas/other/template/configuration.json | 37 ++++++++++++++++++- test/unit/module/context/test_transforms.py | 17 +++------ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/cfnlint/context/context.py b/src/cfnlint/context/context.py index e3aaeba8db..8bfb407a18 100644 --- a/src/cfnlint/context/context.py +++ b/src/cfnlint/context/context.py @@ -38,7 +38,7 @@ def __post_init__(self, transforms) -> None: for transform in transforms: if not isinstance(transform, str): - raise ValueError("Transform must be a string") + continue self._transforms.append(transform) def has_language_extensions_transform(self): diff --git a/src/cfnlint/data/schemas/other/template/configuration.json b/src/cfnlint/data/schemas/other/template/configuration.json index c7b825e88b..4fb54a76ee 100644 --- a/src/cfnlint/data/schemas/other/template/configuration.json +++ b/src/cfnlint/data/schemas/other/template/configuration.json @@ -1,5 +1,32 @@ { "additionalProperties": false, + "definitions": { + "Transform": { + "properties": { + "Name": { + "type": "string" + }, + "Properties": { + "patternProperties": { + ".*": { + "type": [ + "string", + "array", + "boolean", + "object", + "number", + "integer" + ] + } + }, + "type": "object" + } + }, + "required": [ + "Name" + ] + } + }, "properties": { "AWSTemplateFormatVersion": { "enum": [ @@ -23,12 +50,18 @@ "type": "object" }, "Transform": { + "$ref": "#/definitions/Transform", "items": { - "type": "string" + "$ref": "#/definitions/Transform", + "type": [ + "string", + "object" + ] }, "type": [ "string", - "array" + "array", + "object" ] } }, diff --git a/test/unit/module/context/test_transforms.py b/test/unit/module/context/test_transforms.py index a852cf7c42..451e9c8566 100644 --- a/test/unit/module/context/test_transforms.py +++ b/test/unit/module/context/test_transforms.py @@ -12,7 +12,11 @@ "name,instance,expected", [ ("Valid transforms", "AWS::LanguageExtensions", True), - ("Valid transforms lists", ["AWS::LanguageExtensions"], True), + ( + "Valid transforms lists", + ["AWS::LanguageExtensions", {"Name": "Include"}], + True, + ), ("Valid transforms lists", None, False), ("Valid transforms lists", "", False), ], @@ -23,14 +27,3 @@ def test_transforms(name, instance, expected): assert ( expected == transforms.has_language_extensions_transform() ), f"{name!r} test got {transforms.has_language_extensions_transform()}" - - -@pytest.mark.parametrize( - "name,instance", - [ - ("Invalid Type", {}), - ], -) -def test_errors(name, instance): - with pytest.raises(ValueError): - Transforms(instance)