Skip to content

Commit

Permalink
logic to not change enum to string type for data-plane path/url param…
Browse files Browse the repository at this point in the history
…eter
  • Loading branch information
haolingdong-msft committed Nov 1, 2024
1 parent 54b0d8a commit 27d1069
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class CodeModelBuilder {
} else {
const schema = this.processSchema(arg.type, arg.name);
this.trackSchemaUsage(schema, {
usage: [SchemaContext.Input, SchemaContext.Output /*SchemaContext.Public*/],
usage: [SchemaContext.Input, SchemaContext.Output, SchemaContext.Public],
});
parameter = new Parameter(arg.name, arg.doc ?? "", schema, {
implementation: ImplementationLocation.Client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.IterableType;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ListType;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.PrimitiveType;
import org.apache.tools.ant.taskdefs.Java;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
Expand Down Expand Up @@ -223,7 +225,12 @@ public static IType removeModelFromParameter(RequestParameterLocation parameterR
returnType = ClassType.BINARY_DATA;
} else if (!(returnType instanceof PrimitiveType)) {
if (type instanceof EnumType) {
returnType = ClassType.STRING;
boolean isPathOrURIParameter = RequestParameterLocation.PATH == parameterRequestLocation
|| RequestParameterLocation.URI == parameterRequestLocation;
boolean isEnumAsString = !(JavaSettings.getInstance().isDataPlaneClient() && isPathOrURIParameter);
if (isEnumAsString) { // do not change enum to string type for data-plane path/url parameter
returnType = ClassType.STRING;
}
}
if (type instanceof IterableType && ((IterableType) type).getElementType() instanceof EnumType) {
returnType = new IterableType(ClassType.STRING);
Expand Down

0 comments on commit 27d1069

Please sign in to comment.