Skip to content

Commit

Permalink
Merge #11418
Browse files Browse the repository at this point in the history
11418: Simplified invokes: SDK-gen and program-gen implementation for dotnet and nodejs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
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

This PR implements simplified invoke gen for both SDKs and PCL programs by allowing invokes to:
 - Accepts multi arguments as inputs (instead of a bag of properties)
 - Return a single value as output (instead of a bag of outputs)

Related to #7435 

This implementation handles dotnet and nodejs. Python and Go can be implementation on a separate pass. Currently both python and go will fail generation (sdk/program) when encountering simplified invokes

## Checklist

<!--- 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 Service,
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 Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
  • Loading branch information
bors[bot] and Zaid-Ajaj committed Dec 16, 2022
2 parents 0b9446f + a6f26d2 commit c000cd7
Show file tree
Hide file tree
Showing 91 changed files with 6,081 additions and 287 deletions.
@@ -0,0 +1,4 @@
changes:
- type: feat
scope: sdkgen/dotnet,nodejs
description: Initial implementation of simplified invokes for dotnet and nodejs.
9 changes: 6 additions & 3 deletions pkg/codegen/docs/gen.go
Expand Up @@ -1721,11 +1721,14 @@ func (mod *modContext) getTypes(member interface{}, types nestedTypeUsageInfo) {
mod.getTypes(m.Function, types)
}
case *schema.Function:
if t.Inputs != nil {
if t.Inputs != nil && !t.MultiArgumentInputs {
mod.getNestedTypes(t.Inputs, types, true)
}
if t.Outputs != nil {
mod.getNestedTypes(t.Outputs, types, false)

if t.ReturnType != nil {
if objectType, ok := t.ReturnType.(*schema.ObjectType); ok && objectType != nil {
mod.getNestedTypes(objectType, types, false)
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/codegen/docs/gen_function.go
Expand Up @@ -443,8 +443,11 @@ func (mod *modContext) genFunction(f *schema.Function) functionDocArgs {
if f.Inputs != nil {
inputProps[lang] = mod.getProperties(f.Inputs.Properties, lang, true, false, false)
}
if f.Outputs != nil {
outputProps[lang] = mod.getProperties(f.Outputs.Properties, lang, false, false, false)
if f.ReturnType != nil {
if objectObject, ok := f.ReturnType.(*schema.ObjectType); ok {
outputProps[lang] = mod.getProperties(objectObject.Properties,
lang, false, false, false)
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/codegen/docs/gen_method.go
Expand Up @@ -78,9 +78,11 @@ func (mod *modContext) genMethod(r *schema.Resource, m *schema.Method) methodDoc
inputProps[lang] = props
}
}
if f.Outputs != nil {
outputProps[lang] = mod.getPropertiesWithIDPrefixAndExclude(f.Outputs.Properties, lang, false, false, false,
fmt.Sprintf("%s_result_", m.Name), nil)
if f.ReturnType != nil {
if objectType, ok := f.ReturnType.(*schema.ObjectType); ok && objectType != nil {
outputProps[lang] = mod.getPropertiesWithIDPrefixAndExclude(objectType.Properties, lang, false, false, false,
fmt.Sprintf("%s_result_", m.Name), nil)
}
}
}

Expand Down Expand Up @@ -324,7 +326,7 @@ func (mod *modContext) getMethodResult(r *schema.Resource, m *schema.Method) map

var resultTypeName string
for _, lang := range dctx.supportedLanguages {
if m.Function.Outputs != nil && len(m.Function.Outputs.Properties) > 0 {
if m.Function.ReturnType != nil {
def, err := mod.pkg.Definition()
contract.AssertNoError(err)
resultTypeName = dctx.getLanguageDocHelper(lang).GetMethodResultName(def, mod.mod, r, m)
Expand Down
20 changes: 18 additions & 2 deletions pkg/codegen/dotnet/doc.go
Expand Up @@ -110,8 +110,24 @@ func (d DocLanguageHelper) GetMethodName(m *schema.Method) string {
func (d DocLanguageHelper) GetMethodResultName(pkg *schema.Package, modName string, r *schema.Resource,
m *schema.Method) string {

var returnType *schema.ObjectType
if m.Function.ReturnType != nil {
if objectType, ok := m.Function.ReturnType.(*schema.ObjectType); ok {
returnType = objectType
} else {
typeDetails := map[*schema.ObjectType]*typeDetails{}
mod := &modContext{
pkg: pkg.Reference(),
mod: modName,
typeDetails: typeDetails,
namespaces: d.Namespaces,
}
return mod.typeString(m.Function.ReturnType, "", false, false, false)
}
}

if info, ok := pkg.Language["csharp"].(CSharpPackageInfo); ok {
if info.LiftSingleValueMethodReturns && m.Function.Outputs != nil && len(m.Function.Outputs.Properties) == 1 {
if info.LiftSingleValueMethodReturns && returnType != nil && len(returnType.Properties) == 1 {
typeDetails := map[*schema.ObjectType]*typeDetails{}
mod := &modContext{
pkg: pkg.Reference(),
Expand All @@ -120,7 +136,7 @@ func (d DocLanguageHelper) GetMethodResultName(pkg *schema.Package, modName stri
namespaces: d.Namespaces,
rootNamespace: info.GetRootNamespace(),
}
return mod.typeString(m.Function.Outputs.Properties[0].Type, "", false, false, false)
return mod.typeString(returnType.Properties[0].Type, "", false, false, false)
}
}
return fmt.Sprintf("%s.%sResult", resourceName(r), d.GetMethodName(m))
Expand Down

0 comments on commit c000cd7

Please sign in to comment.