(serviceName string, method reflect.Method, meta tsgenmeta.MethodMeta, isFirst bool, tsTypesMap map[reflect.Type]string)
| 347 | } |
| 348 | |
| 349 | func GenerateMethodSignature(serviceName string, method reflect.Method, meta tsgenmeta.MethodMeta, isFirst bool, tsTypesMap map[reflect.Type]string) string { |
| 350 | var sb strings.Builder |
| 351 | mayReturnUpdates := hasUpdatesReturn(method) |
| 352 | if (meta.Desc != "" || meta.ReturnDesc != "" || mayReturnUpdates) && !isFirst { |
| 353 | sb.WriteString("\n") |
| 354 | } |
| 355 | if meta.Desc != "" { |
| 356 | sb.WriteString(fmt.Sprintf(" // %s\n", meta.Desc)) |
| 357 | } |
| 358 | if mayReturnUpdates || meta.ReturnDesc != "" { |
| 359 | if mayReturnUpdates && meta.ReturnDesc != "" { |
| 360 | sb.WriteString(fmt.Sprintf(" // @returns %s (and object updates)\n", meta.ReturnDesc)) |
| 361 | } else if mayReturnUpdates { |
| 362 | sb.WriteString(" // @returns object updates\n") |
| 363 | } else { |
| 364 | sb.WriteString(fmt.Sprintf(" // @returns %s\n", meta.ReturnDesc)) |
| 365 | } |
| 366 | } |
| 367 | sb.WriteString(" ") |
| 368 | sb.WriteString(method.Name) |
| 369 | sb.WriteString("(") |
| 370 | wroteArg := false |
| 371 | // skip first arg, which is the receiver |
| 372 | for idx := 1; idx < method.Type.NumIn(); idx++ { |
| 373 | if wroteArg { |
| 374 | sb.WriteString(", ") |
| 375 | } |
| 376 | inType := method.Type.In(idx) |
| 377 | if inType == contextRType || inType == uiContextRType { |
| 378 | continue |
| 379 | } |
| 380 | tsTypeName, _ := TypeToTSType(inType, tsTypesMap) |
| 381 | var argName string |
| 382 | if idx-1 < len(meta.ArgNames) { |
| 383 | argName = meta.ArgNames[idx-1] // subtract 1 for receiver |
| 384 | } else { |
| 385 | argName = fmt.Sprintf("arg%d", idx) |
| 386 | } |
| 387 | sb.WriteString(fmt.Sprintf("%s: %s", argName, tsTypeName)) |
| 388 | wroteArg = true |
| 389 | } |
| 390 | sb.WriteString("): ") |
| 391 | rtnTypes := []string{} |
| 392 | for idx := 0; idx < method.Type.NumOut(); idx++ { |
| 393 | outType := method.Type.Out(idx) |
| 394 | if outType == errorRType { |
| 395 | continue |
| 396 | } |
| 397 | if outType == updatesRtnRType { |
| 398 | continue |
| 399 | } |
| 400 | tsTypeName, _ := TypeToTSType(outType, tsTypesMap) |
| 401 | rtnTypes = append(rtnTypes, tsTypeName) |
| 402 | } |
| 403 | if len(rtnTypes) == 0 { |
| 404 | sb.WriteString("Promise<void>") |
| 405 | } else if len(rtnTypes) == 1 { |
| 406 | sb.WriteString(fmt.Sprintf("Promise<%s>", rtnTypes[0])) |
no test coverage detected