diff --git a/crossplane/function/resource.py b/crossplane/function/resource.py index 322a482..cbf9189 100644 --- a/crossplane/function/resource.py +++ b/crossplane/function/resource.py @@ -70,7 +70,9 @@ def struct_to_dict(s: structpb.Struct) -> dict: dictionary. """ return { - k: (struct_to_dict(v) if isinstance(v, structpb.Struct) else v) + k: (struct_to_dict(v) if isinstance(v, structpb.Struct) else ( + list(v) if isinstance(v, structpb.ListValue) else v + )) for k, v in s.items() } diff --git a/tests/test_resource.py b/tests/test_resource.py index e9c818f..c04ca14 100644 --- a/tests/test_resource.py +++ b/tests/test_resource.py @@ -275,6 +275,28 @@ class TestCase: ), want={"foo": {"bar": "baz"}}, ), + TestCase( + reason="Convert a nested struct containing ListValues to a dictionary.", + s=structpb.Struct( + fields={ + "foo": structpb.Value( + struct_value=structpb.Struct( + fields={ + "bar": structpb.Value( + list_value=structpb.ListValue( + values=[ + structpb.Value(string_value="baz"), + structpb.Value(string_value="qux"), + ] + ) + ) + } + ) + ) + } + ), + want={"foo": {"bar": ["baz", "qux"]}}, + ), ] for case in cases: