Skip to content

Commit

Permalink
Simplified invokes for dotnet and nodejs: schema, sdk-gen and program…
Browse files Browse the repository at this point in the history
…-gen
  • Loading branch information
Zaid-Ajaj committed Dec 8, 2022
1 parent ffc01c1 commit 378db6c
Show file tree
Hide file tree
Showing 95 changed files with 6,032 additions and 441 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 @@ -1684,11 +1684,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 @@ -433,8 +433,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 @@ -77,9 +77,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 @@ -321,7 +323,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 {
resultTypeName = dctx.getLanguageDocHelper(lang).GetMethodResultName(mod.pkg, mod.mod, r, m)
}
resourceMap[lang] = propertyType{
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,
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,
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 378db6c

Please sign in to comment.