Skip to content

Commit

Permalink
Add support for object type as Any in component schema (#509)
Browse files Browse the repository at this point in the history
## Summary
- Add support for mapping `object` type properties to `Any` in component
schemas
- Add test cases for both required and optional `object` type properties
- This allows component providers to accept arbitrary data structures
through `object` type properties

## Test plan
- Added unit tests verifying both required and optional object
properties are correctly mapped to the 'Any' type in schemas
- All unit tests passing
  • Loading branch information
mikhailshilkov authored Feb 25, 2025
1 parent e3323bd commit ad24762
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
48 changes: 48 additions & 0 deletions sdk/Pulumi.Tests/Provider/ComponentAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,54 @@ public void TestAnalyzeAsset()
AssertSchemaEqual(expected, schema);
}

class AnyTypesArgs : ResourceArgs
{
[Input("inputAny", required: true)]
public Input<object> InputAny { get; set; } = null!;

[Input("optionalInputAny")]
public Input<object>? OptionalInputAny { get; set; }
}

class AnyTypesComponent : ComponentResource
{
[Output("outputAny")]
public Output<object> OutputAny { get; private set; } = null!;

[Output("optionalOutputAny")]
public Output<object?> OptionalOutputAny { get; private set; } = null!;

public AnyTypesComponent(string name, AnyTypesArgs args, ComponentResourceOptions? options = null)
: base("my-component:index:AnyTypesComponent", name, args, options)
{
}
}

[Fact]
public void TestAnalyzeAny()
{
var schema = ComponentAnalyzer.GenerateSchema(_metadata, typeof(AnyTypesComponent));

var resources = new Dictionary<string, ResourceSpec>();
resources.Add("my-component:index:AnyTypesComponent",
new ResourceSpec(
new Dictionary<string, PropertySpec>
{
["inputAny"] = PropertySpec.CreateReference("pulumi.json#/Any"),
["optionalInputAny"] = PropertySpec.CreateReference("pulumi.json#/Any")
},
new HashSet<string> { "inputAny" },
new Dictionary<string, PropertySpec>
{
["outputAny"] = PropertySpec.CreateReference("pulumi.json#/Any"),
["optionalOutputAny"] = PropertySpec.CreateReference("pulumi.json#/Any")
},
new HashSet<string> { "outputAny" }));

var expected = CreateBasePackageSpec(resources);
AssertSchemaEqual(expected, schema);
}

class MyResource : CustomResource
{
public MyResource(string name)
Expand Down
2 changes: 2 additions & 0 deletions sdk/Pulumi/Provider/ComponentAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ private string GetTypeName(Type type)
return "pulumi.json#/Archive";
if (type == typeof(Asset))
return "pulumi.json#/Asset";
if (type == typeof(object))
return "pulumi.json#/Any";
return null;
}
}
Expand Down

0 comments on commit ad24762

Please sign in to comment.