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

Add interfaces to OpenSearchClient's namespaces API specifications (fixes #423) #646

Merged
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### ⚠️ Breaking Changes ⚠️
- As part of [efforts to re-generate the client](https://github.com/opensearch-project/opensearch-net/pulls?q=is%3Apr+label%3Acode-gen+is%3Aclosed) from our [OpenAPI specification](https://github.com/opensearch-project/opensearch-api-specification) there have been numerous corrections and changes that resulted in breaking changes. Please refer to [UPGRADING.md](UPGRADING.md) for a complete list of these breakages and any relevant guidance for upgrading to this version of the client.

### Changed
- Changed the namespace client properties on `IOpenSearchClient` to return corresponding interfaces to better enable mocking & unit testing ([#646](https://github.com/opensearch-project/opensearch-net/pull/646))

### Added
- Added support for `MinScore` on `ScriptScoreQuery` ([#624](https://github.com/opensearch-project/opensearch-net/pull/624))
- Added support for the `Cat.PitSegments` and `Cat.SegmentReplication` APIs ([#527](https://github.com/opensearch-project/opensearch-net/pull/527))
Expand Down Expand Up @@ -184,4 +187,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
[1.6.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.5.0...v1.6.0
[1.5.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.4.0...v1.5.0
[1.4.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0
[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
#### General
- The `MasterTimeout` parameters on all actions have been marked `[Obsolete]`, please migrate to using `ClusterManagerTimeout` if your OpenSearch cluster is at least version `2.0.0` as `MasterTimeout` may be removed in future major versions.
- The `ExpandWildcards` enum is now attributed with `[Flags]` to allow combining of multiple values e.g. `ExpandWildcards.Open | ExpandWildcards.Closed` to match open and closed indexes but not hidden.
- The namespaced APIs exposed in `IOpenSearchClient` have each gained a corresponding interface and the types of the properties on `IOpenSearchClient` and `OpenSearchClient` have been changed from the concrete implementations to the matching interfaces. For example, `IOpenSearchClient.Cluster` was `ClusterNamespace` and now is `IClusterNamespace`.

#### Cat.Indices Action
- The `Health` parameter now accepts a new `HealthStatus` enum instead of the `Health` enum. The values are identical and are now unified with other parts of the API that utilize the same enum.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@using System
@using ApiGenerator.Domain.Code.HighLevel.Methods
@inherits ApiGenerator.CodeTemplatePage<FluentSyntaxView>
@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", Model.Syntax); }
@{ await IncludeAsync("HighLevel/Client/FluentSyntax/FluentMethodHeader.cshtml", Model);}@Raw(";")
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@using ApiGenerator
@using ApiGenerator.Domain.Code.HighLevel.Methods
@using HighLevelModel = ApiGenerator.Domain.Code.HighLevel.Methods.HighLevelModel
@inherits CodeTemplatePage<HighLevelModel>
@{
const string fluentPath = "HighLevel/Client/FluentSyntax/FluentInterfaceMethod.cshtml";
const string initializerPath = "HighLevel/Client/InitializerSyntax/InitializerInterfaceMethod.cshtml";
}
@{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.Fluent, async: false)); }
@{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.Fluent, async: true)); }
@if (Model.FluentBound != null)
{
<text>
@{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.FluentBound, async: false)); }
@{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.FluentBound, async: true)); }
</text>
}
@{ await IncludeAsync(initializerPath, new InitializerSyntaxView(Model.Initializer, async: false)); }
@{ await IncludeAsync(initializerPath, new InitializerSyntaxView(Model.Initializer, async: true)); }
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@inherits ApiGenerator.CodeTemplatePage<IEnumerable<HttpMethod>>
@{
const string ns = "Http";
var generic = Raw("<TResponse>");
}
@{ await IncludeGeneratorNotice(); }

Expand All @@ -15,16 +16,43 @@ namespace OpenSearch.Client.@(CsharpNames.ApiNamespace).@ns@(CsharpNames.ApiName

/// <summary>
/// @ns.SplitPascalCase() APIs.
/// <para>Use the <see cref="IOpenSearchClient.@ns"/> property on <see cref="IOpenSearchClient"/>.</para>
/// </summary>
public interface @(CsharpNames.HighLevelClientNamespacePrefix)I@(ns)@(CsharpNames.ClientNamespaceSuffix)
{
@{
foreach (var m in Model)
{
var selector = Raw($"Func<{m.Descriptor}, {m.IRequest}> selector = null");
<text>

TResponse @(m)@(generic)(string path, @(selector))
where TResponse : class, IOpenSearchResponse, new();

Task@(generic) @(m)Async@(generic)(string path, @(selector), CancellationToken ct = default)
where TResponse : class, IOpenSearchResponse, new();

TResponse @(m)@(generic)(@m.IRequest request)
where TResponse : class, IOpenSearchResponse, new();

Task@(generic) @(m)Async@(generic)(@m.IRequest request, CancellationToken ct = default)
where TResponse : class, IOpenSearchResponse, new();

</text>
}
}
}

/// <summary>
/// @ns.SplitPascalCase() implementation.
/// <para>Not intended to be instantiated directly. Use the <see cref="IOpenSearchClient.@ns"/> property
/// on <see cref="IOpenSearchClient"/>.
/// </para>
/// </summary>
public class @(CsharpNames.HighLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix) : NamespacedClientProxy
public class @(CsharpNames.HighLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix) : NamespacedClientProxy, @(CsharpNames.HighLevelClientNamespacePrefix)I@(ns)@(CsharpNames.ClientNamespaceSuffix)
{
internal @(CsharpNames.HighLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix)(OpenSearchClient client) : base(client) {}
@{
var generic = Raw("<TResponse>");

foreach (var m in Model)
{
var bodySelector = Raw(m.TakesBody ? "r => r.Body" : "_ => null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@ namespace OpenSearch.Client.@(CsharpNames.ApiNamespace).@ns@(CsharpNames.ApiName
{
/// <summary>
/// @ns.SplitPascalCase() APIs.
/// <para>Use the <see cref="IOpenSearchClient.@ns"/> property on <see cref="IOpenSearchClient"/>.</para>
/// </summary>
public partial interface I@(CsharpNames.HighLevelClientNamespacePrefix)@(ns)@(CsharpNames.ClientNamespaceSuffix)
{
@foreach(var e in endpoints)
{
await IncludeAsync("HighLevel/Client/Implementation/MethodInterface.cshtml", e.HighLevelModel);
}
}

/// <summary>
/// @ns.SplitPascalCase() implementation.
/// <para>Not intended to be instantiated directly. Use the <see cref="IOpenSearchClient.@ns"/> property
/// on <see cref="IOpenSearchClient"/>.
/// </para>
/// </summary>
public partial class @(CsharpNames.HighLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix) : NamespacedClientProxy
public partial class @(CsharpNames.HighLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix) : NamespacedClientProxy, I@(CsharpNames.HighLevelClientNamespacePrefix)@(ns)@(CsharpNames.ClientNamespaceSuffix)
{
internal @(CsharpNames.HighLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix)(OpenSearchClient client) : base(client) {}
@foreach(var e in endpoints)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace OpenSearch.Client
foreach (var ns in namespaces)
{
<text> /// <summary>@(ns.SplitPascalCase()) APIs</summary>
public @CsharpNames.HighLevelClientNamespacePrefix@(ns)@CsharpNames.ClientNamespaceSuffix @ns { get; private set; }
public @(CsharpNames.HighLevelClientNamespacePrefix)I@(ns)@(CsharpNames.ClientNamespaceSuffix) @ns { get; private set; }
</text>
}
<text>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@using System
@using ApiGenerator.Domain.Code.HighLevel.Methods
@inherits ApiGenerator.CodeTemplatePage<InitializerSyntaxView>
@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", Model.Syntax); }
@{ await IncludeAsync("HighLevel/Client/InitializerSyntax/InitializerMethodHeader.cshtml", Model); }@Raw(";")

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace OpenSearch.Client
foreach (var ns in namespaces)
{
<text> /// <summary>@ns.SplitPascalCase() APIs</summary>
@CsharpNames.HighLevelClientNamespacePrefix@(ns)@CsharpNames.ClientNamespaceSuffix @ns { get; }
@(CsharpNames.HighLevelClientNamespacePrefix)I@(ns)@(CsharpNames.ClientNamespaceSuffix) @ns { get; }
</text>
}

Expand Down
Loading
Loading