Skip to content

Commit 40ba065

Browse files
fix(http-client-java): preserve sync versioning overloads
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e5dff7f2-5849-4374-b6b3-9c7177834a21
1 parent 2043bed commit 40ba065

3 files changed

Lines changed: 57 additions & 4 deletions

File tree

packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ClientMethodMapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ private void createPageStreamingClientMethods(boolean isSync, ClientMethod baseM
584584
// Pageable op '[Operation]' overloads for versioning
585585
createOverloadForVersioning(methods, isModelMaxOverload ? clientMethodWithContext : pagingMethod,
586586
clientMethodWithContext, methodWithContextVisibility, methodPageDetailsWithContext, isProtocolMethod, true);
587-
// async method without Context parameter
588-
if (!isSync) {
587+
// method without RequestOptions/Context parameter
588+
if (!isSync || isModelMaxOverload) {
589589
createOverloadForVersioning(methods, pagingMethod, pagingMethod, methodVisibility, methodPageDetails,
590590
isProtocolMethod, false);
591591
}
@@ -803,8 +803,8 @@ private void createLroBeginClientMethods(boolean isSync, ClientMethod lroBaseMet
803803
// LRO 'begin[Operation]' sync or async method overloads with versioning.
804804
createOverloadForVersioning(methods, isModelMaxOverload ? clientMethodWithContext : beginLroMethod,
805805
clientMethodWithContext, methodWithContextVisibility, null, isProtocolMethod, true);
806-
// async method without Context parameter
807-
if (!isSync) {
806+
// method without RequestOptions/Context parameter
807+
if (!isSync || isModelMaxOverload) {
808808
createOverloadForVersioning(methods, beginLroMethod, beginLroMethod, methodVisibility, null,
809809
isProtocolMethod, false);
810810
}

packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/maxoverloadmodel/MaxOverloadModelClient.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,30 @@ public SyncPoller<PollOperationDetails, ResourceModel> beginExport(String name,
729729
return serviceClient.beginExportWithModel(name, requestOptions);
730730
}
731731

732+
/**
733+
* Long-running resource action operation template.
734+
*
735+
* @param name The name parameter.
736+
* @param optional The optional parameter.
737+
* @throws IllegalArgumentException thrown if parameters fail the validation.
738+
* @throws HttpResponseException thrown if the request is rejected by server.
739+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
740+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
741+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
742+
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
743+
* @return the {@link SyncPoller} for polling of provides status details for long running operations.
744+
*/
745+
@Generated
746+
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
747+
public SyncPoller<PollOperationDetails, ResourceModel> beginExport(String name, String optional) {
748+
// Generated convenience method for beginExportWithModel
749+
RequestOptions requestOptions = new RequestOptions();
750+
if (optional != null) {
751+
requestOptions.addQueryParam("optional", optional, false);
752+
}
753+
return serviceClient.beginExportWithModel(name, requestOptions);
754+
}
755+
732756
/**
733757
* Long-running resource action operation template.
734758
*
@@ -879,6 +903,30 @@ public PagedIterable<ResourceModel> list(String filter, RequestOptions requestOp
879903
.mapPage(bodyItemValue -> bodyItemValue.toObject(ResourceModel.class));
880904
}
881905

906+
/**
907+
* Resource list operation template.
908+
*
909+
* @param filter The filter parameter.
910+
* @throws IllegalArgumentException thrown if parameters fail the validation.
911+
* @throws HttpResponseException thrown if the request is rejected by server.
912+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
913+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
914+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
915+
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
916+
* @return paged collection of ResourceModel items as paginated response with {@link PagedIterable}.
917+
*/
918+
@Generated
919+
@ServiceMethod(returns = ReturnType.COLLECTION)
920+
public PagedIterable<ResourceModel> list(String filter) {
921+
// Generated convenience method for listInternal
922+
RequestOptions requestOptions = new RequestOptions();
923+
if (filter != null) {
924+
requestOptions.addQueryParam("filter", filter, false);
925+
}
926+
return serviceClient.listInternal(requestOptions)
927+
.mapPage(bodyItemValue -> bodyItemValue.toObject(ResourceModel.class));
928+
}
929+
882930
/**
883931
* Resource list operation template.
884932
*

packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/maxoverloadmodel/MaxOverloadModelTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ public void testLroAndPageableMethods() throws ReflectiveOperationException {
9191
= MaxOverloadModelClient.class.getDeclaredMethod("list", String.class, String.class, RequestOptions.class);
9292
Method syncPageablePastMax
9393
= MaxOverloadModelClient.class.getDeclaredMethod("list", String.class, RequestOptions.class);
94+
Method syncPageablePast = MaxOverloadModelClient.class.getDeclaredMethod("list", String.class);
9495
Assertions.assertTrue(Modifier.isPublic(syncPageableMax.getModifiers()));
9596
Assertions.assertTrue(Modifier.isPublic(syncPageablePastMax.getModifiers()));
97+
Assertions.assertTrue(Modifier.isPublic(syncPageablePast.getModifiers()));
9698

9799
Method syncProtocolPageable
98100
= MaxOverloadModelClient.class.getDeclaredMethod("listInternal", RequestOptions.class);
@@ -117,8 +119,11 @@ public void testLroAndPageableMethods() throws ReflectiveOperationException {
117119
String.class, String.class, RequestOptions.class);
118120
Method syncLroVersionedPastMax = MaxOverloadModelClient.class.getDeclaredMethod("beginExport", String.class,
119121
String.class, RequestOptions.class);
122+
Method syncLroVersionedPast
123+
= MaxOverloadModelClient.class.getDeclaredMethod("beginExport", String.class, String.class);
120124
Assertions.assertTrue(Modifier.isPublic(syncLroVersionedMax.getModifiers()));
121125
Assertions.assertTrue(Modifier.isPublic(syncLroVersionedPastMax.getModifiers()));
126+
Assertions.assertTrue(Modifier.isPublic(syncLroVersionedPast.getModifiers()));
122127

123128
Method asyncLroVersionedMax = MaxOverloadModelAsyncClient.class.getDeclaredMethod("beginExport", String.class,
124129
String.class, String.class, RequestOptions.class);

0 commit comments

Comments
 (0)