Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACS Chat: Swagger update #18744

Merged
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
2 changes: 1 addition & 1 deletion sdk/communication/azure-communication-chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ A `String` response returned from sending a chat message, it contains an id, whi

<!-- embedme ./src/samples/java/com/azure/communication/chat/ReadmeSamples.java#L142-L148 -->
```Java

SendChatMessageOptions sendChatMessageOptions = new SendChatMessageOptions()
.setContent("Message content")
.setPriority(ChatMessagePriority.NORMAL)
.setSenderDisplayName("Sender Display Name");


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ Mono<Response<Void>> updateTopic(String topic, Context context) {
public Mono<Response<AddChatParticipantsResult>> addParticipants(AddChatParticipantsOptions options) {
try {
Objects.requireNonNull(options, "'options' cannot be null.");
return withContext(context -> addParticipants(options, context)); } catch (RuntimeException ex) {
return withContext(context -> addParticipants(options, context));
} catch (RuntimeException ex) {

return monoError(logger, ex);
}
Expand All @@ -152,7 +153,8 @@ public Mono<Response<AddChatParticipantsResult>> addParticipants(AddChatParticip
public Mono<Response<AddChatParticipantsResult>> addParticipantsWithResponse(AddChatParticipantsOptions options) {
try {
Objects.requireNonNull(options, "'options' cannot be null.");
return withContext(context -> addParticipants(options, context)); } catch (RuntimeException ex) {
return withContext(context -> addParticipants(options, context));
} catch (RuntimeException ex) {

return monoError(logger, ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ public ChatImpl getChatClient() {
return this.chatClient;
}

/** Initializes an instance of AzureCommunicationChatService client. */
/**
* Initializes an instance of AzureCommunicationChatService client.
*
* @param endpoint The endpoint of the Azure Communication resource.
*/
AzureCommunicationChatServiceImpl(String endpoint) {
this(
new HttpPipelineBuilder()
Expand All @@ -100,6 +104,7 @@ public ChatImpl getChatClient() {
* Initializes an instance of AzureCommunicationChatService client.
*
* @param httpPipeline The HTTP pipeline to send requests through.
* @param endpoint The endpoint of the Azure Communication resource.
*/
AzureCommunicationChatServiceImpl(HttpPipeline httpPipeline, String endpoint) {
this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint);
Expand All @@ -110,6 +115,7 @@ public ChatImpl getChatClient() {
*
* @param httpPipeline The HTTP pipeline to send requests through.
* @param serializerAdapter The serializer to serialize an object into a string.
* @param endpoint The endpoint of the Azure Communication resource.
*/
AzureCommunicationChatServiceImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint) {
this.httpPipeline = httpPipeline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,38 @@
package com.azure.communication.chat.implementation;

import com.azure.core.annotation.ServiceClientBuilder;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.CookiePolicy;
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.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.util.Configuration;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.SerializerAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** A builder for creating a new instance of the AzureCommunicationChatService type. */
@ServiceClientBuilder(serviceClients = {AzureCommunicationChatServiceImpl.class})
public final class AzureCommunicationChatServiceImplBuilder {
private static final String SDK_NAME = "name";

private static final String SDK_VERSION = "version";

private final Map<String, String> properties = new HashMap<>();

/** Create an instance of the AzureCommunicationChatServiceImplBuilder. */
public AzureCommunicationChatServiceImplBuilder() {
this.pipelinePolicies = new ArrayList<>();
}

/*
* The endpoint of the Azure Communication resource.
*/
Expand Down Expand Up @@ -64,17 +85,96 @@ public AzureCommunicationChatServiceImplBuilder serializerAdapter(SerializerAdap
return this;
}

/*
* The HTTP client used to send the request.
*/
private HttpClient httpClient;

/**
* Sets The HTTP client used to send the request.
*
* @param httpClient the httpClient value.
* @return the AzureCommunicationChatServiceImplBuilder.
*/
public AzureCommunicationChatServiceImplBuilder httpClient(HttpClient httpClient) {
this.httpClient = httpClient;
return this;
}

/*
* The configuration store that is used during construction of the service
* client.
*/
private Configuration configuration;

/**
* Sets The configuration store that is used during construction of the service client.
*
* @param configuration the configuration value.
* @return the AzureCommunicationChatServiceImplBuilder.
*/
public AzureCommunicationChatServiceImplBuilder configuration(Configuration configuration) {
this.configuration = configuration;
return this;
}

/*
* The logging configuration for HTTP requests and responses.
*/
private HttpLogOptions httpLogOptions;

/**
* Sets The logging configuration for HTTP requests and responses.
*
* @param httpLogOptions the httpLogOptions value.
* @return the AzureCommunicationChatServiceImplBuilder.
*/
public AzureCommunicationChatServiceImplBuilder httpLogOptions(HttpLogOptions httpLogOptions) {
this.httpLogOptions = httpLogOptions;
return this;
}

/*
* The retry policy that will attempt to retry failed requests, if
* applicable.
*/
private RetryPolicy retryPolicy;

/**
* Sets The retry policy that will attempt to retry failed requests, if applicable.
*
* @param retryPolicy the retryPolicy value.
* @return the AzureCommunicationChatServiceImplBuilder.
*/
public AzureCommunicationChatServiceImplBuilder retryPolicy(RetryPolicy retryPolicy) {
this.retryPolicy = retryPolicy;
return this;
}

/*
* The list of Http pipeline policies to add.
*/
private final List<HttpPipelinePolicy> pipelinePolicies;

/**
* Adds a custom Http pipeline policy.
*
* @param customPolicy The custom Http pipeline policy to add.
* @return the AzureCommunicationChatServiceImplBuilder.
*/
public AzureCommunicationChatServiceImplBuilder addPolicy(HttpPipelinePolicy customPolicy) {
pipelinePolicies.add(customPolicy);
return this;
}

/**
* Builds an instance of AzureCommunicationChatServiceImpl with the provided parameters.
*
* @return an instance of AzureCommunicationChatServiceImpl.
*/
public AzureCommunicationChatServiceImpl buildClient() {
if (pipeline == null) {
this.pipeline =
new HttpPipelineBuilder()
.policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy())
.build();
this.pipeline = createHttpPipeline();
}
if (serializerAdapter == null) {
this.serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter();
Expand All @@ -83,4 +183,29 @@ public AzureCommunicationChatServiceImpl buildClient() {
new AzureCommunicationChatServiceImpl(pipeline, serializerAdapter, endpoint);
return client;
}

private HttpPipeline createHttpPipeline() {
Configuration buildConfiguration =
(configuration == null) ? Configuration.getGlobalConfiguration() : configuration;
if (httpLogOptions == null) {
httpLogOptions = new HttpLogOptions();
}
List<HttpPipelinePolicy> policies = new ArrayList<>();
String clientName = properties.getOrDefault(SDK_NAME, "UnknownName");
String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion");
policies.add(
new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion, buildConfiguration));
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy);
policies.add(new CookiePolicy());
policies.addAll(this.pipelinePolicies);
HttpPolicyProviders.addAfterRetryPolicies(policies);
policies.add(new HttpLoggingPolicy(httpLogOptions));
HttpPipeline httpPipeline =
new HttpPipelineBuilder()
.policies(policies.toArray(new HttpPipelinePolicy[0]))
.httpClient(httpClient)
.build();
return httpPipeline;
}
}
Loading