Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attribute to handle deserialization of constructor parameters with name overrides #231

Merged
merged 5 commits into from
Mar 8, 2024
Merged

Conversation

praneetloke
Copy link
Contributor

@praneetloke praneetloke commented Feb 17, 2024

This PR is in support of pulumi/pulumi#14130.

I have a local override for the native provider in question to use the changes in this PR, as well as codegen changes in pulumi/pulumi using the PR pulumi/pulumi#14246 with additional changes to emit the attribute introduced in this PR.

Here's how it looks in practice in a provider's SDK:

    [OutputType]
    public sealed class ListOneClicksProperties
    {
        public readonly ImmutableArray<Outputs.OneClicks> _1Clicks;

        [OutputConstructor]
        private ListOneClicksProperties([OutputConstructorParameterAttribute("1_clicks")] ImmutableArray<Outputs.OneClicks> _1Clicks)
        {
            this._1Clicks = _1Clicks;
        }
    }

Copy link
Member

@justinvp justinvp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @praneetloke! Some comments.

Also, this needs tests. See

Your usage in the PR description doesn't quite look how I'd expect it to. I'd expect something like:

    [OutputType]
    public sealed class ListOneClicksProperties
    {
        public readonly ImmutableArray<Outputs.OneClicks> _1Clicks;

        [OutputConstructor]
        private ListOneClicksProperties([OutputConstructorParameter("1_clicks")] ImmutableArray<Outputs.OneClicks> _1Clicks)
        {
            this._1Clicks = _1Clicks;
        }
    }

/// constructor parameters with a name override.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter)]
public class ConstructorParameterNameOverrideAttribute : Attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type should be sealed.

Also, I wonder if a better name would be OutputConstructorParameterAttribute, to align with OutputConstructorAttribute:

Suggested change
public class ConstructorParameterNameOverrideAttribute : Attribute
public sealed class OutputConstructorParameterAttribute : Attribute

I also wonder if this should be moved directly below OutputConstructorAttribute (line 76).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made changes for both suggestions you've made here. Also on the topic of the attribute class being sealed I noticed that ResourceTypeAttribute is not marked as such. That's the one I was using as reference and hence didn't mark the new one as sealed initially. Would you like me to mark it as sealed as well?

@praneetloke
Copy link
Contributor Author

@justinvp I've pushed new commits with changes based on your feedback.

Your usage in the PR description doesn't quite look how I'd expect it to. I'd expect something like:

Ah, indeed. I made a mistake in the codegen and wrote out the attribute on the class member instead of the constructor param...despite the name of the attribute 🤦‍♂️ . I'll fix that when I open the PR in pulumi/pulumi though. I've noted it down.

@praneetloke praneetloke requested a review from justinvp February 19, 2024 18:27
@praneetloke
Copy link
Contributor Author

Bump.

Copy link
Member

@justinvp justinvp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you @praneetloke and apologies for the long delay getting this reviewed!

@praneetloke
Copy link
Contributor Author

@justinvp awesome! The status checks for this PR still says that the workflow requires approval from a maintainer though and haven't run. Any idea why that might be?

@Frassle Frassle enabled auto-merge March 8, 2024 08:43
@Frassle
Copy link
Member

Frassle commented Mar 8, 2024

Looks like you just need to run "dotnet run format-sdk"

@Frassle Frassle added this pull request to the merge queue Mar 8, 2024
Merged via the queue into pulumi:main with commit 8a545f2 Mar 8, 2024
16 of 17 checks passed
@praneetloke
Copy link
Contributor Author

Ah got it. I'll remember that for next time. Thanks, @Frassle.

jkerken pushed a commit to algompluecker/pulumi-dotnet that referenced this pull request Jul 24, 2024
…h name overrides (pulumi#231)

* Add attribute to handle deserialization of constructor parameters with name overrides

* changie new

* Update names

* Add a test. Address PR feedback.

* Relocate new attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants