From 8214ed6bb1d27becbecd9315a7126059d082f3f7 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 19 Dec 2024 20:11:32 +0800 Subject: [PATCH] http-client-java, initial on unbranded pageable (#5410) link https://github.com/microsoft/typespec/issues/5350 target https://github.com/Azure/azure-sdk-for-java/pull/43484/files first step to get most things ready. detail still depends on clientcore API locally tested against the azure/payload/pageable case --- .../emitter/src/code-model-builder.ts | 7 +- .../http-client-java/emitter/src/emitter.ts | 13 ++- .../core/mapper/ClientMethodMapper.java | 18 +-- .../core/mapper/ProxyMethodMapper.java | 1 + .../core/model/clientmodel/ClassType.java | 4 +- .../core/model/clientmodel/GenericType.java | 12 +- .../core/template/ClientMethodTemplate.java | 103 +++++++++++------- .../template/ClientMethodTemplateBase.java | 2 +- .../example/ProtocolExampleWriter.java | 3 +- .../generator/core/util/TemplateUtil.java | 8 +- .../http/client/generator/util/ModelUtil.java | 5 +- 11 files changed, 110 insertions(+), 66 deletions(-) diff --git a/packages/http-client-java/emitter/src/code-model-builder.ts b/packages/http-client-java/emitter/src/code-model-builder.ts index 691af914bd..7aeee04156 100644 --- a/packages/http-client-java/emitter/src/code-model-builder.ts +++ b/packages/http-client-java/emitter/src/code-model-builder.ts @@ -2562,8 +2562,11 @@ export class CodeModelBuilder { return this.baseJavaNamespace; } } else { - // special handling for namespace of model in TypeSpec.Rest.Resource - if (type.crossLanguageDefinitionId.startsWith("TypeSpec.Rest.Resource.")) { + // special handling for namespace of model in TypeSpec + if (type.crossLanguageDefinitionId === "TypeSpec.Http.File") { + // TypeSpec.Http.File + return this.baseJavaNamespace; + } else if (type.crossLanguageDefinitionId.startsWith("TypeSpec.Rest.Resource.")) { // models in TypeSpec.Rest.Resource return this.baseJavaNamespace; } diff --git a/packages/http-client-java/emitter/src/emitter.ts b/packages/http-client-java/emitter/src/emitter.ts index ca4246c473..5bd109978f 100644 --- a/packages/http-client-java/emitter/src/emitter.ts +++ b/packages/http-client-java/emitter/src/emitter.ts @@ -10,6 +10,7 @@ import { dump } from "js-yaml"; import { dirname } from "path"; import { fileURLToPath } from "url"; import { CodeModelBuilder } from "./code-model-builder.js"; +import { CodeModel } from "./common/code-model.js"; import { logError, spawnAsync } from "./utils.js"; import { JDK_NOT_FOUND_MESSAGE, validateDependencies } from "./validate.js"; @@ -125,10 +126,16 @@ export async function $onEmit(context: EmitContext) { options["flavor"] = "azure"; } } - const builder = new CodeModelBuilder(program, context); - const codeModel = await builder.build(); - if (!program.hasError() && !program.compilerOptions.noEmit) { + let codeModel: CodeModel | undefined; + try { + const builder = new CodeModelBuilder(program, context); + codeModel = await builder.build(); + } catch (error: any) { + logError(program, error.message); + } + + if (codeModel && !program.hasError() && !program.compilerOptions.noEmit) { const __dirname = dirname(fileURLToPath(import.meta.url)); const moduleRoot = resolvePath(__dirname, "..", ".."); diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ClientMethodMapper.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ClientMethodMapper.java index 9ed03cdecc..cfab551578 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ClientMethodMapper.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ClientMethodMapper.java @@ -296,17 +296,10 @@ private List createClientMethods(Operation operation, boolean isPr // in this case, it is not original parameter from any other parameters for (Parameter parameter : request.getParameters() .stream() - .filter(p -> p.isFlattened() && p.getProtocol() != null && p.getProtocol().getHttp() != null) // flattened - // proxy - // parameter - .filter(p -> !originalParameters.contains(p)) // but - // not - // original - // parameter - // from - // any - // other - // parameters + // flattened proxy parameter + .filter(p -> p.isFlattened() && p.getProtocol() != null && p.getProtocol().getHttp() != null) + // but not original parameter from any other parameters + .filter(p -> !originalParameters.contains(p)) .collect(Collectors.toList())) { ClientMethodParameter outParameter = Mappers.getClientParameterMapper().map(parameter); methodTransformationDetails.add(new MethodTransformationDetail(outParameter, new ArrayList<>())); @@ -616,7 +609,8 @@ private ReturnTypeHolder getReturnTypes(Operation operation, boolean isProtocolM .ifPresentOrElse(itemProperty -> { IType listType = itemProperty.getWireType(); IType elementType = ((ListType) listType).getElementType(); - if (isProtocolMethod) { + // unbranded would use the model, instead of BinaryData, as return type + if (isProtocolMethod && settings.isBranded()) { returnTypeHolder.asyncRestResponseReturnType = createProtocolPagedRestResponseReturnType(); returnTypeHolder.asyncReturnType = createProtocolPagedAsyncReturnType(); returnTypeHolder.syncReturnType = createProtocolPagedSyncReturnType(); diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ProxyMethodMapper.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ProxyMethodMapper.java index 10cb481dc8..361ba58b1a 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ProxyMethodMapper.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ProxyMethodMapper.java @@ -99,6 +99,7 @@ public Map> map(Operation operation) { builder.responseExpectedStatusCodes(expectedStatusCodes); IType responseBodyType = MapperUtils.handleResponseSchema(operation, settings); + // unbranded would use the model, instead of BinaryData, as return type if (settings.isDataPlaneClient() && settings.isBranded()) { builder.rawResponseBodyType(responseBodyType); responseBodyType = SchemaUtil.removeModelFromResponse(responseBodyType, operation); diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClassType.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClassType.java index 37e8ae191e..a555b1688d 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClassType.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClassType.java @@ -451,7 +451,9 @@ private static ClassType.Builder getClassTypeBuilder(Class classKey) { public static final ClassType INPUT_STREAM = new ClassType.Builder(false).knownClass(InputStream.class).build(); public static final ClassType CONTEXT = ClassType.getClassTypeBuilder(Context.class) - .defaultValueExpressionConverter(epr -> "com.azure.core.util.Context.NONE") + .defaultValueExpressionConverter( + epr -> (JavaSettings.getInstance().isBranded() ? "com.azure.core.util." : "io.clientcore.core.util.") + + TemplateUtil.getContextNone()) .build(); public static final ClassType ANDROID_CONTEXT diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/GenericType.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/GenericType.java index 2ab1de233b..6b24c13169 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/GenericType.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/GenericType.java @@ -84,7 +84,11 @@ public static GenericType RestResponse(IType headersType, IType bodyType) { } public static GenericType PagedResponse(IType bodyType) { - return new GenericType("com.azure.core.http.rest", "PagedResponse", bodyType); + if (JavaSettings.getInstance().isBranded()) { + return new GenericType("com.azure.core.http.rest", "PagedResponse", bodyType); + } else { + return new GenericType("io.clientcore.core.http.models", "PagedResponse", bodyType); + } } public static GenericType PagedFlux(IType bodyType) { @@ -92,7 +96,11 @@ public static GenericType PagedFlux(IType bodyType) { } public static GenericType PagedIterable(IType bodyType) { - return new GenericType("com.azure.core.http.rest", "PagedIterable", bodyType); + if (JavaSettings.getInstance().isBranded()) { + return new GenericType("com.azure.core.http.rest", "PagedIterable", bodyType); + } else { + return new GenericType("io.clientcore.core.http.models", "PagedIterable", bodyType); + } } public static GenericType Function(IType inputType, IType outputType) { diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java index 1f8ac5fe25..b47a895ce0 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java @@ -699,7 +699,8 @@ protected void generateProtocolPagingPlainSync(ClientMethod clientMethod, JavaTy function.line("RequestOptions requestOptionsForNextPage = new RequestOptions();"); function.line( - "requestOptionsForNextPage.setContext(requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE);"); + "requestOptionsForNextPage.setContext(requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : " + + TemplateUtil.getContextNone() + ");"); function.line("return new PagedIterable<>("); function.indent(() -> { @@ -768,32 +769,49 @@ private void generatePagedSinglePage(ClientMethod clientMethod, JavaType typeBlo String serviceMethodCall = checkAndReplaceParamNameCollision(clientMethod, restAPIMethod, requestOptionsLocal, settings); function.line(String.format("%s res = %s;", restAPIMethod.getReturnType(), serviceMethodCall)); - function.line("return new PagedResponseBase<>("); - function.line("res.getRequest(),"); - function.line("res.getStatusCode(),"); - function.line("res.getHeaders(),"); - if (settings.isDataPlaneClient()) { - function.line("getValues(res.getValue(), \"%s\"),", - clientMethod.getMethodPageDetails().getSerializedItemName()); - } else { - function.line("res.getValue().%s(),", CodeNamer.getModelNamer() - .modelPropertyGetterName(clientMethod.getMethodPageDetails().getItemName())); - } - if (clientMethod.getMethodPageDetails().nonNullNextLink()) { + if (settings.isBranded()) { + function.line("return new PagedResponseBase<>("); + function.line("res.getRequest(),"); + function.line("res.getStatusCode(),"); + function.line("res.getHeaders(),"); if (settings.isDataPlaneClient()) { - function.line("getNextLink(res.getValue(), \"%s\"),", - clientMethod.getMethodPageDetails().getSerializedNextLinkName()); + function.line("getValues(res.getValue(), \"%s\"),", + clientMethod.getMethodPageDetails().getSerializedItemName()); } else { - function.line(nextLinkLine(clientMethod)); + function.line("res.getValue().%s(),", CodeNamer.getModelNamer() + .modelPropertyGetterName(clientMethod.getMethodPageDetails().getItemName())); + } + if (clientMethod.getMethodPageDetails().nonNullNextLink()) { + if (settings.isDataPlaneClient()) { + function.line("getNextLink(res.getValue(), \"%s\"),", + clientMethod.getMethodPageDetails().getSerializedNextLinkName()); + } else { + function.line(nextLinkLine(clientMethod)); + } + } else { + function.line("null,"); } - } else { - function.line("null,"); - } - if (responseTypeHasDeserializedHeaders(clientMethod.getProxyMethod().getReturnType())) { - function.line("res.getDeserializedHeaders());"); + if (responseTypeHasDeserializedHeaders(clientMethod.getProxyMethod().getReturnType())) { + function.line("res.getDeserializedHeaders());"); + } else { + function.line("null);"); + } } else { - function.line("null);"); + function.line("return new PagedResponse<>("); + function.line("res.getRequest(),"); + function.line("res.getStatusCode(),"); + function.line("res.getHeaders(),"); + function.line("res.getBody(),"); + function.line("res.getValue().%s(),", CodeNamer.getModelNamer() + .modelPropertyGetterName(clientMethod.getMethodPageDetails().getItemName())); + if (clientMethod.getMethodPageDetails().nonNullNextLink()) { + String nextLinkLine = nextLinkLine(clientMethod); + nextLinkLine = nextLinkLine.substring(0, nextLinkLine.length() - 1); + function.line(nextLinkLine + ");"); + } else { + function.line("null);"); + } } }); } @@ -816,7 +834,8 @@ protected void generatePagingPlainSync(ClientMethod clientMethod, JavaType typeB if (settings.isDataPlaneClient()) { function.line("RequestOptions requestOptionsForNextPage = new RequestOptions();"); function.line( - "requestOptionsForNextPage.setContext(requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE);"); + "requestOptionsForNextPage.setContext(requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : " + + TemplateUtil.getContextNone() + ");"); } function.line("return new PagedIterable<>("); @@ -826,12 +845,12 @@ protected void generatePagingPlainSync(ClientMethod clientMethod, JavaType typeB .replace("requestOptions", "requestOptionsForNextPage"); String firstPageArgs = clientMethod.getArgumentList(); if (clientMethod.getParameters().stream().noneMatch(p -> p.getClientType() == ClassType.CONTEXT)) { - nextMethodArgs = nextMethodArgs.replace("context", "Context.NONE"); + nextMethodArgs = nextMethodArgs.replace("context", TemplateUtil.getContextNone()); if (!CoreUtils.isNullOrEmpty(firstPageArgs)) { - firstPageArgs = firstPageArgs + ", Context.NONE"; + firstPageArgs = firstPageArgs + ", " + TemplateUtil.getContextNone(); } else { // If there are no first page arguments don't include a leading comma. - firstPageArgs = "Context.NONE"; + firstPageArgs = TemplateUtil.getContextNone(); } } String effectiveNextMethodArgs = nextMethodArgs; @@ -856,10 +875,10 @@ protected void generatePagingPlainSync(ClientMethod clientMethod, JavaType typeB String firstPageArgs = clientMethod.getArgumentList(); if (clientMethod.getParameters().stream().noneMatch(p -> p.getClientType() == ClassType.CONTEXT)) { if (!CoreUtils.isNullOrEmpty(firstPageArgs)) { - firstPageArgs = firstPageArgs + ", Context.NONE"; + firstPageArgs = firstPageArgs + ", " + TemplateUtil.getContextNone(); } else { // If there are no first page arguments don't include a leading comma. - firstPageArgs = "Context.NONE"; + firstPageArgs = TemplateUtil.getContextNone(); } } String effectiveFirstPageArgs = firstPageArgs; @@ -881,7 +900,8 @@ protected void generatePagingAsync(ClientMethod clientMethod, JavaType typeBlock if (settings.isDataPlaneClient()) { function.line("RequestOptions requestOptionsForNextPage = new RequestOptions();"); function.line( - "requestOptionsForNextPage.setContext(requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE);"); + "requestOptionsForNextPage.setContext(requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : " + + TemplateUtil.getContextNone() + ");"); } function.line("return new PagedFlux<>("); function.indent(() -> { @@ -955,10 +975,10 @@ private void generateSimpleSyncMethod(ClientMethod clientMethod, JavaType typeBl String argumentList = clientMethod.getArgumentList(); if (CoreUtils.isNullOrEmpty(argumentList)) { // If there are no arguments the argument is Context.NONE - argumentList = "Context.NONE"; + argumentList = TemplateUtil.getContextNone(); } else if (clientMethod.getParameters().stream().noneMatch(p -> p.getClientType() == ClassType.CONTEXT)) { // If the arguments don't contain Context append Context.NONE - argumentList += ", Context.NONE"; + argumentList += ", " + TemplateUtil.getContextNone(); } if (ClassType.STREAM_RESPONSE.equals(clientMethod.getReturnValue().getType())) { @@ -981,10 +1001,10 @@ private void generateSimplePlainSyncMethod(ClientMethod clientMethod, JavaType t String argumentList = clientMethod.getArgumentList(); if (CoreUtils.isNullOrEmpty(argumentList)) { // If there are no arguments the argument is Context.NONE - argumentList = "Context.NONE"; + argumentList = TemplateUtil.getContextNone(); } else if (clientMethod.getParameters().stream().noneMatch(p -> p.getClientType() == ClassType.CONTEXT)) { // If the arguments don't contain Context append Context.NONE - argumentList += ", Context.NONE"; + argumentList += ", " + TemplateUtil.getContextNone(); } if (clientMethod.getReturnValue().getType().equals(PrimitiveType.VOID)) { @@ -1225,7 +1245,7 @@ protected void generatePagedAsyncSinglePage(ClientMethod clientMethod, JavaType function.line("res.getRequest(),"); function.line("res.getStatusCode(),"); function.line("res.getHeaders(),"); - if (settings.isDataPlaneClient()) { + if (settings.isDataPlaneClient() && settings.isBranded()) { function.line("getValues(res.getValue(), \"%s\"),", clientMethod.getMethodPageDetails().getSerializedItemName()); } else { @@ -1233,7 +1253,7 @@ protected void generatePagedAsyncSinglePage(ClientMethod clientMethod, JavaType .modelPropertyGetterName(clientMethod.getMethodPageDetails().getItemName())); } if (clientMethod.getMethodPageDetails().nonNullNextLink()) { - if (settings.isDataPlaneClient()) { + if (settings.isDataPlaneClient() && settings.isBranded()) { function.line("getNextLink(res.getValue(), \"%s\"),", clientMethod.getMethodPageDetails().getSerializedNextLinkName()); } else { @@ -1319,7 +1339,7 @@ private static String checkAndReplaceParamNameCollision(ClientMethod clientMetho // which isn't 'Context'. This can be done by looking for the 'ProxyMethodParameter' with the // matching name and checking if it's the 'Context' parameter. parameterName = (parameter == null && "context".equals(proxyMethodArgument)) - ? "Context.NONE" + ? TemplateUtil.getContextNone() : proxyMethodArgument; } } @@ -1422,7 +1442,7 @@ protected void generateLongRunningBeginAsync(ClientMethod clientMethod, JavaType if (clientMethod.getParameters().stream().anyMatch(p -> p.getClientType().equals(ClassType.CONTEXT))) { contextParam = "context"; } else { - contextParam = "Context.NONE"; + contextParam = TemplateUtil.getContextNone(); } String pollingStrategy = getPollingStrategy(clientMethod, contextParam); typeBlock.annotation("ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)"); @@ -1471,17 +1491,17 @@ protected void generateLongRunningBeginSync(ClientMethod clientMethod, JavaType if (clientMethod.getParameters().stream().anyMatch(p -> p.getClientType().equals(ClassType.CONTEXT))) { contextParam = "context"; } else { - contextParam = "Context.NONE"; + contextParam = TemplateUtil.getContextNone(); } String pollingStrategy = getSyncPollingStrategy(clientMethod, contextParam); String argumentList = clientMethod.getArgumentList(); if (CoreUtils.isNullOrEmpty(argumentList)) { // If there are no arguments the argument is Context.NONE - argumentList = "Context.NONE"; + argumentList = TemplateUtil.getContextNone(); } else if (clientMethod.getParameters().stream().noneMatch(p -> p.getClientType() == ClassType.CONTEXT)) { // If the arguments don't contain Context append Context.NONE - argumentList += ", Context.NONE"; + argumentList += ", " + TemplateUtil.getContextNone(); } String effectiveArgumentList = argumentList; @@ -1502,7 +1522,8 @@ protected void generateLongRunningBeginSync(ClientMethod clientMethod, JavaType private void generateProtocolLongRunningBeginSync(ClientMethod clientMethod, JavaType typeBlock) { String contextParam - = "requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE"; + = "requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : " + + TemplateUtil.getContextNone(); String pollingStrategy = getSyncPollingStrategy(clientMethod, contextParam); typeBlock.annotation("ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)"); writeMethod(typeBlock, clientMethod.getMethodVisibility(), clientMethod.getDeclaration(), function -> { diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplateBase.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplateBase.java index ecd24a326e..3f82443f39 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplateBase.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplateBase.java @@ -86,7 +86,7 @@ protected static void generateProtocolMethodJavadoc(ClientMethod clientMethod, J // Response body IType responseBodyType; - if (JavaSettings.getInstance().isDataPlaneClient()) { + if (JavaSettings.getInstance().isDataPlaneClient() && JavaSettings.getInstance().isBranded()) { // special handling for paging method if (clientMethod.getType().isPaging()) { String itemName = clientMethod.getMethodPageDetails().getItemName(); diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/example/ProtocolExampleWriter.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/example/ProtocolExampleWriter.java index 71b94a70c0..0d4264d73b 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/example/ProtocolExampleWriter.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/example/ProtocolExampleWriter.java @@ -30,6 +30,7 @@ import com.microsoft.typespec.http.client.generator.core.model.javamodel.JavaBlock; import com.microsoft.typespec.http.client.generator.core.util.CodeNamer; import com.microsoft.typespec.http.client.generator.core.util.ModelExampleUtil; +import com.microsoft.typespec.http.client.generator.core.util.TemplateUtil; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -222,7 +223,7 @@ public ProtocolExampleWriter(ProtocolExample protocolExample) { if (parameter.getClientType() == ClassType.REQUEST_OPTIONS) { params.set(i, "requestOptions"); } else if (parameter.getClientType() == ClassType.CONTEXT) { - params.set(i, "Context.NONE"); + params.set(i, TemplateUtil.getContextNone()); } } String methodCall = String.format("%s.%s(%s)", clientVarName, method.getName(), String.join(", ", params)); diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java index 9afe9513ee..d511f7e3d9 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java @@ -161,7 +161,9 @@ public static void writeClientMethodsAndHelpers(JavaClass classBlock, List m.getMethodPageDetails() != null)) { + if (settings.isDataPlaneClient() + && settings.isBranded() + && clientMethods.stream().anyMatch(m -> m.getMethodPageDetails() != null)) { writePagingHelperMethods(classBlock); } } @@ -368,4 +370,8 @@ public static String escapeString(String str) { builder.append(str, last, str.length()); return builder.toString(); } + + public static String getContextNone() { + return JavaSettings.getInstance().isBranded() ? "Context.NONE" : "Context.none()"; + } } diff --git a/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/util/ModelUtil.java b/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/util/ModelUtil.java index c13e10621c..7cc5495e98 100644 --- a/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/util/ModelUtil.java +++ b/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/util/ModelUtil.java @@ -3,6 +3,7 @@ package com.microsoft.typespec.http.client.generator.util; +import com.microsoft.typespec.http.client.generator.core.extension.plugin.JavaSettings; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClassType; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientModel; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientResponse; @@ -12,13 +13,13 @@ import com.microsoft.typespec.http.client.generator.core.model.clientmodel.UnionModel; import com.microsoft.typespec.http.client.generator.core.util.ClientModelUtil; -public class ModelUtil { +public final class ModelUtil { public static boolean isGeneratingModel(ClientModel model) { return model.getImplementationDetails() != null && (model.getImplementationDetails().isPublic() || model.getImplementationDetails().isInternal()) && !(isExternalModel(model.getImplementationDetails())) - && !(isPagedModel(model.getImplementationDetails())); + && !(JavaSettings.getInstance().isBranded() && isPagedModel(model.getImplementationDetails())); } public static boolean isGeneratingModel(EnumType model) {