Skip to content

Commit

Permalink
Add a nested type for docs in async magic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Oct 29, 2024
1 parent ad31252 commit aa67ff0
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 29 deletions.
12 changes: 11 additions & 1 deletion src/Generation/GapicClientV2Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private function magicAsyncDocs(): PhpDoc
->filter(fn($m) => !$m->isStreaming())
->map(fn($m) => PhpDoc::method(
$m->methodName . "Async",
$this->ctx->type(Type::fromName(PromiseInterface::class))->type->name,
$this->asyncReturnType($m),
$m->requestType->name, // the request type will already be imported for the sync variants
));
return PhpDoc::block($methodDocs);
Expand Down Expand Up @@ -876,4 +876,14 @@ private function snippetPathForMethod(MethodDetails $method): string

return "samples/{$version}{$emptyClientName}/{$methodName}.php";
}

private function asyncReturnType(MethodDetails $method): string
{
$returnType = $this->ctx->type(Type::fromName(PromiseInterface::class))->type->name;
$nestedType = ($method->hasEmptyResponse) ?
'void' :
$this->ctx->type($method->methodReturnType)->type->name;

return sprintf('%s<%s>', $returnType, $nestedType);
}
}
4 changes: 2 additions & 2 deletions tests/Unit/ProtoTests/Basic/out/src/Client/BasicClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
* This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods.
*
* @method PromiseInterface aMethodAsync(Request $request, array $optionalArgs = [])
* @method PromiseInterface methodWithArgsAsync(RequestWithArgs $request, array $optionalArgs = [])
* @method PromiseInterface<Response> aMethodAsync(Request $request, array $optionalArgs = [])
* @method PromiseInterface<Response> methodWithArgsAsync(RequestWithArgs $request, array $optionalArgs = [])
*/
final class BasicClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods.
*
* @method PromiseInterface aMethodAsync(Request $request, array $optionalArgs = [])
* @method PromiseInterface<Response> aMethodAsync(Request $request, array $optionalArgs = [])
*/
final class BasicOneofNewClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods.
*
* @method PromiseInterface createFooAsync(CreateFooRequest $request, array $optionalArgs = [])
* @method PromiseInterface<OperationResponse> createFooAsync(CreateFooRequest $request, array $optionalArgs = [])
*/
final class CustomLroClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
* This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods.
*
* @method PromiseInterface cancelAsync(CancelOperationRequest $request, array $optionalArgs = [])
* @method PromiseInterface deleteAsync(DeleteOperationRequest $request, array $optionalArgs = [])
* @method PromiseInterface getAsync(GetOperationRequest $request, array $optionalArgs = [])
* @method PromiseInterface<void> cancelAsync(CancelOperationRequest $request, array $optionalArgs = [])
* @method PromiseInterface<void> deleteAsync(DeleteOperationRequest $request, array $optionalArgs = [])
* @method PromiseInterface<CustomOperationResponse> getAsync(GetOperationRequest $request, array $optionalArgs = [])
*/
final class CustomLroOperationsClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
* name, and additionally a parseName method to extract the individual identifiers
* contained within formatted names that are returned by the API.
*
* @method PromiseInterface fileLevelChildTypeRefMethodAsync(FileLevelChildTypeRefRequest $request, array $optionalArgs = [])
* @method PromiseInterface fileLevelTypeRefMethodAsync(FileLevelTypeRefRequest $request, array $optionalArgs = [])
* @method PromiseInterface multiPatternMethodAsync(MultiPatternRequest $request, array $optionalArgs = [])
* @method PromiseInterface nestedReferenceMethodAsync(NestedReferenceRequest $request, array $optionalArgs = [])
* @method PromiseInterface singlePatternMethodAsync(SinglePatternRequest $request, array $optionalArgs = [])
* @method PromiseInterface wildcardChildReferenceMethodAsync(WildcardChildReferenceRequest $request, array $optionalArgs = [])
* @method PromiseInterface wildcardMethodAsync(WildcardPatternRequest $request, array $optionalArgs = [])
* @method PromiseInterface wildcardMultiMethodAsync(WildcardMultiPatternRequest $request, array $optionalArgs = [])
* @method PromiseInterface wildcardReferenceMethodAsync(WildcardReferenceRequest $request, array $optionalArgs = [])
* @method PromiseInterface<PlaceholderResponse> fileLevelChildTypeRefMethodAsync(FileLevelChildTypeRefRequest $request, array $optionalArgs = [])
* @method PromiseInterface<PlaceholderResponse> fileLevelTypeRefMethodAsync(FileLevelTypeRefRequest $request, array $optionalArgs = [])
* @method PromiseInterface<PlaceholderResponse> multiPatternMethodAsync(MultiPatternRequest $request, array $optionalArgs = [])
* @method PromiseInterface<PlaceholderResponse> nestedReferenceMethodAsync(NestedReferenceRequest $request, array $optionalArgs = [])
* @method PromiseInterface<PlaceholderResponse> singlePatternMethodAsync(SinglePatternRequest $request, array $optionalArgs = [])
* @method PromiseInterface<PlaceholderResponse> wildcardChildReferenceMethodAsync(WildcardChildReferenceRequest $request, array $optionalArgs = [])
* @method PromiseInterface<PlaceholderResponse> wildcardMethodAsync(WildcardPatternRequest $request, array $optionalArgs = [])
* @method PromiseInterface<PlaceholderResponse> wildcardMultiMethodAsync(WildcardMultiPatternRequest $request, array $optionalArgs = [])
* @method PromiseInterface<PlaceholderResponse> wildcardReferenceMethodAsync(WildcardReferenceRequest $request, array $optionalArgs = [])
*/
final class ResourceNamesClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@
* This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods.
*
* @method PromiseInterface deleteMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface getMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface getNoPlaceholdersMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface getNoTemplateMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface nestedMethodAsync(NestedRequest $request, array $optionalArgs = [])
* @method PromiseInterface nestedMultiMethodAsync(NestedRequest $request, array $optionalArgs = [])
* @method PromiseInterface orderingMethodAsync(OrderRequest $request, array $optionalArgs = [])
* @method PromiseInterface patchMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface postMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface putMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface routingRuleWithOutParametersAsync(NestedRequest $request, array $optionalArgs = [])
* @method PromiseInterface routingRuleWithParametersAsync(NestedRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> deleteMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> getMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> getNoPlaceholdersMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> getNoTemplateMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> nestedMethodAsync(NestedRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> nestedMultiMethodAsync(NestedRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> orderingMethodAsync(OrderRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> patchMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> postMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> putMethodAsync(SimpleRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> routingRuleWithOutParametersAsync(NestedRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Response> routingRuleWithParametersAsync(NestedRequest $request, array $optionalArgs = [])
*/
final class RoutingHeadersClient
{
Expand Down

0 comments on commit aa67ff0

Please sign in to comment.