Skip to content

Commit

Permalink
Search SDK: Removing redundant name parameter from CreateOrUpdate met…
Browse files Browse the repository at this point in the history
…hods

This is a workaround for the following AutoRest issue:

Azure/autorest#382

Unfortunately there is no way to work around this without modifying the
generated code.
  • Loading branch information
brjohnstmsft committed Nov 19, 2015
1 parent 28a7476 commit dc4bc78
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 211 deletions.
2 changes: 1 addition & 1 deletion src/Search/Search.Tests/Tests/DataSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void CreateOrUpdateCreatesWhenDataSourceDoesNotExist()
DataSource dataSource = CreateTestDataSource();

AzureOperationResponse<DataSource> response =
searchClient.DataSources.CreateOrUpdateWithHttpMessagesAsync(dataSource.Name, dataSource).Result;
searchClient.DataSources.CreateOrUpdateWithHttpMessagesAsync(dataSource).Result;
Assert.Equal(HttpStatusCode.Created, response.Response.StatusCode);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Search/Search.Tests/Tests/IndexManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void CreateOrUpdateCreatesWhenIndexDoesNotExist()
Index index = CreateTestIndex();

AzureOperationResponse<Index> createOrUpdateResponse =
searchClient.Indexes.CreateOrUpdateWithHttpMessagesAsync(index.Name, index).Result;
searchClient.Indexes.CreateOrUpdateWithHttpMessagesAsync(index).Result;
Assert.Equal(HttpStatusCode.Created, createOrUpdateResponse.Response.StatusCode);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Search/Search.Tests/Tests/IndexerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void CreateOrUpdateCreatesWhenIndexerDoesNotExist()
Indexer indexer = Data.CreateTestIndexer();

AzureOperationResponse<Indexer> response =
searchClient.Indexers.CreateOrUpdateWithHttpMessagesAsync(indexer.Name, indexer).Result;
searchClient.Indexers.CreateOrUpdateWithHttpMessagesAsync(indexer).Result;
Assert.Equal(HttpStatusCode.Created, response.Response.StatusCode);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,6 @@ namespace Microsoft.Azure.Search

