Skip to content

ClientMethodTemplate: Remove method parameters that can be obtained from other parameters and Improve ClientType to WireType function #7483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

anuchandy
Copy link
Member

@anuchandy anuchandy commented May 27, 2025

  1. In ClientMethodTemplate (and its extended types) methods, there is no need to pass ProxyMethod as an explicit argument, since it can be obtained from ClientMethod argument.
  2. Similarly, no need to provide List<ProxyMethodParameter> explicitly when it can be obtained from ClientMethod ::ProxyMethod::parameters
  3. The function convertClientTypesToWireTypes has been simplified and updated to be extensible for future prs that aim to simplify inherited templates such as client core.
  4. Few other minor cleanup for readability.

AutoRest validation pr.

@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:java Issue for the Java client emitter: @typespec/http-client-java label May 27, 2025
Copy link
Contributor

No changes needing a change description found.

@anuchandy anuchandy self-assigned this May 27, 2025
@azure-sdk
Copy link
Collaborator

azure-sdk commented May 27, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@anuchandy anuchandy marked this pull request as draft May 28, 2025 02:24
Comment on lines -112 to -115
if (!expressionsToCheckSet.contains(validateExpression.getKey())) {
function.ifBlock(validateExpression.getKey() + " != null",
ifBlock -> ifBlock.line(validateExpression.getValue() + ";"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure whether there could be impact from this condition.

Copy link
Member Author

Choose a reason for hiding this comment

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

We now use a HashMap (validateParamExpressions) from which already validated expressions are removed during the first iteration. So, the remaining expressions those have not yet been validated are handled here. Hence there will be no change in how the generated code looks like.

@anuchandy anuchandy force-pushed the clientMethodTemplate-minor-cleanup branch from d8a2342 to e73a408 Compare May 28, 2025 20:13
List<ProxyMethodParameter> autoRestMethodRetrofitParameters) {
for (ProxyMethodParameter parameter : autoRestMethodRetrofitParameters) {
protected static void convertClientTypesToWireTypes(JavaBlock function, ClientMethod clientMethod) {
final List<ProxyMethodParameter> proxyMethodParameters = clientMethod.getProxyMethod().getParameters();
Copy link
Member Author

Choose a reason for hiding this comment

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

Conditional checks in this method are simplified, reduced variable scopes and making it extensible so derived templates can reuse or override parts of the conversion.

* @param wireType the wire type of the parameter, used to determine the method to call for encoding.
* @return Java code that converts a byte[] parameter to a Base64 URL encoded string.
*/
private static String byteArrayToBase64UrlEncodedString(String parameterName, IType wireType) {
Copy link
Member Author

Choose a reason for hiding this comment

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

For example, plan is to change this new method to protected instance method so client-core template can override to use Base64 type from new core.

// Refer iterableToWireStringValuesList(..)'
parameterWireType = new ListType(ClassType.STRING);
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This block is an expanded version of the original code, but with structure now consistent with structure of conversion code, which improves the readability. It also simplifies, for instance, the explode is applicable only to IterableType, as seen in the subsequent code generating the conversion.

@anuchandy anuchandy changed the title ClientMethodTemplate: Remove method parameters that can be obtained from other parameters ClientMethodTemplate: Remove method parameters that can be obtained from other parameters and Improve ClientType to WireType function May 29, 2025
@anuchandy anuchandy marked this pull request as ready for review May 29, 2025 00:15
@anuchandy anuchandy force-pushed the clientMethodTemplate-minor-cleanup branch from 7912cb5 to cff5f07 Compare May 29, 2025 00:33
@haolingdong-msft
Copy link
Member

The changes look good to me.
Good to see we have autorest validation pipeline now. Would like to learn more about working with autorest core submodule(we had submodule before I leave, but at that time, we will just sync the code from typespec repo to autorest.java's core module in local before doing release). Got below questions:

  • My understanding is this pipeline is to run the tests (e.g. vanilla test, fluent test, typespec test) and make sure those are not broken by this pr's change. But I saw it is triggerred on main branch in autorest.java, so it does not include this pr's change, I'm a bit confused on what is this pipeline validating?
  • Is the pipeline triggered manually and when do we trigger it?
  • What is the current process of updating codegen?

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.

4 participants