Skip to content

Commit

Permalink
http-client-java, fix client accessor method parameter description (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaofeiCao authored Dec 10, 2024
1 parent 86f3649 commit 8919ac8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClassType;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientEnumValue;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientMethod;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientMethodParameter;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientModel;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientModelProperty;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.EnumType;
Expand All @@ -25,6 +24,7 @@
import com.microsoft.typespec.http.client.generator.core.model.javamodel.JavaType;
import com.microsoft.typespec.http.client.generator.core.util.ClientModelUtil;
import com.microsoft.typespec.http.client.generator.core.util.CodeNamer;
import com.microsoft.typespec.http.client.generator.core.util.MethodUtil;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -136,7 +136,7 @@ protected static void generateProtocolMethodJavadoc(ClientMethod clientMethod, J
}

clientMethod.getParameters()
.forEach(p -> commentBlock.param(p.getName(), methodParameterDescriptionOrDefault(p)));
.forEach(p -> commentBlock.param(p.getName(), MethodUtil.methodParameterDescriptionOrDefault(p)));
if (clientMethod.getProxyMethod() != null) {
generateJavadocExceptions(clientMethod, commentBlock, false);
}
Expand Down Expand Up @@ -353,14 +353,6 @@ private static String parameterDescriptionOrDefault(ProxyMethodParameter paramet
return description;
}

private static String methodParameterDescriptionOrDefault(ClientMethodParameter p) {
String doc = p.getDescription();
if (CoreUtils.isNullOrEmpty(doc)) {
doc = String.format("The %1$s parameter", p.getName());
}
return doc;
}

private static String appendOptionalOrRequiredAttribute(boolean isRequired, boolean isRequiredForCreate,
boolean isRootSchema) {
if (isRootSchema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.microsoft.typespec.http.client.generator.core.model.javamodel.JavaFile;
import com.microsoft.typespec.http.client.generator.core.model.javamodel.JavaVisibility;
import com.microsoft.typespec.http.client.generator.core.util.ClientModelUtil;
import com.microsoft.typespec.http.client.generator.core.util.MethodUtil;
import com.microsoft.typespec.http.client.generator.core.util.ModelNamer;
import com.microsoft.typespec.http.client.generator.core.util.TemplateUtil;
import java.util.HashSet;
Expand Down Expand Up @@ -241,7 +242,7 @@ static void writeSubClientAccessors(ServiceClient serviceClient, JavaClass class
classBlock.javadocComment(comment -> {
comment.description("Gets an instance of " + subClientClassName + " class.");
for (ClientMethodParameter property : methodParameters) {
comment.param(property.getName(), property.getDescription());
comment.param(property.getName(), MethodUtil.methodParameterDescriptionOrDefault(property));
}
comment.methodReturns("an instance of " + subClientClassName + "class");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.microsoft.typespec.http.client.generator.core.template.prototype.MethodTemplate;
import com.microsoft.typespec.http.client.generator.core.util.ClientModelUtil;
import com.microsoft.typespec.http.client.generator.core.util.CodeNamer;
import com.microsoft.typespec.http.client.generator.core.util.MethodUtil;
import com.microsoft.typespec.http.client.generator.core.util.ModelNamer;
import com.microsoft.typespec.http.client.generator.core.util.TemplateUtil;
import java.util.ArrayList;
Expand Down Expand Up @@ -386,7 +387,7 @@ private static void writeClientAccessorMethods(JavaClass classBlock,
classBlock.javadocComment(comment -> {
comment.description("Gets an instance of " + subClientName + " class.");
for (ClientMethodParameter parameter : methodParameters) {
comment.param(parameter.getName(), parameter.getDescription());
comment.param(parameter.getName(), MethodUtil.methodParameterDescriptionOrDefault(parameter));
}
comment.methodReturns("an instance of " + subClientName + "class");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClassType;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientEnumValue;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientMethod;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientMethodParameter;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.EnumType;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.IType;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ProxyMethod;
Expand Down Expand Up @@ -326,6 +327,20 @@ public static Optional<String> serializedNameOfMaxPageSizeParameter(ProxyMethod
.findFirst();
}

/**
* Gets method parameter description, or a default description if not exists.
*
* @param p the client method parameter
* @return the method parameter description
*/
public static String methodParameterDescriptionOrDefault(ClientMethodParameter p) {
String doc = p.getDescription();
if (CoreUtils.isNullOrEmpty(doc)) {
doc = String.format("The %1$s parameter", p.getName());
}
return doc;
}

/**
*
* @param request the input request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class ClientInitializationAsyncClient {
/**
* Gets an instance of SubAsyncClient class.
*
* @param name
* @param name The name parameter.
* @return an instance of SubAsyncClientclass.
*/
public SubAsyncClient getSubAsyncClient(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class ClientInitializationClient {
/**
* Gets an instance of SubClient class.
*
* @param name
* @param name The name parameter.
* @return an instance of SubClientclass.
*/
public SubClient getSubClient(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ClientInitializationClientImpl(HttpPipeline httpPipeline, SerializerAdapt
/**
* Gets an instance of SubClientImpl class.
*
* @param name
* @param name The name parameter.
* @return an instance of SubClientImplclass.
*/
public SubClientImpl getSubClient(String name) {
Expand Down

0 comments on commit 8919ac8

Please sign in to comment.