mirror of https://github.com/pulumi/pulumi.git
70ba80b7cc
# Description While working on on #14585 I tried to add a test schema for assets and archives that generate a `generics-only` go SDK but the the output didn't compile. At first I thought the issue was specific to asset and archive types but actually it was a broader issue where the function`pkg.genPlainType(InputObjectType)` would always reduce `Input[T]` and `Optional[T]` to just `T` on each property of `InputObjectType`. It is probably fine to reduce `Input[T]` because we are generating a plain type after all. However, reducing `Optional[T]` to `T` is incorrect because the generic variant of go sdks are more strict about optionality of types. > It probably works in non-generic SDKs today because it relies on a runtime cast Example type `TypeWithAssets` from schema that has a plain and optional property called `plainAsset`: ❌ Before it was the following and it didn't compile for generic go sdks ```go type TypeWithAssets struct { PlainAsset pulumi.AssetOrArchive `pulumi:"plainAsset"` } type TypeWithAssetsArgs struct { PlainAsset pulumix.Input[*pulumi.AssetOrArchive] `pulumi:"plainAsset"` } func (o TypeWithAssetsOutput) PlainAsset() pulumix.Output[*pulumi.AssetOrArchive] { return pulumix.Apply[TypeWithAssets](o, func(v TypeWithAssets) pulumi.AssetOrArchive { return v.PlainAsset }) } ``` ✅ Now it generates: ```go type TypeWithAssets struct { PlainAsset *pulumi.AssetOrArchive `pulumi:"plainAsset"` } type TypeWithAssetsArgs struct { PlainAsset *pulumi.AssetOrArchive `pulumi:"plainAsset"` } func (o TypeWithAssetsOutput) PlainAsset() pulumix.Output[*pulumi.AssetOrArchive] { return pulumix.Apply[TypeWithAssets](o, func(v TypeWithAssets) *pulumi.AssetOrArchive { return v.PlainAsset }) } ``` Which is correct and compiles The behavior for current non-generic SDKs remains unchanged ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. --> |
||
---|---|---|
.. | ||
mypkg | ||
codegen-manifest.json |