Skip to content

Commit

Permalink
CodeGen from PR 24199 in Azure/azure-rest-api-specs
Browse files Browse the repository at this point in the history
[TypeSpec] Remove "./" from tspconfig.yaml (Azure#24199)

- Prefix is unnecessary and clutters config
  • Loading branch information
SDKAuto committed Jun 2, 2023
1 parent 88daf5e commit 4e3817a
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 225 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
import com.azure.ai.translation.text.implementation.TextTranslationClientImpl;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ServiceClientBuilder;
import com.azure.core.client.traits.AzureKeyCredentialTrait;
import com.azure.core.client.traits.ConfigurationTrait;
import com.azure.core.client.traits.EndpointTrait;
import com.azure.core.client.traits.HttpTrait;
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpPipeline;
Expand All @@ -22,8 +18,6 @@
import com.azure.core.http.policy.AddDatePolicy;
import com.azure.core.http.policy.AddHeadersFromContextPolicy;
import com.azure.core.http.policy.AddHeadersPolicy;
import com.azure.core.http.policy.AzureKeyCredentialPolicy;
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy;
import com.azure.core.http.policy.CookiePolicy;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpLoggingPolicy;
Expand All @@ -37,9 +31,8 @@
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.builder.ClientBuilderUtil;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.serializer.JacksonAdapter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -50,20 +43,11 @@
public final class TextTranslationClientBuilder
implements HttpTrait<TextTranslationClientBuilder>,
ConfigurationTrait<TextTranslationClientBuilder>,
EndpointTrait<TextTranslationClientBuilder>,
AzureKeyCredentialTrait<TextTranslationClientBuilder>,
TokenCredentialTrait<TextTranslationClientBuilder> {
EndpointTrait<TextTranslationClientBuilder> {
@Generated private static final String SDK_NAME = "name";

@Generated private static final String SDK_VERSION = "version";

private static final String DEFAULT_SCOPE = "https://cognitiveservices.azure.com/.default";
private static final String OCP_APIM_SUBSCRIPTION_KEY = "Ocp-Apim-Subscription-Key";

private String region;
private AzureKeyCredential credential;
private TokenCredential tokenCredential;

@Generated
private static final Map<String, String> PROPERTIES =
CoreUtils.getProperties("azure-ai-translation-text.properties");
Expand All @@ -85,6 +69,9 @@ public TextTranslationClientBuilder() {
@Generated
@Override
public TextTranslationClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
}
Expand Down Expand Up @@ -168,14 +155,11 @@ public TextTranslationClientBuilder configuration(Configuration configuration) {
*/
@Generated private String endpoint;

private Boolean isCustomEndpoint = false;

/** {@inheritDoc}. */
@Generated
@Override
public TextTranslationClientBuilder endpoint(String endpoint) {
this.endpoint = endpoint;
this.isCustomEndpoint = CustomEndpointUtils.isPlatformHost(endpoint);
return this;
}

Expand Down Expand Up @@ -213,47 +197,6 @@ public TextTranslationClientBuilder retryPolicy(RetryPolicy retryPolicy) {
return this;
}

/**
* Sets the {@link AzureKeyCredential} used to authorize requests sent to the service.
*
* @param credential {@link AzureKeyCredential} used to authorize requests sent to the service.
* @return The updated {@link TextTranslationClientBuilder} object.
* @throws NullPointerException If {@code credential} is null.
*/
public TextTranslationClientBuilder credential(AzureKeyCredential credential) {
Objects.requireNonNull(credential, "'credential' cannot be null.");
this.credential = credential;
return this;
}

/**
* Sets the region used to authorize requests sent to the service.
*
* @param region where the Translator resource is created.
* @return The updated {@link TextTranslationClientBuilder} object.
* @throws NullPointerException If {@code tokenCredential} is null.
*/
public TextTranslationClientBuilder region(String region) {
Objects.requireNonNull(region, "'region' cannot be null.");
this.region = region;
return this;
}

/**
* Sets the {@link TokenCredential} used to authorize requests sent to the service. Refer to the Azure SDK for Java
* <a href="https://aka.ms/azsdk/java/docs/identity">identity and authentication</a>
* documentation for more details on proper usage of the {@link TokenCredential} type.
*
* @param tokenCredential {@link TokenCredential} used to authorize requests sent to the service.
* @return The updated {@link TextTranslationClientBuilder} object.
* @throws NullPointerException If {@code tokenCredential} is null.
*/
public TextTranslationClientBuilder credential(TokenCredential tokenCredential) {
Objects.requireNonNull(tokenCredential, "'tokenCredential' cannot be null.");
this.tokenCredential = tokenCredential;
return this;
}

/**
* Builds an instance of TextTranslationClientImpl with the provided parameters.
*
Expand All @@ -264,25 +207,9 @@ private TextTranslationClientImpl buildInnerClient() {
HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline();
TextTranslationServiceVersion localServiceVersion =
(serviceVersion != null) ? serviceVersion : TextTranslationServiceVersion.getLatest();

String serviceEndpoint;
if (this.endpoint == null) {
serviceEndpoint = "https://api.cognitive.microsofttranslator.com";
} else if (this.isCustomEndpoint) {
try {
URL hostUri = new URL(endpoint);
URL fullUri = new URL(hostUri, "/translator/text/v" + localServiceVersion.getVersion());
serviceEndpoint = fullUri.toString();
} catch (MalformedURLException ex) {
serviceEndpoint = endpoint;
}
} else {
serviceEndpoint = endpoint;
}

TextTranslationClientImpl client =
new TextTranslationClientImpl(
localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), serviceEndpoint, localServiceVersion);
localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, localServiceVersion);
return client;
}

Expand Down Expand Up @@ -311,19 +238,6 @@ private HttpPipeline createHttpPipeline() {
policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy()));
policies.add(new AddDatePolicy());
policies.add(new CookiePolicy());

if (tokenCredential != null) {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPE));
}

if (this.credential != null) {
policies.add(new AzureKeyCredentialPolicy(OCP_APIM_SUBSCRIPTION_KEY, credential));

if (this.region != null) {
policies.add(new TranslatorRegionAuthenticationPolicy(this.region));
}
}

this.pipelinePolicies.stream()
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
.forEach(p -> policies.add(p));
Expand Down Expand Up @@ -357,4 +271,6 @@ public TextTranslationAsyncClient buildAsyncClient() {
public TextTranslationClient buildClient() {
return new TextTranslationClient(new TextTranslationAsyncClient(buildInnerClient()));
}

private static final ClientLogger LOGGER = new ClientLogger(TextTranslationClientBuilder.class);
}
Loading

0 comments on commit 4e3817a

Please sign in to comment.