Skip to content

Commit

Permalink
Add var doc comment to executors that return sendPrimitive.
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasKenneth committed Oct 30, 2023
1 parent af26dc0 commit c012160
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,17 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, CodeClass parentCl
? $", '{returnTypeName}'"
: returnEnumType;
var requestAdapterProperty = parentClass.GetPropertyOfKind(CodePropertyKind.RequestAdapter) ?? throw new InvalidOperationException("Request adapter property not found");
writer.WriteLine(
$"return {GetPropertyCall(requestAdapterProperty, string.Empty)}->{methodName}({RequestInfoVarName}{finalReturn}, {(hasErrorMappings ? $"{errorMappingsVarName}" : "null")});");

var methodCall = $"{GetPropertyCall(requestAdapterProperty, string.Empty)}->{methodName}({RequestInfoVarName}{finalReturn}, {(hasErrorMappings ? $"{errorMappingsVarName}" : "null")});";
if (methodName.Contains("sendPrimitive", StringComparison.OrdinalIgnoreCase))
{
writer.WriteLines($"/** @var Promise<{GetDocCommentReturnType(codeElement)}|null> $result",
$"$result = {methodCall}",
"return $result;"
);
}
else writer.WriteLines(
$"return {methodCall}");
}

private static void WriteApiConstructorBody(CodeClass parentClass, CodeMethod codeMethod, LanguageWriter writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ public async void WriteRequestExecutor()
Assert.Contains("$requestInfo = $this->createPostRequestInformation();", result);
Assert.Contains("@link https://learn.microsoft.com/ Learning", result);
Assert.Contains("'401' => [Error401::class, 'createFromDiscriminatorValue']", result);
Assert.Contains("return $this->requestAdapter->sendPrimitiveAsync($requestInfo, StreamInterface::class, $errorMappings);", result);
Assert.Contains("$result = $this->requestAdapter->sendPrimitiveAsync($requestInfo, StreamInterface::class, $errorMappings);", result);
Assert.Contains("return $result;", result);
}

[Fact]
Expand Down Expand Up @@ -383,7 +384,9 @@ public async void WritesRequestExecutorForEnumTypes()
Assert.Contains("$requestInfo = $this->createPostRequestInformation();", result);
Assert.Contains("@link https://learn.microsoft.com/ Learning", result);
Assert.Contains("'401' => [Error401::class, 'createFromDiscriminatorValue']", result);
Assert.Contains("return $this->requestAdapter->sendPrimitiveAsync($requestInfo, PhoneNumberPrefix::class, $errorMappings);", result);
Assert.Contains("/** @var Promise<PhoneNumberPrefix|null> $result", result);
Assert.Contains("$result = $this->requestAdapter->sendPrimitiveAsync($requestInfo, PhoneNumberPrefix::class, $errorMappings);", result);
Assert.Contains("return $result;", result);
}

public static IEnumerable<object[]> SerializerProperties => new List<object[]>
Expand Down

0 comments on commit c012160

Please sign in to comment.