Skip to content

Commit

Permalink
Call into overload with context instead of duplicating logic (#2862)
Browse files Browse the repository at this point in the history
Call into overload with context instead of duplicating logic
  • Loading branch information
alzimmermsft authored Jul 17, 2024
1 parent 04814b6 commit 8ee3658
Show file tree
Hide file tree
Showing 134 changed files with 1,806 additions and 10,382 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,38 @@ public class AndroidClientMethod extends ClientMethod {

/**
* Create a new ClientMethod with the provided properties.
*
* @param description The description of this ClientMethod.
* @param returnValue The return value of this ClientMethod.
* @param name The name of this ClientMethod.
* @param parameters The parameters of this ClientMethod.
* @param onlyRequiredParameters Whether or not this ClientMethod has omitted optional parameters.
* @param onlyRequiredParameters Whether this ClientMethod has omitted optional parameters.
* @param type The type of this ClientMethod.
* @param proxyMethod The ProxyMethod that this ClientMethod eventually calls.
* @param validateExpressions The expressions (parameters and service client properties) that need to be validated in this ClientMethod.
* @param validateExpressions The expressions (parameters and service client properties) that need to be validated
* in this ClientMethod.
* @param clientReference The reference to the service client.
* @param requiredNullableParameterExpressions The parameter expressions which are required.
* @param isGroupedParameterRequired The parameter that needs to transformed before pagination.
* @param groupedParameterTypeName The type name of groupedParameter.
* @param methodPageDetails The pagination information if this is a paged method.
* @param methodTransformationDetails The parameter transformations before calling ProxyMethod.
* @param externalDocumentation The external documentation.
* @param hasWithContextOverload Whether this ClientMethod has a withContext overload.
*/
protected AndroidClientMethod(String description, ReturnValue returnValue, String name,
List<ClientMethodParameter> parameters, boolean onlyRequiredParameters,
ClientMethodType type, ProxyMethod proxyMethod, Map<String, String> validateExpressions,
String clientReference, List<String> requiredNullableParameterExpressions,
boolean isGroupedParameterRequired, String groupedParameterTypeName,
MethodPageDetails methodPageDetails, List<MethodTransformationDetail> methodTransformationDetails,
JavaVisibility methodVisibility, JavaVisibility methodVisibilityInWrapperClient, MethodPollingDetails methodPollingDetails, ExternalDocumentation externalDocumentation) {
super(description,
returnValue,
name,
parameters,
onlyRequiredParameters,
type,
proxyMethod,
validateExpressions,
clientReference,
requiredNullableParameterExpressions,
isGroupedParameterRequired,
groupedParameterTypeName,
methodPageDetails,
methodTransformationDetails,
methodVisibility,
methodVisibilityInWrapperClient,
null,
methodPollingDetails,
externalDocumentation,
null);
List<ClientMethodParameter> parameters, boolean onlyRequiredParameters, ClientMethodType type,
ProxyMethod proxyMethod, Map<String, String> validateExpressions, String clientReference,
List<String> requiredNullableParameterExpressions, boolean isGroupedParameterRequired,
String groupedParameterTypeName, MethodPageDetails methodPageDetails,
List<MethodTransformationDetail> methodTransformationDetails, JavaVisibility methodVisibility,
JavaVisibility methodVisibilityInWrapperClient, MethodPollingDetails methodPollingDetails,
ExternalDocumentation externalDocumentation, boolean hasWithContextOverload) {
super(description, returnValue, name, parameters, onlyRequiredParameters, type, proxyMethod,
validateExpressions, clientReference, requiredNullableParameterExpressions, isGroupedParameterRequired,
groupedParameterTypeName, methodPageDetails, methodTransformationDetails, methodVisibility,
methodVisibilityInWrapperClient, null, methodPollingDetails, externalDocumentation, null,
hasWithContextOverload);
}

@Override
Expand Down Expand Up @@ -101,29 +90,12 @@ public void addImportsTo(Set<String> imports, boolean includeImplementationImpor

public static class Builder extends ClientMethod.Builder {
@Override
/**
* @return an immutable ClientMethod instance with the configurations on this builder.
*/
public ClientMethod build() {
return new AndroidClientMethod(
description,
returnValue,
name,
parameters,
onlyRequiredParameters,
type,
proxyMethod,
validateExpressions,
clientReference,
requiredNullableParameterExpressions,
isGroupedParameterRequired,
groupedParameterTypeName,
methodPageDetails,
methodTransformationDetails,
methodVisibility,
methodVisibilityInWrapperClient,
methodPollingDetails,
externalDocumentation);
return new AndroidClientMethod(description, returnValue, name, parameters, onlyRequiredParameters, type,
proxyMethod, validateExpressions, clientReference, requiredNullableParameterExpressions,
isGroupedParameterRequired, groupedParameterTypeName, methodPageDetails, methodTransformationDetails,
methodVisibility, methodVisibilityInWrapperClient, methodPollingDetails, externalDocumentation,
hasWithContextOverload);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,8 @@ Response<GetDocumentModelsResponse> listModelsNextSync(
public Mono<ResponseBase<DocumentModelsAnalyzeDocumentHeaders, Void>> analyzeDocumentWithResponseAsync(
String modelId, String pages, String locale, StringIndexType stringIndexType,
AnalyzeDocumentRequest analyzeRequest) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.analyzeDocument(this.client.getEndpoint(), modelId, pages,
locale, stringIndexType, this.client.getApiVersion(), analyzeRequest, accept, context));
return FluxUtil.withContext(context -> analyzeDocumentWithResponseAsync(modelId, pages, locale, stringIndexType,
analyzeRequest, context));
}

/**
Expand Down Expand Up @@ -563,9 +562,8 @@ public SyncPoller<BinaryData, BinaryData> beginAnalyzeDocument(String modelId, S
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> analyzeDocumentNoCustomHeadersWithResponseAsync(String modelId, String pages,
String locale, StringIndexType stringIndexType, AnalyzeDocumentRequest analyzeRequest) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.analyzeDocumentNoCustomHeaders(this.client.getEndpoint(),
modelId, pages, locale, stringIndexType, this.client.getApiVersion(), analyzeRequest, accept, context));
return FluxUtil.withContext(context -> analyzeDocumentNoCustomHeadersWithResponseAsync(modelId, pages, locale,
stringIndexType, analyzeRequest, context));
}

/**
Expand Down Expand Up @@ -740,10 +738,8 @@ public SyncPoller<BinaryData, BinaryData> beginAnalyzeDocumentNoCustomHeaders(St
public Mono<ResponseBase<DocumentModelsAnalyzeDocumentHeaders, Void>> analyzeDocumentWithResponseAsync(
String modelId, ContentType contentType, String pages, String locale, StringIndexType stringIndexType,
Flux<ByteBuffer> analyzeRequest, Long contentLength) {
final String accept = "application/json";
return FluxUtil.withContext(
context -> service.analyzeDocument(this.client.getEndpoint(), modelId, pages, locale, stringIndexType,
this.client.getApiVersion(), contentType, analyzeRequest, contentLength, accept, context));
return FluxUtil.withContext(context -> analyzeDocumentWithResponseAsync(modelId, contentType, pages, locale,
stringIndexType, analyzeRequest, contentLength, context));
}

/**
Expand Down Expand Up @@ -851,10 +847,8 @@ public PollerFlux<BinaryData, BinaryData> beginAnalyzeDocumentAsync(String model
public Mono<Response<Void>> analyzeDocumentNoCustomHeadersWithResponseAsync(String modelId, ContentType contentType,
String pages, String locale, StringIndexType stringIndexType, Flux<ByteBuffer> analyzeRequest,
Long contentLength) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.analyzeDocumentNoCustomHeaders(this.client.getEndpoint(),
modelId, pages, locale, stringIndexType, this.client.getApiVersion(), contentType, analyzeRequest,
contentLength, accept, context));
return FluxUtil.withContext(context -> analyzeDocumentNoCustomHeadersWithResponseAsync(modelId, contentType,
pages, locale, stringIndexType, analyzeRequest, contentLength, context));
}

/**
Expand Down Expand Up @@ -962,10 +956,8 @@ public PollerFlux<BinaryData, BinaryData> beginAnalyzeDocumentNoCustomHeadersAsy
public Mono<ResponseBase<DocumentModelsAnalyzeDocumentHeaders, Void>> analyzeDocumentWithResponseAsync(
String modelId, ContentType contentType, String pages, String locale, StringIndexType stringIndexType,
BinaryData analyzeRequest, Long contentLength) {
final String accept = "application/json";
return FluxUtil.withContext(
context -> service.analyzeDocument(this.client.getEndpoint(), modelId, pages, locale, stringIndexType,
this.client.getApiVersion(), contentType, analyzeRequest, contentLength, accept, context));
return FluxUtil.withContext(context -> analyzeDocumentWithResponseAsync(modelId, contentType, pages, locale,
stringIndexType, analyzeRequest, contentLength, context));
}

/**
Expand Down Expand Up @@ -1155,10 +1147,8 @@ public SyncPoller<BinaryData, BinaryData> beginAnalyzeDocument(String modelId, C
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> analyzeDocumentNoCustomHeadersWithResponseAsync(String modelId, ContentType contentType,
String pages, String locale, StringIndexType stringIndexType, BinaryData analyzeRequest, Long contentLength) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.analyzeDocumentNoCustomHeaders(this.client.getEndpoint(),
modelId, pages, locale, stringIndexType, this.client.getApiVersion(), contentType, analyzeRequest,
contentLength, accept, context));
return FluxUtil.withContext(context -> analyzeDocumentNoCustomHeadersWithResponseAsync(modelId, contentType,
pages, locale, stringIndexType, analyzeRequest, contentLength, context));
}

/**
Expand Down Expand Up @@ -1343,9 +1333,7 @@ public SyncPoller<BinaryData, BinaryData> beginAnalyzeDocumentNoCustomHeaders(St
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<AnalyzeResultOperation>> getAnalyzeResultWithResponseAsync(String modelId, String resultId) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.getAnalyzeResult(this.client.getEndpoint(), modelId, resultId,
this.client.getApiVersion(), accept, context));
return FluxUtil.withContext(context -> getAnalyzeResultWithResponseAsync(modelId, resultId, context));
}

/**
Expand Down Expand Up @@ -1445,9 +1433,7 @@ public AnalyzeResultOperation getAnalyzeResult(String modelId, String resultId)
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<ResponseBase<DocumentModelsBuildModelHeaders, Void>>
buildModelWithResponseAsync(BuildDocumentModelRequest buildRequest) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.buildModel(this.client.getEndpoint(),
this.client.getApiVersion(), buildRequest, accept, context));
return FluxUtil.withContext(context -> buildModelWithResponseAsync(buildRequest, context));
}

/**
Expand Down Expand Up @@ -1573,9 +1559,7 @@ public SyncPoller<BinaryData, BinaryData> beginBuildModel(BuildDocumentModelRequ
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> buildModelNoCustomHeadersWithResponseAsync(BuildDocumentModelRequest buildRequest) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.buildModelNoCustomHeaders(this.client.getEndpoint(),
this.client.getApiVersion(), buildRequest, accept, context));
return FluxUtil.withContext(context -> buildModelNoCustomHeadersWithResponseAsync(buildRequest, context));
}

/**
Expand Down Expand Up @@ -1707,9 +1691,7 @@ public SyncPoller<BinaryData, BinaryData> beginBuildModelNoCustomHeaders(BuildDo
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<ResponseBase<DocumentModelsComposeModelHeaders, Void>>
composeModelWithResponseAsync(ComposeDocumentModelRequest composeRequest) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.composeModel(this.client.getEndpoint(),
this.client.getApiVersion(), composeRequest, accept, context));
return FluxUtil.withContext(context -> composeModelWithResponseAsync(composeRequest, context));
}

/**
Expand Down Expand Up @@ -1839,9 +1821,7 @@ public SyncPoller<BinaryData, BinaryData> beginComposeModel(ComposeDocumentModel
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>>
composeModelNoCustomHeadersWithResponseAsync(ComposeDocumentModelRequest composeRequest) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.composeModelNoCustomHeaders(this.client.getEndpoint(),
this.client.getApiVersion(), composeRequest, accept, context));
return FluxUtil.withContext(context -> composeModelNoCustomHeadersWithResponseAsync(composeRequest, context));
}

/**
Expand Down Expand Up @@ -1976,9 +1956,7 @@ public Response<Void> composeModelNoCustomHeadersWithResponse(ComposeDocumentMod
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<CopyAuthorization>>
authorizeModelCopyWithResponseAsync(AuthorizeCopyRequest authorizeCopyRequest) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.authorizeModelCopy(this.client.getEndpoint(),
this.client.getApiVersion(), authorizeCopyRequest, accept, context));
return FluxUtil.withContext(context -> authorizeModelCopyWithResponseAsync(authorizeCopyRequest, context));
}

/**
Expand Down Expand Up @@ -2084,9 +2062,7 @@ public CopyAuthorization authorizeModelCopy(AuthorizeCopyRequest authorizeCopyRe
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<ResponseBase<DocumentModelsCopyModelToHeaders, Void>> copyModelToWithResponseAsync(String modelId,
CopyAuthorization copyToRequest) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.copyModelTo(this.client.getEndpoint(), modelId,
this.client.getApiVersion(), copyToRequest, accept, context));
return FluxUtil.withContext(context -> copyModelToWithResponseAsync(modelId, copyToRequest, context));
}

/**
Expand Down Expand Up @@ -2223,9 +2199,8 @@ public SyncPoller<BinaryData, BinaryData> beginCopyModelTo(String modelId, CopyA
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> copyModelToNoCustomHeadersWithResponseAsync(String modelId,
CopyAuthorization copyToRequest) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.copyModelToNoCustomHeaders(this.client.getEndpoint(), modelId,
this.client.getApiVersion(), copyToRequest, accept, context));
return FluxUtil
.withContext(context -> copyModelToNoCustomHeadersWithResponseAsync(modelId, copyToRequest, context));
}

/**
Expand Down Expand Up @@ -2488,9 +2463,7 @@ public PagedIterable<DocumentModelSummary> listModels(Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<DocumentModelDetails>> getModelWithResponseAsync(String modelId) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.getModel(this.client.getEndpoint(), modelId,
this.client.getApiVersion(), accept, context));
return FluxUtil.withContext(context -> getModelWithResponseAsync(modelId, context));
}

/**
Expand Down Expand Up @@ -2579,9 +2552,7 @@ public DocumentModelDetails getModel(String modelId) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> deleteModelWithResponseAsync(String modelId) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.deleteModel(this.client.getEndpoint(), modelId,
this.client.getApiVersion(), accept, context));
return FluxUtil.withContext(context -> deleteModelWithResponseAsync(modelId, context));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ public PagedIterable<OperationSummary> listOperations(Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<OperationDetails>> getOperationWithResponseAsync(String operationId) {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.getOperation(this.client.getEndpoint(), operationId,
this.client.getApiVersion(), accept, context));
return FluxUtil.withContext(context -> getOperationWithResponseAsync(operationId, context));
}

/**
Expand Down Expand Up @@ -343,9 +341,7 @@ public OperationDetails getOperation(String operationId) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<ResourceDetails>> getResourceInfoWithResponseAsync() {
final String accept = "application/json";
return FluxUtil.withContext(context -> service.getResourceInfo(this.client.getEndpoint(),
this.client.getApiVersion(), accept, context));
return FluxUtil.withContext(context -> getResourceInfoWithResponseAsync(context));
}

/**
Expand Down
Loading

0 comments on commit 8ee3658

Please sign in to comment.