Skip to content
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
7c81a00
fallback to version compare by date
weidongxu-microsoft Oct 21, 2025
941939b
set to undefined, if cannot find version in apiVersions
weidongxu-microsoft Oct 21, 2025
c598d4e
nit
weidongxu-microsoft Oct 21, 2025
e49c321
fix lint
weidongxu-microsoft Oct 21, 2025
225dd59
test case
weidongxu-microsoft Oct 21, 2025
a668d88
nit to cover the case of the erasure of preview api-version
weidongxu-microsoft Oct 21, 2025
ea588f3
Merge branch 'main' into http-client-java_versioning-non-dpg
weidongxu-microsoft Oct 22, 2025
8d2f7ab
partial tool
weidongxu-microsoft Oct 22, 2025
ff2e84e
simple method uses WithResponse
weidongxu-microsoft Oct 22, 2025
bb96c02
enhance
weidongxu-microsoft Oct 23, 2025
032f3a9
Merge branch 'main' into http-client-java_versioning-non-dpg
weidongxu-microsoft Nov 18, 2025
99ae880
improve client method template to recognize parameter that need to be…
weidongxu-microsoft Nov 18, 2025
f01061b
format
weidongxu-microsoft Nov 18, 2025
d6652f0
regen
weidongxu-microsoft Nov 18, 2025
0aa271a
advanced versioning for arm-versioned test
weidongxu-microsoft Nov 18, 2025
5e17044
regen with advanced-versioning
weidongxu-microsoft Nov 18, 2025
a61c34a
test
weidongxu-microsoft Nov 18, 2025
ce526d0
Merge branch 'main' into http-client-java_versioning-non-dpg
weidongxu-microsoft Nov 25, 2025
0fa3f33
update addOptionalVariables
weidongxu-microsoft Nov 25, 2025
b4fa958
Revert "update addOptionalVariables"
weidongxu-microsoft Nov 25, 2025
d8f7ed4
overload for LRO createOrUpdate in mgmt
weidongxu-microsoft Nov 25, 2025
ffb4c88
overload for method for lro and pageable
weidongxu-microsoft Nov 25, 2025
a451335
regen
weidongxu-microsoft Nov 25, 2025
64218ae
mgmt, update logic for taking the client method of full parameters
weidongxu-microsoft Nov 25, 2025
d99c9cd
update npm deps
weidongxu-microsoft Nov 25, 2025
2b3b222
bug fix
weidongxu-microsoft Nov 25, 2025
9653e35
regen
weidongxu-microsoft Nov 25, 2025
7648f09
update test
weidongxu-microsoft Nov 25, 2025
4991205
make a diff
weidongxu-microsoft Nov 25, 2025
2fe0045
Revert "make a diff"
weidongxu-microsoft Nov 25, 2025
00fcc47
Merge branch 'http-client-java_versioning-non-dpg' of https://github.…
weidongxu-microsoft Nov 25, 2025
0686df8
comment
weidongxu-microsoft Nov 25, 2025
1f57aed
delete type that not used
weidongxu-microsoft Nov 25, 2025
218b6ba
we can remove the condition
weidongxu-microsoft Nov 25, 2025
ccf67b6
Update packages/http-client-java/generator/http-client-generator-core…
weidongxu-microsoft Nov 26, 2025
7c93f90
format
weidongxu-microsoft Nov 26, 2025
bf9d6ea
Merge branch 'main' into http-client-java_versioning-non-dpg
weidongxu-microsoft Nov 26, 2025
e730949
add more API to test case
weidongxu-microsoft Nov 26, 2025
f4f4461
bug fix for not taking the client method of full parameters
weidongxu-microsoft Nov 26, 2025
7e90d5c
Merge branch 'http-client-java_versioning-non-dpg' of https://github.…
weidongxu-microsoft Nov 26, 2025
dd89acb
regen
weidongxu-microsoft Nov 26, 2025
66dcfba
update test
weidongxu-microsoft Nov 26, 2025
55551cf
regen
weidongxu-microsoft Nov 26, 2025
f420686
update test
weidongxu-microsoft Nov 26, 2025
07fb92f
fix and test
weidongxu-microsoft Nov 26, 2025
8e13f79
comment
weidongxu-microsoft Nov 26, 2025
3f11d0d
regen
weidongxu-microsoft Nov 26, 2025
6a8d204
demonstrate for case without advanced-versioning
weidongxu-microsoft Nov 26, 2025
2fba784
Revert "demonstrate for case without advanced-versioning"
weidongxu-microsoft Nov 26, 2025
90c1119
rename to make the var easier to understand
weidongxu-microsoft Nov 27, 2025
ef26163
add overloadedClientMethod var to ClientMethod
weidongxu-microsoft Nov 27, 2025
a041c47
refine the logic
weidongxu-microsoft Nov 27, 2025
02dd013
fix
weidongxu-microsoft Nov 27, 2025
18abe5b
regen
weidongxu-microsoft Nov 27, 2025
fbba5d9
comment
weidongxu-microsoft Nov 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@typespec/streams": "0.76.0",
"@azure-tools/typespec-azure-core": "0.62.0",
"@azure-tools/typespec-client-generator-core": "0.62.0",
"@azure-tools/typespec-azure-resource-manager": "0.62.0",
"@azure-tools/typespec-azure-resource-manager": "0.62.1",
"@azure-tools/typespec-autorest": "0.62.0"
},
"private": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,33 @@ private static JavaVisibility methodVisibilityInWrapperClient(Operation operatio
}
}

