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 d3606c60929..bd8f8dfc932 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 @@ -355,16 +355,35 @@ private static JavaVisibility methodVisibilityInWrapperClient(Operation operatio } } - private static void createOverloadForVersioning(boolean isProtocolMethod, List methods, - ClientMethod baseMethod) { + protected void createOverloadForVersioning(List methods, ClientMethod baseMethod, + ClientMethod overloadedMethod, JavaVisibility methodWithContextVisibility, + MethodPageDetails methodPageDetailsWithContext, boolean isProtocolMethod) { final List parameters = baseMethod.getParameters(); - if (!isProtocolMethod && JavaSettings.getInstance().isDataPlaneClient()) { + if (!isProtocolMethod) { if (parameters.stream().anyMatch(p -> p.getVersioning() != null && p.getVersioning().getAdded() != null)) { + // versioning of @added exists final List> signatures = findOverloadedSignatures(parameters); for (List overloadedParameters : signatures) { - final ClientMethod overloadedMethod - = baseMethod.newBuilder().parameters(overloadedParameters).build(); - methods.add(overloadedMethod); + if (JavaSettings.getInstance().isDataPlaneClient()) { + // DPG + final ClientMethod overloadMethod = baseMethod.newBuilder() + .overloadedClientMethod(overloadedMethod) + .parameters(overloadedParameters) + .build(); + methods.add(overloadMethod); + } else { + // non-DPG + ClientMethod.Builder overloadedMethodBuilder = baseMethod.newBuilder() + .overloadedClientMethod(overloadedMethod) + .parameters(overloadedParameters); + if (methodPageDetailsWithContext != null) { + overloadedMethodBuilder + = overloadedMethodBuilder.methodPageDetails(methodPageDetailsWithContext); + } + final ClientMethod overloadMethod = overloadedMethodBuilder.build(); + addClientMethodWithContext(methods, overloadMethod, methodWithContextVisibility, + isProtocolMethod); + } } } } @@ -457,7 +476,12 @@ private void createSinglePageClientMethods(boolean isSync, ClientMethod baseMeth } // Generate '[Operation]SinglePage' overload with all parameters and Context. - addClientMethodWithContext(methods, singlePageMethod, methodWithContextVisibility, isProtocolMethod); + ClientMethod clientMethodWithContext + = addClientMethodWithContext(methods, singlePageMethod, methodWithContextVisibility, isProtocolMethod); + + // Pageable op '[Operation]SinglePage' overloads for versioning + createOverloadForVersioning(methods, singlePageMethod, clientMethodWithContext, methodWithContextVisibility, + null, isProtocolMethod); } private void createPageStreamingClientMethods(boolean isSync, ClientMethod baseMethod, @@ -508,8 +532,6 @@ private void createPageStreamingClientMethods(boolean isSync, ClientMethod baseM if (settings.getSyncMethods() != SyncMethodsGeneration.NONE) { // generate the overload, if "sync-methods != NONE" methods.add(pagingMethod); - // overload for versioning - createOverloadForVersioning(isProtocolMethod, methods, pagingMethod); } if (generateRequiredOnlyParametersOverload) { @@ -526,7 +548,12 @@ private void createPageStreamingClientMethods(boolean isSync, ClientMethod baseM } else { pagingMethodWithContext = pagingMethod; } - addClientMethodWithContext(methods, pagingMethodWithContext, methodWithContextVisibility, isProtocolMethod); + ClientMethod clientMethodWithContext = addClientMethodWithContext(methods, pagingMethodWithContext, + methodWithContextVisibility, isProtocolMethod); + + // Pageable op '[Operation]' overloads for versioning + createOverloadForVersioning(methods, pagingMethod, clientMethodWithContext, methodWithContextVisibility, + methodPageDetailsWithContext, isProtocolMethod); } private void createLroWithResponseClientMethods(boolean isSync, ClientMethod baseMethod, List methods, @@ -575,7 +602,13 @@ private void createLroWithResponseClientMethods(boolean isSync, ClientMethod bas .hasWithContextOverload(methodWithContextVisibility != NOT_GENERATE) .build(); methods.add(withResponseMethod); - addClientMethodWithContext(methods, withResponseMethod, methodWithContextVisibility, isProtocolMethod); + + ClientMethod clientMethodWithContext + = addClientMethodWithContext(methods, withResponseMethod, methodWithContextVisibility, isProtocolMethod); + + // LRO '[Operation]WithResponse' overloads for versioning + createOverloadForVersioning(methods, withResponseMethod, clientMethodWithContext, methodWithContextVisibility, + null, isProtocolMethod); } private void createFluentLroWithResponseSyncClientMethods(Operation operation, ClientMethod baseMethod, @@ -614,7 +647,13 @@ private void createFluentLroWithResponseSyncClientMethods(Operation operation, C .methodVisibility(NOT_VISIBLE) .build(); methods.add(withResponseSyncMethod); - addClientMethodWithContext(methods, withResponseSyncMethod, NOT_VISIBLE, isProtocolMethod); + + ClientMethod clientMethodWithContext + = addClientMethodWithContext(methods, withResponseSyncMethod, NOT_VISIBLE, isProtocolMethod); + + // LRO '[Operation]' overloads for versioning + createOverloadForVersioning(methods, withResponseSyncMethod, clientMethodWithContext, NOT_VISIBLE, null, + isProtocolMethod); } private void createProtocolLroBeginClientMethods(ClientMethod baseMethod, PollingMetadata pollingMetadata, @@ -704,9 +743,6 @@ private void createLroBeginClientMethods(boolean isSync, ClientMethod lroBaseMet .build(); methods.add(beginLroMethod); - // LRO 'begin[Operation]' sync or async method overloads with versioning. - createOverloadForVersioning(isProtocolMethod, methods, beginLroMethod); - if (generateRequiredOnlyParametersOverload) { // LRO 'begin[Operation]' sync or async method overload with only required parameters. final ClientMethod beginLroMethodWithRequiredParameters = beginLroMethod.newBuilder() @@ -717,7 +753,12 @@ private void createLroBeginClientMethods(boolean isSync, ClientMethod lroBaseMet } // LRO 'begin[Operation]' sync or async method overload with only required with context parameters. - addClientMethodWithContext(methods, beginLroMethod, methodWithContextVisibility, isProtocolMethod); + ClientMethod clientMethodWithContext + = addClientMethodWithContext(methods, beginLroMethod, methodWithContextVisibility, isProtocolMethod); + + // LRO 'begin[Operation]' sync or async method overloads with versioning. + createOverloadForVersioning(methods, beginLroMethod, clientMethodWithContext, methodWithContextVisibility, null, + isProtocolMethod); } private void createSimpleClientMethods(boolean isSync, ClientMethod baseMethod, List methods, @@ -764,10 +805,16 @@ private void createSimpleWithResponseClientMethods(boolean isSync, ClientMethod .hasWithContextOverload(hasContextOverload) .methodVisibility(methodVisibility) .build(); + // Always generate an overload of WithResponse with non-required parameters without Context. It is only for sync // proxy method, and is usually filtered out in methodVisibility function. methods.add(withResponseMethod); - addClientMethodWithContext(methods, withResponseMethod, methodWithContextVisibility, isProtocolMethod); + ClientMethod clientMethodWithContext + = addClientMethodWithContext(methods, withResponseMethod, methodWithContextVisibility, isProtocolMethod); + + // Simple op '[Operation]WithResponse' overloads for versioning + createOverloadForVersioning(methods, withResponseMethod, clientMethodWithContext, methodWithContextVisibility, + null, isProtocolMethod); } private void createSimpleValueClientMethods(boolean isSync, ClientMethod baseMethod, List methods, @@ -807,9 +854,6 @@ private void createSimpleValueClientMethods(boolean isSync, ClientMethod baseMet .build(); methods.add(simpleMethod); - // overload for versioning - createOverloadForVersioning(isProtocolMethod, methods, simpleMethod); - if (generateRequiredOnlyParametersOverload) { final ClientMethod simpleMethodWithRequiredParameters = simpleMethod.newBuilder() .methodVisibility(methodWithRequiredParametersVisibility) @@ -817,7 +861,12 @@ private void createSimpleValueClientMethods(boolean isSync, ClientMethod baseMet .build(); methods.add(simpleMethodWithRequiredParameters); } - addClientMethodWithContext(methods, simpleMethod, methodWithContextVisibility, isProtocolMethod); + ClientMethod clientMethodWithContext + = addClientMethodWithContext(methods, simpleMethod, methodWithContextVisibility, isProtocolMethod); + + // Simple op '[Operation]' overloads for versioning + createOverloadForVersioning(methods, simpleMethod, clientMethodWithContext, methodWithContextVisibility, null, + isProtocolMethod); } /** @@ -937,8 +986,9 @@ protected ClientMethodParameter getContextParameter(boolean isProtocolMethod) { * @param baseMethod The method to use to obtain the builder for context enabled {@link ClientMethod}. * @param visibility The visibility for the context enabled client method. * @param isProtocolMethod Is protocol method. + * @return the client method with Context parameter. */ - protected void addClientMethodWithContext(List methods, ClientMethod baseMethod, + protected ClientMethod addClientMethodWithContext(List methods, ClientMethod baseMethod, JavaVisibility visibility, boolean isProtocolMethod) { final ClientMethodParameter contextParameter = getContextParameter(isProtocolMethod); final List parameters = new ArrayList<>(baseMethod.getParameters()); @@ -954,6 +1004,7 @@ protected void addClientMethodWithContext(List methods, ClientMeth .hasWithContextOverload(false) // WithContext overload doesn't have a withContext overload .build(); methods.add(withContextMethod); + return withContextMethod; } private static MethodNamer resolveMethodNamer(ProxyMethod proxyMethod, ConvenienceApi convenienceApi, diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/clientcore/ClientCoreClientMethodMapper.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/clientcore/ClientCoreClientMethodMapper.java index 6a29b714c95..7ba333d8fd2 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/clientcore/ClientCoreClientMethodMapper.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/clientcore/ClientCoreClientMethodMapper.java @@ -34,7 +34,7 @@ protected ClientMethodParameter getContextParameter(boolean isProtocolMethod) { } @Override - protected void addClientMethodWithContext(List methods, ClientMethod baseMethod, + protected ClientMethod addClientMethodWithContext(List methods, ClientMethod baseMethod, JavaVisibility visibility, boolean isProtocolMethod) { final ClientMethodParameter contextParameter = getContextParameter(isProtocolMethod); final List parameters = new ArrayList<>(baseMethod.getParameters()); @@ -48,5 +48,6 @@ protected void addClientMethodWithContext(List methods, ClientMeth .hasWithContextOverload(false) .build(); methods.add(withContextMethod); + return withContextMethod; } } diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClientMethod.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClientMethod.java index 64c21351671..292a655b7c7 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClientMethod.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClientMethod.java @@ -115,6 +115,8 @@ public class ClientMethod { private final String argumentList; private final OperationInstrumentationInfo instrumentationInfo; + private final ClientMethod overloadedClientMethod; + public ClientMethod.Builder newBuilder() { return new ClientMethod.Builder().description(description) .returnValue(returnValue) @@ -137,7 +139,8 @@ public ClientMethod.Builder newBuilder() { .methodDocumentation(externalDocumentation) .operationInstrumentationInfo(instrumentationInfo) .setCrossLanguageDefinitionId(crossLanguageDefinitionId) - .hasWithContextOverload(hasWithContextOverload); + .hasWithContextOverload(hasWithContextOverload) + .overloadedClientMethod(overloadedClientMethod); } /** @@ -171,7 +174,7 @@ protected ClientMethod(String description, ReturnValue returnValue, String name, JavaVisibility methodVisibilityInWrapperClient, ImplementationDetails implementationDetails, MethodPollingDetails methodPollingDetails, ExternalDocumentation externalDocumentation, String crossLanguageDefinitionId, boolean hasWithContextOverload, - OperationInstrumentationInfo instrumentationInfo) { + OperationInstrumentationInfo instrumentationInfo, ClientMethod overloadedClientMethod) { this.description = description; this.returnValue = returnValue; this.name = name; @@ -216,6 +219,7 @@ protected ClientMethod(String description, ReturnValue returnValue, String name, this.argumentList = getMethodParameters().stream().map(ClientMethodParameter::getName).collect(Collectors.joining(", ")); this.instrumentationInfo = instrumentationInfo; + this.overloadedClientMethod = overloadedClientMethod; } @Override @@ -443,6 +447,15 @@ public OperationInstrumentationInfo getOperationInstrumentationInfo() { return instrumentationInfo; } + /** + * Get the overloaded client method associated with this ClientMethod. + * + * @return the overloaded client method. + */ + public ClientMethod getOverloadedClientMethod() { + return overloadedClientMethod; + } + /** * Add this ClientMethod's imports to the provided set of imports. * @@ -633,6 +646,7 @@ public static class Builder { protected boolean hasWithContextOverload; protected boolean hidePageableParams; protected OperationInstrumentationInfo instrumentationInfo; + protected ClientMethod overloadedClientMethod; public Builder setCrossLanguageDefinitionId(String crossLanguageDefinitionId) { this.crossLanguageDefinitionId = crossLanguageDefinitionId; @@ -882,6 +896,17 @@ public Builder operationInstrumentationInfo(OperationInstrumentationInfo instrum return this; } + /** + * Sets the overloaded client method associated with this ClientMethod. + * + * @param overloadedClientMethod the overloaded client method + * @return the Builder itself + */ + public Builder overloadedClientMethod(ClientMethod overloadedClientMethod) { + this.overloadedClientMethod = overloadedClientMethod; + return this; + } + /** * @return an immutable ClientMethod instance with the configurations on this builder. */ @@ -891,7 +916,8 @@ public ClientMethod build() { clientReference, CollectionUtil.toImmutableList(requiredNullableParameterExpressions), isGroupedParameterRequired, groupedParameterTypeName, methodPageDetails, parameterTransformations, methodVisibility, methodVisibilityInWrapperClient, implementationDetails, methodPollingDetails, - externalDocumentation, crossLanguageDefinitionId, hasWithContextOverload, instrumentationInfo); + externalDocumentation, crossLanguageDefinitionId, hasWithContextOverload, instrumentationInfo, + overloadedClientMethod); } } } diff --git a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClientMethodType.java b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClientMethodType.java index 37f9cd5dabc..59e8eaa270c 100644 --- a/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClientMethodType.java +++ b/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ClientMethodType.java @@ -23,8 +23,6 @@ public enum ClientMethodType { * Mono<PagedResponseBase<H,T>>. */ PagingAsyncSinglePage(2, true, false, false), - SimulatedPagingSync(3, false, false, true), // unused - SimulatedPagingAsync(4, false, false, false), // unused /** * represents long-running method that returns T where T is the final result of the LRO. */ 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 deb71804c76..5798d1ad879 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 @@ -39,6 +39,7 @@ import io.clientcore.core.annotations.ReturnType; import io.clientcore.core.http.models.HttpHeaderName; import io.clientcore.core.utils.CoreUtils; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -140,6 +141,16 @@ protected static void addOptionalVariables(JavaBlock function, ClientMethod clie protected static void addOptionalAndConstantVariables(JavaBlock function, ClientMethod clientMethod, JavaSettings settings) { final List proxyMethodParameters = clientMethod.getProxyMethod().getParameters(); + + // for client method that overload another method (of full parameters) + // clientMethod.getOverloadedClientMethod() + List methodParameters + = MethodUtil.getParameters(clientMethod, false); + List overloadedMethodParameters + = clientMethod.getOverloadedClientMethod() == null + ? Collections.emptyList() + : MethodUtil.getParameters(clientMethod.getOverloadedClientMethod(), false); + for (ProxyMethodParameter parameter : proxyMethodParameters) { if (parameter.isFromClient()) { // parameter is scoped to the client, hence no local variable instantiation for it. @@ -162,13 +173,25 @@ protected static void addOptionalAndConstantVariables(JavaBlock function, Client parameterWireType = ClassType.STRING; } - // 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, + // optional parameters will need to be locally instantiated in the method. + boolean optionalParameterToInitialize = !parameter.isRequired() && clientMethod.getOnlyRequiredParameters(); + if (!parameter.isRequired() && clientMethod.getOverloadedClientMethod() != null) { + // for overload client method for versioning of "@added" + boolean parameterInClientMethodSignature + = methodParameters.stream().anyMatch(p -> p.getProxyMethodParameter() == parameter); + boolean parameterInOverloadedClientMethodSignature + = overloadedMethodParameters.stream().anyMatch(p -> p.getProxyMethodParameter() == parameter); + // if the parameter is not defined in this client method, + // but it is defined in the overloaded client method (the one with full parameters), + // we would need to treat it as optional parameter and locally initialize it in this client method. + optionalParameterToInitialize + = !parameterInClientMethodSignature && parameterInOverloadedClientMethodSignature; + } // Optional variables and constants are always null if their wire type and client type differ and applying // conversions between the types is ignored. - boolean alwaysNull = parameterWireType != parameterClientType && optionalOmitted; + boolean alwaysNull = parameterWireType != parameterClientType && optionalParameterToInitialize; // Constants should be included if the parameter is a constant, and it's either required or optional // constants aren't generated as enums. @@ -178,7 +201,7 @@ protected static void addOptionalAndConstantVariables(JavaBlock function, Client // Client methods only add local variable instantiations when the parameter isn't passed by the caller, // isn't always null, is an optional parameter that was omitted or is a constant that is either required // or AutoRest isn't generating with optional constant as enums. - if (!alwaysNull && (optionalOmitted || includeConstant)) { + if (!alwaysNull && (optionalParameterToInitialize || includeConstant)) { final String defaultValue = parameterDefaultValueExpression(parameter); function.line("final %s %s = %s;", parameterClientType, parameter.getParameterReference(), defaultValue == null ? "null" : defaultValue); diff --git a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentClientMethodMapper.java b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentClientMethodMapper.java index 2d136d7ffcc..54a1d9ba028 100644 --- a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentClientMethodMapper.java +++ b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/mapper/FluentClientMethodMapper.java @@ -143,6 +143,11 @@ private void createLroGetFinalResultClientMethods(boolean isSync, ClientMethod b methods.add(lroGetFinalResultMethodWithRequiredOnlyParameters); } - addClientMethodWithContext(methods, lroGetFinalResultMethod, methodWithContextVisibility, isProtocolMethod); + ClientMethod clientMethodWithContext = addClientMethodWithContext(methods, lroGetFinalResultMethod, + methodWithContextVisibility, isProtocolMethod); + + // LRO '[Operation]' sync or async method overloads with versioning (for management). + createOverloadForVersioning(methods, lroGetFinalResultMethod, clientMethodWithContext, + methodWithContextVisibility, null, isProtocolMethod); } } diff --git a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/fluentmodel/ResourceOperation.java b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/fluentmodel/ResourceOperation.java index 73e70070b87..1c3983adde3 100644 --- a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/fluentmodel/ResourceOperation.java +++ b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/fluentmodel/ResourceOperation.java @@ -166,11 +166,21 @@ public Collection getLocalVariables() { return this.getResourceLocalVariables().getLocalVariablesMap().values(); } + /** + * Gets the method references, filter out those with only required parameters. + * + * @return the method references returns is sorted by the number of parameters in descending order. + */ protected List getMethodReferencesOfFullParameters() { // method references of full parameters (include optional parameters) return this.getMethodReferences() .stream() .filter(m -> !m.getInnerClientMethod().getOnlyRequiredParameters()) + .sorted((m1, m2) -> { + int count1 = m1.getInnerClientMethod().getParameters().size(); + int count2 = m2.getInnerClientMethod().getParameters().size(); + return -Integer.compare(count1, count2); + }) .collect(Collectors.toList()); } diff --git a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/fluentmodel/delete/ResourceDelete.java b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/fluentmodel/delete/ResourceDelete.java index 67c3023d279..4e1e2f59d58 100644 --- a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/fluentmodel/delete/ResourceDelete.java +++ b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/fluentmodel/delete/ResourceDelete.java @@ -4,8 +4,8 @@ package com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.fluentmodel.delete; import com.microsoft.typespec.http.client.generator.core.extension.plugin.PluginLogger; -import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientMethodParameter; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.examplemodel.MethodParameter; +import com.microsoft.typespec.http.client.generator.core.model.javamodel.JavaVisibility; import com.microsoft.typespec.http.client.generator.core.template.prototype.MethodTemplate; import com.microsoft.typespec.http.client.generator.mgmt.FluentGen; import com.microsoft.typespec.http.client.generator.mgmt.model.arm.UrlPathSegments; @@ -15,11 +15,12 @@ import com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.fluentmodel.ResourceOperation; import com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.fluentmodel.method.CollectionMethodOperationByIdTemplate; import com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.fluentmodel.method.FluentMethod; +import com.microsoft.typespec.http.client.generator.mgmt.util.FluentUtils; import com.microsoft.typespec.http.client.generator.mgmt.util.Utils; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Optional; +import java.util.stream.Collectors; import org.slf4j.Logger; public class ResourceDelete extends ResourceOperation { @@ -45,25 +46,37 @@ public String getLocalVariablePrefix() { public List getDeleteByIdCollectionMethods() { List methods = new ArrayList<>(); - List parameters = new ArrayList<>(); - Optional methodOpt = this.findMethod(true, parameters); - if (methodOpt.isPresent()) { - FluentCollectionMethod collectionMethod = methodOpt.get(); + List collectionMethods = this.findMethodsWithContext(); + if (!collectionMethods.isEmpty()) { + FluentCollectionMethod oneCollectionMethod = collectionMethods.iterator().next(); - String name = getDeleteByIdMethodName(collectionMethod.getMethodName()); + String name = getDeleteByIdMethodName(oneCollectionMethod.getMethodName()); if (!hasConflictingMethod(name)) { + // deleteById without Context List pathParameters = this.getPathParameters(); - methods.add(new CollectionMethodOperationByIdTemplate(resourceModel, name, pathParameters, - urlPathSegments, false, getResourceLocalVariables(), collectionMethod).getMethodTemplate()); + urlPathSegments, false, getResourceLocalVariables(), oneCollectionMethod).getMethodTemplate()); - methods.add(new CollectionMethodOperationByIdTemplate(resourceModel, name, pathParameters, - urlPathSegments, true, getResourceLocalVariables(), collectionMethod).getMethodTemplate()); + for (FluentCollectionMethod collectionMethod : collectionMethods) { + // deleteByIdWithResponse with Context + // There can be multiple such methods, due to overload from versioning (optional parameter @added) + methods.add(new CollectionMethodOperationByIdTemplate(resourceModel, name, pathParameters, + urlPathSegments, true, getResourceLocalVariables(), collectionMethod).getMethodTemplate()); + } } } return methods; } + protected List findMethodsWithContext() { + return this.getMethodReferencesOfFullParameters() + .stream() + .filter(m -> m.getInnerClientMethod().getParameters().stream().anyMatch(FluentUtils::isContextParameter)) + // fluent method implementation calls client interface API, thus we need the method to be public + .filter(method -> JavaVisibility.Public == method.getInnerClientMethod().getMethodVisibility()) + .collect(Collectors.toList()); + } + private static String getDeleteByIdMethodName(String methodName) { String getByIdMethodName = methodName; int indexOfBy = methodName.indexOf("By"); diff --git a/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 b/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 index d344a462f98..2ca6a7e0283 100644 --- a/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 +++ b/packages/http-client-java/generator/http-client-generator-test/Generate.ps1 @@ -107,6 +107,9 @@ $generateScript = { $tspOptions += " --option ""@typespec/http-client-java.generate-tests=false""" # add customization code $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""" } elseif ($tspFile -match "tsp[\\/]subclient.tsp") { $tspOptions += " --option ""@typespec/http-client-java.enable-subclient=true""" # test for include-api-view-properties diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/resiliency/servicedriven/ResiliencyServiceDrivenAsyncClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/resiliency/servicedriven/ResiliencyServiceDrivenAsyncClient.java index ef087b93546..c2890ccd4ca 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/resiliency/servicedriven/ResiliencyServiceDrivenAsyncClient.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/resiliency/servicedriven/ResiliencyServiceDrivenAsyncClient.java @@ -275,8 +275,6 @@ public Mono fromOneOptional(String parameter, String newParameter) { * Tests that we can grow up an operation from accepting one optional parameter to accepting two optional * parameters. * - * @param parameter I am an optional parameter. - * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. @@ -286,12 +284,9 @@ public Mono fromOneOptional(String parameter, String newParameter) { */ @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public Mono fromOneOptional(String parameter) { + public Mono fromOneOptional() { // Generated convenience method for fromOneOptionalWithResponse RequestOptions requestOptions = new RequestOptions(); - if (parameter != null) { - requestOptions.addQueryParam("parameter", parameter, false); - } return fromOneOptionalWithResponse(requestOptions).flatMap(FluxUtil::toMono); } @@ -299,6 +294,8 @@ public Mono fromOneOptional(String parameter) { * Tests that we can grow up an operation from accepting one optional parameter to accepting two optional * parameters. * + * @param parameter I am an optional parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. @@ -308,9 +305,12 @@ public Mono fromOneOptional(String parameter) { */ @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public Mono fromOneOptional() { + public Mono fromOneOptional(String parameter) { // Generated convenience method for fromOneOptionalWithResponse RequestOptions requestOptions = new RequestOptions(); + if (parameter != null) { + requestOptions.addQueryParam("parameter", parameter, false); + } return fromOneOptionalWithResponse(requestOptions).flatMap(FluxUtil::toMono); } } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/resiliency/servicedriven/ResiliencyServiceDrivenClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/resiliency/servicedriven/ResiliencyServiceDrivenClient.java index 01f4fb89e4d..44c7799e4be 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/resiliency/servicedriven/ResiliencyServiceDrivenClient.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/resiliency/servicedriven/ResiliencyServiceDrivenClient.java @@ -268,8 +268,6 @@ public void fromOneOptional(String parameter, String newParameter) { * Tests that we can grow up an operation from accepting one optional parameter to accepting two optional * parameters. * - * @param parameter I am an optional parameter. - * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. @@ -278,12 +276,9 @@ public void fromOneOptional(String parameter, String newParameter) { */ @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public void fromOneOptional(String parameter) { + public void fromOneOptional() { // Generated convenience method for fromOneOptionalWithResponse RequestOptions requestOptions = new RequestOptions(); - if (parameter != null) { - requestOptions.addQueryParam("parameter", parameter, false); - } fromOneOptionalWithResponse(requestOptions).getValue(); } @@ -291,6 +286,8 @@ public void fromOneOptional(String parameter) { * Tests that we can grow up an operation from accepting one optional parameter to accepting two optional * parameters. * + * @param parameter I am an optional parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. @@ -299,9 +296,12 @@ public void fromOneOptional(String parameter) { */ @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public void fromOneOptional() { + public void fromOneOptional(String parameter) { // Generated convenience method for fromOneOptionalWithResponse RequestOptions requestOptions = new RequestOptions(); + if (parameter != null) { + requestOptions.addQueryParam("parameter", parameter, false); + } fromOneOptionalWithResponse(requestOptions).getValue(); } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/ArmVersionedManager.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/ArmVersionedManager.java new file mode 100644 index 00000000000..316d4b6e8e4 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/ArmVersionedManager.java @@ -0,0 +1,282 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import tsptest.armversioned.fluent.ArmVersionedClient; +import tsptest.armversioned.implementation.ArmVersionedClientBuilder; +import tsptest.armversioned.implementation.TopLevelArmResourcesImpl; +import tsptest.armversioned.models.TopLevelArmResources; + +/** + * Entry point to ArmVersionedManager. + * Arm Resource Provider management API. + */ +public final class ArmVersionedManager { + private TopLevelArmResources topLevelArmResources; + + private final ArmVersionedClient clientObject; + + private ArmVersionedManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + this.clientObject = new ArmVersionedClientBuilder().pipeline(httpPipeline) + .endpoint(profile.getEnvironment().getResourceManagerEndpoint()) + .subscriptionId(profile.getSubscriptionId()) + .defaultPollInterval(defaultPollInterval) + .buildClient(); + } + + /** + * Creates an instance of ArmVersioned service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the ArmVersioned service API instance. + */ + public static ArmVersionedManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return configure().authenticate(credential, profile); + } + + /** + * Creates an instance of ArmVersioned service API entry point. + * + * @param httpPipeline the {@link HttpPipeline} configured with Azure authentication credential. + * @param profile the Azure profile for client. + * @return the ArmVersioned service API instance. + */ + public static ArmVersionedManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return new ArmVersionedManager(httpPipeline, profile, null); + } + + /** + * Gets a Configurable instance that can be used to create ArmVersionedManager with optional configuration. + * + * @return the Configurable instance allowing configurations. + */ + public static Configurable configure() { + return new ArmVersionedManager.Configurable(); + } + + /** + * The Configurable allowing configurations to be set. + */ + public static final class Configurable { + private static final ClientLogger LOGGER = new ClientLogger(Configurable.class); + private static final String SDK_VERSION = "version"; + private static final Map PROPERTIES + = CoreUtils.getProperties("azure-resourcemanager-armversioned-generated.properties"); + + private HttpClient httpClient; + private HttpLogOptions httpLogOptions; + private final List policies = new ArrayList<>(); + private final List scopes = new ArrayList<>(); + private RetryPolicy retryPolicy; + private RetryOptions retryOptions; + private Duration defaultPollInterval; + + private Configurable() { + } + + /** + * Sets the http client. + * + * @param httpClient the HTTP client. + * @return the configurable object itself. + */ + public Configurable withHttpClient(HttpClient httpClient) { + this.httpClient = Objects.requireNonNull(httpClient, "'httpClient' cannot be null."); + return this; + } + + /** + * Sets the logging options to the HTTP pipeline. + * + * @param httpLogOptions the HTTP log options. + * @return the configurable object itself. + */ + public Configurable withLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = Objects.requireNonNull(httpLogOptions, "'httpLogOptions' cannot be null."); + return this; + } + + /** + * Adds the pipeline policy to the HTTP pipeline. + * + * @param policy the HTTP pipeline policy. + * @return the configurable object itself. + */ + public Configurable withPolicy(HttpPipelinePolicy policy) { + this.policies.add(Objects.requireNonNull(policy, "'policy' cannot be null.")); + return this; + } + + /** + * Adds the scope to permission sets. + * + * @param scope the scope. + * @return the configurable object itself. + */ + public Configurable withScope(String scope) { + this.scopes.add(Objects.requireNonNull(scope, "'scope' cannot be null.")); + return this; + } + + /** + * Sets the retry policy to the HTTP pipeline. + * + * @param retryPolicy the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = Objects.requireNonNull(retryPolicy, "'retryPolicy' cannot be null."); + return this; + } + + /** + * Sets the retry options for the HTTP pipeline retry policy. + *

+ * This setting has no effect, if retry policy is set via {@link #withRetryPolicy(RetryPolicy)}. + * + * @param retryOptions the retry options for the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryOptions(RetryOptions retryOptions) { + this.retryOptions = Objects.requireNonNull(retryOptions, "'retryOptions' cannot be null."); + return this; + } + + /** + * Sets the default poll interval, used when service does not provide "Retry-After" header. + * + * @param defaultPollInterval the default poll interval. + * @return the configurable object itself. + */ + public Configurable withDefaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval + = Objects.requireNonNull(defaultPollInterval, "'defaultPollInterval' cannot be null."); + if (this.defaultPollInterval.isNegative()) { + throw LOGGER + .logExceptionAsError(new IllegalArgumentException("'defaultPollInterval' cannot be negative")); + } + return this; + } + + /** + * Creates an instance of ArmVersioned service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the ArmVersioned service API instance. + */ + public ArmVersionedManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + + StringBuilder userAgentBuilder = new StringBuilder(); + userAgentBuilder.append("azsdk-java") + .append("-") + .append("tsptest.armversioned") + .append("/") + .append(clientVersion); + if (!Configuration.getGlobalConfiguration().get("AZURE_TELEMETRY_DISABLED", false)) { + userAgentBuilder.append(" (") + .append(Configuration.getGlobalConfiguration().get("java.version")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.name")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.version")) + .append("; auto-generated)"); + } else { + userAgentBuilder.append(" (auto-generated)"); + } + + if (scopes.isEmpty()) { + scopes.add(profile.getEnvironment().getManagementEndpoint() + "/.default"); + } + if (retryPolicy == null) { + if (retryOptions != null) { + retryPolicy = new RetryPolicy(retryOptions); + } else { + retryPolicy = new RetryPolicy("Retry-After", ChronoUnit.SECONDS); + } + } + List policies = new ArrayList<>(); + policies.add(new UserAgentPolicy(userAgentBuilder.toString())); + policies.add(new AddHeadersFromContextPolicy()); + policies.add(new RequestIdPolicy()); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .collect(Collectors.toList())); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(retryPolicy); + policies.add(new AddDatePolicy()); + policies.add(new BearerTokenAuthenticationPolicy(credential, scopes.toArray(new String[0]))); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .collect(Collectors.toList())); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(httpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(httpClient) + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .build(); + return new ArmVersionedManager(httpPipeline, profile, defaultPollInterval); + } + } + + /** + * Gets the resource collection API of TopLevelArmResources. It manages TopLevelArmResource. + * + * @return Resource collection API of TopLevelArmResources. + */ + public TopLevelArmResources topLevelArmResources() { + if (this.topLevelArmResources == null) { + this.topLevelArmResources = new TopLevelArmResourcesImpl(clientObject.getTopLevelArmResources(), this); + } + return topLevelArmResources; + } + + /** + * Gets wrapped service client ArmVersionedClient providing direct access to the underlying auto-generated API + * implementation, based on Azure REST API. + * + * @return Wrapped service client ArmVersionedClient. + */ + public ArmVersionedClient serviceClient() { + return this.clientObject; + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/ArmVersionedClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/ArmVersionedClient.java new file mode 100644 index 00000000000..0c52b974851 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/ArmVersionedClient.java @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.fluent; + +import com.azure.core.http.HttpPipeline; +import java.time.Duration; + +/** + * The interface for ArmVersionedClient class. + */ +public interface ArmVersionedClient { + /** + * Gets Service host. + * + * @return the endpoint value. + */ + String getEndpoint(); + + /** + * Gets Version parameter. + * + * @return the apiVersion value. + */ + String getApiVersion(); + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + String getSubscriptionId(); + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + HttpPipeline getHttpPipeline(); + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + Duration getDefaultPollInterval(); + + /** + * Gets the TopLevelArmResourcesClient object to access its operations. + * + * @return the TopLevelArmResourcesClient object. + */ + TopLevelArmResourcesClient getTopLevelArmResources(); +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/TopLevelArmResourcesClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/TopLevelArmResourcesClient.java new file mode 100644 index 00000000000..47f358f13b6 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/TopLevelArmResourcesClient.java @@ -0,0 +1,340 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.fluent; + +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.Context; +import com.azure.core.util.polling.SyncPoller; +import tsptest.armversioned.fluent.models.TopLevelArmResourceInner; + +/** + * An instance of this class provides access to all the operations defined in TopLevelArmResourcesClient. + */ +public interface TopLevelArmResourcesClient { + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of concrete tracked resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, TopLevelArmResourceInner> beginCreateOrUpdate( + String resourceGroupName, String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource); + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of concrete tracked resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, TopLevelArmResourceInner> beginCreateOrUpdate( + String resourceGroupName, String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource, + String parameter, String newParameter, Context context); + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of concrete tracked resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, TopLevelArmResourceInner> beginCreateOrUpdate( + String resourceGroupName, String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource, + String parameter, Context context); + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + TopLevelArmResourceInner createOrUpdate(String resourceGroupName, String topLevelArmResourcePropertiesName, + TopLevelArmResourceInner resource); + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + TopLevelArmResourceInner createOrUpdate(String resourceGroupName, String topLevelArmResourcePropertiesName, + TopLevelArmResourceInner resource, String parameter, String newParameter, Context context); + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + TopLevelArmResourceInner createOrUpdate(String resourceGroupName, String topLevelArmResourcePropertiesName, + TopLevelArmResourceInner resource, String parameter, Context context); + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(); + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(String parameter, String newParameter, Context context); + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(String parameter, Context context); + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listByResourceGroup(String resourceGroupName); + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listByResourceGroup(String resourceGroupName, String parameter, + String newParameter, Context context); + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listByResourceGroup(String resourceGroupName, String parameter, + Context context); + + /** + * Get a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response getByResourceGroupWithResponse(String resourceGroupName, + String topLevelArmResourcePropertiesName, String parameter, String newParameter, Context context); + + /** + * Get a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response getByResourceGroupWithResponse(String resourceGroupName, + String topLevelArmResourcePropertiesName, String parameter, Context context); + + /** + * Get a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + TopLevelArmResourceInner getByResourceGroup(String resourceGroupName, String topLevelArmResourcePropertiesName); + + /** + * Delete a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response deleteWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, String newParameter, Context context); + + /** + * Delete a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response deleteWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, Context context); + + /** + * Delete a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + void delete(String resourceGroupName, String topLevelArmResourcePropertiesName); + + /** + * A synchronous resource action. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response actionWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, String newParameter, Context context); + + /** + * A synchronous resource action. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response actionWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, Context context); + + /** + * A synchronous resource action. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + void action(String resourceGroupName, String topLevelArmResourcePropertiesName); +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/models/TopLevelArmResourceInner.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/models/TopLevelArmResourceInner.java new file mode 100644 index 00000000000..54adc39e6a9 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/models/TopLevelArmResourceInner.java @@ -0,0 +1,181 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.fluent.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.management.Resource; +import com.azure.core.management.SystemData; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.Map; +import tsptest.armversioned.models.TopLevelArmResourceProperties; + +/** + * Concrete tracked resource types can be created by aliasing this type using a specific property type. + */ +@Fluent +public final class TopLevelArmResourceInner extends Resource { + /* + * The resource-specific properties for this resource. + */ + private TopLevelArmResourceProperties properties; + + /* + * Azure Resource Manager metadata containing createdBy and modifiedBy information. + */ + private SystemData systemData; + + /* + * The type of the resource. + */ + private String type; + + /* + * The name of the resource. + */ + private String name; + + /* + * Fully qualified resource Id for the resource. + */ + private String id; + + /** + * Creates an instance of TopLevelArmResourceInner class. + */ + public TopLevelArmResourceInner() { + } + + /** + * Get the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + public TopLevelArmResourceProperties properties() { + return this.properties; + } + + /** + * Set the properties property: The resource-specific properties for this resource. + * + * @param properties the properties value to set. + * @return the TopLevelArmResourceInner object itself. + */ + public TopLevelArmResourceInner withProperties(TopLevelArmResourceProperties properties) { + this.properties = properties; + return this; + } + + /** + * Get the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + public SystemData systemData() { + return this.systemData; + } + + /** + * Get the type property: The type of the resource. + * + * @return the type value. + */ + @Override + public String type() { + return this.type; + } + + /** + * Get the name property: The name of the resource. + * + * @return the name value. + */ + @Override + public String name() { + return this.name; + } + + /** + * Get the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + @Override + public String id() { + return this.id; + } + + /** + * {@inheritDoc} + */ + @Override + public TopLevelArmResourceInner withLocation(String location) { + super.withLocation(location); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public TopLevelArmResourceInner withTags(Map tags) { + super.withTags(tags); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("location", location()); + jsonWriter.writeMapField("tags", tags(), (writer, element) -> writer.writeString(element)); + jsonWriter.writeJsonField("properties", this.properties); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of TopLevelArmResourceInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of TopLevelArmResourceInner if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the TopLevelArmResourceInner. + */ + public static TopLevelArmResourceInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + TopLevelArmResourceInner deserializedTopLevelArmResourceInner = new TopLevelArmResourceInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedTopLevelArmResourceInner.id = reader.getString(); + } else if ("name".equals(fieldName)) { + deserializedTopLevelArmResourceInner.name = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedTopLevelArmResourceInner.type = reader.getString(); + } else if ("location".equals(fieldName)) { + deserializedTopLevelArmResourceInner.withLocation(reader.getString()); + } else if ("tags".equals(fieldName)) { + Map tags = reader.readMap(reader1 -> reader1.getString()); + deserializedTopLevelArmResourceInner.withTags(tags); + } else if ("properties".equals(fieldName)) { + deserializedTopLevelArmResourceInner.properties = TopLevelArmResourceProperties.fromJson(reader); + } else if ("systemData".equals(fieldName)) { + deserializedTopLevelArmResourceInner.systemData = SystemData.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedTopLevelArmResourceInner; + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/models/package-info.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/models/package-info.java new file mode 100644 index 00000000000..efa70b16308 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the inner data models for ArmVersioned. + * Arm Resource Provider management API. + */ +package tsptest.armversioned.fluent.models; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/package-info.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/package-info.java new file mode 100644 index 00000000000..304185e7846 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/fluent/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the service clients for ArmVersioned. + * Arm Resource Provider management API. + */ +package tsptest.armversioned.fluent; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/ArmVersionedClientBuilder.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/ArmVersionedClientBuilder.java new file mode 100644 index 00000000000..6498c099e69 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/ArmVersionedClientBuilder.java @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.implementation; + +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.serializer.SerializerFactory; +import com.azure.core.util.serializer.SerializerAdapter; +import java.time.Duration; + +/** + * A builder for creating a new instance of the ArmVersionedClientImpl type. + */ +@ServiceClientBuilder(serviceClients = { ArmVersionedClientImpl.class }) +public final class ArmVersionedClientBuilder { + /* + * Service host + */ + private String endpoint; + + /** + * Sets Service host. + * + * @param endpoint the endpoint value. + * @return the ArmVersionedClientBuilder. + */ + public ArmVersionedClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * The ID of the target subscription. The value must be an UUID. + */ + private String subscriptionId; + + /** + * Sets The ID of the target subscription. The value must be an UUID. + * + * @param subscriptionId the subscriptionId value. + * @return the ArmVersionedClientBuilder. + */ + public ArmVersionedClientBuilder subscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /* + * The environment to connect to + */ + private AzureEnvironment environment; + + /** + * Sets The environment to connect to. + * + * @param environment the environment value. + * @return the ArmVersionedClientBuilder. + */ + public ArmVersionedClientBuilder environment(AzureEnvironment environment) { + this.environment = environment; + return this; + } + + /* + * The HTTP pipeline to send requests through + */ + private HttpPipeline pipeline; + + /** + * Sets The HTTP pipeline to send requests through. + * + * @param pipeline the pipeline value. + * @return the ArmVersionedClientBuilder. + */ + public ArmVersionedClientBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /* + * The default poll interval for long-running operation + */ + private Duration defaultPollInterval; + + /** + * Sets The default poll interval for long-running operation. + * + * @param defaultPollInterval the defaultPollInterval value. + * @return the ArmVersionedClientBuilder. + */ + public ArmVersionedClientBuilder defaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval = defaultPollInterval; + return this; + } + + /* + * The serializer to serialize an object into a string + */ + private SerializerAdapter serializerAdapter; + + /** + * Sets The serializer to serialize an object into a string. + * + * @param serializerAdapter the serializerAdapter value. + * @return the ArmVersionedClientBuilder. + */ + public ArmVersionedClientBuilder serializerAdapter(SerializerAdapter serializerAdapter) { + this.serializerAdapter = serializerAdapter; + return this; + } + + /** + * Builds an instance of ArmVersionedClientImpl with the provided parameters. + * + * @return an instance of ArmVersionedClientImpl. + */ + public ArmVersionedClientImpl buildClient() { + String localEndpoint = (endpoint != null) ? endpoint : "https://management.azure.com"; + AzureEnvironment localEnvironment = (environment != null) ? environment : AzureEnvironment.AZURE; + HttpPipeline localPipeline = (pipeline != null) + ? pipeline + : new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(); + Duration localDefaultPollInterval + = (defaultPollInterval != null) ? defaultPollInterval : Duration.ofSeconds(30); + SerializerAdapter localSerializerAdapter = (serializerAdapter != null) + ? serializerAdapter + : SerializerFactory.createDefaultManagementSerializerAdapter(); + ArmVersionedClientImpl client = new ArmVersionedClientImpl(localPipeline, localSerializerAdapter, + localDefaultPollInterval, localEnvironment, localEndpoint, this.subscriptionId); + return client; + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/ArmVersionedClientImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/ArmVersionedClientImpl.java new file mode 100644 index 00000000000..60ee7879dcf --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/ArmVersionedClientImpl.java @@ -0,0 +1,308 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.implementation; + +import com.azure.core.annotation.ServiceClient; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpResponse; +import com.azure.core.http.rest.Response; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.exception.ManagementError; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.management.polling.PollerFactory; +import com.azure.core.management.polling.SyncPollerFactory; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.AsyncPollResponse; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.core.util.serializer.SerializerEncoding; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.time.Duration; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import tsptest.armversioned.fluent.ArmVersionedClient; +import tsptest.armversioned.fluent.TopLevelArmResourcesClient; + +/** + * Initializes a new instance of the ArmVersionedClientImpl type. + */ +@ServiceClient(builder = ArmVersionedClientBuilder.class) +public final class ArmVersionedClientImpl implements ArmVersionedClient { + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * Version parameter. + */ + private final String apiVersion; + + /** + * Gets Version parameter. + * + * @return the apiVersion value. + */ + public String getApiVersion() { + return this.apiVersion; + } + + /** + * The ID of the target subscription. The value must be an UUID. + */ + private final String subscriptionId; + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + public String getSubscriptionId() { + return this.subscriptionId; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The default poll interval for long-running operation. + */ + private final Duration defaultPollInterval; + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + public Duration getDefaultPollInterval() { + return this.defaultPollInterval; + } + + /** + * The TopLevelArmResourcesClient object to access its operations. + */ + private final TopLevelArmResourcesClient topLevelArmResources; + + /** + * Gets the TopLevelArmResourcesClient object to access its operations. + * + * @return the TopLevelArmResourcesClient object. + */ + public TopLevelArmResourcesClient getTopLevelArmResources() { + return this.topLevelArmResources; + } + + /** + * Initializes an instance of ArmVersionedClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param defaultPollInterval The default poll interval for long-running operation. + * @param environment The Azure environment. + * @param endpoint Service host. + * @param subscriptionId The ID of the target subscription. The value must be an UUID. + */ + ArmVersionedClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, Duration defaultPollInterval, + AzureEnvironment environment, String endpoint, String subscriptionId) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.defaultPollInterval = defaultPollInterval; + this.endpoint = endpoint; + this.subscriptionId = subscriptionId; + this.apiVersion = "2024-12-01"; + this.topLevelArmResources = new TopLevelArmResourcesClientImpl(this); + } + + /** + * Gets default client context. + * + * @return the default client context. + */ + public Context getContext() { + return Context.NONE; + } + + /** + * Merges default client context with provided context. + * + * @param context the context to be merged with default client context. + * @return the merged context. + */ + public Context mergeContext(Context context) { + return CoreUtils.mergeContexts(this.getContext(), context); + } + + /** + * Gets long running operation result. + * + * @param activationResponse the response of activation operation. + * @param httpPipeline the http pipeline. + * @param pollResultType type of poll result. + * @param finalResultType type of final result. + * @param context the context shared by all requests. + * @param type of poll result. + * @param type of final result. + * @return poller flux for poll result and final result. + */ + public PollerFlux, U> getLroResult(Mono>> activationResponse, + HttpPipeline httpPipeline, Type pollResultType, Type finalResultType, Context context) { + return PollerFactory.create(serializerAdapter, httpPipeline, pollResultType, finalResultType, + defaultPollInterval, activationResponse, context); + } + + /** + * Gets long running operation result. + * + * @param activationResponse the response of activation operation. + * @param pollResultType type of poll result. + * @param finalResultType type of final result. + * @param context the context shared by all requests. + * @param type of poll result. + * @param type of final result. + * @return SyncPoller for poll result and final result. + */ + public SyncPoller, U> getLroResult(Response activationResponse, + Type pollResultType, Type finalResultType, Context context) { + return SyncPollerFactory.create(serializerAdapter, httpPipeline, pollResultType, finalResultType, + defaultPollInterval, () -> activationResponse, context); + } + + /** + * Gets the final result, or an error, based on last async poll response. + * + * @param response the last async poll response. + * @param type of poll result. + * @param type of final result. + * @return the final result, or an error. + */ + public Mono getLroFinalResultOrError(AsyncPollResponse, U> response) { + if (response.getStatus() != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) { + String errorMessage; + ManagementError managementError = null; + HttpResponse errorResponse = null; + PollResult.Error lroError = response.getValue().getError(); + if (lroError != null) { + errorResponse = new HttpResponseImpl(lroError.getResponseStatusCode(), lroError.getResponseHeaders(), + lroError.getResponseBody()); + + errorMessage = response.getValue().getError().getMessage(); + String errorBody = response.getValue().getError().getResponseBody(); + if (errorBody != null) { + // try to deserialize error body to ManagementError + try { + managementError = this.getSerializerAdapter() + .deserialize(errorBody, ManagementError.class, SerializerEncoding.JSON); + if (managementError.getCode() == null || managementError.getMessage() == null) { + managementError = null; + } + } catch (IOException | RuntimeException ioe) { + LOGGER.logThrowableAsWarning(ioe); + } + } + } else { + // fallback to default error message + errorMessage = "Long running operation failed."; + } + if (managementError == null) { + // fallback to default ManagementError + managementError = new ManagementError(response.getStatus().toString(), errorMessage); + } + return Mono.error(new ManagementException(errorMessage, errorResponse, managementError)); + } else { + return response.getFinalResult(); + } + } + + private static final class HttpResponseImpl extends HttpResponse { + private final int statusCode; + + private final byte[] responseBody; + + private final HttpHeaders httpHeaders; + + HttpResponseImpl(int statusCode, HttpHeaders httpHeaders, String responseBody) { + super(null); + this.statusCode = statusCode; + this.httpHeaders = httpHeaders; + this.responseBody = responseBody == null ? null : responseBody.getBytes(StandardCharsets.UTF_8); + } + + public int getStatusCode() { + return statusCode; + } + + public String getHeaderValue(String s) { + return httpHeaders.getValue(HttpHeaderName.fromString(s)); + } + + public HttpHeaders getHeaders() { + return httpHeaders; + } + + public Flux getBody() { + return Flux.just(ByteBuffer.wrap(responseBody)); + } + + public Mono getBodyAsByteArray() { + return Mono.just(responseBody); + } + + public Mono getBodyAsString() { + return Mono.just(new String(responseBody, StandardCharsets.UTF_8)); + } + + public Mono getBodyAsString(Charset charset) { + return Mono.just(new String(responseBody, charset)); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(ArmVersionedClientImpl.class); +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/ResourceManagerUtils.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/ResourceManagerUtils.java new file mode 100644 index 00000000000..f52d86253ad --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/ResourceManagerUtils.java @@ -0,0 +1,195 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.implementation; + +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.util.CoreUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import reactor.core.publisher.Flux; + +final class ResourceManagerUtils { + private ResourceManagerUtils() { + } + + static String getValueFromIdByName(String id, String name) { + if (id == null) { + return null; + } + Iterator itr = Arrays.stream(id.split("/")).iterator(); + while (itr.hasNext()) { + String part = itr.next(); + if (part != null && !part.trim().isEmpty()) { + if (part.equalsIgnoreCase(name)) { + if (itr.hasNext()) { + return itr.next(); + } else { + return null; + } + } + } + } + return null; + } + + static String getValueFromIdByParameterName(String id, String pathTemplate, String parameterName) { + if (id == null || pathTemplate == null) { + return null; + } + String parameterNameParentheses = "{" + parameterName + "}"; + List idSegmentsReverted = Arrays.asList(id.split("/")); + List pathSegments = Arrays.asList(pathTemplate.split("/")); + Collections.reverse(idSegmentsReverted); + Iterator idItrReverted = idSegmentsReverted.iterator(); + int pathIndex = pathSegments.size(); + while (idItrReverted.hasNext() && pathIndex > 0) { + String idSegment = idItrReverted.next(); + String pathSegment = pathSegments.get(--pathIndex); + if (!CoreUtils.isNullOrEmpty(idSegment) && !CoreUtils.isNullOrEmpty(pathSegment)) { + if (pathSegment.equalsIgnoreCase(parameterNameParentheses)) { + if (pathIndex == 0 || (pathIndex == 1 && pathSegments.get(0).isEmpty())) { + List segments = new ArrayList<>(); + segments.add(idSegment); + idItrReverted.forEachRemaining(segments::add); + Collections.reverse(segments); + if (!segments.isEmpty() && segments.get(0).isEmpty()) { + segments.remove(0); + } + return String.join("/", segments); + } else { + return idSegment; + } + } + } + } + return null; + } + + static PagedIterable mapPage(PagedIterable pageIterable, Function mapper) { + return new PagedIterableImpl<>(pageIterable, mapper); + } + + private static final class PagedIterableImpl extends PagedIterable { + + private final PagedIterable pagedIterable; + private final Function mapper; + private final Function, PagedResponse> pageMapper; + + private PagedIterableImpl(PagedIterable pagedIterable, Function mapper) { + super(PagedFlux.create(() -> (continuationToken, pageSize) -> Flux + .fromStream(pagedIterable.streamByPage().map(getPageMapper(mapper))))); + this.pagedIterable = pagedIterable; + this.mapper = mapper; + this.pageMapper = getPageMapper(mapper); + } + + private static Function, PagedResponse> getPageMapper(Function mapper) { + return page -> new PagedResponseBase(page.getRequest(), page.getStatusCode(), page.getHeaders(), + page.getElements().stream().map(mapper).collect(Collectors.toList()), page.getContinuationToken(), + null); + } + + @Override + public Stream stream() { + return pagedIterable.stream().map(mapper); + } + + @Override + public Stream> streamByPage() { + return pagedIterable.streamByPage().map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken) { + return pagedIterable.streamByPage(continuationToken).map(pageMapper); + } + + @Override + public Stream> streamByPage(int preferredPageSize) { + return pagedIterable.streamByPage(preferredPageSize).map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken, int preferredPageSize) { + return pagedIterable.streamByPage(continuationToken, preferredPageSize).map(pageMapper); + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(pagedIterable.iterator(), mapper); + } + + @Override + public Iterable> iterableByPage() { + return new IterableImpl<>(pagedIterable.iterableByPage(), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken), pageMapper); + } + + @Override + public Iterable> iterableByPage(int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(preferredPageSize), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken, int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken, preferredPageSize), pageMapper); + } + } + + private static final class IteratorImpl implements Iterator { + + private final Iterator iterator; + private final Function mapper; + + private IteratorImpl(Iterator iterator, Function mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public S next() { + return mapper.apply(iterator.next()); + } + + @Override + public void remove() { + iterator.remove(); + } + } + + private static final class IterableImpl implements Iterable { + + private final Iterable iterable; + private final Function mapper; + + private IterableImpl(Iterable iterable, Function mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(iterable.iterator(), mapper); + } + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/TopLevelArmResourceImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/TopLevelArmResourceImpl.java new file mode 100644 index 00000000000..56789e16392 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/TopLevelArmResourceImpl.java @@ -0,0 +1,227 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.implementation; + +import com.azure.core.http.rest.Response; +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import java.util.Collections; +import java.util.Map; +import tsptest.armversioned.fluent.models.TopLevelArmResourceInner; +import tsptest.armversioned.models.TopLevelArmResource; +import tsptest.armversioned.models.TopLevelArmResourceProperties; + +public final class TopLevelArmResourceImpl + implements TopLevelArmResource, TopLevelArmResource.Definition, TopLevelArmResource.Update { + private TopLevelArmResourceInner innerObject; + + private final tsptest.armversioned.ArmVersionedManager serviceManager; + + public String id() { + return this.innerModel().id(); + } + + public String name() { + return this.innerModel().name(); + } + + public String type() { + return this.innerModel().type(); + } + + public String location() { + return this.innerModel().location(); + } + + public Map tags() { + Map inner = this.innerModel().tags(); + if (inner != null) { + return Collections.unmodifiableMap(inner); + } else { + return Collections.emptyMap(); + } + } + + public TopLevelArmResourceProperties properties() { + return this.innerModel().properties(); + } + + public SystemData systemData() { + return this.innerModel().systemData(); + } + + public Region region() { + return Region.fromName(this.regionName()); + } + + public String regionName() { + return this.location(); + } + + public String resourceGroupName() { + return resourceGroupName; + } + + public TopLevelArmResourceInner innerModel() { + return this.innerObject; + } + + private tsptest.armversioned.ArmVersionedManager manager() { + return this.serviceManager; + } + + private String resourceGroupName; + + private String topLevelArmResourcePropertiesName; + + private String createParameter; + + private String createNewParameter; + + private String updateParameter; + + private String updateNewParameter; + + public TopLevelArmResourceImpl withExistingResourceGroup(String resourceGroupName) { + this.resourceGroupName = resourceGroupName; + return this; + } + + public TopLevelArmResource create() { + this.innerObject = serviceManager.serviceClient() + .getTopLevelArmResources() + .createOrUpdate(resourceGroupName, topLevelArmResourcePropertiesName, this.innerModel(), createParameter, + createNewParameter, Context.NONE); + return this; + } + + public TopLevelArmResource create(Context context) { + this.innerObject = serviceManager.serviceClient() + .getTopLevelArmResources() + .createOrUpdate(resourceGroupName, topLevelArmResourcePropertiesName, this.innerModel(), createParameter, + createNewParameter, context); + return this; + } + + TopLevelArmResourceImpl(String name, tsptest.armversioned.ArmVersionedManager serviceManager) { + this.innerObject = new TopLevelArmResourceInner(); + this.serviceManager = serviceManager; + this.topLevelArmResourcePropertiesName = name; + this.createParameter = null; + this.createNewParameter = null; + } + + public TopLevelArmResourceImpl update() { + this.updateParameter = null; + this.updateNewParameter = null; + return this; + } + + public TopLevelArmResource apply() { + this.innerObject = serviceManager.serviceClient() + .getTopLevelArmResources() + .createOrUpdate(resourceGroupName, topLevelArmResourcePropertiesName, this.innerModel(), updateParameter, + updateNewParameter, Context.NONE); + return this; + } + + public TopLevelArmResource apply(Context context) { + this.innerObject = serviceManager.serviceClient() + .getTopLevelArmResources() + .createOrUpdate(resourceGroupName, topLevelArmResourcePropertiesName, this.innerModel(), updateParameter, + updateNewParameter, context); + return this; + } + + TopLevelArmResourceImpl(TopLevelArmResourceInner innerObject, + tsptest.armversioned.ArmVersionedManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + this.resourceGroupName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroups"); + this.topLevelArmResourcePropertiesName + = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "topLevelArmResources"); + } + + public TopLevelArmResource refresh() { + String localParameter = null; + String localNewParameter = null; + this.innerObject = serviceManager.serviceClient() + .getTopLevelArmResources() + .getByResourceGroupWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, localParameter, + localNewParameter, Context.NONE) + .getValue(); + return this; + } + + public TopLevelArmResource refresh(Context context) { + String localParameter = null; + String localNewParameter = null; + this.innerObject = serviceManager.serviceClient() + .getTopLevelArmResources() + .getByResourceGroupWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, localParameter, + localNewParameter, context) + .getValue(); + return this; + } + + public Response actionWithResponse(String parameter, String newParameter, Context context) { + return serviceManager.topLevelArmResources() + .actionWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, newParameter, context); + } + + public Response actionWithResponse(String parameter, Context context) { + return serviceManager.topLevelArmResources() + .actionWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, context); + } + + public void action() { + serviceManager.topLevelArmResources().action(resourceGroupName, topLevelArmResourcePropertiesName); + } + + public TopLevelArmResourceImpl withRegion(Region location) { + this.innerModel().withLocation(location.toString()); + return this; + } + + public TopLevelArmResourceImpl withRegion(String location) { + this.innerModel().withLocation(location); + return this; + } + + public TopLevelArmResourceImpl withTags(Map tags) { + this.innerModel().withTags(tags); + return this; + } + + public TopLevelArmResourceImpl withProperties(TopLevelArmResourceProperties properties) { + this.innerModel().withProperties(properties); + return this; + } + + public TopLevelArmResourceImpl withParameter(String parameter) { + if (isInCreateMode()) { + this.createParameter = parameter; + return this; + } else { + this.updateParameter = parameter; + return this; + } + } + + public TopLevelArmResourceImpl withNewParameter(String newParameter) { + if (isInCreateMode()) { + this.createNewParameter = newParameter; + return this; + } else { + this.updateNewParameter = newParameter; + return this; + } + } + + private boolean isInCreateMode() { + return this.innerModel() == null || this.innerModel().id() == null; + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/TopLevelArmResourcesClientImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/TopLevelArmResourcesClientImpl.java new file mode 100644 index 00000000000..28cc7a6e6e8 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/TopLevelArmResourcesClientImpl.java @@ -0,0 +1,1346 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.implementation; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.Delete; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Headers; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.Put; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import java.nio.ByteBuffer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import tsptest.armversioned.fluent.TopLevelArmResourcesClient; +import tsptest.armversioned.fluent.models.TopLevelArmResourceInner; +import tsptest.armversioned.implementation.models.TopLevelArmResourceListResult; + +/** + * An instance of this class provides access to all the operations defined in TopLevelArmResourcesClient. + */ +public final class TopLevelArmResourcesClientImpl implements TopLevelArmResourcesClient { + /** + * The proxy service used to perform REST calls. + */ + private final TopLevelArmResourcesService service; + + /** + * The service client containing this operation class. + */ + private final ArmVersionedClientImpl client; + + /** + * Initializes an instance of TopLevelArmResourcesClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + TopLevelArmResourcesClientImpl(ArmVersionedClientImpl client) { + this.service = RestProxy.create(TopLevelArmResourcesService.class, client.getHttpPipeline(), + client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for ArmVersionedClientTopLevelArmResources to be used by the proxy + * service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "ArmVersionedClientTopLevelArmResources") + public interface TopLevelArmResourcesService { + @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmVersioned/topLevelArmResources/{topLevelArmResourcePropertiesName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono>> createOrUpdate(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, + @PathParam("topLevelArmResourcePropertiesName") String topLevelArmResourcePropertiesName, + @QueryParam("parameter") String parameter, @QueryParam("newParameter") String newParameter, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") TopLevelArmResourceInner resource, Context context); + + @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmVersioned/topLevelArmResources/{topLevelArmResourcePropertiesName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response createOrUpdateSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, + @PathParam("topLevelArmResourcePropertiesName") String topLevelArmResourcePropertiesName, + @QueryParam("parameter") String parameter, @QueryParam("newParameter") String newParameter, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") TopLevelArmResourceInner resource, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/providers/TspTest.ArmVersioned/topLevelArmResources") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> list(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @QueryParam("parameter") String parameter, @QueryParam("newParameter") String newParameter, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/providers/TspTest.ArmVersioned/topLevelArmResources") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response listSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @QueryParam("parameter") String parameter, @QueryParam("newParameter") String newParameter, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmVersioned/topLevelArmResources") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listByResourceGroup(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @QueryParam("parameter") String parameter, + @QueryParam("newParameter") String newParameter, @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmVersioned/topLevelArmResources") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response listByResourceGroupSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @QueryParam("parameter") String parameter, + @QueryParam("newParameter") String newParameter, @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmVersioned/topLevelArmResources/{topLevelArmResourcePropertiesName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> getByResourceGroup(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, + @PathParam("topLevelArmResourcePropertiesName") String topLevelArmResourcePropertiesName, + @QueryParam("parameter") String parameter, @QueryParam("newParameter") String newParameter, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmVersioned/topLevelArmResources/{topLevelArmResourcePropertiesName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response getByResourceGroupSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, + @PathParam("topLevelArmResourcePropertiesName") String topLevelArmResourcePropertiesName, + @QueryParam("parameter") String parameter, @QueryParam("newParameter") String newParameter, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" }) + @Delete("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmVersioned/topLevelArmResources/{topLevelArmResourcePropertiesName}") + @ExpectedResponses({ 200, 204 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> delete(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, + @PathParam("topLevelArmResourcePropertiesName") String topLevelArmResourcePropertiesName, + @QueryParam("parameter") String parameter, @QueryParam("newParameter") String newParameter, + Context context); + + @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" }) + @Delete("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmVersioned/topLevelArmResources/{topLevelArmResourcePropertiesName}") + @ExpectedResponses({ 200, 204 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response deleteSync(@HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, + @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, + @PathParam("topLevelArmResourcePropertiesName") String topLevelArmResourcePropertiesName, + @QueryParam("parameter") String parameter, @QueryParam("newParameter") String newParameter, + Context context); + + @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" }) + @Post("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmVersioned/topLevelArmResources/{topLevelArmResourcePropertiesName}/action") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> action(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, + @PathParam("topLevelArmResourcePropertiesName") String topLevelArmResourcePropertiesName, + @QueryParam("parameter") String parameter, @QueryParam("newParameter") String newParameter, + Context context); + + @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" }) + @Post("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmVersioned/topLevelArmResources/{topLevelArmResourcePropertiesName}/action") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response actionSync(@HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, + @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, + @PathParam("topLevelArmResourcePropertiesName") String topLevelArmResourcePropertiesName, + @QueryParam("parameter") String parameter, @QueryParam("newParameter") String newParameter, + Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listBySubscriptionNext( + @PathParam(value = "nextLink", encoded = true) String nextLink, @HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response listBySubscriptionNextSync( + @PathParam(value = "nextLink", encoded = true) String nextLink, @HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listByResourceGroupNext( + @PathParam(value = "nextLink", encoded = true) String nextLink, @HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response listByResourceGroupNextSync( + @PathParam(value = "nextLink", encoded = true) String nextLink, @HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, Context context); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type along + * with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono>> createOrUpdateWithResponseAsync(String resourceGroupName, + String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource, String parameter, + String newParameter) { + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, contentType, accept, resource, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type along + * with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWithResponse(String resourceGroupName, + String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource, String parameter, + String newParameter) { + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, contentType, accept, resource, Context.NONE); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type along + * with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWithResponse(String resourceGroupName, + String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource, String parameter, + String newParameter, Context context) { + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, contentType, accept, resource, context); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type along + * with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWithResponse(String resourceGroupName, + String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource, String parameter, + Context context) { + final String newParameter = null; + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, contentType, accept, resource, context); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of concrete tracked resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, TopLevelArmResourceInner> beginCreateOrUpdateAsync( + String resourceGroupName, String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource, + String parameter, String newParameter) { + Mono>> mono = createOrUpdateWithResponseAsync(resourceGroupName, + topLevelArmResourcePropertiesName, resource, parameter, newParameter); + return this.client.getLroResult(mono, + this.client.getHttpPipeline(), TopLevelArmResourceInner.class, TopLevelArmResourceInner.class, + this.client.getContext()); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of concrete tracked resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, TopLevelArmResourceInner> beginCreateOrUpdateAsync( + String resourceGroupName, String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource) { + final String parameter = null; + final String newParameter = null; + Mono>> mono = createOrUpdateWithResponseAsync(resourceGroupName, + topLevelArmResourcePropertiesName, resource, parameter, newParameter); + return this.client.getLroResult(mono, + this.client.getHttpPipeline(), TopLevelArmResourceInner.class, TopLevelArmResourceInner.class, + this.client.getContext()); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of concrete tracked resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, TopLevelArmResourceInner> beginCreateOrUpdate( + String resourceGroupName, String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource, + String parameter, String newParameter) { + Response response = createOrUpdateWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, + resource, parameter, newParameter); + return this.client.getLroResult(response, + TopLevelArmResourceInner.class, TopLevelArmResourceInner.class, Context.NONE); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of concrete tracked resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, TopLevelArmResourceInner> beginCreateOrUpdate( + String resourceGroupName, String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource) { + final String parameter = null; + final String newParameter = null; + Response response = createOrUpdateWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, + resource, parameter, newParameter); + return this.client.getLroResult(response, + TopLevelArmResourceInner.class, TopLevelArmResourceInner.class, Context.NONE); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of concrete tracked resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, TopLevelArmResourceInner> beginCreateOrUpdate( + String resourceGroupName, String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource, + String parameter, String newParameter, Context context) { + Response response = createOrUpdateWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, + resource, parameter, newParameter, context); + return this.client.getLroResult(response, + TopLevelArmResourceInner.class, TopLevelArmResourceInner.class, context); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of concrete tracked resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, TopLevelArmResourceInner> beginCreateOrUpdate( + String resourceGroupName, String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource, + String parameter, Context context) { + Response response = createOrUpdateWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, + resource, parameter, context); + return this.client.getLroResult(response, + TopLevelArmResourceInner.class, TopLevelArmResourceInner.class, context); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono createOrUpdateAsync(String resourceGroupName, + String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource, String parameter, + String newParameter) { + return beginCreateOrUpdateAsync(resourceGroupName, topLevelArmResourcePropertiesName, resource, parameter, + newParameter).last().flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono createOrUpdateAsync(String resourceGroupName, + String topLevelArmResourcePropertiesName, TopLevelArmResourceInner resource) { + final String parameter = null; + final String newParameter = null; + return beginCreateOrUpdateAsync(resourceGroupName, topLevelArmResourcePropertiesName, resource, parameter, + newParameter).last().flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public TopLevelArmResourceInner createOrUpdate(String resourceGroupName, String topLevelArmResourcePropertiesName, + TopLevelArmResourceInner resource) { + final String parameter = null; + final String newParameter = null; + return beginCreateOrUpdate(resourceGroupName, topLevelArmResourcePropertiesName, resource, parameter, + newParameter).getFinalResult(); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public TopLevelArmResourceInner createOrUpdate(String resourceGroupName, String topLevelArmResourcePropertiesName, + TopLevelArmResourceInner resource, String parameter, String newParameter, Context context) { + return beginCreateOrUpdate(resourceGroupName, topLevelArmResourcePropertiesName, resource, parameter, + newParameter, context).getFinalResult(); + } + + /** + * Create a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param resource Resource create parameters. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete tracked resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public TopLevelArmResourceInner createOrUpdate(String resourceGroupName, String topLevelArmResourcePropertiesName, + TopLevelArmResourceInner resource, String parameter, Context context) { + return beginCreateOrUpdate(resourceGroupName, topLevelArmResourcePropertiesName, resource, parameter, context) + .getFinalResult(); + } + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSinglePageAsync(String parameter, String newParameter) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.list(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), parameter, newParameter, accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), + res.getStatusCode(), res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync(String parameter, String newParameter) { + return new PagedFlux<>(() -> listSinglePageAsync(parameter, newParameter), + nextLink -> listBySubscriptionNextSinglePageAsync(nextLink)); + } + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync() { + final String parameter = null; + final String newParameter = null; + return new PagedFlux<>(() -> listSinglePageAsync(parameter, newParameter), + nextLink -> listBySubscriptionNextSinglePageAsync(nextLink)); + } + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listSinglePage(String parameter, String newParameter) { + final String accept = "application/json"; + Response res + = service.listSync(this.client.getEndpoint(), this.client.getApiVersion(), this.client.getSubscriptionId(), + parameter, newParameter, accept, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), + res.getValue().nextLink(), null); + } + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listSinglePage(String parameter, String newParameter, + Context context) { + final String accept = "application/json"; + Response res = service.listSync(this.client.getEndpoint(), + this.client.getApiVersion(), this.client.getSubscriptionId(), parameter, newParameter, accept, context); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), + res.getValue().nextLink(), null); + } + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listSinglePage(String parameter, Context context) { + final String newParameter = null; + final String accept = "application/json"; + Response res = service.listSync(this.client.getEndpoint(), + this.client.getApiVersion(), this.client.getSubscriptionId(), parameter, newParameter, accept, context); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), + res.getValue().nextLink(), null); + } + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list() { + final String parameter = null; + final String newParameter = null; + return new PagedIterable<>(() -> listSinglePage(parameter, newParameter), + nextLink -> listBySubscriptionNextSinglePage(nextLink)); + } + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list(String parameter, String newParameter, Context context) { + return new PagedIterable<>(() -> listSinglePage(parameter, newParameter, context), + nextLink -> listBySubscriptionNextSinglePage(nextLink, context)); + } + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list(String parameter, Context context) { + return new PagedIterable<>(() -> listSinglePage(parameter, context), + nextLink -> listBySubscriptionNextSinglePage(nextLink, context)); + } + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByResourceGroupSinglePageAsync(String resourceGroupName, + String parameter, String newParameter) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listByResourceGroup(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, parameter, newParameter, accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), + res.getStatusCode(), res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listByResourceGroupAsync(String resourceGroupName, String parameter, + String newParameter) { + return new PagedFlux<>(() -> listByResourceGroupSinglePageAsync(resourceGroupName, parameter, newParameter), + nextLink -> listByResourceGroupNextSinglePageAsync(nextLink)); + } + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listByResourceGroupAsync(String resourceGroupName) { + final String parameter = null; + final String newParameter = null; + return new PagedFlux<>(() -> listByResourceGroupSinglePageAsync(resourceGroupName, parameter, newParameter), + nextLink -> listByResourceGroupNextSinglePageAsync(nextLink)); + } + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listByResourceGroupSinglePage(String resourceGroupName, + String parameter, String newParameter) { + final String accept = "application/json"; + Response res + = service.listByResourceGroupSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, parameter, newParameter, accept, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), + res.getValue().nextLink(), null); + } + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listByResourceGroupSinglePage(String resourceGroupName, + String parameter, String newParameter, Context context) { + final String accept = "application/json"; + Response res + = service.listByResourceGroupSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, parameter, newParameter, accept, context); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), + res.getValue().nextLink(), null); + } + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listByResourceGroupSinglePage(String resourceGroupName, + String parameter, Context context) { + final String newParameter = null; + final String accept = "application/json"; + Response res + = service.listByResourceGroupSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, parameter, newParameter, accept, context); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), + res.getValue().nextLink(), null); + } + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listByResourceGroup(String resourceGroupName) { + final String parameter = null; + final String newParameter = null; + return new PagedIterable<>(() -> listByResourceGroupSinglePage(resourceGroupName, parameter, newParameter), + nextLink -> listByResourceGroupNextSinglePage(nextLink)); + } + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listByResourceGroup(String resourceGroupName, String parameter, + String newParameter, Context context) { + return new PagedIterable<>( + () -> listByResourceGroupSinglePage(resourceGroupName, parameter, newParameter, context), + nextLink -> listByResourceGroupNextSinglePage(nextLink, context)); + } + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listByResourceGroup(String resourceGroupName, String parameter, + Context context) { + return new PagedIterable<>(() -> listByResourceGroupSinglePage(resourceGroupName, parameter, context), + nextLink -> listByResourceGroupNextSinglePage(nextLink, context)); + } + + /** + * Get a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getByResourceGroupWithResponseAsync(String resourceGroupName, + String topLevelArmResourcePropertiesName, String parameter, String newParameter) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono getByResourceGroupAsync(String resourceGroupName, + String topLevelArmResourcePropertiesName) { + final String parameter = null; + final String newParameter = null; + return getByResourceGroupWithResponseAsync(resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter).flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Get a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getByResourceGroupWithResponse(String resourceGroupName, + String topLevelArmResourcePropertiesName, String parameter, String newParameter, Context context) { + final String accept = "application/json"; + return service.getByResourceGroupSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, accept, context); + } + + /** + * Get a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getByResourceGroupWithResponse(String resourceGroupName, + String topLevelArmResourcePropertiesName, String parameter, Context context) { + final String newParameter = null; + final String accept = "application/json"; + return service.getByResourceGroupSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, accept, context); + } + + /** + * Get a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public TopLevelArmResourceInner getByResourceGroup(String resourceGroupName, + String topLevelArmResourcePropertiesName) { + final String parameter = null; + final String newParameter = null; + return getByResourceGroupWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, Context.NONE).getValue(); + } + + /** + * Delete a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> deleteWithResponseAsync(String resourceGroupName, + String topLevelArmResourcePropertiesName, String parameter, String newParameter) { + return FluxUtil + .withContext(context -> service.delete(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Delete a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono deleteAsync(String resourceGroupName, String topLevelArmResourcePropertiesName) { + final String parameter = null; + final String newParameter = null; + return deleteWithResponseAsync(resourceGroupName, topLevelArmResourcePropertiesName, parameter, newParameter) + .flatMap(ignored -> Mono.empty()); + } + + /** + * Delete a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response deleteWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, String newParameter, Context context) { + return service.deleteSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, context); + } + + /** + * Delete a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response deleteWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, Context context) { + final String newParameter = null; + return service.deleteSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, context); + } + + /** + * Delete a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void delete(String resourceGroupName, String topLevelArmResourcePropertiesName) { + final String parameter = null; + final String newParameter = null; + deleteWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, newParameter, Context.NONE); + } + + /** + * A synchronous resource action. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> actionWithResponseAsync(String resourceGroupName, + String topLevelArmResourcePropertiesName, String parameter, String newParameter) { + return FluxUtil + .withContext(context -> service.action(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * A synchronous resource action. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono actionAsync(String resourceGroupName, String topLevelArmResourcePropertiesName) { + final String parameter = null; + final String newParameter = null; + return actionWithResponseAsync(resourceGroupName, topLevelArmResourcePropertiesName, parameter, newParameter) + .flatMap(ignored -> Mono.empty()); + } + + /** + * A synchronous resource action. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response actionWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, String newParameter, Context context) { + return service.actionSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, context); + } + + /** + * A synchronous resource action. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response actionWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, Context context) { + final String newParameter = null; + return service.actionSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, context); + } + + /** + * A synchronous resource action. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void action(String resourceGroupName, String topLevelArmResourcePropertiesName) { + final String parameter = null; + final String newParameter = null; + actionWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, newParameter, Context.NONE); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listBySubscriptionNextSinglePageAsync(String nextLink) { + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), + res.getStatusCode(), res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listBySubscriptionNextSinglePage(String nextLink) { + final String accept = "application/json"; + Response res + = service.listBySubscriptionNextSync(nextLink, this.client.getEndpoint(), accept, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), + res.getValue().nextLink(), null); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listBySubscriptionNextSinglePage(String nextLink, Context context) { + final String accept = "application/json"; + Response res + = service.listBySubscriptionNextSync(nextLink, this.client.getEndpoint(), accept, context); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), + res.getValue().nextLink(), null); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByResourceGroupNextSinglePageAsync(String nextLink) { + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.listByResourceGroupNext(nextLink, this.client.getEndpoint(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), + res.getStatusCode(), res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listByResourceGroupNextSinglePage(String nextLink) { + final String accept = "application/json"; + Response res + = service.listByResourceGroupNextSync(nextLink, this.client.getEndpoint(), accept, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), + res.getValue().nextLink(), null); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listByResourceGroupNextSinglePage(String nextLink, + Context context) { + final String accept = "application/json"; + Response res + = service.listByResourceGroupNextSync(nextLink, this.client.getEndpoint(), accept, context); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), + res.getValue().nextLink(), null); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/TopLevelArmResourcesImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/TopLevelArmResourcesImpl.java new file mode 100644 index 00000000000..a0b31f30dba --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/TopLevelArmResourcesImpl.java @@ -0,0 +1,228 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.implementation; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; +import tsptest.armversioned.fluent.TopLevelArmResourcesClient; +import tsptest.armversioned.fluent.models.TopLevelArmResourceInner; +import tsptest.armversioned.models.TopLevelArmResource; +import tsptest.armversioned.models.TopLevelArmResources; + +public final class TopLevelArmResourcesImpl implements TopLevelArmResources { + private static final ClientLogger LOGGER = new ClientLogger(TopLevelArmResourcesImpl.class); + + private final TopLevelArmResourcesClient innerClient; + + private final tsptest.armversioned.ArmVersionedManager serviceManager; + + public TopLevelArmResourcesImpl(TopLevelArmResourcesClient innerClient, + tsptest.armversioned.ArmVersionedManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public PagedIterable list() { + PagedIterable inner = this.serviceClient().list(); + return ResourceManagerUtils.mapPage(inner, inner1 -> new TopLevelArmResourceImpl(inner1, this.manager())); + } + + public PagedIterable list(String parameter, String newParameter, Context context) { + PagedIterable inner = this.serviceClient().list(parameter, newParameter, context); + return ResourceManagerUtils.mapPage(inner, inner1 -> new TopLevelArmResourceImpl(inner1, this.manager())); + } + + public PagedIterable list(String parameter, Context context) { + PagedIterable inner = this.serviceClient().list(parameter, context); + return ResourceManagerUtils.mapPage(inner, inner1 -> new TopLevelArmResourceImpl(inner1, this.manager())); + } + + public PagedIterable listByResourceGroup(String resourceGroupName) { + PagedIterable inner = this.serviceClient().listByResourceGroup(resourceGroupName); + return ResourceManagerUtils.mapPage(inner, inner1 -> new TopLevelArmResourceImpl(inner1, this.manager())); + } + + public PagedIterable listByResourceGroup(String resourceGroupName, String parameter, + String newParameter, Context context) { + PagedIterable inner + = this.serviceClient().listByResourceGroup(resourceGroupName, parameter, newParameter, context); + return ResourceManagerUtils.mapPage(inner, inner1 -> new TopLevelArmResourceImpl(inner1, this.manager())); + } + + public PagedIterable listByResourceGroup(String resourceGroupName, String parameter, + Context context) { + PagedIterable inner + = this.serviceClient().listByResourceGroup(resourceGroupName, parameter, context); + return ResourceManagerUtils.mapPage(inner, inner1 -> new TopLevelArmResourceImpl(inner1, this.manager())); + } + + public Response getByResourceGroupWithResponse(String resourceGroupName, + String topLevelArmResourcePropertiesName, String parameter, String newParameter, Context context) { + Response inner = this.serviceClient() + .getByResourceGroupWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new TopLevelArmResourceImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public Response getByResourceGroupWithResponse(String resourceGroupName, + String topLevelArmResourcePropertiesName, String parameter, Context context) { + Response inner = this.serviceClient() + .getByResourceGroupWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new TopLevelArmResourceImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public TopLevelArmResource getByResourceGroup(String resourceGroupName, String topLevelArmResourcePropertiesName) { + TopLevelArmResourceInner inner + = this.serviceClient().getByResourceGroup(resourceGroupName, topLevelArmResourcePropertiesName); + if (inner != null) { + return new TopLevelArmResourceImpl(inner, this.manager()); + } else { + return null; + } + } + + public Response deleteWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, String newParameter, Context context) { + return this.serviceClient() + .deleteWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, newParameter, context); + } + + public Response deleteWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, Context context) { + return this.serviceClient() + .deleteWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, context); + } + + public void delete(String resourceGroupName, String topLevelArmResourcePropertiesName) { + this.serviceClient().delete(resourceGroupName, topLevelArmResourcePropertiesName); + } + + public Response actionWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, String newParameter, Context context) { + return this.serviceClient() + .actionWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, newParameter, context); + } + + public Response actionWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, Context context) { + return this.serviceClient() + .actionWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, context); + } + + public void action(String resourceGroupName, String topLevelArmResourcePropertiesName) { + this.serviceClient().action(resourceGroupName, topLevelArmResourcePropertiesName); + } + + public TopLevelArmResource getById(String id) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String topLevelArmResourcePropertiesName + = ResourceManagerUtils.getValueFromIdByName(id, "topLevelArmResources"); + if (topLevelArmResourcePropertiesName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'topLevelArmResources'.", id))); + } + String localParameter = null; + String localNewParameter = null; + return this + .getByResourceGroupWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, localParameter, + localNewParameter, Context.NONE) + .getValue(); + } + + public Response getByIdWithResponse(String id, String parameter, String newParameter, + Context context) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String topLevelArmResourcePropertiesName + = ResourceManagerUtils.getValueFromIdByName(id, "topLevelArmResources"); + if (topLevelArmResourcePropertiesName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'topLevelArmResources'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, + newParameter, context); + } + + public void deleteById(String id) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String topLevelArmResourcePropertiesName + = ResourceManagerUtils.getValueFromIdByName(id, "topLevelArmResources"); + if (topLevelArmResourcePropertiesName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'topLevelArmResources'.", id))); + } + String localParameter = null; + String localNewParameter = null; + this.deleteWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, localParameter, localNewParameter, + Context.NONE); + } + + public Response deleteByIdWithResponse(String id, String parameter, String newParameter, Context context) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String topLevelArmResourcePropertiesName + = ResourceManagerUtils.getValueFromIdByName(id, "topLevelArmResources"); + if (topLevelArmResourcePropertiesName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'topLevelArmResources'.", id))); + } + return this.deleteWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, newParameter, + context); + } + + public Response deleteByIdWithResponse(String id, String parameter, Context context) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String topLevelArmResourcePropertiesName + = ResourceManagerUtils.getValueFromIdByName(id, "topLevelArmResources"); + if (topLevelArmResourcePropertiesName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'topLevelArmResources'.", id))); + } + return this.deleteWithResponse(resourceGroupName, topLevelArmResourcePropertiesName, parameter, context); + } + + private TopLevelArmResourcesClient serviceClient() { + return this.innerClient; + } + + private tsptest.armversioned.ArmVersionedManager manager() { + return this.serviceManager; + } + + public TopLevelArmResourceImpl define(String name) { + return new TopLevelArmResourceImpl(name, this.manager()); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/models/TopLevelArmResourceListResult.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/models/TopLevelArmResourceListResult.java new file mode 100644 index 00000000000..89c6c334369 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/models/TopLevelArmResourceListResult.java @@ -0,0 +1,97 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.implementation.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.List; +import tsptest.armversioned.fluent.models.TopLevelArmResourceInner; + +/** + * The response of a TopLevelArmResource list operation. + */ +@Immutable +public final class TopLevelArmResourceListResult implements JsonSerializable { + /* + * The TopLevelArmResource items on this page + */ + private List value; + + /* + * The link to the next page of items + */ + private String nextLink; + + /** + * Creates an instance of TopLevelArmResourceListResult class. + */ + private TopLevelArmResourceListResult() { + } + + /** + * Get the value property: The TopLevelArmResource items on this page. + * + * @return the value value. + */ + public List value() { + return this.value; + } + + /** + * Get the nextLink property: The link to the next page of items. + * + * @return the nextLink value. + */ + public String nextLink() { + return this.nextLink; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("nextLink", this.nextLink); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of TopLevelArmResourceListResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of TopLevelArmResourceListResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the TopLevelArmResourceListResult. + */ + public static TopLevelArmResourceListResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + TopLevelArmResourceListResult deserializedTopLevelArmResourceListResult + = new TopLevelArmResourceListResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value + = reader.readArray(reader1 -> TopLevelArmResourceInner.fromJson(reader1)); + deserializedTopLevelArmResourceListResult.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedTopLevelArmResourceListResult.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedTopLevelArmResourceListResult; + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/package-info.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/package-info.java new file mode 100644 index 00000000000..414dcf31448 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/implementation/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the implementations for ArmVersioned. + * Arm Resource Provider management API. + */ +package tsptest.armversioned.implementation; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/ResourceProvisioningState.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/ResourceProvisioningState.java new file mode 100644 index 00000000000..2ebeed742f0 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/ResourceProvisioningState.java @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The provisioning state of a resource type. + */ +public final class ResourceProvisioningState extends ExpandableStringEnum { + /** + * Resource has been created. + */ + public static final ResourceProvisioningState SUCCEEDED = fromString("Succeeded"); + + /** + * Resource creation failed. + */ + public static final ResourceProvisioningState FAILED = fromString("Failed"); + + /** + * Resource creation was canceled. + */ + public static final ResourceProvisioningState CANCELED = fromString("Canceled"); + + /** + * Creates a new instance of ResourceProvisioningState value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public ResourceProvisioningState() { + } + + /** + * Creates or finds a ResourceProvisioningState from its string representation. + * + * @param name a name to look for. + * @return the corresponding ResourceProvisioningState. + */ + public static ResourceProvisioningState fromString(String name) { + return fromString(name, ResourceProvisioningState.class); + } + + /** + * Gets known ResourceProvisioningState values. + * + * @return known ResourceProvisioningState values. + */ + public static Collection values() { + return values(ResourceProvisioningState.class); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/TopLevelArmResource.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/TopLevelArmResource.java new file mode 100644 index 00000000000..5de933bb660 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/TopLevelArmResource.java @@ -0,0 +1,353 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.models; + +import com.azure.core.http.rest.Response; +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import java.util.Map; +import tsptest.armversioned.fluent.models.TopLevelArmResourceInner; + +/** + * An immutable client-side representation of TopLevelArmResource. + */ +public interface TopLevelArmResource { + /** + * Gets the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + String id(); + + /** + * Gets the name property: The name of the resource. + * + * @return the name value. + */ + String name(); + + /** + * Gets the type property: The type of the resource. + * + * @return the type value. + */ + String type(); + + /** + * Gets the location property: The geo-location where the resource lives. + * + * @return the location value. + */ + String location(); + + /** + * Gets the tags property: Resource tags. + * + * @return the tags value. + */ + Map tags(); + + /** + * Gets the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + TopLevelArmResourceProperties properties(); + + /** + * Gets the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + SystemData systemData(); + + /** + * Gets the region of the resource. + * + * @return the region of the resource. + */ + Region region(); + + /** + * Gets the name of the resource region. + * + * @return the name of the resource region. + */ + String regionName(); + + /** + * Gets the name of the resource group. + * + * @return the name of the resource group. + */ + String resourceGroupName(); + + /** + * Gets the inner tsptest.armversioned.fluent.models.TopLevelArmResourceInner object. + * + * @return the inner object. + */ + TopLevelArmResourceInner innerModel(); + + /** + * The entirety of the TopLevelArmResource definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithLocation, + DefinitionStages.WithResourceGroup, DefinitionStages.WithCreate { + } + + /** + * The TopLevelArmResource definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the TopLevelArmResource definition. + */ + interface Blank extends WithLocation { + } + + /** + * The stage of the TopLevelArmResource definition allowing to specify location. + */ + interface WithLocation { + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(Region location); + + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(String location); + } + + /** + * The stage of the TopLevelArmResource definition allowing to specify parent resource. + */ + interface WithResourceGroup { + /** + * Specifies resourceGroupName. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @return the next definition stage. + */ + WithCreate withExistingResourceGroup(String resourceGroupName); + } + + /** + * The stage of the TopLevelArmResource definition which contains all the minimum required properties for the + * resource to be created, but also allows for any other optional properties to be specified. + */ + interface WithCreate extends DefinitionStages.WithTags, DefinitionStages.WithProperties, + DefinitionStages.WithParameter, DefinitionStages.WithNewParameter { + /** + * Executes the create request. + * + * @return the created resource. + */ + TopLevelArmResource create(); + + /** + * Executes the create request. + * + * @param context The context to associate with this operation. + * @return the created resource. + */ + TopLevelArmResource create(Context context); + } + + /** + * The stage of the TopLevelArmResource definition allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + WithCreate withTags(Map tags); + } + + /** + * The stage of the TopLevelArmResource definition allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + WithCreate withProperties(TopLevelArmResourceProperties properties); + } + + /** + * The stage of the TopLevelArmResource definition allowing to specify parameter. + */ + interface WithParameter { + /** + * Specifies the parameter property: The parameter parameter. + * + * @param parameter The parameter parameter. + * @return the next definition stage. + */ + WithCreate withParameter(String parameter); + } + + /** + * The stage of the TopLevelArmResource definition allowing to specify newParameter. + */ + interface WithNewParameter { + /** + * Specifies the newParameter property: The newParameter parameter. + * + * @param newParameter The newParameter parameter. + * @return the next definition stage. + */ + WithCreate withNewParameter(String newParameter); + } + } + + /** + * Begins update for the TopLevelArmResource resource. + * + * @return the stage of resource update. + */ + TopLevelArmResource.Update update(); + + /** + * The template for TopLevelArmResource update. + */ + interface Update extends UpdateStages.WithTags, UpdateStages.WithProperties, UpdateStages.WithParameter, + UpdateStages.WithNewParameter { + /** + * Executes the update request. + * + * @return the updated resource. + */ + TopLevelArmResource apply(); + + /** + * Executes the update request. + * + * @param context The context to associate with this operation. + * @return the updated resource. + */ + TopLevelArmResource apply(Context context); + } + + /** + * The TopLevelArmResource update stages. + */ + interface UpdateStages { + /** + * The stage of the TopLevelArmResource update allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + Update withTags(Map tags); + } + + /** + * The stage of the TopLevelArmResource update allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + Update withProperties(TopLevelArmResourceProperties properties); + } + + /** + * The stage of the TopLevelArmResource update allowing to specify parameter. + */ + interface WithParameter { + /** + * Specifies the parameter property: The parameter parameter. + * + * @param parameter The parameter parameter. + * @return the next definition stage. + */ + Update withParameter(String parameter); + } + + /** + * The stage of the TopLevelArmResource update allowing to specify newParameter. + */ + interface WithNewParameter { + /** + * Specifies the newParameter property: The newParameter parameter. + * + * @param newParameter The newParameter parameter. + * @return the next definition stage. + */ + Update withNewParameter(String newParameter); + } + } + + /** + * Refreshes the resource to sync with Azure. + * + * @return the refreshed resource. + */ + TopLevelArmResource refresh(); + + /** + * Refreshes the resource to sync with Azure. + * + * @param context The context to associate with this operation. + * @return the refreshed resource. + */ + TopLevelArmResource refresh(Context context); + + /** + * A synchronous resource action. + * + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + Response actionWithResponse(String parameter, String newParameter, Context context); + + /** + * A synchronous resource action. + * + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + Response actionWithResponse(String parameter, Context context); + + /** + * A synchronous resource action. + * + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void action(); +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/TopLevelArmResourceProperties.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/TopLevelArmResourceProperties.java new file mode 100644 index 00000000000..4cf68776cea --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/TopLevelArmResourceProperties.java @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Top Level Arm Resource Properties. + */ +@Immutable +public final class TopLevelArmResourceProperties implements JsonSerializable { + /* + * The provisioningState property. + */ + private ResourceProvisioningState provisioningState; + + /** + * Creates an instance of TopLevelArmResourceProperties class. + */ + public TopLevelArmResourceProperties() { + } + + /** + * Get the provisioningState property: The provisioningState property. + * + * @return the provisioningState value. + */ + public ResourceProvisioningState provisioningState() { + return this.provisioningState; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of TopLevelArmResourceProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of TopLevelArmResourceProperties if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the TopLevelArmResourceProperties. + */ + public static TopLevelArmResourceProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + TopLevelArmResourceProperties deserializedTopLevelArmResourceProperties + = new TopLevelArmResourceProperties(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("provisioningState".equals(fieldName)) { + deserializedTopLevelArmResourceProperties.provisioningState + = ResourceProvisioningState.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedTopLevelArmResourceProperties; + }); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/TopLevelArmResources.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/TopLevelArmResources.java new file mode 100644 index 00000000000..ebc8b5ca2b2 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/TopLevelArmResources.java @@ -0,0 +1,285 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.models; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; + +/** + * Resource collection API of TopLevelArmResources. + */ +public interface TopLevelArmResources { + /** + * List TopLevelArmResource resources by subscription ID. + * + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable list(); + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable list(String parameter, String newParameter, Context context); + + /** + * List TopLevelArmResource resources by subscription ID. + * + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable list(String parameter, Context context); + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable listByResourceGroup(String resourceGroupName); + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable listByResourceGroup(String resourceGroupName, String parameter, + String newParameter, Context context); + + /** + * List TopLevelArmResource resources by resource group. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response of a TopLevelArmResource list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable listByResourceGroup(String resourceGroupName, String parameter, Context context); + + /** + * Get a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource along with {@link Response}. + */ + Response getByResourceGroupWithResponse(String resourceGroupName, + String topLevelArmResourcePropertiesName, String parameter, String newParameter, Context context); + + /** + * Get a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource along with {@link Response}. + */ + Response getByResourceGroupWithResponse(String resourceGroupName, + String topLevelArmResourcePropertiesName, String parameter, Context context); + + /** + * Get a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource. + */ + TopLevelArmResource getByResourceGroup(String resourceGroupName, String topLevelArmResourcePropertiesName); + + /** + * Delete a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + Response deleteWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, String newParameter, Context context); + + /** + * Delete a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + Response deleteWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, Context context); + + /** + * Delete a TopLevelArmResource. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void delete(String resourceGroupName, String topLevelArmResourcePropertiesName); + + /** + * A synchronous resource action. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + Response actionWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, String newParameter, Context context); + + /** + * A synchronous resource action. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + Response actionWithResponse(String resourceGroupName, String topLevelArmResourcePropertiesName, + String parameter, Context context); + + /** + * A synchronous resource action. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param topLevelArmResourcePropertiesName The name of the TopLevelArmResourceProperties. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void action(String resourceGroupName, String topLevelArmResourcePropertiesName); + + /** + * Get a TopLevelArmResource. + * + * @param id the resource ID. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource along with {@link Response}. + */ + TopLevelArmResource getById(String id); + + /** + * Get a TopLevelArmResource. + * + * @param id the resource ID. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a TopLevelArmResource along with {@link Response}. + */ + Response getByIdWithResponse(String id, String parameter, String newParameter, + Context context); + + /** + * Delete a TopLevelArmResource. + * + * @param id the resource ID. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void deleteById(String id); + + /** + * Delete a TopLevelArmResource. + * + * @param id the resource ID. + * @param parameter The parameter parameter. + * @param newParameter The newParameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + Response deleteByIdWithResponse(String id, String parameter, String newParameter, Context context); + + /** + * Delete a TopLevelArmResource. + * + * @param id the resource ID. + * @param parameter The parameter parameter. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + Response deleteByIdWithResponse(String id, String parameter, Context context); + + /** + * Begins definition for a new TopLevelArmResource resource. + * + * @param name resource name. + * @return the first stage of the new TopLevelArmResource definition. + */ + TopLevelArmResource.DefinitionStages.Blank define(String name); +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/package-info.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/package-info.java new file mode 100644 index 00000000000..aca33de66ee --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the data models for ArmVersioned. + * Arm Resource Provider management API. + */ +package tsptest.armversioned.models; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/package-info.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/package-info.java new file mode 100644 index 00000000000..b306aaf7b89 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/armversioned/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the classes for ArmVersioned. + * Arm Resource Provider management API. + */ +package tsptest.armversioned; diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/azure-resourcemanager-armversioned-generated_apiview_properties.json b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/azure-resourcemanager-armversioned-generated_apiview_properties.json new file mode 100644 index 00000000000..6f845da1398 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/azure-resourcemanager-armversioned-generated_apiview_properties.json @@ -0,0 +1,22 @@ +{ + "flavor": "Azure", + "CrossLanguageDefinitionId": { + "tsptest.armversioned.fluent.ArmVersionedClient": "TspTest.ArmVersioned", + "tsptest.armversioned.fluent.TopLevelArmResourcesClient": "TspTest.ArmVersioned.TopLevelArmResources", + "tsptest.armversioned.fluent.TopLevelArmResourcesClient.action": "TspTest.ArmVersioned.TopLevelArmResources.action", + "tsptest.armversioned.fluent.TopLevelArmResourcesClient.actionWithResponse": "TspTest.ArmVersioned.TopLevelArmResources.action", + "tsptest.armversioned.fluent.TopLevelArmResourcesClient.beginCreateOrUpdate": "TspTest.ArmVersioned.TopLevelArmResources.createOrUpdate", + "tsptest.armversioned.fluent.TopLevelArmResourcesClient.createOrUpdate": "TspTest.ArmVersioned.TopLevelArmResources.createOrUpdate", + "tsptest.armversioned.fluent.TopLevelArmResourcesClient.delete": "TspTest.ArmVersioned.TopLevelArmResources.delete", + "tsptest.armversioned.fluent.TopLevelArmResourcesClient.deleteWithResponse": "TspTest.ArmVersioned.TopLevelArmResources.delete", + "tsptest.armversioned.fluent.TopLevelArmResourcesClient.getByResourceGroup": "TspTest.ArmVersioned.TopLevelArmResources.get", + "tsptest.armversioned.fluent.TopLevelArmResourcesClient.getByResourceGroupWithResponse": "TspTest.ArmVersioned.TopLevelArmResources.get", + "tsptest.armversioned.fluent.TopLevelArmResourcesClient.list": "TspTest.ArmVersioned.TopLevelArmResources.listBySubscription", + "tsptest.armversioned.fluent.TopLevelArmResourcesClient.listByResourceGroup": "TspTest.ArmVersioned.TopLevelArmResources.listByResourceGroup", + "tsptest.armversioned.fluent.models.TopLevelArmResourceInner": "TspTest.ArmVersioned.TopLevelArmResource", + "tsptest.armversioned.implementation.ArmVersionedClientBuilder": "TspTest.ArmVersioned", + "tsptest.armversioned.implementation.models.TopLevelArmResourceListResult": "Azure.ResourceManager.ResourceListResult", + "tsptest.armversioned.models.ResourceProvisioningState": "Azure.ResourceManager.ResourceProvisioningState", + "tsptest.armversioned.models.TopLevelArmResourceProperties": "TspTest.ArmVersioned.TopLevelArmResourceProperties" + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/azure-resourcemanager-armversioned-generated_metadata.json b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/azure-resourcemanager-armversioned-generated_metadata.json new file mode 100644 index 00000000000..5eb8d805513 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/azure-resourcemanager-armversioned-generated_metadata.json @@ -0,0 +1 @@ +{"flavor":"Azure","apiVersion":"2024-12-01","crossLanguageDefinitions":{"tsptest.armversioned.fluent.ArmVersionedClient":"TspTest.ArmVersioned","tsptest.armversioned.fluent.TopLevelArmResourcesClient":"TspTest.ArmVersioned.TopLevelArmResources","tsptest.armversioned.fluent.TopLevelArmResourcesClient.action":"TspTest.ArmVersioned.TopLevelArmResources.action","tsptest.armversioned.fluent.TopLevelArmResourcesClient.actionWithResponse":"TspTest.ArmVersioned.TopLevelArmResources.action","tsptest.armversioned.fluent.TopLevelArmResourcesClient.beginCreateOrUpdate":"TspTest.ArmVersioned.TopLevelArmResources.createOrUpdate","tsptest.armversioned.fluent.TopLevelArmResourcesClient.createOrUpdate":"TspTest.ArmVersioned.TopLevelArmResources.createOrUpdate","tsptest.armversioned.fluent.TopLevelArmResourcesClient.delete":"TspTest.ArmVersioned.TopLevelArmResources.delete","tsptest.armversioned.fluent.TopLevelArmResourcesClient.deleteWithResponse":"TspTest.ArmVersioned.TopLevelArmResources.delete","tsptest.armversioned.fluent.TopLevelArmResourcesClient.getByResourceGroup":"TspTest.ArmVersioned.TopLevelArmResources.get","tsptest.armversioned.fluent.TopLevelArmResourcesClient.getByResourceGroupWithResponse":"TspTest.ArmVersioned.TopLevelArmResources.get","tsptest.armversioned.fluent.TopLevelArmResourcesClient.list":"TspTest.ArmVersioned.TopLevelArmResources.listBySubscription","tsptest.armversioned.fluent.TopLevelArmResourcesClient.listByResourceGroup":"TspTest.ArmVersioned.TopLevelArmResources.listByResourceGroup","tsptest.armversioned.fluent.models.TopLevelArmResourceInner":"TspTest.ArmVersioned.TopLevelArmResource","tsptest.armversioned.implementation.ArmVersionedClientBuilder":"TspTest.ArmVersioned","tsptest.armversioned.implementation.models.TopLevelArmResourceListResult":"Azure.ResourceManager.ResourceListResult","tsptest.armversioned.models.ResourceProvisioningState":"Azure.ResourceManager.ResourceProvisioningState","tsptest.armversioned.models.TopLevelArmResourceProperties":"TspTest.ArmVersioned.TopLevelArmResourceProperties"},"generatedFiles":["src/main/java/module-info.java","src/main/java/tsptest/armversioned/ArmVersionedManager.java","src/main/java/tsptest/armversioned/fluent/ArmVersionedClient.java","src/main/java/tsptest/armversioned/fluent/TopLevelArmResourcesClient.java","src/main/java/tsptest/armversioned/fluent/models/TopLevelArmResourceInner.java","src/main/java/tsptest/armversioned/fluent/models/package-info.java","src/main/java/tsptest/armversioned/fluent/package-info.java","src/main/java/tsptest/armversioned/implementation/ArmVersionedClientBuilder.java","src/main/java/tsptest/armversioned/implementation/ArmVersionedClientImpl.java","src/main/java/tsptest/armversioned/implementation/ResourceManagerUtils.java","src/main/java/tsptest/armversioned/implementation/TopLevelArmResourceImpl.java","src/main/java/tsptest/armversioned/implementation/TopLevelArmResourcesClientImpl.java","src/main/java/tsptest/armversioned/implementation/TopLevelArmResourcesImpl.java","src/main/java/tsptest/armversioned/implementation/models/TopLevelArmResourceListResult.java","src/main/java/tsptest/armversioned/implementation/package-info.java","src/main/java/tsptest/armversioned/models/ResourceProvisioningState.java","src/main/java/tsptest/armversioned/models/TopLevelArmResource.java","src/main/java/tsptest/armversioned/models/TopLevelArmResourceProperties.java","src/main/java/tsptest/armversioned/models/TopLevelArmResources.java","src/main/java/tsptest/armversioned/models/package-info.java","src/main/java/tsptest/armversioned/package-info.java"]} \ No newline at end of file diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armversioned-generated/proxy-config.json b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armversioned-generated/proxy-config.json new file mode 100644 index 00000000000..12fd27ce30c --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armversioned-generated/proxy-config.json @@ -0,0 +1 @@ +[["tsptest.armversioned.implementation.TopLevelArmResourcesClientImpl$TopLevelArmResourcesService"]] \ No newline at end of file diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armversioned-generated/reflect-config.json b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armversioned-generated/reflect-config.json new file mode 100644 index 00000000000..0637a088a01 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armversioned-generated/reflect-config.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/resources/azure-resourcemanager-armversioned-generated.properties b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/azure-resourcemanager-armversioned-generated.properties new file mode 100644 index 00000000000..defbd48204e --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/resources/azure-resourcemanager-armversioned-generated.properties @@ -0,0 +1 @@ +version=${project.version} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/ArmVersionedTests.java b/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/ArmVersionedTests.java new file mode 100644 index 00000000000..14310a475cd --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/ArmVersionedTests.java @@ -0,0 +1,92 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package tsptest.armversioned; + +import com.azure.core.management.Region; +import com.azure.core.util.Context; +import org.mockito.Mockito; +import tsptest.armversioned.fluent.models.TopLevelArmResourceInner; +import tsptest.armversioned.models.TopLevelArmResource; + +public class ArmVersionedTests { + + // only to test compilation + public void testVersionedApi() { + ArmVersionedManager manager = Mockito.mock(ArmVersionedManager.class); + TopLevelArmResourceInner resourceInner = Mockito.mock(TopLevelArmResourceInner.class); + + // API without optional parameter + // this API exists in all versions + manager.topLevelArmResources().list(); + + manager.topLevelArmResources().listByResourceGroup("resourceGroup"); + + manager.topLevelArmResources().action("resourceGroup", "resourceName"); + + manager.serviceClient() + .getTopLevelArmResources() + .createOrUpdate("resourceGroup", "resourceName", resourceInner); + TopLevelArmResource resource = manager.topLevelArmResources() + .define("resourceName") + .withRegion(Region.US_WEST3) + .withExistingResourceGroup("resourceGroup") + .create(); + + resource.update().apply(); + + manager.topLevelArmResources().delete("resourceGroup", "resourceName"); + manager.topLevelArmResources().deleteById("id"); + + resource.refresh(); + + // API in 2024-12-01 + manager.topLevelArmResources().list("parameter", "newParameter", Context.NONE); + + manager.topLevelArmResources().listByResourceGroup("resourceGroup", "parameter", "newParameter", Context.NONE); + + manager.topLevelArmResources() + .actionWithResponse("resourceGroup", "resourceName", "parameter", "newParameter", Context.NONE); + + manager.serviceClient() + .getTopLevelArmResources() + .createOrUpdate("resourceGroup", "resourceName", resourceInner, "parameter", "newParameter", Context.NONE); + manager.topLevelArmResources() + .define("resourceName") + .withRegion(Region.US_WEST3) + .withExistingResourceGroup("resourceGroup") + .withParameter("parameter") + .withNewParameter("newParameter") + .create(); + + resource.update().withParameter("parameter").withNewParameter("newParameter").apply(); + + manager.topLevelArmResources() + .deleteWithResponse("resourceGroup", "resourceName", "parameter", "newParameter", Context.NONE); + manager.topLevelArmResources().deleteByIdWithResponse("id", "parameter", "newParameter", Context.NONE); + + // API in 2023-12-01 + // this op will be generated, if tspconfig has "advanced-versioning" option + // REST API allow adding optional parameter to operation + manager.topLevelArmResources().list("parameter", Context.NONE); + + manager.topLevelArmResources().listByResourceGroup("resourceGroup", "parameter", Context.NONE); + + manager.topLevelArmResources().actionWithResponse("resourceGroup", "resourceName", "parameter", Context.NONE); + + manager.serviceClient() + .getTopLevelArmResources() + .createOrUpdate("resourceGroup", "resourceName", resourceInner, "parameter", Context.NONE); + manager.topLevelArmResources() + .define("resourceName") + .withRegion(Region.US_WEST3) + .withExistingResourceGroup("resourceGroup") + .withParameter("parameter") + .create(); + + resource.update().withParameter("parameter").apply(); + + manager.topLevelArmResources().deleteWithResponse("resourceGroup", "resourceName", "parameter", Context.NONE); + manager.topLevelArmResources().deleteByIdWithResponse("id", "parameter", Context.NONE); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceInnerTests.java b/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceInnerTests.java new file mode 100644 index 00000000000..c0f8f2fc1ee --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceInnerTests.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.generated; + +import com.azure.core.util.BinaryData; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Assertions; +import tsptest.armversioned.fluent.models.TopLevelArmResourceInner; +import tsptest.armversioned.models.TopLevelArmResourceProperties; + +public final class TopLevelArmResourceInnerTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + TopLevelArmResourceInner model = BinaryData.fromString( + "{\"properties\":{\"provisioningState\":\"Succeeded\"},\"location\":\"uv\",\"tags\":{\"phrupidgsybbejhp\":\"pybczmehmtzopb\"},\"id\":\"oycmsxaobhdxbmt\",\"name\":\"ioq\",\"type\":\"zehtbmu\"}") + .toObject(TopLevelArmResourceInner.class); + Assertions.assertEquals("uv", model.location()); + Assertions.assertEquals("pybczmehmtzopb", model.tags().get("phrupidgsybbejhp")); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + TopLevelArmResourceInner model = new TopLevelArmResourceInner().withLocation("uv") + .withTags(mapOf("phrupidgsybbejhp", "pybczmehmtzopb")) + .withProperties(new TopLevelArmResourceProperties()); + model = BinaryData.fromObject(model).toObject(TopLevelArmResourceInner.class); + Assertions.assertEquals("uv", model.location()); + Assertions.assertEquals("pybczmehmtzopb", model.tags().get("phrupidgsybbejhp")); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceListResultTests.java b/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceListResultTests.java new file mode 100644 index 00000000000..bc7524675a2 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourceListResultTests.java @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.generated; + +import com.azure.core.util.BinaryData; +import org.junit.jupiter.api.Assertions; +import tsptest.armversioned.implementation.models.TopLevelArmResourceListResult; + +public final class TopLevelArmResourceListResultTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + TopLevelArmResourceListResult model = BinaryData.fromString( + "{\"value\":[{\"properties\":{\"provisioningState\":\"Failed\"},\"location\":\"hwlrx\",\"tags\":{\"dmbpazlobcufpdz\":\"soqijg\",\"qqjnqgl\":\"rbt\",\"foooj\":\"qgn\"},\"id\":\"wifsq\",\"name\":\"saagdf\",\"type\":\"glzlhjxrifkwmrv\"}],\"nextLink\":\"siznto\"}") + .toObject(TopLevelArmResourceListResult.class); + Assertions.assertEquals("hwlrx", model.value().get(0).location()); + Assertions.assertEquals("soqijg", model.value().get(0).tags().get("dmbpazlobcufpdz")); + Assertions.assertEquals("siznto", model.nextLink()); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourcePropertiesTests.java b/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourcePropertiesTests.java new file mode 100644 index 00000000000..fe3644035e9 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/test/java/tsptest/armversioned/generated/TopLevelArmResourcePropertiesTests.java @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armversioned.generated; + +import com.azure.core.util.BinaryData; +import tsptest.armversioned.models.TopLevelArmResourceProperties; + +public final class TopLevelArmResourcePropertiesTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + TopLevelArmResourceProperties model = BinaryData.fromString("{\"provisioningState\":\"Canceled\"}") + .toObject(TopLevelArmResourceProperties.class); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + TopLevelArmResourceProperties model = new TopLevelArmResourceProperties(); + model = BinaryData.fromObject(model).toObject(TopLevelArmResourceProperties.class); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/tsp/arm-versioned.tsp b/packages/http-client-java/generator/http-client-generator-test/tsp/arm-versioned.tsp new file mode 100644 index 00000000000..413fa7e7505 --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/tsp/arm-versioned.tsp @@ -0,0 +1,59 @@ +import "@typespec/http"; +import "@typespec/rest"; +import "@typespec/versioning"; +import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-azure-resource-manager"; +import "@azure-tools/typespec-client-generator-core"; + +using TypeSpec.Http; +using TypeSpec.Rest; +using TypeSpec.Versioning; +using Azure.ResourceManager; + +@armProviderNamespace +@service(#{ title: "ArmVersioned" }) +@versioned(Versions) +@doc("Arm Resource Provider management API.") +namespace TspTest.ArmVersioned; + +enum Versions { + v2023_12_01: "2023-12-01", + v2024_10_01_preview: "2024-10-01-preview", + v2024_12_01: "2024-12-01", +} + +@resource("topLevelArmResources") +model TopLevelArmResource is TrackedResource { + ...ResourceNameParameter; +} + +@doc("Top Level Arm Resource Properties.") +model TopLevelArmResourceProperties { + @visibility(Lifecycle.Read) + provisioningState?: ResourceProvisioningState; +} + +model OpParameters { + @query + parameter?: string; + + @added(Versions.v2024_10_01_preview) + @query + newParameter?: string; +} + +model Response {} + +interface TopLevelArmResources { + createOrUpdate is ArmResourceCreateOrUpdateAsync; + listBySubscription is ArmListBySubscription; + listByResourceGroup is ArmResourceListByParent; + get is ArmResourceRead; + delete is ArmResourceDeleteSync; + action is ArmResourceActionSync< + TopLevelArmResource, + Request = void, + Response = Response, + Parameters = OpParameters + >; +}