Skip to content

Conversation

@weidongxu-microsoft
Copy link
Contributor

@weidongxu-microsoft weidongxu-microsoft commented Nov 25, 2025

fix Azure/autorest.java#3225

This is already supported in DPG.
Here we support this for management. It should also apply to azure-v2, but we do not have test on it (as azure-v2 lib is not released).

This is enabled by advanced-versioning emitter option.

Test case

@added(Versions.v2024_10_01_preview)
@query
newParameter?: string;

The difference on output be demonstrated here
2fe0045

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for advanced-versioning in non-DPG (Data Plane Generation) mode for the http-client-java emitter, specifically targeting management (ARM) scenarios. The feature generates method overloads for operations with versioned parameters, allowing REST APIs to add optional parameters across versions while maintaining backward compatibility.

Key changes:

  • Updates @azure-tools/typespec-azure-resource-manager dependency from 0.62.0 to 0.62.1
  • Extends versioning support from DPG to management plane code generation
  • Adds logic to generate multiple method signatures for operations with @added versioned parameters
  • Includes comprehensive test case with ARM resource operations demonstrating the feature

Reviewed changes

Copilot reviewed 36 out of 40 changed files in this pull request and generated 62 comments.

Show a summary per file
File Description
packages/http-client-java/package.json Updates dependency versions including ARM resource manager to 0.62.1
packages/http-client-java/package-lock.json Lock file updates matching package.json changes
packages/http-client-java/generator/http-client-generator-test/tsp/arm-versioned.tsp New TypeSpec test specification demonstrating versioned ARM operations
packages/http-client-java/generator/http-client-generator-test/Generate.ps1 Adds configuration to enable advanced-versioning option for arm-versioned test
packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ClientMethodMapper.java Refactors versioning overload generation to support non-DPG scenarios with context parameters
packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java Improves logic for determining when optional parameters need local variable instantiation
packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentClientMethodMapper.java Adds versioning overload generation for LRO methods in management plane
packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/fluentmodel/ResourceOperation.java Improves parameter selection by choosing client method with most parameters
Multiple generated Java files Generated test code demonstrating the advanced-versioning feature output
Files not reviewed (1)
  • packages/http-client-java/package-lock.json: Language not supported

@weidongxu-microsoft weidongxu-microsoft marked this pull request as draft November 26, 2025 09:06
@weidongxu-microsoft
Copy link
Contributor Author

weidongxu-microsoft commented Nov 26, 2025

Updated test case (now include Get and Delete)

Difference on output demonstrated

@weidongxu-microsoft weidongxu-microsoft marked this pull request as ready for review November 26, 2025 10:14
@weidongxu-microsoft weidongxu-microsoft marked this pull request as draft November 27, 2025 01:39
@weidongxu-microsoft weidongxu-microsoft changed the title http-client-java, support advanced-versioning in non-DPG http-client-java, support advanced-versioning on @added optional parameter in TypeSpec, in non-DPG Nov 27, 2025
@weidongxu-microsoft weidongxu-microsoft marked this pull request as ready for review November 28, 2025 01:52
$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?

* Mono<PagedResponseBase<H,T>>.
*/
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?

// 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();
// If the parameter isn't required and the client method only uses required parameters,
Copy link
Member

Choose a reason for hiding this comment

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

the client method only uses required parameters: just trying to understasnd the meaning. Does it mean in the client method with only required parameters, we need to initialize the optional parameters value? But I thought in client method with full parameters, we need to initialize optional parameters if user does not provide as well.
Would be awesome if we could add an example (better in javadoc) to explain the case we want to handle in the logics from line 176-190?


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.

* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
void delete(String resourceGroupName, String topLevelArmResourcePropertiesName);
Copy link
Member

Choose a reason for hiding this comment

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

Does delete need overloaded functions similar as deleteWithResponse? e.g.

void delete(String resourceGroupName, String topLevelArmResourcePropertiesName, String parameter, Context context)

void delete(String resourceGroupName, String topLevelArmResourcePropertiesName, String parameter, String newParameter, Context context)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:java Issue for the Java client emitter: @typespec/http-client-java

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mgmt, support advanced-versioning on @added optional parameter in TypeSpec

4 participants