Skip to content

Commit

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

Reverts #11701 and fixes the problem which caused the issue in the first place:
 - Binding `Outputs` field from `FunctionSpec` into `Function.ReturnType` when available
 - Adding a test that verifies the above works as expected

Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
  • Loading branch information
bors[bot] and Zaid-Ajaj committed Jan 12, 2023
2 parents 5f11fc1 + 330676a commit b4dd454
Show file tree
Hide file tree
Showing 91 changed files with 6,188 additions and 286 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 @@ -1722,11 +1722,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 b4dd454

Please sign in to comment.