mirror of https://github.com/pulumi/pulumi.git
3 Commits
Author | SHA1 | Message | Date |
---|---|---|---|
![]() |
70ba80b7cc
|
[go/sdk-gen] Fixes plain and optional properties for generated types for Go SDKs using generics (#14616)
# 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. --> |
|
![]() |
ba039c20f8
|
Support returning plain values from methods (#13592)
Support returning plain values from methods. Implements Node, Python and Go support. Remaining: - [x] test receiving unknowns - [x] acceptance tests written and passing locally for Node, Python, Go clients against a Go server - [x] acceptance tests passing in CI - [x] tickets filed for remaining languages - [x] https://github.com/pulumi/pulumi-yaml/issues/499 - [x] https://github.com/pulumi/pulumi-java/issues/1193 - [x] https://github.com/pulumi/pulumi-dotnet/issues/170 Known limitations: - this is technically a breaking change in case there is code out there that already uses methods that return Plain: true - struct-wrapping limitation: the provider for the component resource needs to still wrap the plain-returning Method response with a 1-arg struct; by convention the field is named "res", and this is how it travels through the plumbing - resources cannot return plain values yet - the provider for the component resource cannot have unknown configuration, if it does, the methods will not be called - Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not be supported/realizable yet <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Fixes https://github.com/pulumi/pulumi/issues/12709 ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [ ] I have run `make lint` to verify my code passes the lint check - [ ] 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. --> |
|
![]() |
9899992657
|
[go/sdk-gen] Fix generics-only option missing ToOutput(...) methods (#14584)
# Description PR #14492 removed `ToOutput(...)` methods for output types when generating non-generic SDK variants. The fix there was added to only include these when `side-by-side` is enabled, which implicitly included `generics-only` except for a _single_ place where that wasn't the case 😓 (see comment below in `gen.go`) This PR fixes issue and includes tests for go sdkgen where `generics` setting is set to `generics-only`: - `output-funcs-go-generics-only` - `plain-and-default-go-generics-only` - `secrets-go-generics-only` - `simple-enum-schema-go-generics-only` - `simple-plain-schema-go-generics-only` ## 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. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] 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. --> |