private static void createOverloadForVersioning(boolean isProtocolMethod, List<ClientMethod> methods,
ClientMethod baseMethod) {
protected void createOverloadForVersioning(List<ClientMethod> methods, ClientMethod baseMethod,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth to add some javadoc about this method.

JavaVisibility methodWithContextVisibility, MethodPageDetails methodPageDetailsWithContext,
boolean isProtocolMethod) {
final ClientMethodType clientMethodType = baseMethod.getType();
final List<ClientMethodParameter> parameters = baseMethod.getParameters();
if (!isProtocolMethod && JavaSettings.getInstance().isDataPlaneClient()) {
if (!isProtocolMethod) {
if (parameters.stream().anyMatch(p -> p.getVersioning() != null && p.getVersioning().getAdded() != null)) {
// versioning of @added exists
final List<List<ClientMethodParameter>> signatures = findOverloadedSignatures(parameters);
for (List<ClientMethodParameter> overloadedParameters : signatures) {
final ClientMethod overloadedMethod
= baseMethod.newBuilder().parameters(overloadedParameters).build();
methods.add(overloadedMethod);
if (JavaSettings.getInstance().isDataPlaneClient()) {
// DPG
final ClientMethod overloadedMethod
= baseMethod.newBuilder().parameters(overloadedParameters).build();
methods.add(overloadedMethod);
} else {
// non-DPG
ClientMethod.Builder overloadedMethodBuilder
= baseMethod.newBuilder().parameters(overloadedParameters);
if (methodPageDetailsWithContext != null) {
overloadedMethodBuilder
= overloadedMethodBuilder.methodPageDetails(methodPageDetailsWithContext);
}
final ClientMethod overloadedMethod = overloadedMethodBuilder.build();
addClientMethodWithContext(methods, overloadedMethod, methodWithContextVisibility,
isProtocolMethod);
}
}
}
}
Expand Down Expand Up @@ -456,6 +473,9 @@ private void createSinglePageClientMethods(boolean isSync, ClientMethod baseMeth
methods.add(singlePageMethod);
}

// Pageable op '[Operation]SinglePage' overloads for versioning
createOverloadForVersioning(methods, singlePageMethod, methodWithContextVisibility, null, isProtocolMethod);

// Generate '[Operation]SinglePage' overload with all parameters and Context.
addClientMethodWithContext(methods, singlePageMethod, methodWithContextVisibility, isProtocolMethod);
}
Expand Down Expand Up @@ -508,8 +528,9 @@ private void createPageStreamingClientMethods(boolean isSync, ClientMethod baseM
if (settings.getSyncMethods() != SyncMethodsGeneration.NONE) {
// generate the overload, if "sync-methods != NONE"
methods.add(pagingMethod);
// overload for versioning
createOverloadForVersioning(isProtocolMethod, methods, pagingMethod);
// Pageable op '[Operation]' overloads for versioning
createOverloadForVersioning(methods, pagingMethod, methodWithContextVisibility,
methodPageDetailsWithContext, isProtocolMethod);
}

if (generateRequiredOnlyParametersOverload) {
Expand Down Expand Up @@ -575,6 +596,10 @@ private void createLroWithResponseClientMethods(boolean isSync, ClientMethod bas
.hasWithContextOverload(methodWithContextVisibility != NOT_GENERATE)
.build();
methods.add(withResponseMethod);

// LRO '[Operation]WithResponse' overloads for versioning
createOverloadForVersioning(methods, withResponseMethod, methodWithContextVisibility, null, isProtocolMethod);

addClientMethodWithContext(methods, withResponseMethod, methodWithContextVisibility, isProtocolMethod);
}

Expand Down Expand Up @@ -614,6 +639,10 @@ private void createFluentLroWithResponseSyncClientMethods(Operation operation, C
.methodVisibility(NOT_VISIBLE)
.build();
methods.add(withResponseSyncMethod);

// LRO '[Operation]' overloads for versioning
createOverloadForVersioning(methods, withResponseSyncMethod, NOT_VISIBLE, null, isProtocolMethod);

addClientMethodWithContext(methods, withResponseSyncMethod, NOT_VISIBLE, isProtocolMethod);
}

Expand Down Expand Up @@ -705,7 +734,7 @@ private void createLroBeginClientMethods(boolean isSync, ClientMethod lroBaseMet
methods.add(beginLroMethod);

// LRO 'begin[Operation]' sync or async method overloads with versioning.
createOverloadForVersioning(isProtocolMethod, methods, beginLroMethod);
createOverloadForVersioning(methods, beginLroMethod, methodWithContextVisibility, null, isProtocolMethod);

if (generateRequiredOnlyParametersOverload) {
// LRO 'begin[Operation]' sync or async method overload with only required parameters.
Expand Down Expand Up @@ -764,6 +793,10 @@ private void createSimpleWithResponseClientMethods(boolean isSync, ClientMethod
.hasWithContextOverload(hasContextOverload)
.methodVisibility(methodVisibility)
.build();

// Simple op '[Operation]WithResponse' overloads for versioning
createOverloadForVersioning(methods, withResponseMethod, methodWithContextVisibility, null, isProtocolMethod);

// Always generate an overload of WithResponse with non-required parameters without Context. It is only for sync
// proxy method, and is usually filtered out in methodVisibility function.
methods.add(withResponseMethod);
Expand Down Expand Up @@ -807,8 +840,8 @@ private void createSimpleValueClientMethods(boolean isSync, ClientMethod baseMet
.build();
methods.add(simpleMethod);

// overload for versioning
createOverloadForVersioning(isProtocolMethod, methods, simpleMethod);
// Simple op '[Operation]' overloads for versioning
createOverloadForVersioning(methods, simpleMethod, methodWithContextVisibility, null, isProtocolMethod);

if (generateRequiredOnlyParametersOverload) {
final ClientMethod simpleMethodWithRequiredParameters = simpleMethod.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public enum ClientMethodType {
* Mono&lt;PagedResponseBase&lt;H,T&gt;&gt;.
*/
PagingAsyncSinglePage(2, true, false, false),
SimulatedPagingSync(3, false, false, true), // unused
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double confirm: is this just code clean up unrelated to advanced versioning?

SimulatedPagingAsync(4, false, false, false), // unused
/**
* represents long-running method that returns T where T is the final result of the LRO.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ protected static void addOptionalVariables(JavaBlock function, ClientMethod clie
protected static void addOptionalAndConstantVariables(JavaBlock function, ClientMethod clientMethod,
JavaSettings settings) {
final List<ProxyMethodParameter> proxyMethodParameters = clientMethod.getProxyMethod().getParameters();
List<com.microsoft.typespec.http.client.generator.core.model.clientmodel.examplemodel.MethodParameter> methodParameters
= MethodUtil.getParameters(clientMethod, false);
for (ProxyMethodParameter parameter : proxyMethodParameters) {
if (parameter.isFromClient()) {
// parameter is scoped to the client, hence no local variable instantiation for it.
Expand All @@ -164,7 +166,17 @@ protected static void addOptionalAndConstantVariables(JavaBlock function, Client

// If the parameter isn't required and the client method only uses required parameters, optional
// parameters are omitted and will need to instantiated in the method.
boolean optionalOmitted = clientMethod.getOnlyRequiredParameters() && !parameter.isRequired();
boolean optionalOmitted = !parameter.isRequired() && parameter.getClientType() != ClassType.CONTEXT;
if (optionalOmitted) {
boolean parameterInClientMethodSignature = methodParameters.stream()
.filter(p -> p.getProxyMethodParameter() == parameter)
.findFirst()
.map(p -> p.getClientMethodParameter())
.isPresent();
// if the parameter is defined in client method signature,
// it does not need to be instantiated in local variable.
optionalOmitted = !parameterInClientMethodSignature;
}

// Optional variables and constants are always null if their wire type and client type differ and applying
// conversions between the types is ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ private void createLroGetFinalResultClientMethods(boolean isSync, ClientMethod b
.build();
methods.add(lroGetFinalResultMethod);

// LRO '[Operation]' sync or async method overloads with versioning (for management).
createOverloadForVersioning(methods, lroGetFinalResultMethod, methodWithContextVisibility, null,
isProtocolMethod);

if (generateRequiredOnlyParametersOverload) {
final ClientMethod lroGetFinalResultMethodWithRequiredOnlyParameters = lroGetFinalResultMethod.newBuilder()
.onlyRequiredParameters(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private List<MethodParameter> getParametersByLocation(RequestParameterLocation p
}

private List<MethodParameter> getParametersByLocation(Set<RequestParameterLocation> parameterLocations) {
ClientMethod clientMethod = getMethodReferencesOfFullParameters().iterator().next().getInnerClientMethod();
ClientMethod clientMethod = getClientMethodOfFullParameters();
Map<String, ProxyMethodParameter> proxyMethodParameterByClientParameterName = clientMethod.getProxyMethod()
.getParameters()
.stream()
Expand All @@ -145,6 +145,18 @@ private List<MethodParameter> getParametersByLocation(Set<RequestParameterLocati
.collect(Collectors.toList());
}

private ClientMethod getClientMethodOfFullParameters() {
List<FluentCollectionMethod> collectionMethods = getMethodReferencesOfFullParameters();
// take the client method with longest parameters
// it should be the client method of full parameters
collectionMethods.sort((m1, m2) -> {
int count1 = m1.getInnerClientMethod().getParameters().size();
int count2 = m2.getInnerClientMethod().getParameters().size();
return -Integer.compare(count1, count2);
});
return collectionMethods.get(0).getInnerClientMethod();
}

public ClientMethodParameter getBodyParameter() {
List<MethodParameter> parameters = getParametersByLocation(RequestParameterLocation.BODY);
return parameters.isEmpty() ? null : parameters.iterator().next().getClientMethodParameter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ $generateScript = {
$tspOptions += " --option ""@typespec/http-client-java.generate-tests=false"""
# add customization code
$tspOptions += " --option ""@typespec/http-client-java.customization-class=../../customization/src/main/java/KeyVaultCustomization.java"""
} elseif ($tspFile -match "tsp[\\/]arm-versioned.tsp") {
# enable advanced versioning for resiliency test
$tspOptions += " --option ""@typespec/http-client-java.advanced-versioning=true"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for understanding purpose: is advanced-versioning default to false, so we have to explicitly set true here? Do we have plan to default it to true?

} elseif ($tspFile -match "tsp[\\/]subclient.tsp") {
$tspOptions += " --option ""@typespec/http-client-java.enable-subclient=true"""
# test for include-api-view-properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@typespec/streams": "0.76.0",
"@azure-tools/typespec-azure-core": "0.62.0",
"@azure-tools/typespec-client-generator-core": "0.62.0",
"@azure-tools/typespec-azure-resource-manager": "0.62.0",
"@azure-tools/typespec-azure-resource-manager": "0.62.1",
"@azure-tools/typespec-autorest": "0.62.0"
},
"private": true
Expand Down
Loading
Loading