Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,16 @@ private List<ClientMethod> createClientMethods(Operation operation, boolean isPr
}

if (settings.isFluent()) {
createLroBeginClientMethods(baseMethod, methodNamer.getLroBeginAsyncMethodName(),
final PollingMetadata pollingMetadata = PollingMetadata.create(operation, proxyMethod,
methodsReturnDescription.getSyncReturnType());
final ClientMethod lroBaseMethod = pollingMetadata != null
? baseMethod.newBuilder()
.methodPollingDetails(pollingMetadata.asMethodPollingDetails())
.build()
: baseMethod;
createLroBeginClientMethods(lroBaseMethod, methodNamer.getLroBeginAsyncMethodName(),
methodNamer.getLroBeginMethodName(), methods, createMethodArgs);
this.createAdditionalLroMethods(baseMethod, methods, createMethodArgs);
this.createAdditionalLroMethods(lroBaseMethod, methods, createMethodArgs);
} else {
final PollingMetadata pollingMetadata = PollingMetadata.create(operation, proxyMethod,
methodsReturnDescription.getSyncReturnType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ public ReturnValue getReturnValue(ClientMethodType methodType, MethodPollingDeta
switch (methodType) {
case LongRunningBeginSync:
if (settings.isFluent()) {
final IType returnType = GenericType.syncPoller(GenericType.pollResult(syncReturnType.asNullable()),
syncReturnType.asNullable());
return createReturnValue(returnType, syncReturnType);
IType resultType = getPollAndFinalTypeForFluent(pollingDetails, true);
final IType returnType = GenericType.syncPoller(GenericType.pollResult(resultType), resultType);
return createReturnValue(returnType, resultType);
} else if (settings.isAzureV2()) {
IType returnType = GenericType.syncPoller(pollingDetails.getPollResultType(),
pollingDetails.getFinalResultType());
Expand All @@ -243,20 +243,44 @@ public ReturnValue getReturnValue(ClientMethodType methodType, MethodPollingDeta
}
case LongRunningBeginAsync:
if (settings.isFluent()) {
IType returnType = GenericType.pollerFlux(GenericType.pollResult(syncReturnType.asNullable()),
syncReturnType.asNullable());
return createReturnValue(returnType, syncReturnType);
IType resultType = getPollAndFinalTypeForFluent(pollingDetails, true);
IType returnType = GenericType.pollerFlux(GenericType.pollResult(resultType), resultType);
return createReturnValue(returnType, resultType);
} else {
IType returnType = GenericType.pollerFlux(pollingDetails.getPollResultType(),
pollingDetails.getFinalResultType());
return createReturnValue(returnType, pollingDetails.getFinalResultType());
}
case LongRunningSync: {
IType resultType = getPollAndFinalTypeForFluent(pollingDetails, false);
return createReturnValue(resultType, resultType);
}

case LongRunningAsync: {
IType resultType = getPollAndFinalTypeForFluent(pollingDetails, true);
return createReturnValue(mono(resultType), resultType);
}

default:
throw new IllegalArgumentException("Unsupported method type: " + methodType
+ ". Use 'getReturnValue(ClientMethodType)' for non-'LongRunningBegin' method types.");
}
}

private IType getPollAndFinalTypeForFluent(MethodPollingDetails pollingDetails, boolean useNullableType) {
// TODO (weidxu): we may use "pollingDetails.getFinalResultType()" as 1st choice
IType resultType = syncReturnType;
if (resultType == ClassType.VOID || resultType == PrimitiveType.VOID) {
// no body in response, check final result from MethodPollingDetails
if (pollingDetails != null
&& pollingDetails.getFinalResultType() != ClassType.VOID
&& pollingDetails.getFinalResultType() != PrimitiveType.VOID) {
resultType = pollingDetails.getFinalResultType();
}
}
return useNullableType ? resultType.asNullable() : resultType;
}

/**
* Creates a {@link ReturnValue} for the given return type and base type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.microsoft.typespec.http.client.generator.core.mapper.ClientMethodsReturnDescription;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientMethod;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientMethodType;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.MethodPollingDetails;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ProxyMethod;
import com.microsoft.typespec.http.client.generator.core.model.javamodel.JavaVisibility;
import com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.FluentStatic;
Expand Down Expand Up @@ -124,9 +125,10 @@ private void createLroGetFinalResultClientMethods(boolean isSync, ClientMethod b
= methodVisibility(clientMethodType, MethodOverloadType.OVERLOAD_MINIMUM, false, isProtocolMethod);
final JavaVisibility methodWithContextVisibility
= methodVisibility(clientMethodType, defaultOverloadType, true, isProtocolMethod);
final MethodPollingDetails methodPollingDetails = baseMethod.getMethodPollingDetails();

final ClientMethod lroGetFinalResultMethod = baseMethod.newBuilder()
.returnValue(methodsReturnDescription.getReturnValue(clientMethodType))
.returnValue(methodsReturnDescription.getReturnValue(clientMethodType, methodPollingDetails))
.name(methodName)
.onlyRequiredParameters(false)
.type(clientMethodType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import tsptest.armresourceprovider.implementation.ChildResourcesInterfacesImpl;
import tsptest.armresourceprovider.implementation.CustomTemplateResourceInterfacesImpl;
import tsptest.armresourceprovider.implementation.ImmutableResourceModelsImpl;
import tsptest.armresourceprovider.implementation.LroNoBodiesImpl;
import tsptest.armresourceprovider.implementation.ManagedMaintenanceWindowStatusOperationsImpl;
import tsptest.armresourceprovider.implementation.ModelInterfaceSameNamesImpl;
import tsptest.armresourceprovider.implementation.OperationsImpl;
Expand All @@ -45,6 +46,7 @@
import tsptest.armresourceprovider.models.ChildResourcesInterfaces;
import tsptest.armresourceprovider.models.CustomTemplateResourceInterfaces;
import tsptest.armresourceprovider.models.ImmutableResourceModels;
import tsptest.armresourceprovider.models.LroNoBodies;
import tsptest.armresourceprovider.models.ManagedMaintenanceWindowStatusOperations;
import tsptest.armresourceprovider.models.ModelInterfaceSameNames;
import tsptest.armresourceprovider.models.Operations;
Expand All @@ -71,6 +73,8 @@ public final class ArmResourceProviderManager {

private ImmutableResourceModels immutableResourceModels;

private LroNoBodies lroNoBodies;

private final ArmClient clientObject;

private ArmResourceProviderManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) {
Expand Down Expand Up @@ -389,6 +393,18 @@ public ImmutableResourceModels immutableResourceModels() {
return immutableResourceModels;
}

/**
* Gets the resource collection API of LroNoBodies.
*
* @return Resource collection API of LroNoBodies.
*/
public LroNoBodies lroNoBodies() {
if (this.lroNoBodies == null) {
this.lroNoBodies = new LroNoBodiesImpl(clientObject.getLroNoBodies(), this);
}
return lroNoBodies;
}

/**
* Gets wrapped service client ArmClient providing direct access to the underlying auto-generated API
* implementation, based on Azure REST API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,11 @@ public interface ArmClient {
* @return the ImmutableResourceModelsClient object.
*/
ImmutableResourceModelsClient getImmutableResourceModels();

/**
* Gets the LroNoBodiesClient object to access its operations.
*
* @return the LroNoBodiesClient object.
*/
LroNoBodiesClient getLroNoBodies();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package tsptest.armresourceprovider.fluent;

import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceMethod;
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.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import java.nio.ByteBuffer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import tsptest.armresourceprovider.models.ResourceLroNoBody;

/**
* An instance of this class provides access to all the operations defined in LroNoBodiesClient.
*/
public interface LroNoBodiesClient {
/**
* Create a ResourceLroNoBody.
*
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param resourceLroNoBodyName The name of the ResourceLroNoBody.
* @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 Response} on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(String resourceGroupName,
String resourceLroNoBodyName, ResourceLroNoBody resource);

/**
* Create a ResourceLroNoBody.
*
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param resourceLroNoBodyName The name of the ResourceLroNoBody.
* @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 PollerFlux} for polling of long-running operation.
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
PollerFlux<PollResult<ResourceLroNoBody>, ResourceLroNoBody> beginCreateOrUpdateAsync(String resourceGroupName,
String resourceLroNoBodyName, ResourceLroNoBody resource);

/**
* Create a ResourceLroNoBody.
*
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param resourceLroNoBodyName The name of the ResourceLroNoBody.
* @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 long-running operation.
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
SyncPoller<PollResult<ResourceLroNoBody>, ResourceLroNoBody> beginCreateOrUpdate(String resourceGroupName,
String resourceLroNoBodyName, ResourceLroNoBody resource);

/**
* Create a ResourceLroNoBody.
*
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param resourceLroNoBodyName The name of the ResourceLroNoBody.
* @param resource Resource create parameters.
* @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 long-running operation.
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
SyncPoller<PollResult<ResourceLroNoBody>, ResourceLroNoBody> beginCreateOrUpdate(String resourceGroupName,
String resourceLroNoBodyName, ResourceLroNoBody resource, Context context);

/**
* Create a ResourceLroNoBody.
*
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param resourceLroNoBodyName The name of the ResourceLroNoBody.
* @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 response body on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
Mono<ResourceLroNoBody> createOrUpdateAsync(String resourceGroupName, String resourceLroNoBodyName,
ResourceLroNoBody resource);

/**
* Create a ResourceLroNoBody.
*
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param resourceLroNoBodyName The name of the ResourceLroNoBody.
* @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 response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
ResourceLroNoBody createOrUpdate(String resourceGroupName, String resourceLroNoBodyName,
ResourceLroNoBody resource);

/**
* Create a ResourceLroNoBody.
*
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param resourceLroNoBodyName The name of the ResourceLroNoBody.
* @param resource Resource create parameters.
* @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.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
ResourceLroNoBody createOrUpdate(String resourceGroupName, String resourceLroNoBodyName, ResourceLroNoBody resource,
Context context);
}
Original file line number Diff line number Diff line change
@@ -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.armresourceprovider.fluent.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 tsptest.armresourceprovider.models.ProvisioningState;

/**
* The ResourceLroNoBodyProperties model.
*/
@Immutable
public final class ResourceLroNoBodyProperties implements JsonSerializable<ResourceLroNoBodyProperties> {
/*
* The status of the last operation.
*/
private ProvisioningState provisioningState;

/**
* Creates an instance of ResourceLroNoBodyProperties class.
*/
public ResourceLroNoBodyProperties() {
}

/**
* Get the provisioningState property: The status of the last operation.
*
* @return the provisioningState value.
*/
public ProvisioningState provisioningState() {
return this.provisioningState;
}

/**
* {@inheritDoc}
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
return jsonWriter.writeEndObject();
}

/**
* Reads an instance of ResourceLroNoBodyProperties from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of ResourceLroNoBodyProperties 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 ResourceLroNoBodyProperties.
*/
public static ResourceLroNoBodyProperties fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
ResourceLroNoBodyProperties deserializedResourceLroNoBodyProperties = new ResourceLroNoBodyProperties();
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();

if ("provisioningState".equals(fieldName)) {
deserializedResourceLroNoBodyProperties.provisioningState
= ProvisioningState.fromString(reader.getString());
} else {
reader.skipChildren();
}
}

return deserializedResourceLroNoBodyProperties;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import tsptest.armresourceprovider.fluent.ChildResourcesInterfacesClient;
import tsptest.armresourceprovider.fluent.CustomTemplateResourceInterfacesClient;
import tsptest.armresourceprovider.fluent.ImmutableResourceModelsClient;
import tsptest.armresourceprovider.fluent.LroNoBodiesClient;
import tsptest.armresourceprovider.fluent.ManagedMaintenanceWindowStatusOperationsClient;
import tsptest.armresourceprovider.fluent.ModelInterfaceSameNamesClient;
import tsptest.armresourceprovider.fluent.OperationsClient;
Expand Down Expand Up @@ -245,6 +246,20 @@ public ImmutableResourceModelsClient getImmutableResourceModels() {
return this.immutableResourceModels;
}

/**
* The LroNoBodiesClient object to access its operations.
*/
private final LroNoBodiesClient lroNoBodies;

/**
* Gets the LroNoBodiesClient object to access its operations.
*
* @return the LroNoBodiesClient object.
*/
public LroNoBodiesClient getLroNoBodies() {
return this.lroNoBodies;
}

/**
* Initializes an instance of ArmClient client.
*
Expand All @@ -271,6 +286,7 @@ public ImmutableResourceModelsClient getImmutableResourceModels() {
this.managedMaintenanceWindowStatusOperations = new ManagedMaintenanceWindowStatusOperationsClientImpl(this);
this.modelInterfaceSameNames = new ModelInterfaceSameNamesClientImpl(this);
this.immutableResourceModels = new ImmutableResourceModelsClientImpl(this);
this.lroNoBodies = new LroNoBodiesClientImpl(this);
}

/**
Expand Down
Loading
Loading