Skip to content

Commit

Permalink
Initial implementation of simplified invokes for dotnet and nodejs an…
Browse files Browse the repository at this point in the history
…d generalized outputs for functions
  • Loading branch information
Zaid-Ajaj committed Nov 23, 2022
1 parent 45dddd8 commit 5ab3f46
Show file tree
Hide file tree
Showing 90 changed files with 2,474 additions and 452 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 @@ -1680,11 +1680,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
31 changes: 18 additions & 13 deletions pkg/codegen/dotnet/doc.go
Expand Up @@ -110,20 +110,25 @@ func (d DocLanguageHelper) GetMethodName(m *schema.Method) string {
func (d DocLanguageHelper) GetMethodResultName(pkg *schema.Package, modName string, r *schema.Resource,
m *schema.Method) string {

if info, ok := pkg.Language["csharp"].(CSharpPackageInfo); ok {
if info.LiftSingleValueMethodReturns && m.Function.Outputs != nil && len(m.Function.Outputs.Properties) == 1 {
typeDetails := map[*schema.ObjectType]*typeDetails{}
mod := &modContext{
pkg: pkg,
mod: modName,
typeDetails: typeDetails,
namespaces: d.Namespaces,
rootNamespace: info.GetRootNamespace(),
}
return mod.typeString(m.Function.Outputs.Properties[0].Type, "", false, false, false)
}
if m.Function.ReturnType == nil {
return "void"
}

// if the return type is an object, assume we generated a Result Type for it
if _, isObject := m.Function.ReturnType.(*schema.ObjectType); isObject {
return fmt.Sprintf("%s.%sResult", resourceName(r), d.GetMethodName(m))
}

// otherwise just generate the non-object type
typeDetails := map[*schema.ObjectType]*typeDetails{}
mod := &modContext{
pkg: pkg,
mod: modName,
typeDetails: typeDetails,
namespaces: d.Namespaces,
}
return fmt.Sprintf("%s.%sResult", resourceName(r), d.GetMethodName(m))

return mod.typeString(m.Function.ReturnType, "", false, false, false)
}

// GetPropertyName uses the property's csharp-specific language info, if available, to generate
Expand Down

0 comments on commit 5ab3f46

Please sign in to comment.