public static partial class DataSourcesOperationsExtensions
{
/// <summary>
/// Creates a new Azure Search datasource or updates a datasource if it
/// already exists.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='dataSource'>
/// The definition of the datasource to create or update.
/// </param>
/// <param name='searchRequestOptions'>
/// Additional parameters for the operation
/// </param>
public static DataSource CreateOrUpdate(
this IDataSourcesOperations operations,
DataSource dataSource,
SearchRequestOptions searchRequestOptions = default(SearchRequestOptions))
{
return operations.CreateOrUpdate(dataSource.Name, dataSource, searchRequestOptions);
}

/// <summary>
/// Creates a new Azure Search datasource or updates a datasource if it
/// already exists.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='dataSource'>
/// The definition of the datasource to create or update.
/// </param>
/// <param name='searchRequestOptions'>
/// Additional parameters for the operation
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
public static Task<DataSource> CreateOrUpdateAsync(
this IDataSourcesOperations operations,
DataSource dataSource,
SearchRequestOptions searchRequestOptions = default(SearchRequestOptions),
CancellationToken cancellationToken = default(CancellationToken))
{
return operations.CreateOrUpdateAsync(dataSource.Name, dataSource, searchRequestOptions, cancellationToken);
}

/// <summary>
/// Determines whether or not the given data source exists in the Azure Search service.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,6 @@ namespace Microsoft.Azure.Search

public static partial class IndexerOperationsExtensions
{
/// <summary>
/// Creates a new Azure Search indexer or updates an indexer if it already
/// exists.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='indexer'>
/// The definition of the indexer to create or update.
/// </param>
/// <param name='searchRequestOptions'>
/// Additional parameters for the operation
/// </param>
public static Indexer CreateOrUpdate(
this IIndexersOperations operations,
Indexer indexer,
SearchRequestOptions searchRequestOptions = default(SearchRequestOptions))
{
return operations.CreateOrUpdate(indexer.Name, indexer, searchRequestOptions);
}

/// <summary>
/// Creates a new Azure Search indexer or updates an indexer if it already
/// exists.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='indexer'>
/// The definition of the indexer to create or update.
/// </param>
/// <param name='searchRequestOptions'>
/// Additional parameters for the operation
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
public static Task<Indexer> CreateOrUpdateAsync(
this IIndexersOperations operations,
Indexer indexer,
SearchRequestOptions searchRequestOptions = default(SearchRequestOptions),
CancellationToken cancellationToken = default(CancellationToken))
{
return operations.CreateOrUpdateAsync(indexer.Name, indexer, searchRequestOptions, cancellationToken);
}

/// <summary>
/// Determines whether or not the given indexer exists in the Azure Search service.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,6 @@ namespace Microsoft.Azure.Search

public static partial class IndexesOperationsExtensions
{
/// <summary>
/// Creates a new Azure Search index or updates an index if it already exists.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='index'>
/// The definition of the index to create or update.
/// </param>
/// <param name='searchRequestOptions'>
/// Additional parameters for the operation
/// </param>
public static Index CreateOrUpdate(
this IIndexesOperations operations,
Index index,
SearchRequestOptions searchRequestOptions = default(SearchRequestOptions))
{
return operations.CreateOrUpdate(index.Name, index, searchRequestOptions);
}

/// <summary>
/// Creates a new Azure Search index or updates an index if it already exists.
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='index'>
/// The definition of the index to create or update.
/// </param>
/// <param name='searchRequestOptions'>
/// Additional parameters for the operation
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
public static Task<Index> CreateOrUpdateAsync(
this IIndexesOperations operations,
Index index,
SearchRequestOptions searchRequestOptions = default(SearchRequestOptions),
CancellationToken cancellationToken = default(CancellationToken))
{
return operations.CreateOrUpdateAsync(index.Name, index, searchRequestOptions, cancellationToken);
}

/// <summary>
/// Determines whether or not the given index exists in the Azure Search service.
/// </summary>
Expand Down
12 changes: 2 additions & 10 deletions src/Search/Search/GeneratedSearchService/DataSourcesOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ internal DataSourcesOperations(SearchServiceClient client)
/// Creates a new Azure Search datasource or updates a datasource if it
/// already exists.
/// </summary>
/// <param name='dataSourceName'>
/// The name of the datasource to create or update.
/// </param>
/// <param name='dataSource'>
/// The definition of the datasource to create or update.
/// </param>
Expand All @@ -67,12 +64,8 @@ internal DataSourcesOperations(SearchServiceClient client)
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
public async Task<AzureOperationResponse<DataSource>> CreateOrUpdateWithHttpMessagesAsync(string dataSourceName, DataSource dataSource, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
public async Task<AzureOperationResponse<DataSource>> CreateOrUpdateWithHttpMessagesAsync(DataSource dataSource, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (dataSourceName == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "dataSourceName");
}
if (dataSource == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "dataSource");
Expand All @@ -97,7 +90,6 @@ internal DataSourcesOperations(SearchServiceClient client)
{
invocationId = ServiceClientTracing.NextInvocationId.ToString();
Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
tracingParameters.Add("dataSourceName", dataSourceName);
tracingParameters.Add("dataSource", dataSource);
tracingParameters.Add("clientRequestId", clientRequestId);
tracingParameters.Add("cancellationToken", cancellationToken);
Expand All @@ -106,7 +98,7 @@ internal DataSourcesOperations(SearchServiceClient client)
// Construct URL
var baseUrl = this.Client.BaseUri.AbsoluteUri;
var url = new Uri(new Uri(baseUrl + (baseUrl.EndsWith("/") ? "" : "/")), "datasources('{dataSourceName}')").ToString();
url = url.Replace("{dataSourceName}", Uri.EscapeDataString(dataSourceName));
url = url.Replace("{dataSourceName}", Uri.EscapeDataString(dataSource.Name));
List<string> queryParameters = new List<string>();
if (this.Client.ApiVersion != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@ public static partial class DataSourcesOperationsExtensions
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='dataSourceName'>
/// The name of the datasource to create or update.
/// </param>
/// <param name='dataSource'>
/// The definition of the datasource to create or update.
/// </param>
/// <param name='searchRequestOptions'>
/// Additional parameters for the operation
/// </param>
public static DataSource CreateOrUpdate(this IDataSourcesOperations operations, string dataSourceName, DataSource dataSource, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions))
public static DataSource CreateOrUpdate(this IDataSourcesOperations operations, DataSource dataSource, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions))
{
return Task.Factory.StartNew(s => ((IDataSourcesOperations)s).CreateOrUpdateAsync(dataSourceName, dataSource, searchRequestOptions), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
return Task.Factory.StartNew(s => ((IDataSourcesOperations)s).CreateOrUpdateAsync(dataSource, searchRequestOptions), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
}

/// <summary>
Expand All @@ -47,9 +44,6 @@ public static partial class DataSourcesOperationsExtensions
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='dataSourceName'>
/// The name of the datasource to create or update.
/// </param>
/// <param name='dataSource'>
/// The definition of the datasource to create or update.
/// </param>
Expand All @@ -59,9 +53,9 @@ public static partial class DataSourcesOperationsExtensions
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
public static async Task<DataSource> CreateOrUpdateAsync( this IDataSourcesOperations operations, string dataSourceName, DataSource dataSource, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), CancellationToken cancellationToken = default(CancellationToken))
public static async Task<DataSource> CreateOrUpdateAsync( this IDataSourcesOperations operations, DataSource dataSource, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), CancellationToken cancellationToken = default(CancellationToken))
{
AzureOperationResponse<DataSource> result = await operations.CreateOrUpdateWithHttpMessagesAsync(dataSourceName, dataSource, searchRequestOptions, null, cancellationToken).ConfigureAwait(false);
AzureOperationResponse<DataSource> result = await operations.CreateOrUpdateWithHttpMessagesAsync(dataSource, searchRequestOptions, null, cancellationToken).ConfigureAwait(false);
return result.Body;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public partial interface IDataSourcesOperations
/// Creates a new Azure Search datasource or updates a datasource if
/// it already exists.
/// </summary>
/// <param name='dataSourceName'>
/// The name of the datasource to create or update.
/// </param>
/// <param name='dataSource'>
/// The definition of the datasource to create or update.
/// </param>
Expand All @@ -41,7 +38,7 @@ public partial interface IDataSourcesOperations
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
Task<AzureOperationResponse<DataSource>> CreateOrUpdateWithHttpMessagesAsync(string dataSourceName, DataSource dataSource, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
Task<AzureOperationResponse<DataSource>> CreateOrUpdateWithHttpMessagesAsync(DataSource dataSource, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Deletes an Azure Search datasource.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ public partial interface IIndexersOperations
/// Creates a new Azure Search indexer or updates an indexer if it
/// already exists.
/// </summary>
/// <param name='indexerName'>
/// The name of the indexer to create or update.
/// </param>
/// <param name='indexer'>
/// The definition of the indexer to create or update.
/// </param>
Expand All @@ -74,7 +71,7 @@ public partial interface IIndexersOperations
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
Task<AzureOperationResponse<Indexer>> CreateOrUpdateWithHttpMessagesAsync(string indexerName, Indexer indexer, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
Task<AzureOperationResponse<Indexer>> CreateOrUpdateWithHttpMessagesAsync(Indexer indexer, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Deletes an Azure Search indexer.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ public partial interface IIndexesOperations
/// Creates a new Azure Search index or updates an index if it already
/// exists.
/// </summary>
/// <param name='indexName'>
/// The definition of the index to create or update.
/// </param>
/// <param name='index'>
/// The definition of the index to create or update.
/// </param>
Expand All @@ -75,7 +72,7 @@ public partial interface IIndexesOperations
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
Task<AzureOperationResponse<Index>> CreateOrUpdateWithHttpMessagesAsync(string indexName, Index index, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
Task<AzureOperationResponse<Index>> CreateOrUpdateWithHttpMessagesAsync(Index index, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Deletes an Azure Search index and all the documents it contains.
/// </summary>
Expand Down
Loading

0 comments on commit dc4bc78

Please sign in to comment.