Skip to content

Commit 7244afb

Browse files
author
SDKAuto
committed
CodeGen from PR 34547 in Azure/azure-rest-api-specs
Merge f28c3d3f943a3efce8d96f00d1383186f072a8a4 into 9f69db7532b6706baedc004f2eda762196a3e1eb
1 parent ac53b7d commit 7244afb

31 files changed

+1574
-3001
lines changed

sdk/translation/azure-ai-translation-text/src/main/java/com/azure/ai/translation/text/TextTranslationAsyncClient.java

+221-1,000
Large diffs are not rendered by default.

sdk/translation/azure-ai-translation-text/src/main/java/com/azure/ai/translation/text/TextTranslationClient.java

+215-1,005
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33
// Code generated by Microsoft (R) TypeSpec Code Generator.
4+
45
package com.azure.ai.translation.text;
56

67
import com.azure.ai.translation.text.implementation.TextTranslationClientImpl;
7-
import com.azure.ai.translation.text.models.TextTranslationAudience;
88
import com.azure.core.annotation.Generated;
99
import com.azure.core.annotation.ServiceClientBuilder;
1010
import com.azure.core.client.traits.ConfigurationTrait;
1111
import com.azure.core.client.traits.EndpointTrait;
1212
import com.azure.core.client.traits.HttpTrait;
13-
import com.azure.core.client.traits.KeyCredentialTrait;
14-
import com.azure.core.client.traits.TokenCredentialTrait;
15-
import com.azure.core.credential.KeyCredential;
16-
import com.azure.core.credential.TokenCredential;
1713
import com.azure.core.http.HttpClient;
18-
import com.azure.core.http.HttpHeaderName;
1914
import com.azure.core.http.HttpHeaders;
2015
import com.azure.core.http.HttpPipeline;
2116
import com.azure.core.http.HttpPipelineBuilder;
2217
import com.azure.core.http.HttpPipelinePosition;
2318
import com.azure.core.http.policy.AddDatePolicy;
2419
import com.azure.core.http.policy.AddHeadersFromContextPolicy;
2520
import com.azure.core.http.policy.AddHeadersPolicy;
26-
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy;
2721
import com.azure.core.http.policy.HttpLogOptions;
2822
import com.azure.core.http.policy.HttpLoggingPolicy;
2923
import com.azure.core.http.policy.HttpPipelinePolicy;
3024
import com.azure.core.http.policy.HttpPolicyProviders;
31-
import com.azure.core.http.policy.KeyCredentialPolicy;
3225
import com.azure.core.http.policy.RequestIdPolicy;
3326
import com.azure.core.http.policy.RetryOptions;
3427
import com.azure.core.http.policy.RetryPolicy;
@@ -39,8 +32,6 @@
3932
import com.azure.core.util.builder.ClientBuilderUtil;
4033
import com.azure.core.util.logging.ClientLogger;
4134
import com.azure.core.util.serializer.JacksonAdapter;
42-
import java.net.MalformedURLException;
43-
import java.net.URL;
4435
import java.util.ArrayList;
4536
import java.util.List;
4637
import java.util.Map;
@@ -51,33 +42,13 @@
5142
*/
5243
@ServiceClientBuilder(serviceClients = { TextTranslationClient.class, TextTranslationAsyncClient.class })
5344
public final class TextTranslationClientBuilder implements HttpTrait<TextTranslationClientBuilder>,
54-
ConfigurationTrait<TextTranslationClientBuilder>, EndpointTrait<TextTranslationClientBuilder>,
55-
KeyCredentialTrait<TextTranslationClientBuilder>, TokenCredentialTrait<TextTranslationClientBuilder> {
56-
45+
ConfigurationTrait<TextTranslationClientBuilder>, EndpointTrait<TextTranslationClientBuilder> {
5746
@Generated
5847
private static final String SDK_NAME = "name";
5948

6049
@Generated
6150
private static final String SDK_VERSION = "version";
6251

63-
private static final String DEFAULT_SCOPE = "/.default";
64-
65-
private static final String OCP_APIM_SUBSCRIPTION_KEY = "Ocp-Apim-Subscription-Key";
66-
67-
private static final String OCP_APIM_SUBSCRIPTION_REGION = "Ocp-Apim-Subscription-Region";
68-
69-
private static final String OCP_APIM_RESOURCE_ID_KEY = "Ocp-Apim-ResourceId";
70-
71-
private String region;
72-
73-
private String resourceId;
74-
75-
private TextTranslationAudience audience;
76-
77-
private KeyCredential credential;
78-
79-
private TokenCredential tokenCredential;
80-
8152
@Generated
8253
private static final Map<String, String> PROPERTIES
8354
= CoreUtils.getProperties("azure-ai-translation-text.properties");
@@ -94,37 +65,37 @@ public TextTranslationClientBuilder() {
9465
}
9566

9667
/*
97-
* The HTTP pipeline to send requests through.
68+
* The HTTP client used to send the request.
9869
*/
9970
@Generated
100-
private HttpPipeline pipeline;
71+
private HttpClient httpClient;
10172

10273
/**
10374
* {@inheritDoc}.
10475
*/
10576
@Generated
10677
@Override
107-
public TextTranslationClientBuilder pipeline(HttpPipeline pipeline) {
108-
if (this.pipeline != null && pipeline == null) {
109-
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
110-
}
111-
this.pipeline = pipeline;
78+
public TextTranslationClientBuilder httpClient(HttpClient httpClient) {
79+
this.httpClient = httpClient;
11280
return this;
11381
}
11482

11583
/*
116-
* The HTTP client used to send the request.
84+
* The HTTP pipeline to send requests through.
11785
*/
11886
@Generated
119-
private HttpClient httpClient;
87+
private HttpPipeline pipeline;
12088

12189
/**
12290
* {@inheritDoc}.
12391
*/
12492
@Generated
12593
@Override
126-
public TextTranslationClientBuilder httpClient(HttpClient httpClient) {
127-
this.httpClient = httpClient;
94+
public TextTranslationClientBuilder pipeline(HttpPipeline pipeline) {
95+
if (this.pipeline != null && pipeline == null) {
96+
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
97+
}
98+
this.pipeline = pipeline;
12899
return this;
129100
}
130101

@@ -209,15 +180,13 @@ public TextTranslationClientBuilder configuration(Configuration configuration) {
209180
@Generated
210181
private String endpoint;
211182

212-
private Boolean isCustomEndpoint = false;
213-
214183
/**
215184
* {@inheritDoc}.
216185
*/
186+
@Generated
217187
@Override
218188
public TextTranslationClientBuilder endpoint(String endpoint) {
219189
this.endpoint = endpoint;
220-
this.isCustomEndpoint = CustomEndpointUtils.isPlatformHost(endpoint);
221190
return this;
222191
}
223192

@@ -229,7 +198,7 @@ public TextTranslationClientBuilder endpoint(String endpoint) {
229198

230199
/**
231200
* Sets Service version.
232-
*
201+
*
233202
* @param serviceVersion the serviceVersion value.
234203
* @return the TextTranslationClientBuilder.
235204
*/
@@ -247,7 +216,7 @@ public TextTranslationClientBuilder serviceVersion(TextTranslationServiceVersion
247216

248217
/**
249218
* Sets The retry policy that will attempt to retry failed requests, if applicable.
250-
*
219+
*
251220
* @param retryPolicy the retryPolicy value.
252221
* @return the TextTranslationClientBuilder.
253222
*/
@@ -257,113 +226,30 @@ public TextTranslationClientBuilder retryPolicy(RetryPolicy retryPolicy) {
257226
return this;
258227
}
259228

260-
/**
261-
* Sets the {@link KeyCredential} used to authorize requests sent to the service.
262-
*
263-
* @param credential {@link KeyCredential} used to authorize requests sent to the service.
264-
* @return The updated {@link TextTranslationClientBuilder} object.
265-
* @throws NullPointerException If {@code credential} is null.
266-
*/
267-
public TextTranslationClientBuilder credential(KeyCredential credential) {
268-
Objects.requireNonNull(credential, "'credential' cannot be null.");
269-
this.credential = credential;
270-
return this;
271-
}
272-
273-
/**
274-
* Sets the region used to authorize requests sent to the service.
275-
*
276-
* @param region where the Translator resource is created.
277-
* @return The updated {@link TextTranslationClientBuilder} object.
278-
* @throws NullPointerException If {@code region} is null.
279-
*/
280-
public TextTranslationClientBuilder region(String region) {
281-
Objects.requireNonNull(region, "'region' cannot be null.");
282-
this.region = region;
283-
return this;
284-
}
285-
286-
/**
287-
* Sets the Azure Resource Id used to authorize requests sent to the service.
288-
*
289-
* @param resourceId Id of the Translator Resource.
290-
* @return The updated {@link TextTranslationClientBuilder} object.
291-
* @throws NullPointerException If {@code resourceId} is null.
292-
*/
293-
public TextTranslationClientBuilder resourceId(String resourceId) {
294-
Objects.requireNonNull(resourceId, "'resourceId' cannot be null.");
295-
this.resourceId = resourceId;
296-
return this;
297-
}
298-
299-
/**
300-
* Sets the Authentication audience used to authorize requests sent to the service.
301-
*
302-
* @param audience Token Audience.
303-
* @return The updated {@link TextTranslationClientBuilder} object.
304-
* @throws NullPointerException If {@code audience} is null.
305-
*/
306-
public TextTranslationClientBuilder audience(TextTranslationAudience audience) {
307-
Objects.requireNonNull(audience, "'audience' cannot be null.");
308-
this.audience = audience;
309-
return this;
310-
}
311-
312-
/**
313-
* Sets the {@link TokenCredential} used to authorize requests sent to the service. Refer to the Azure SDK for Java
314-
* <a href="https://aka.ms/azsdk/java/docs/identity">identity and authentication</a>
315-
* documentation for more details on proper usage of the {@link TokenCredential} type.
316-
*
317-
* @param tokenCredential {@link TokenCredential} used to authorize requests sent to the service.
318-
* @return The updated {@link TextTranslationClientBuilder} object.
319-
* @throws NullPointerException If {@code tokenCredential} is null.
320-
*/
321-
public TextTranslationClientBuilder credential(TokenCredential tokenCredential) {
322-
Objects.requireNonNull(tokenCredential, "'tokenCredential' cannot be null.");
323-
this.tokenCredential = tokenCredential;
324-
return this;
325-
}
326-
327229
/**
328230
* Builds an instance of TextTranslationClientImpl with the provided parameters.
329-
*
231+
*
330232
* @return an instance of TextTranslationClientImpl.
331233
*/
234+
@Generated
332235
private TextTranslationClientImpl buildInnerClient() {
236+
this.validateClient();
333237
HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline();
334238
TextTranslationServiceVersion localServiceVersion
335239
= (serviceVersion != null) ? serviceVersion : TextTranslationServiceVersion.getLatest();
336-
String serviceEndpoint;
337-
if (this.endpoint == null) {
338-
serviceEndpoint = "https://api.cognitive.microsofttranslator.com";
339-
} else if (this.isCustomEndpoint) {
340-
try {
341-
URL hostUri = new URL(endpoint);
342-
URL fullUri = new URL(hostUri, "/translator/text/v" + localServiceVersion.getVersion());
343-
serviceEndpoint = fullUri.toString();
344-
} catch (MalformedURLException ex) {
345-
serviceEndpoint = endpoint;
346-
}
347-
} else {
348-
serviceEndpoint = endpoint;
349-
}
350-
if (tokenCredential != null && (this.region != null || this.resourceId != null)) {
351-
Objects.requireNonNull(this.region, "'region' cannot be null.");
352-
Objects.requireNonNull(this.resourceId, "'resourceId' cannot be null.");
353-
}
354-
if (this.credential != null && !CoreUtils.isNullOrEmpty(this.resourceId)) {
355-
throw LOGGER.logExceptionAsError(
356-
new IllegalStateException("Resource Id cannot be used with key credential. Set resourceId to null."));
357-
}
358-
if (tokenCredential != null && this.credential != null) {
359-
throw LOGGER.logExceptionAsError(
360-
new IllegalStateException("Both token credential and key credential cannot be set."));
361-
}
362240
TextTranslationClientImpl client = new TextTranslationClientImpl(localPipeline,
363-
JacksonAdapter.createDefaultSerializerAdapter(), serviceEndpoint, localServiceVersion);
241+
JacksonAdapter.createDefaultSerializerAdapter(), this.endpoint, localServiceVersion);
364242
return client;
365243
}
366244

245+
@Generated
246+
private void validateClient() {
247+
// This method is invoked from 'buildInnerClient'/'buildClient' method.
248+
// Developer can customize this method, to validate that the necessary conditions are met for the new client.
249+
Objects.requireNonNull(endpoint, "'endpoint' cannot be null.");
250+
}
251+
252+
@Generated
367253
private HttpPipeline createHttpPipeline() {
368254
Configuration buildConfiguration
369255
= (configuration == null) ? Configuration.getGlobalConfiguration() : configuration;
@@ -376,10 +262,8 @@ private HttpPipeline createHttpPipeline() {
376262
policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration));
377263
policies.add(new RequestIdPolicy());
378264
policies.add(new AddHeadersFromContextPolicy());
379-
HttpHeaders headers = new HttpHeaders();
380-
localClientOptions.getHeaders()
381-
.forEach(header -> headers.set(HttpHeaderName.fromString(header.getName()), header.getValue()));
382-
if (headers.getSize() > 0) {
265+
HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions);
266+
if (headers != null) {
383267
policies.add(new AddHeadersPolicy(headers));
384268
}
385269
this.pipelinePolicies.stream()
@@ -388,27 +272,6 @@ private HttpPipeline createHttpPipeline() {
388272
HttpPolicyProviders.addBeforeRetryPolicies(policies);
389273
policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy()));
390274
policies.add(new AddDatePolicy());
391-
if (tokenCredential != null) {
392-
TextTranslationAudience authAudience = TextTranslationAudience.AZURE_PUBLIC_CLOUD;
393-
if (this.audience != null) {
394-
authAudience = this.audience;
395-
}
396-
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, authAudience + DEFAULT_SCOPE));
397-
if (this.region != null || this.resourceId != null) {
398-
HttpHeaders aadHeaders = new HttpHeaders();
399-
aadHeaders.put(OCP_APIM_RESOURCE_ID_KEY, this.resourceId);
400-
aadHeaders.put(OCP_APIM_SUBSCRIPTION_REGION, this.region);
401-
policies.add(new AddHeadersPolicy(aadHeaders));
402-
}
403-
}
404-
if (this.credential != null) {
405-
policies.add(new KeyCredentialPolicy(OCP_APIM_SUBSCRIPTION_KEY, credential));
406-
if (this.region != null) {
407-
HttpHeaders regionHeaders = new HttpHeaders();
408-
regionHeaders.put(OCP_APIM_SUBSCRIPTION_REGION, this.region);
409-
policies.add(new AddHeadersPolicy(regionHeaders));
410-
}
411-
}
412275
this.pipelinePolicies.stream()
413276
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
414277
.forEach(p -> policies.add(p));
@@ -423,7 +286,7 @@ private HttpPipeline createHttpPipeline() {
423286

424287
/**
425288
* Builds an instance of TextTranslationAsyncClient class.
426-
*
289+
*
427290
* @return an instance of TextTranslationAsyncClient.
428291
*/
429292
@Generated
@@ -433,7 +296,7 @@ public TextTranslationAsyncClient buildAsyncClient() {
433296

434297
/**
435298
* Builds an instance of TextTranslationClient class.
436-
*
299+
*
437300
* @return an instance of TextTranslationClient.
438301
*/
439302
@Generated
@@ -442,11 +305,4 @@ public TextTranslationClient buildClient() {
442305
}
443306

444307
private static final ClientLogger LOGGER = new ClientLogger(TextTranslationClientBuilder.class);
445-
446-
@Generated
447-
private void validateClient() {
448-
// This method is invoked from 'buildInnerClient'/'buildClient' method.
449-
// Developer can customize this method, to validate that the necessary conditions are met for the new client.
450-
Objects.requireNonNull(endpoint, "'endpoint' cannot be null.");
451-
}
452308
}

sdk/translation/azure-ai-translation-text/src/main/java/com/azure/ai/translation/text/TextTranslationServiceVersion.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
*/
1212
public enum TextTranslationServiceVersion implements ServiceVersion {
1313
/**
14-
* Enum value 3.0.
14+
* Enum value v3.0.
1515
*/
16-
V3_0("3.0");
16+
V3_0("v3.0"),
17+
18+
/**
19+
* Enum value 2025-05-01-preview.
20+
*/
21+
V2025_05_01_PREVIEW("2025-05-01-preview");
1722

1823
private final String version;
1924

@@ -35,6 +40,6 @@ public String getVersion() {
3540
* @return The latest {@link TextTranslationServiceVersion}.
3641
*/
3742
public static TextTranslationServiceVersion getLatest() {
38-
return V3_0;
43+
return V2025_05_01_PREVIEW;
3944
}
4045
}

0 commit comments

Comments
 (0)